@cortexkit/pi-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 (30) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/compaction-marker-candidates-cd17s4ys.js +18 -0
  3. package/dist/compaction-marker-candidates-worker.js +24 -0
  4. package/dist/{embedding-backfill-scywarbn.js → embedding-backfill-r7n7dj50.js} +4 -4
  5. package/dist/{index-vakawmbc.js → index-2apf1afe.js} +5 -20
  6. package/dist/index-399p688g.js +19 -0
  7. package/dist/{index-0rasmwm8.js → index-57njcjax.js} +6 -6
  8. package/dist/{index-fqb1bddn.js → index-590pwxvr.js} +14 -3
  9. package/dist/{index-kjd1fj55.js → index-9n88gmpf.js} +45 -7
  10. package/dist/{index-b2anqqad.js → index-9ygacw4e.js} +101 -31
  11. package/dist/{index-p5zesr4e.js → index-a1jmtv6r.js} +3 -3
  12. package/dist/{index-r874cgmv.js → index-g1csz24n.js} +1 -1
  13. package/dist/index-g3600tpw.js +212 -0
  14. package/dist/{index-g7hndmqm.js → index-g7984a4r.js} +4 -2
  15. package/dist/{index-28vnkyy7.js → index-gxk9hcd1.js} +2945 -2862
  16. package/dist/{index-rd53pk0h.js → index-mzn6t38b.js} +1 -1
  17. package/dist/{index-rdtgp48t.js → index-xvm5cdyn.js} +1 -1
  18. package/dist/index.js +34750 -33347
  19. package/dist/message-index-2damq13v.js +56 -0
  20. package/dist/{message-index-bounded-110sb4fm.js → message-index-bounded-0qa5eacp.js} +16 -15
  21. package/dist/migration-worker.js +3 -3
  22. package/dist/{project-embedding-registry-64t0mw8y.js → project-embedding-registry-fzc4eb29.js} +3 -3
  23. package/dist/raw-ordinal-warmup-worker.js +22 -5
  24. package/dist/{read-session-chunk-rvmc25n5.js → read-session-chunk-q05ztqg5.js} +4 -3
  25. package/dist/{read-session-raw-npx3920c.js → read-session-raw-527m0yxx.js} +2 -1
  26. package/dist/{search-7z3w8pmz.js → search-5m0jjf29.js} +11 -10
  27. package/dist/{storage-tags-kjnsqbdb.js → storage-tags-1b2w0wst.js} +1 -1
  28. package/dist/subagent-entry.js +13 -11
  29. package/package.json +2 -2
  30. /package/dist/{index-2pp04pmg.js → index-69vas84q.js} +0 -0
@@ -45,7 +45,7 @@ import {
45
45
  hasPendingMigrations,
46
46
  getMainThreadMigrationBodyCount,
47
47
  runMigrations
48
- } from "./index-rd53pk0h.js";
48
+ } from "./index-mzn6t38b.js";
49
49
  import {
50
50
  closeQuietly,
51
51
  ensureColumn,
@@ -61,7 +61,7 @@ import {
61
61
  import {
62
62
  bootQuietRemainingMs,
63
63
  scheduleAfterBootQuiet
64
- } from "./index-g7hndmqm.js";
64
+ } from "./index-g7984a4r.js";
65
65
  import {
66
66
  logSlowWriteTransaction
67
67
  } from "./index-0vrkp1jq.js";
@@ -1287,7 +1287,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
1287
1287
  startMessageFtsRowidMapBackfill(db).then(async () => {
1288
1288
  if (!readsOpenCodeStore)
1289
1289
  return;
1290
- const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-rvmc25n5.js"));
1290
+ const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-q05ztqg5.js"));
1291
1291
  const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-05ppypkz.js"));
1292
1292
  await startMessageTimeBackfill(db, Object.assign(readRawSessionMessages, {
1293
1293
  readPage: readRawSessionMessagePage
@@ -8,7 +8,7 @@ import {
8
8
  import {
9
9
  isUserHomeDirectory,
10
10
  setBootQuietPeriodForTests
11
- } from "./index-g7hndmqm.js";
11
+ } from "./index-g7984a4r.js";
12
12
  import {
13
13
  withSqliteBackgroundWriter2,
14
14
  withoutSqliteTransformPass2,
@@ -0,0 +1,212 @@
1
+ import {
2
+ registerExitAbort
3
+ } from "./index-399p688g.js";
4
+ import {
5
+ log2
6
+ } from "./index-x3dcnxh0.js";
7
+ import {
8
+ getSqliteDatabasePath2
9
+ } from "./index-3cgbv47m.js";
10
+
11
+ // ../plugin/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 };
@@ -183,10 +183,10 @@ function classifyGitError(error, rawDirectory) {
183
183
  }
184
184
  return new ProjectIdentityError("unknown", rawDirectory, "git rev-list failed while resolving project identity", asError(error));
185
185
  }
186
- function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectPermission) {
186
+ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectPermission, options = {}) {
187
187
  assertProjectAllowed(directory, allowHomeProject);
188
188
  const canonical = path2.resolve(directory);
189
- const cached = identityCache.get(canonical);
189
+ const cached = options.cache === false ? undefined : identityCache.get(canonical);
190
190
  if (cached !== undefined) {
191
191
  return cached;
192
192
  }
@@ -217,6 +217,8 @@ function resolveProjectIdentityStrict(directory, allowHomeProject = homeProjectP
217
217
  throw new ProjectIdentityError("unknown", directory, "git rev-list returned no valid root commit hash");
218
218
  }
219
219
  const identity = `git:${rootCommit}`;
220
+ if (options.cache === false)
221
+ return identity;
220
222
  identityCache.set(canonical, identity);
221
223
  lastKnownGitIdentityCache.set(canonical, identity);
222
224
  rememberGitIdentity(canonical, identity);