@cortexkit/opencode-magic-context 0.49.2 → 0.49.4

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 (120) hide show
  1. package/README.md +2 -38
  2. package/dist/auto-search-worker.js +3 -3
  3. package/dist/compaction-marker-candidates-dd638ypn.js +19 -0
  4. package/dist/compaction-marker-candidates-worker.js +24 -0
  5. package/dist/{conflict-warning-hook-asnt6hfc.js → conflict-warning-hook-ae8nmv7c.js} +5 -4
  6. package/dist/{context-tfyhtdcs.js → context-yg023c5r.js} +64 -30
  7. package/dist/{embedding-backfill-wyc3ykyf.js → embedding-backfill-aj488s8x.js} +5 -5
  8. package/dist/features/magic-context/compaction-marker-candidates-worker.d.ts +2 -0
  9. package/dist/features/magic-context/compaction-marker-candidates-worker.d.ts.map +1 -0
  10. package/dist/features/magic-context/compaction-marker-candidates.d.ts +47 -0
  11. package/dist/features/magic-context/compaction-marker-candidates.d.ts.map +1 -0
  12. package/dist/features/magic-context/compaction-marker.d.ts +12 -0
  13. package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
  14. package/dist/features/magic-context/historian-failure-reason.d.ts +7 -0
  15. package/dist/features/magic-context/historian-failure-reason.d.ts.map +1 -0
  16. package/dist/features/magic-context/memory/project-identity.d.ts +5 -1
  17. package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
  18. package/dist/features/magic-context/message-index-async.d.ts +3 -0
  19. package/dist/features/magic-context/message-index-async.d.ts.map +1 -1
  20. package/dist/features/magic-context/message-index.d.ts.map +1 -1
  21. package/dist/features/magic-context/storage-clone.d.ts +2 -0
  22. package/dist/features/magic-context/storage-clone.d.ts.map +1 -1
  23. package/dist/features/magic-context/storage-historian-runs.d.ts.map +1 -1
  24. package/dist/features/magic-context/storage-tags.d.ts +1 -1
  25. package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
  26. package/dist/hooks/magic-context/compaction-marker-manager.d.ts +3 -0
  27. package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
  28. package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
  29. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  30. package/dist/hooks/magic-context/compartment-runner-types.d.ts +3 -0
  31. package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
  32. package/dist/hooks/magic-context/history-boundary-repair.d.ts +11 -2
  33. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  34. package/dist/hooks/magic-context/protected-tail-boundary.d.ts +4 -3
  35. package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
  36. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts +10 -0
  37. package/dist/hooks/magic-context/raw-ordinal-warmup.d.ts.map +1 -1
  38. package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
  39. package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
  40. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  41. package/dist/{index-p0n5ryq8.js → index-2mqps3c1.js} +19 -9
  42. package/dist/{index-sfhndpcb.js → index-3wckxwfp.js} +39 -39
  43. package/dist/{index-gzky5rva.js → index-41gqa557.js} +4 -2
  44. package/dist/{index-r2zcs71c.js → index-7ndnvw7a.js} +1 -1
  45. package/dist/{index-sv0bb7vg.js → index-7zg9dvx0.js} +35 -4
  46. package/dist/{index-xgrwmj82.js → index-bhk710rw.js} +1 -1
  47. package/dist/{index-fg00p1cg.js → index-c0b01zrc.js} +2 -2
  48. package/dist/{index-eypn4ba6.js → index-dd18gej8.js} +3 -3
  49. package/dist/{index-rafsaxac.js → index-fjtgekd4.js} +2 -2
  50. package/dist/{index-fdtkt5r1.js → index-fst3t0d9.js} +9 -9
  51. package/dist/{index-h5zfkjyk.js → index-jpm52v9x.js} +6 -24
  52. package/dist/{index-s7fc0fkn.js → index-m4p77myp.js} +1 -1
  53. package/dist/{index-6tfxmc4n.js → index-p2hs3rps.js} +4 -4
  54. package/dist/{index-0pjvpfkf.js → index-qvr78ej6.js} +1 -1
  55. package/dist/index-v0p37hm2.js +22 -0
  56. package/dist/{index-zfzdpeq2.js → index-v4bqjy56.js} +4662 -4545
  57. package/dist/{index-xnanvj3w.js → index-x3y1np1h.js} +604 -576
  58. package/dist/{index-att4bfan.js → index-xfbfrngb.js} +1 -1
  59. package/dist/{index-nydv6g8r.js → index-yqps2zsv.js} +44 -6
  60. package/dist/index-yxawqmdd.js +212 -0
  61. package/dist/{index-zg8yq4ya.js → index-znzgze2v.js} +3 -3
  62. package/dist/index.js +38 -35
  63. package/dist/{message-index-bounded-hqktkhdy.js → message-index-bounded-pv6ct15d.js} +18 -17
  64. package/dist/message-index-jqa7qd0s.js +60 -0
  65. package/dist/migration-worker.js +3 -3
  66. package/dist/{project-embedding-registry-0gv3h6y8.js → project-embedding-registry-fcmszatg.js} +4 -4
  67. package/dist/raw-ordinal-warmup-worker.js +22 -5
  68. package/dist/{read-session-chunk-5mh0bh8y.js → read-session-chunk-cwgjwjd0.js} +7 -6
  69. package/dist/{read-session-raw-8sjbc9h0.js → read-session-raw-z38cn0as.js} +2 -1
  70. package/dist/{recomp-orchestrator-kpkhkjhq.js → recomp-orchestrator-xw9wt5bm.js} +19 -17
  71. package/dist/{search-p9w39qv4.js → search-v1t47s2q.js} +14 -13
  72. package/dist/{send-session-notification-xffh3bbe.js → send-session-notification-yp9m5g4p.js} +4 -3
  73. package/dist/shared/tag-owner-id.d.ts +1 -0
  74. package/dist/shared/tag-owner-id.d.ts.map +1 -1
  75. package/dist/{storage-tags-k0pda32s.js → storage-tags-0ssbmzg9.js} +2 -2
  76. package/dist/{transform-postprocess-phase-481j5a7z.js → transform-postprocess-phase-ttra554y.js} +19 -17
  77. package/dist/v2/auto-search-worker.js +3 -3
  78. package/dist/v2/compaction-marker-candidates-1s21e2fz.js +18 -0
  79. package/dist/v2/compaction-marker-candidates-worker.js +24 -0
  80. package/dist/v2/{context-gsdtha5v.js → context-6en6a8ar.js} +121 -50
  81. package/dist/v2/{embedding-backfill-dbvjbcmm.js → embedding-backfill-9hbkfvnz.js} +5 -5
  82. package/dist/v2/{message-index-bounded-p6v0n8qh.js → message-index-bounded-c0810p5w.js} +17 -16
  83. package/dist/v2/message-index-h8ssgq3q.js +59 -0
  84. package/dist/v2/migration-worker.js +3 -3
  85. package/dist/v2/{project-embedding-registry-nyq7z8y6.js → project-embedding-registry-42th7k1z.js} +4 -4
  86. package/dist/v2/raw-ordinal-warmup-worker.js +22 -5
  87. package/dist/v2/{read-session-chunk-fhyfe4qa.js → read-session-chunk-n86v9xfg.js} +6 -5
  88. package/dist/v2/{read-session-raw-j8dvp7f4.js → read-session-raw-3b3ehga4.js} +2 -1
  89. package/dist/v2/{recomp-orchestrator-5xy7w136.js → recomp-orchestrator-krvsbnds.js} +16 -14
  90. package/dist/v2/{search-j7bakcwa.js → search-048v8y02.js} +13 -12
  91. package/dist/v2/{send-session-notification-f6v698r5.js → send-session-notification-a4h2azxa.js} +2 -1
  92. package/dist/v2/{server-bgzy0phk.js → server-3bc6k4k4.js} +62 -33
  93. package/dist/v2/{server-7h861yms.js → server-3dqjhchy.js} +5 -18
  94. package/dist/v2/{server-c7n2ftng.js → server-4n2tknpc.js} +34 -3
  95. package/dist/v2/server-51779zs2.js +19 -0
  96. package/dist/v2/{server-kh958yj8.js → server-5zrpr764.js} +1 -1
  97. package/dist/v2/{server-6tcrjfw8.js → server-8pqnnmf9.js} +1 -1
  98. package/dist/v2/server-9290a1mb.js +212 -0
  99. package/dist/v2/{server-7vkj6zhb.js → server-9a6v0wth.js} +3 -3
  100. package/dist/v2/{server-1fszbabv.js → server-cjz51jm2.js} +2 -2
  101. package/dist/v2/{server-7spkq1y6.js → server-e2v4m8xe.js} +4084 -3967
  102. package/dist/v2/{server-mqvtz7wz.js → server-hetyb88z.js} +9 -9
  103. package/dist/v2/{server-4c7jt8gq.js → server-pcygfdbs.js} +44 -6
  104. package/dist/v2/{server-8xmq9h3f.js → server-q6j5dasr.js} +4 -2
  105. package/dist/v2/{server-zbxjj2mz.js → server-rygvffsf.js} +2 -2
  106. package/dist/v2/server.js +4 -4
  107. package/dist/v2/{storage-tags-5yxrvkaf.js → storage-tags-3a4cavqb.js} +2 -2
  108. package/dist/v2/{wrapup-orchestrator-yem5422s.js → wrapup-orchestrator-r2v7kgy3.js} +14 -12
  109. package/dist/{wrapup-orchestrator-xvrr27ws.js → wrapup-orchestrator-z7agncp8.js} +20 -18
  110. package/package.json +3 -3
  111. package/src/config/latch-permanence-guard.test.ts +6 -1
  112. package/src/shared/sqlite-writer-diagnostics.test.ts +21 -10
  113. package/src/shared/tag-owner-id.ts +13 -0
  114. package/src/shared/tag-transcript.test.ts +6 -1
  115. package/src/shared/tag-transcript.ts +2 -1
  116. package/src/shared/windows-hidden-spawns.test.ts +60 -4
  117. /package/dist/{index-69vas84q.js → index-e6xnpach.js} +0 -0
  118. /package/dist/{index-p1hnwfd8.js → index-gcdb3rqw.js} +0 -0
  119. /package/dist/v2/{index-69vas84q.js → index-e6xnpach.js} +0 -0
  120. /package/dist/v2/{server-s2st631p.js → server-8wcf79fe.js} +0 -0
