@cortexkit/pi-magic-context 0.49.12 → 0.49.14
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.
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +87 -0
- package/dist/{embedding-backfill-14tqcfrn.js → embedding-backfill-7kj16fh9.js} +5 -4
- package/dist/embedding-worker.js +1 -1
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/{index-gykw2zhn.js → index-0awvkeb5.js} +5 -5
- package/dist/index-1mrvw9en.js +225 -0
- package/dist/index-1vw4f2pe.js +907 -0
- package/dist/{index-zapgkmp7.js → index-65kty5te.js} +37 -48
- package/dist/{index-53xdqb3d.js → index-75ah9413.js} +1 -1
- package/dist/{index-af9nb5db.js → index-7qc73yk5.js} +60 -3
- package/dist/{index-xpsht877.js → index-7wagp5jp.js} +2 -2
- package/dist/{index-6hex51s9.js → index-a4pk5yv9.js} +2 -2
- package/dist/{index-z5ftst3e.js → index-ccsscaap.js} +3 -3
- package/dist/{index-ed9d2ded.js → index-j0n09wtp.js} +4 -1
- package/dist/{index-f6e8jsrh.js → index-nwbhe6qv.js} +188 -241
- package/dist/{index-xmdkde4v.js → index-y29y2j2w.js} +12 -1
- package/dist/index.js +2398 -2068
- package/dist/{message-index-bounded-ws37m1nt.js → message-index-bounded-z4d3x9ty.js} +4 -4
- package/dist/{message-index-dfs6k35a.js → message-index-dw4z9efj.js} +4 -4
- package/dist/migration-worker.js +2 -2
- package/dist/{project-embedding-registry-ymvne11v.js → project-embedding-registry-52zwmtbn.js} +4 -3
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-83864b37.js → read-session-chunk-0fsgg2k1.js} +2 -2
- package/dist/{search-85e21wb8.js → search-ddbz6v60.js} +12 -11
- package/dist/{storage-tags-zmf30zqp.js → storage-tags-3kb5tvgg.js} +3 -1
- package/dist/subagent-entry.js +12 -11
- package/dist/tag-snapshot-worker-pi.js +235 -0
- package/package.json +3 -3
- /package/dist/{index-j24916mq.js → index-9jvktm7k.js} +0 -0
- /package/dist/{index-69vas84q.js → index-b7p25tm0.js} +0 -0
- /package/dist/{index-3cnarwf8.js → index-bet4sd3e.js} +0 -0
|
@@ -18,11 +18,11 @@ var [
|
|
|
18
18
|
{ Database, registerSqliteDiagnosticSink },
|
|
19
19
|
{ log }
|
|
20
20
|
] = await Promise.all([
|
|
21
|
-
import("./embedding-backfill-
|
|
21
|
+
import("./embedding-backfill-7kj16fh9.js"),
|
|
22
22
|
import("./embedding-cache-7rp4gqzr.js"),
|
|
23
23
|
import("./storage-memory-axnsk5t1.js"),
|
|
24
|
-
import("./project-embedding-registry-
|
|
25
|
-
import("./search-
|
|
24
|
+
import("./project-embedding-registry-52zwmtbn.js"),
|
|
25
|
+
import("./search-ddbz6v60.js"),
|
|
26
26
|
import("./embedding-activity-ew6dshfd.js"),
|
|
27
27
|
import("./harness-9872e0ym.js"),
|
|
28
28
|
import("./sqlite-adjpy399.js"),
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setHarness2
|
|
3
|
+
} from "./index-0h2mkab2.js";
|
|
4
|
+
import {
|
|
5
|
+
Database2
|
|
6
|
+
} from "./index-asrxgdt4.js";
|
|
7
|
+
import {
|
|
8
|
+
configureContextDatabasePragmas2
|
|
9
|
+
} from "./index-fapenpch.js";
|
|
10
|
+
import"./index-g4jf772p.js";
|
|
11
|
+
import"./index-7bqrfyny.js";
|
|
12
|
+
import"./index-6dz2ed1v.js";
|
|
13
|
+
import"./index-djxc8w8c.js";
|
|
14
|
+
import {
|
|
15
|
+
replaceCompartmentChunkEmbeddings,
|
|
16
|
+
recordChunkEmbedBackoff,
|
|
17
|
+
loadUnembeddedSessionChunkCandidates,
|
|
18
|
+
countUnembeddedSessionCompartments
|
|
19
|
+
} from "./index-7qc73yk5.js";
|
|
20
|
+
import {
|
|
21
|
+
recordSessionProjectIdentity,
|
|
22
|
+
acquireGitSweepLease,
|
|
23
|
+
renewGitSweepLease,
|
|
24
|
+
releaseGitSweepLease
|
|
25
|
+
} from "./index-1mrvw9en.js";
|
|
26
|
+
import"./index-6ex901g3.js";
|
|
27
|
+
import"./index-apgwdby5.js";
|
|
28
|
+
import {
|
|
29
|
+
LATEST_SUPPORTED_VERSION,
|
|
30
|
+
enforceSchemaFence
|
|
31
|
+
} from "./index-ccsscaap.js";
|
|
32
|
+
import"./index-bet4sd3e.js";
|
|
33
|
+
import"./index-jrap43gc.js";
|
|
34
|
+
import"./index-135e8hvg.js";
|
|
35
|
+
import"./index-8976mezv.js";
|
|
36
|
+
import"./index-d4dt19md.js";
|
|
37
|
+
|
|
38
|
+
// ../plugin/src/features/magic-context/chunk-embedding-write-worker.ts
|
|
39
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
40
|
+
var port = parentPort;
|
|
41
|
+
if (!port)
|
|
42
|
+
throw new Error("chunk embedding writer requires a parent port");
|
|
43
|
+
setHarness2(workerData.harness);
|
|
44
|
+
var db = new Database2(workerData.path);
|
|
45
|
+
if (!enforceSchemaFence(db, workerData.path, LATEST_SUPPORTED_VERSION)) {
|
|
46
|
+
db.close();
|
|
47
|
+
throw new Error("chunk embedding writer rejected an unsupported store schema");
|
|
48
|
+
}
|
|
49
|
+
var timeout = Math.max(0, Math.floor(workerData.timeout));
|
|
50
|
+
db.exec(`PRAGMA busy_timeout=${timeout}; PRAGMA foreign_keys=ON`);
|
|
51
|
+
configureContextDatabasePragmas2(db);
|
|
52
|
+
port.on("message", (input) => {
|
|
53
|
+
try {
|
|
54
|
+
let value;
|
|
55
|
+
switch (input.kind) {
|
|
56
|
+
case "replace":
|
|
57
|
+
replaceCompartmentChunkEmbeddings(db, input.rows, input.sourceKey);
|
|
58
|
+
break;
|
|
59
|
+
case "project":
|
|
60
|
+
recordSessionProjectIdentity(db, input.session, input.project);
|
|
61
|
+
break;
|
|
62
|
+
case "count":
|
|
63
|
+
value = countUnembeddedSessionCompartments(db, input.project, input.session, input.model, input.tokens);
|
|
64
|
+
break;
|
|
65
|
+
case "candidates":
|
|
66
|
+
value = loadUnembeddedSessionChunkCandidates(db, input.project, input.session, input.model, input.limit, input.excluded, input.tokens, true);
|
|
67
|
+
break;
|
|
68
|
+
case "backoff":
|
|
69
|
+
recordChunkEmbedBackoff(db, input.candidate, input.project, input.model);
|
|
70
|
+
break;
|
|
71
|
+
case "acquire":
|
|
72
|
+
value = acquireGitSweepLease(db, input.project, input.holder, {
|
|
73
|
+
ignoreCooldown: true
|
|
74
|
+
});
|
|
75
|
+
break;
|
|
76
|
+
case "renew":
|
|
77
|
+
value = renewGitSweepLease(db, input.project, input.holder);
|
|
78
|
+
break;
|
|
79
|
+
case "release":
|
|
80
|
+
releaseGitSweepLease(db, input.project, input.holder);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
port.postMessage({ value });
|
|
84
|
+
} catch (error) {
|
|
85
|
+
port.postMessage({ error: error instanceof Error ? error.message : String(error) });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureMemoryEmbeddings2
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
3
|
+
} from "./index-7wagp5jp.js";
|
|
4
|
+
import"./index-nwbhe6qv.js";
|
|
5
5
|
import"./index-9p40dgkm.js";
|
|
6
|
-
import"./index-af9nb5db.js";
|
|
7
6
|
import"./index-yhzhdp3m.js";
|
|
8
|
-
import"./index-
|
|
7
|
+
import"./index-1mrvw9en.js";
|
|
8
|
+
import"./index-7qc73yk5.js";
|
|
9
|
+
import"./index-9jvktm7k.js";
|
|
9
10
|
import"./index-6dz2ed1v.js";
|
|
10
11
|
import"./index-1k729e4f.js";
|
|
11
12
|
import"./index-6ex901g3.js";
|
package/dist/embedding-worker.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
resolveLocalEmbeddingWorkerRuntime,
|
|
13
13
|
getLocalEmbeddingNativeMemoryStats,
|
|
14
14
|
LocalEmbeddingProvider
|
|
15
|
-
} from "./index-
|
|
15
|
+
} from "./index-9jvktm7k.js";
|
|
16
16
|
import {
|
|
17
17
|
setStoragePrivatePermissionEnforcement
|
|
18
18
|
} from "./index-81nthk8j.js";
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
resolveStoredPathWorkspaceIdentity,
|
|
23
23
|
sourceNameForMemory,
|
|
24
24
|
managedAuthorityNoteRow
|
|
25
|
-
} from "./index-
|
|
25
|
+
} from "./index-bet4sd3e.js";
|
|
26
26
|
import {
|
|
27
27
|
isKnownAutocommit
|
|
28
28
|
} from "./index-jrap43gc.js";
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
import {
|
|
33
33
|
buildCanonicalChunkTextFromFts,
|
|
34
34
|
loadCompartmentChunkEmbeddingsForSearch
|
|
35
|
-
} from "./index-
|
|
35
|
+
} from "./index-7qc73yk5.js";
|
|
36
36
|
import {
|
|
37
37
|
recordEmbeddingMeasurement,
|
|
38
38
|
saveCommitEmbedding,
|
|
@@ -50,7 +50,7 @@ import {
|
|
|
50
50
|
getProjectEmbeddingSnapshot2,
|
|
51
51
|
embedTextForProject2,
|
|
52
52
|
embedItemsForProject2
|
|
53
|
-
} from "./index-
|
|
53
|
+
} from "./index-nwbhe6qv.js";
|
|
54
54
|
import {
|
|
55
55
|
saveEmbeddingIfHashMatches,
|
|
56
56
|
getProjectEmbeddings2
|
|
@@ -60,7 +60,7 @@ import {
|
|
|
60
60
|
isEmbeddingEnabled,
|
|
61
61
|
embedText,
|
|
62
62
|
ensureMemoryEmbeddings2
|
|
63
|
-
} from "./index-
|
|
63
|
+
} from "./index-7wagp5jp.js";
|
|
64
64
|
import {
|
|
65
65
|
getMemorySelectColumns2,
|
|
66
66
|
isMemoryRow2,
|
|
@@ -77,7 +77,7 @@ import {
|
|
|
77
77
|
} from "./index-hy44m6jc.js";
|
|
78
78
|
import {
|
|
79
79
|
getIndexedMessageCorpusSize2
|
|
80
|
-
} from "./index-
|
|
80
|
+
} from "./index-a4pk5yv9.js";
|
|
81
81
|
import {
|
|
82
82
|
computeNormalizedHash
|
|
83
83
|
} from "./index-9x1f96r8.js";
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getHarness2
|
|
3
|
+
} from "./index-0h2mkab2.js";
|
|
4
|
+
import {
|
|
5
|
+
isUserHomeDirectory
|
|
6
|
+
} from "./index-6ex901g3.js";
|
|
7
|
+
import {
|
|
8
|
+
logSlowWriteTransaction
|
|
9
|
+
} from "./index-d4dt19md.js";
|
|
10
|
+
|
|
11
|
+
// ../plugin/src/features/magic-context/session-project-storage.ts
|
|
12
|
+
var SESSION_CHUNK_REPAIR_BATCH_SIZE = 100;
|
|
13
|
+
var upsertSessionProjectStatements = new WeakMap;
|
|
14
|
+
var repairSessionChunkProjectStatements = new WeakMap;
|
|
15
|
+
var misScopedProjectChunkStatements = new WeakMap;
|
|
16
|
+
var MIS_SCOPED_PROJECT_CHUNK_IDS_SQL = `
|
|
17
|
+
SELECT e.id FROM compartment_chunk_embeddings e
|
|
18
|
+
JOIN session_projects sp ON sp.session_id = e.session_id AND sp.harness = e.harness
|
|
19
|
+
WHERE e.project_path = ? AND sp.project_path <> e.project_path
|
|
20
|
+
UNION ALL
|
|
21
|
+
SELECT e.id FROM session_projects sp
|
|
22
|
+
JOIN compartment_chunk_embeddings e ON e.session_id = sp.session_id
|
|
23
|
+
WHERE sp.project_path = ? AND e.harness = sp.harness AND e.project_path <> sp.project_path`;
|
|
24
|
+
function getUpsertSessionProjectStatement(db) {
|
|
25
|
+
let stmt = upsertSessionProjectStatements.get(db);
|
|
26
|
+
if (!stmt) {
|
|
27
|
+
stmt = db.prepare(`INSERT INTO session_projects (session_id, harness, project_path, updated_at)
|
|
28
|
+
VALUES (?, ?, ?, ?)
|
|
29
|
+
ON CONFLICT(session_id, harness) DO UPDATE SET
|
|
30
|
+
project_path = excluded.project_path,
|
|
31
|
+
updated_at = excluded.updated_at
|
|
32
|
+
WHERE session_projects.project_path <> excluded.project_path`);
|
|
33
|
+
upsertSessionProjectStatements.set(db, stmt);
|
|
34
|
+
}
|
|
35
|
+
return stmt;
|
|
36
|
+
}
|
|
37
|
+
function getRepairSessionChunkProjectStatement(db) {
|
|
38
|
+
let stmt = repairSessionChunkProjectStatements.get(db);
|
|
39
|
+
if (!stmt) {
|
|
40
|
+
stmt = db.prepare(`UPDATE compartment_chunk_embeddings
|
|
41
|
+
SET project_path = ?
|
|
42
|
+
WHERE id IN (
|
|
43
|
+
SELECT id
|
|
44
|
+
FROM compartment_chunk_embeddings
|
|
45
|
+
WHERE session_id = ?
|
|
46
|
+
AND harness = ?
|
|
47
|
+
AND project_path <> ?
|
|
48
|
+
LIMIT ?
|
|
49
|
+
)`);
|
|
50
|
+
repairSessionChunkProjectStatements.set(db, stmt);
|
|
51
|
+
}
|
|
52
|
+
return stmt;
|
|
53
|
+
}
|
|
54
|
+
function findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectPath) {
|
|
55
|
+
return db.prepare(`SELECT id FROM (${MIS_SCOPED_PROJECT_CHUNK_IDS_SQL}) LIMIT 25`).all(projectPath, projectPath).map(({ id }) => id);
|
|
56
|
+
}
|
|
57
|
+
function recordSessionProjectIdentity(db, sessionId, projectPath) {
|
|
58
|
+
if (!sessionId || !projectPath)
|
|
59
|
+
return;
|
|
60
|
+
if (!projectPath.startsWith("git:") && !projectPath.startsWith("dir:") && isUserHomeDirectory(projectPath))
|
|
61
|
+
return;
|
|
62
|
+
const harness = getHarness2();
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
let previousProjectPath;
|
|
65
|
+
db.transaction(() => {
|
|
66
|
+
const existing = db.prepare("SELECT project_path FROM session_projects WHERE session_id = ? AND harness = ?").get(sessionId, harness);
|
|
67
|
+
previousProjectPath = existing?.project_path;
|
|
68
|
+
getUpsertSessionProjectStatement(db).run(sessionId, harness, projectPath, now);
|
|
69
|
+
getRepairSessionChunkProjectStatement(db).run(projectPath, sessionId, harness, projectPath, SESSION_CHUNK_REPAIR_BATCH_SIZE);
|
|
70
|
+
}).immediate();
|
|
71
|
+
return previousProjectPath === projectPath ? undefined : { previousProjectPath, projectPath };
|
|
72
|
+
}
|
|
73
|
+
function repairMisScopedCompartmentChunkEmbeddingsForProject(db, projectPath, ids = findMisScopedCompartmentChunkEmbeddingIdsForProject(db, projectPath)) {
|
|
74
|
+
if (!projectPath || ids.length === 0)
|
|
75
|
+
return 0;
|
|
76
|
+
return db.prepare(`UPDATE compartment_chunk_embeddings
|
|
77
|
+
SET project_path = (SELECT sp.project_path FROM session_projects sp
|
|
78
|
+
WHERE sp.session_id = compartment_chunk_embeddings.session_id
|
|
79
|
+
AND sp.harness = compartment_chunk_embeddings.harness)
|
|
80
|
+
WHERE id IN (${ids.map(() => "?").join(",")}) AND EXISTS (
|
|
81
|
+
SELECT 1 FROM session_projects sp
|
|
82
|
+
WHERE sp.session_id = compartment_chunk_embeddings.session_id
|
|
83
|
+
AND sp.harness = compartment_chunk_embeddings.harness
|
|
84
|
+
AND sp.project_path <> compartment_chunk_embeddings.project_path
|
|
85
|
+
AND (sp.project_path = ? OR compartment_chunk_embeddings.project_path = ?)
|
|
86
|
+
)`).run(...ids, projectPath, projectPath).changes;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ../plugin/src/features/magic-context/git-commits/sweep-coordinator.ts
|
|
90
|
+
var GIT_SWEEP_COOLDOWN_MS = 10 * 60 * 1000;
|
|
91
|
+
var GIT_SWEEP_LEASE_TTL_MS = 5 * 60 * 1000;
|
|
92
|
+
var GIT_SWEEP_NON_INDEXABLE_REPROBE_MS = 24 * 60 * 60 * 1000;
|
|
93
|
+
var GIT_SWEEP_LEASE_RENEWAL_MS = 60 * 1000;
|
|
94
|
+
function runImmediate(db, body) {
|
|
95
|
+
db.exec("BEGIN IMMEDIATE");
|
|
96
|
+
const transactionStartedAt = performance.now();
|
|
97
|
+
let committed = false;
|
|
98
|
+
try {
|
|
99
|
+
const result = body();
|
|
100
|
+
db.exec("COMMIT");
|
|
101
|
+
committed = true;
|
|
102
|
+
logSlowWriteTransaction("git_sweep_lease", transactionStartedAt);
|
|
103
|
+
return result;
|
|
104
|
+
} finally {
|
|
105
|
+
if (!committed) {
|
|
106
|
+
try {
|
|
107
|
+
db.exec("ROLLBACK");
|
|
108
|
+
} catch {}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function rowToState(row) {
|
|
113
|
+
return {
|
|
114
|
+
projectPath: row.project_path,
|
|
115
|
+
leaseHolder: row.lease_holder,
|
|
116
|
+
leaseExpiresAt: row.lease_expires_at,
|
|
117
|
+
lastSweptAt: row.last_swept_at
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function getGitSweepCoordinatorState(db, projectPath) {
|
|
121
|
+
const row = db.prepare(`SELECT project_path, lease_holder, lease_expires_at, last_swept_at
|
|
122
|
+
FROM git_sweep_coordinator
|
|
123
|
+
WHERE project_path = ?`).get(projectPath);
|
|
124
|
+
return row ? rowToState(row) : null;
|
|
125
|
+
}
|
|
126
|
+
function acquireGitSweepLease(db, projectPath, holderId, options = {}) {
|
|
127
|
+
const cooldownMs = options.cooldownMs ?? GIT_SWEEP_COOLDOWN_MS;
|
|
128
|
+
const leaseTtlMs = options.leaseTtlMs ?? GIT_SWEEP_LEASE_TTL_MS;
|
|
129
|
+
return runImmediate(db, () => {
|
|
130
|
+
const now = Date.now();
|
|
131
|
+
const row = getGitSweepCoordinatorState(db, projectPath);
|
|
132
|
+
if (row?.leaseHolder && row.leaseExpiresAt !== null && row.leaseExpiresAt > now) {
|
|
133
|
+
return {
|
|
134
|
+
acquired: false,
|
|
135
|
+
projectPath,
|
|
136
|
+
reason: "lease_active",
|
|
137
|
+
leaseHolder: row.leaseHolder,
|
|
138
|
+
leaseExpiresAt: row.leaseExpiresAt,
|
|
139
|
+
lastSweptAt: row.lastSweptAt,
|
|
140
|
+
nextAllowedAt: null
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (!options.ignoreCooldown && row?.lastSweptAt !== null && row?.lastSweptAt !== undefined) {
|
|
144
|
+
const nextAllowedAt = row.lastSweptAt + cooldownMs;
|
|
145
|
+
if (nextAllowedAt > now) {
|
|
146
|
+
return {
|
|
147
|
+
acquired: false,
|
|
148
|
+
projectPath,
|
|
149
|
+
reason: "cooldown_active",
|
|
150
|
+
leaseHolder: row.leaseHolder,
|
|
151
|
+
leaseExpiresAt: row.leaseExpiresAt,
|
|
152
|
+
lastSweptAt: row.lastSweptAt,
|
|
153
|
+
nextAllowedAt
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const leaseExpiresAt = now + leaseTtlMs;
|
|
158
|
+
db.prepare(`INSERT INTO git_sweep_coordinator (
|
|
159
|
+
project_path,
|
|
160
|
+
lease_holder,
|
|
161
|
+
lease_expires_at,
|
|
162
|
+
last_swept_at
|
|
163
|
+
) VALUES (?, ?, ?, NULL)
|
|
164
|
+
ON CONFLICT(project_path) DO UPDATE SET
|
|
165
|
+
lease_holder = excluded.lease_holder,
|
|
166
|
+
lease_expires_at = excluded.lease_expires_at`).run(projectPath, holderId, leaseExpiresAt);
|
|
167
|
+
return {
|
|
168
|
+
acquired: true,
|
|
169
|
+
projectPath,
|
|
170
|
+
holderId,
|
|
171
|
+
acquiredAt: now,
|
|
172
|
+
leaseExpiresAt
|
|
173
|
+
};
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
function renewGitSweepLease(db, projectPath, holderId, leaseTtlMs = GIT_SWEEP_LEASE_TTL_MS) {
|
|
177
|
+
return runImmediate(db, () => {
|
|
178
|
+
const now = Date.now();
|
|
179
|
+
const leaseExpiresAt = now + leaseTtlMs;
|
|
180
|
+
const result = db.prepare(`UPDATE git_sweep_coordinator
|
|
181
|
+
SET lease_expires_at = ?
|
|
182
|
+
WHERE project_path = ?
|
|
183
|
+
AND lease_holder = ?
|
|
184
|
+
AND lease_expires_at > ?`).run(leaseExpiresAt, projectPath, holderId, now);
|
|
185
|
+
return result.changes === 1;
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function markGitSweepSuccessAndRelease(db, projectPath, holderId) {
|
|
189
|
+
return runImmediate(db, () => {
|
|
190
|
+
const now = Date.now();
|
|
191
|
+
const result = db.prepare(`UPDATE git_sweep_coordinator
|
|
192
|
+
SET lease_holder = NULL,
|
|
193
|
+
lease_expires_at = NULL,
|
|
194
|
+
last_swept_at = ?
|
|
195
|
+
WHERE project_path = ?
|
|
196
|
+
AND lease_holder = ?
|
|
197
|
+
AND lease_expires_at > ?`).run(now, projectPath, holderId, now);
|
|
198
|
+
return result.changes === 1;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function parkGitSweepNonIndexable(db, projectPath, holderId, reprobeMs = GIT_SWEEP_NON_INDEXABLE_REPROBE_MS) {
|
|
202
|
+
return runImmediate(db, () => {
|
|
203
|
+
const now = Date.now();
|
|
204
|
+
const sweptAt = now + reprobeMs - GIT_SWEEP_COOLDOWN_MS;
|
|
205
|
+
const result = db.prepare(`UPDATE git_sweep_coordinator
|
|
206
|
+
SET lease_holder = NULL,
|
|
207
|
+
lease_expires_at = NULL,
|
|
208
|
+
last_swept_at = ?
|
|
209
|
+
WHERE project_path = ?
|
|
210
|
+
AND lease_holder = ?
|
|
211
|
+
AND lease_expires_at > ?`).run(sweptAt, projectPath, holderId, now);
|
|
212
|
+
return result.changes === 1;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function releaseGitSweepLease(db, projectPath, holderId) {
|
|
216
|
+
runImmediate(db, () => {
|
|
217
|
+
db.prepare(`UPDATE git_sweep_coordinator
|
|
218
|
+
SET lease_holder = NULL,
|
|
219
|
+
lease_expires_at = NULL
|
|
220
|
+
WHERE project_path = ?
|
|
221
|
+
AND lease_holder = ?`).run(projectPath, holderId);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export { findMisScopedCompartmentChunkEmbeddingIdsForProject, recordSessionProjectIdentity, repairMisScopedCompartmentChunkEmbeddingsForProject, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease };
|