@@ -0,0 +1,212 @@
1
+ import {
2
+ registerExitAbort
3
+ } from "./server-51779zs2.js";
4
+ import {
5
+ log2
6
+ } from "./server-t4k4qexw.js";
7
+ import {
8
+ getSqliteDatabasePath2
9
+ } from "./server-kb9nn0a0.js";
10
+
11
+ // src/features/magic-context/compaction-marker-candidates.ts
12
+ import { existsSync, realpathSync } from "node:fs";
13
+ import { fileURLToPath } from "node:url";
14
+ import { Worker } from "node:worker_threads";
15
+ var candidates = new WeakMap;
16
+ var pending = new WeakMap;
17
+ var workers = new Set;
18
+ var missingWorkerWarnings = new Set;
19
+ var ownWriteRevisions = new Map;
20
+ var exitRegistered = false;
21
+ function reportWorkerUnavailable(entry, detail) {
22
+ if (missingWorkerWarnings.has(entry.href))
23
+ return;
24
+ missingWorkerWarnings.add(entry.href);
25
+ const path = entry.protocol === "file:" ? fileURLToPath(entry) : entry.href;
26
+ log2(`[magic-context] [ERROR] compaction-marker: candidate worker unavailable ${path}: ${detail}; marker unchanged, advancement deferred`);
27
+ }
28
+ var MARKER_CERTIFICATION_SQL = `SELECT
29
+ (SELECT rowid FROM message WHERE id = ?) AS previousRowid,
30
+ (SELECT rowid FROM message ORDER BY rowid DESC LIMIT 1) AS newestRowid,
31
+ (SELECT id FROM message ORDER BY rowid DESC LIMIT 1) AS newestId,
32
+ EXISTS(SELECT 1 FROM message
33
+ WHERE rowid > ? AND +session_id = ? AND json_valid(data)
34
+ AND COALESCE(json_extract(data, '$.summary'), 0) = 1) AS newSummary`;
35
+ function isMarkerCandidateBasisCurrent2(db, basis) {
36
+ if (basis.connection !== db || ownWriteRevisions.get(basis.revisionKey) !== basis.ownWriteRevision)
37
+ return false;
38
+ try {
39
+ const current = db.prepare(MARKER_CERTIFICATION_SQL).get(basis.frontier?.id ?? null, basis.frontier?.rowid ?? 0, basis.sessionId);
40
+ if (current.newSummary || basis.frontier && (current.previousRowid !== basis.frontier.rowid || current.newestRowid === null || current.newestRowid < basis.frontier.rowid))
41
+ return false;
42
+ if (current.newestRowid !== null && (!Number.isSafeInteger(current.newestRowid) || current.newestId === null))
43
+ return false;
44
+ basis.frontier = current.newestRowid === null || current.newestId === null ? null : { rowid: current.newestRowid, id: current.newestId };
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ function invalidateMarkerCandidateBasis2(db, sessionId) {
51
+ candidates.get(db)?.delete(sessionId);
52
+ const path = getSqliteDatabasePath2(db);
53
+ if (!path)
54
+ return;
55
+ const key = `${realpathSync(path)}\x00${sessionId}`;
56
+ const revision = ownWriteRevisions.get(key);
57
+ if (revision !== undefined)
58
+ ownWriteRevisions.set(key, revision + 1);
59
+ }
60
+ function readMarkerCandidateBasis2(db, sessionId) {
61
+ const basis = candidates.get(db)?.get(sessionId);
62
+ if (basis && isMarkerCandidateBasisCurrent2(db, basis))
63
+ return basis;
64
+ candidates.get(db)?.delete(sessionId);
65
+ return;
66
+ }
67
+ function prepareMarkerCandidateBasis2(db, sessionId, options = {}) {
68
+ if (readMarkerCandidateBasis2(db, sessionId))
69
+ return Promise.resolve(true);
70
+ const path = getSqliteDatabasePath2(db);
71
+ if (!path || db.inTransaction)
72
+ return Promise.resolve(false);
73
+ const active = pending.get(db) ?? new Map;
74
+ const existing = active.get(sessionId);
75
+ if (existing)
76
+ return existing;
77
+ const revisionKey = `${realpathSync(path)}\x00${sessionId}`;
78
+ const ownWriteRevision = ownWriteRevisions.get(revisionKey) ?? 0;
79
+ ownWriteRevisions.set(revisionKey, ownWriteRevision);
80
+ const entry = options.entry ?? markerWorkerEntry();
81
+ if (entry.protocol === "file:" && !existsSync(fileURLToPath(entry))) {
82
+ reportWorkerUnavailable(entry, "file missing");
83
+ return Promise.resolve(false);
84
+ }
85
+ const preparation = runCandidateWorker(path, sessionId, options).then((snapshot) => {
86
+ if (!snapshot)
87
+ return false;
88
+ const basis = {
89
+ ...snapshot,
90
+ connection: db,
91
+ sessionId,
92
+ revisionKey,
93
+ ownWriteRevision
94
+ };
95
+ if (!isMarkerCandidateBasisCurrent2(db, basis)) {
96
+ candidates.get(db)?.delete(sessionId);
97
+ log2(`[magic-context] compaction-marker: deferred candidate preparation for ${sessionId}: summary set or frontier changed during discovery; marker unchanged`);
98
+ return false;
99
+ }
100
+ const sessions = candidates.get(db) ?? new Map;
101
+ sessions.set(sessionId, basis);
102
+ candidates.set(db, sessions);
103
+ return true;
104
+ }).finally(() => {
105
+ if (active.get(sessionId) === preparation)
106
+ active.delete(sessionId);
107
+ });
108
+ active.set(sessionId, preparation);
109
+ pending.set(db, active);
110
+ return preparation;
111
+ }
112
+ function markerWorkerEntry() {
113
+ return new URL(new URL(import.meta.url).pathname.endsWith(".ts") ? "./compaction-marker-candidates-worker.ts" : "./compaction-marker-candidates-worker.js", import.meta.url);
114
+ }
115
+ function runCandidateWorker(path, sessionId, options) {
116
+ if (!exitRegistered) {
117
+ exitRegistered = true;
118
+ const controller = new AbortController;
119
+ controller.signal.addEventListener("abort", () => {
120
+ for (const worker of workers) {
121
+ worker.terminate();
122
+ worker.unref();
123
+ }
124
+ }, { once: true });
125
+ registerExitAbort(controller);
126
+ }
127
+ return new Promise((resolve) => {
128
+ const entry = options.entry ?? markerWorkerEntry();
129
+ let worker;
130
+ let timer;
131
+ let done = false;
132
+ const finish = (snapshot) => {
133
+ if (done)
134
+ return;
135
+ done = true;
136
+ clearTimeout(timer);
137
+ if (!worker) {
138
+ resolve(snapshot);
139
+ return;
140
+ }
141
+ workers.delete(worker);
142
+ const stopped = worker.terminate();
143
+ worker.unref();
144
+ stopped.then(() => resolve(snapshot), () => resolve(snapshot));
145
+ };
146
+ const deadline = (ms) => {
147
+ clearTimeout(timer);
148
+ timer = setTimeout(() => {
149
+ reportWorkerUnavailable(entry, "worker deadline exceeded");
150
+ finish();
151
+ }, ms);
152
+ timer.unref?.();
153
+ };
154
+ try {
155
+ worker = new Worker(entry, { workerData: { path, sessionId } });
156
+ workers.add(worker);
157
+ worker.unref();
158
+ deadline(options.acceptMs ?? 2000);
159
+ worker.on("message", (reply) => {
160
+ if (reply.kind === "accepted")
161
+ deadline(options.resultMs ?? 600000);
162
+ else if (reply.kind === "candidates")
163
+ finish(reply.snapshot);
164
+ else {
165
+ reportWorkerUnavailable(entry, reply.error);
166
+ finish();
167
+ }
168
+ });
169
+ worker.on("error", (error) => {
170
+ reportWorkerUnavailable(entry, error.message);
171
+ finish();
172
+ });
173
+ worker.on("exit", (code) => {
174
+ if (!done)
175
+ reportWorkerUnavailable(entry, `worker exited before replying (${code})`);
176
+ finish();
177
+ });
178
+ } catch (error) {
179
+ reportWorkerUnavailable(entry, error instanceof Error ? error.message : String(error));
180
+ finish();
181
+ }
182
+ });
183
+ }
184
+ function scanMarkerSummaryCandidates(db, sessionId) {
185
+ const ownsSnapshot = !db.inTransaction;
186
+ if (ownsSnapshot)
187
+ db.exec("BEGIN");
188
+ try {
189
+ return db.prepare(`SELECT id FROM message WHERE session_id=? AND
190
+ CASE WHEN json_valid(data) THEN COALESCE(json_extract(data,'$.summary'),0) ELSE 0 END=1`).all(sessionId).map((row) => row.id);
191
+ } finally {
192
+ if (ownsSnapshot)
193
+ db.exec("ROLLBACK");
194
+ }
195
+ }
196
+ function scanMarkerCandidateSnapshot2(db, sessionId) {
197
+ const ownsSnapshot = !db.inTransaction;
198
+ if (ownsSnapshot)
199
+ db.exec("BEGIN");
200
+ try {
201
+ const ids = scanMarkerSummaryCandidates(db, sessionId);
202
+ const frontier = db.prepare("SELECT rowid,id FROM message ORDER BY rowid DESC LIMIT 1").get() ?? null;
203
+ if (frontier && !Number.isSafeInteger(frontier.rowid))
204
+ throw new Error("marker frontier rowid is not a safe integer");
205
+ return { ids, frontier };
206
+ } finally {
207
+ if (ownsSnapshot)
208
+ db.exec("ROLLBACK");
209
+ }
210
+ }
211
+
212
+ export { isMarkerCandidateBasisCurrent2, invalidateMarkerCandidateBasis2, readMarkerCandidateBasis2, prepareMarkerCandidateBasis2, scanMarkerCandidateSnapshot2 };
@@ -45,7 +45,7 @@ import {
45
45
  hasPendingMigrations,
46
46
  getMainThreadMigrationBodyCount,
47
47
  runMigrations
48
- } from "./server-6tcrjfw8.js";
48
+ } from "./server-8pqnnmf9.js";
49
49
  import {
50
50
  ensureColumn,
51
51
  installV95PerfSchema,
@@ -58,7 +58,7 @@ import {
58
58
  import {
59
59
  bootQuietRemainingMs,
60
60
  scheduleAfterBootQuiet
61
- } from "./server-8xmq9h3f.js";
61
+ } from "./server-q6j5dasr.js";
62
62
  import {
63
63
  setDatabase,
64
64
  loadToolDefinitionMeasurements
@@ -1198,7 +1198,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1198
1198
  startMessageFtsRowidMapBackfill(db).then(async () => {
1199
1199
  if (!readsOpenCodeStore)
1200
1200
  return;
1201
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-fhyfe4qa.js"));
1201
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-n86v9xfg.js"));
1202
1202
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-cje68egj.js"));
1203
1203
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
1204
1204
  readPage: readRawSessionMessagePage
@@ -40,7 +40,7 @@ import {
40
40
  loadUnembeddedSessionChunkCandidatesPolite,
41
41
  countSessionCompartmentEmbedCoverage,
42
42
  countUnembeddedSessionCompartmentsPolite
43
- } from "./server-s2st631p.js";
43
+ } from "./server-8wcf79fe.js";
44
44
  import {
45
45
  saveEmbeddingIfHashMatches,
46
46
  getMemoryEmbedCoverage,
@@ -56,7 +56,7 @@ import {
56
56
  import {
57
57
  isUserHomeDirectory,
58
58
  setBootQuietPeriodForTests
59
- } from "./server-8xmq9h3f.js";
59
+ } from "./server-q6j5dasr.js";
60
60
  import {
61
61
  logSlowWriteTransaction
62
62
  } from "./server-3t0q2cqx.js";