@cortexkit/pi-magic-context 0.47.0 → 0.48.0
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 +27 -22
- package/dist/embedding-activity-ew6dshfd.js +10 -0
- package/dist/embedding-backfill-bnnytehy.js +20 -0
- package/dist/embedding-cache-7rp4gqzr.js +16 -0
- package/dist/embedding-worker.js +11 -8
- package/dist/harness-9872e0ym.js +10 -0
- package/dist/historian-calibration-extension.js +3 -2
- package/dist/index-0am8a7k1.js +152 -0
- package/dist/index-0h2mkab2.js +17 -0
- package/dist/index-135e8hvg.js +43 -0
- package/dist/{index-0qejsd7f.js → index-3cgbv47m.js} +289 -45
- package/dist/index-419bndtm.js +2309 -0
- package/dist/index-544c0e0x.js +3026 -0
- package/dist/index-5hd7h4rr.js +3098 -0
- package/dist/index-5jp1h0bz.js +750 -0
- package/dist/index-603mt6nm.js +171 -0
- package/dist/index-674f6qs2.js +16 -0
- package/dist/{index-vgcemg0n.js → index-6pgq5ns2.js} +151 -2452
- package/dist/{index-xpbh1ypk.js → index-72bdc1bd.js} +38 -741
- package/dist/index-8976mezv.js +209 -0
- package/dist/{index-td885aah.js → index-8y5knskr.js} +98 -231
- package/dist/{index-k3ezsjng.js → index-98z1c1r0.js} +14574 -13942
- package/dist/index-9p40dgkm.js +22 -0
- package/dist/index-9x1f96r8.js +11 -0
- package/dist/{index-266qrgss.js → index-9xb0axhc.js} +301 -27
- package/dist/{index-spk5vrhy.js → index-bgmv2kaf.js} +1 -16
- package/dist/index-dkx0b1kt.js +514 -0
- package/dist/{index-7n8gb6j3.js → index-f956htf3.js} +28 -31
- package/dist/index-fapenpch.js +13 -0
- package/dist/index-fm3ksh5e.js +1060 -0
- package/dist/{index-2p1e8706.js → index-fp37he9a.js} +3 -3
- package/dist/index-hrf13mn3.js +2388 -0
- package/dist/index-pvm4pd5d.js +3069 -0
- package/dist/{index-kztsbkqq.js → index-r7xg4hvw.js} +171 -168
- package/dist/index-rt5jgzp1.js +1127 -0
- package/dist/{index-n3g5mwa8.js → index-wrm4nbj7.js} +3 -3
- package/dist/index-xjqheg7a.js +931 -0
- package/dist/index-yhzhdp3m.js +143 -0
- package/dist/{index-w76x3af7.js → index-zrr5t5a7.js} +1 -3
- package/dist/index.js +4203 -2183
- package/dist/logger-v3dsxdnm.js +19 -0
- package/dist/message-index-bounded-t7vvty76.js +120 -0
- package/dist/{message-time-backfill-d3db2etr.js → message-time-backfill-4ndf7hrq.js} +7 -6
- package/dist/migration-worker.js +20 -14
- package/dist/project-embedding-registry-jy2hmq28.js +85 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-atxsyfqv.js → read-session-chunk-47pjn7fz.js} +12 -6
- package/dist/read-session-raw-yn8nawav.js +55 -0
- package/dist/{safe-notification-target-6cn3z99t.js → safe-notification-target-3c1ns931.js} +3 -2
- package/dist/search-42szfhwp.js +40 -0
- package/dist/sqlite-3yye76ht.js +44 -0
- package/dist/sqlite-context-pragmas-gcgch6qz.js +6 -0
- package/dist/storage-memory-1z20y55x.js +71 -0
- package/dist/storage-tags-jym5z6yk.js +127 -0
- package/dist/subagent-entry.js +34 -17
- package/dist/transformers-node-wasm.js +18415 -18415
- package/package.json +3 -3
- package/dist/index-7s8vw2y0.js +0 -5207
- package/dist/index-qaa5j277.js +0 -8544
- /package/dist/{index-en1k8h8m.js → index-5prbx026.js} +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// ../plugin/src/features/magic-context/memory/storage-memory-embeddings.ts
|
|
2
|
+
var saveEmbeddingStatements = new WeakMap;
|
|
3
|
+
var saveEmbeddingIfHashMatchesStatements = new WeakMap;
|
|
4
|
+
var loadAllEmbeddingsStatements = new WeakMap;
|
|
5
|
+
var deleteEmbeddingStatements = new WeakMap;
|
|
6
|
+
var getStoredModelIdStatements = new WeakMap;
|
|
7
|
+
var clearAllEmbeddingsStatements = new WeakMap;
|
|
8
|
+
var clearModelEmbeddingsStatements = new WeakMap;
|
|
9
|
+
function isEmbeddingBlob(value) {
|
|
10
|
+
return value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
11
|
+
}
|
|
12
|
+
function isEmbeddingRow(row) {
|
|
13
|
+
if (row === null || typeof row !== "object")
|
|
14
|
+
return false;
|
|
15
|
+
const candidate = row;
|
|
16
|
+
return typeof candidate.memoryId === "number" && isEmbeddingBlob(candidate.embedding) && (candidate.modelId === null || typeof candidate.modelId === "string");
|
|
17
|
+
}
|
|
18
|
+
function toFloat32Array(blob) {
|
|
19
|
+
if (blob instanceof Uint8Array) {
|
|
20
|
+
const buffer = blob.buffer.slice(blob.byteOffset, blob.byteOffset + blob.byteLength);
|
|
21
|
+
return new Float32Array(buffer);
|
|
22
|
+
}
|
|
23
|
+
return new Float32Array(blob.slice(0));
|
|
24
|
+
}
|
|
25
|
+
function getSaveEmbeddingStatement(db) {
|
|
26
|
+
let stmt = saveEmbeddingStatements.get(db);
|
|
27
|
+
if (!stmt) {
|
|
28
|
+
stmt = db.prepare("INSERT INTO memory_embeddings (memory_id, embedding, model_id) VALUES (?, ?, ?) ON CONFLICT(memory_id, model_id) DO UPDATE SET embedding = excluded.embedding");
|
|
29
|
+
saveEmbeddingStatements.set(db, stmt);
|
|
30
|
+
}
|
|
31
|
+
return stmt;
|
|
32
|
+
}
|
|
33
|
+
function getSaveEmbeddingIfHashMatchesStatement(db) {
|
|
34
|
+
let stmt = saveEmbeddingIfHashMatchesStatements.get(db);
|
|
35
|
+
if (!stmt) {
|
|
36
|
+
stmt = db.prepare("INSERT INTO memory_embeddings (memory_id, embedding, model_id) SELECT ?, ?, ? FROM memories WHERE id = ? AND normalized_hash = ? ON CONFLICT(memory_id, model_id) DO UPDATE SET embedding = excluded.embedding");
|
|
37
|
+
saveEmbeddingIfHashMatchesStatements.set(db, stmt);
|
|
38
|
+
}
|
|
39
|
+
return stmt;
|
|
40
|
+
}
|
|
41
|
+
function getLoadAllEmbeddingsStatement(db) {
|
|
42
|
+
let stmt = loadAllEmbeddingsStatements.get(db);
|
|
43
|
+
if (!stmt) {
|
|
44
|
+
stmt = db.prepare("SELECT memory_embeddings.memory_id AS memoryId, memory_embeddings.embedding AS embedding, memory_embeddings.model_id AS modelId FROM memory_embeddings INNER JOIN memories ON memories.id = memory_embeddings.memory_id WHERE memories.project_path = ? AND memory_embeddings.model_id = ? ORDER BY memory_embeddings.memory_id ASC");
|
|
45
|
+
loadAllEmbeddingsStatements.set(db, stmt);
|
|
46
|
+
}
|
|
47
|
+
return stmt;
|
|
48
|
+
}
|
|
49
|
+
function saveEmbedding(db, memoryId, embedding, modelId) {
|
|
50
|
+
const blob = Buffer.from(embedding.buffer, embedding.byteOffset, embedding.byteLength);
|
|
51
|
+
getSaveEmbeddingStatement(db).run(memoryId, blob, modelId);
|
|
52
|
+
}
|
|
53
|
+
function saveEmbeddingIfHashMatches(db, memoryId, embedding, modelId, normalizedHash) {
|
|
54
|
+
const blob = Buffer.from(embedding.buffer, embedding.byteOffset, embedding.byteLength);
|
|
55
|
+
return getSaveEmbeddingIfHashMatchesStatement(db).run(memoryId, blob, modelId, memoryId, normalizedHash).changes > 0;
|
|
56
|
+
}
|
|
57
|
+
function loadAllEmbeddings(db, projectPath, modelId) {
|
|
58
|
+
const rows = getLoadAllEmbeddingsStatement(db).all(projectPath, modelId).filter(isEmbeddingRow);
|
|
59
|
+
const embeddings = new Map;
|
|
60
|
+
for (const row of rows) {
|
|
61
|
+
embeddings.set(row.memoryId, {
|
|
62
|
+
embedding: toFloat32Array(row.embedding),
|
|
63
|
+
modelId: row.modelId
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return embeddings;
|
|
67
|
+
}
|
|
68
|
+
function getMemoryEmbedCoverage(db, projectPath, modelId) {
|
|
69
|
+
const row = db.prepare(`SELECT
|
|
70
|
+
COUNT(*) AS total,
|
|
71
|
+
SUM(CASE WHEN EXISTS (
|
|
72
|
+
SELECT 1 FROM memory_embeddings e
|
|
73
|
+
WHERE e.memory_id = m.id AND e.model_id = ?
|
|
74
|
+
) THEN 1 ELSE 0 END) AS embedded
|
|
75
|
+
FROM memories m
|
|
76
|
+
WHERE m.project_path = ? AND m.status = 'active'`).get(modelId, projectPath);
|
|
77
|
+
return {
|
|
78
|
+
total: typeof row?.total === "number" ? row.total : 0,
|
|
79
|
+
embedded: typeof row?.embedded === "number" ? row.embedded : 0
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// ../plugin/src/features/magic-context/memory/embedding-cache.ts
|
|
84
|
+
var DEFAULT_EMBEDDING_CACHE_TTL_MS = 60000;
|
|
85
|
+
var projectEmbeddingCache = new Map;
|
|
86
|
+
var embeddingCacheTtlMs = DEFAULT_EMBEDDING_CACHE_TTL_MS;
|
|
87
|
+
function cacheKey(projectPath, modelId) {
|
|
88
|
+
return `${projectPath}\x00${modelId}`;
|
|
89
|
+
}
|
|
90
|
+
function getValidCacheEntry(projectPath, modelId) {
|
|
91
|
+
const entry = projectEmbeddingCache.get(cacheKey(projectPath, modelId));
|
|
92
|
+
if (!entry) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
if (entry.expiresAt <= Date.now()) {
|
|
96
|
+
projectEmbeddingCache.delete(cacheKey(projectPath, modelId));
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return entry;
|
|
100
|
+
}
|
|
101
|
+
function getProjectEmbeddings2(db, projectPath, modelId) {
|
|
102
|
+
const cached = getValidCacheEntry(projectPath, modelId);
|
|
103
|
+
if (cached) {
|
|
104
|
+
return cached.embeddings;
|
|
105
|
+
}
|
|
106
|
+
const embeddings = loadAllEmbeddings(db, projectPath, modelId);
|
|
107
|
+
projectEmbeddingCache.set(cacheKey(projectPath, modelId), {
|
|
108
|
+
embeddings,
|
|
109
|
+
expiresAt: Date.now() + embeddingCacheTtlMs
|
|
110
|
+
});
|
|
111
|
+
return embeddings;
|
|
112
|
+
}
|
|
113
|
+
function peekProjectEmbeddings2(projectPath, modelId) {
|
|
114
|
+
return getValidCacheEntry(projectPath, modelId)?.embeddings ?? null;
|
|
115
|
+
}
|
|
116
|
+
function invalidateProject2(projectPath) {
|
|
117
|
+
for (const key of projectEmbeddingCache.keys()) {
|
|
118
|
+
if (key.startsWith(`${projectPath}\x00`)) {
|
|
119
|
+
projectEmbeddingCache.delete(key);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function invalidateMemory2(projectPath, memoryId) {
|
|
124
|
+
for (const key of projectEmbeddingCache.keys()) {
|
|
125
|
+
if (!key.startsWith(`${projectPath}\x00`))
|
|
126
|
+
continue;
|
|
127
|
+
const entry = projectEmbeddingCache.get(key);
|
|
128
|
+
if (!entry || entry.expiresAt <= Date.now()) {
|
|
129
|
+
projectEmbeddingCache.delete(key);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
entry.embeddings.delete(memoryId);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function resetEmbeddingCacheForTests2() {
|
|
136
|
+
projectEmbeddingCache.clear();
|
|
137
|
+
embeddingCacheTtlMs = DEFAULT_EMBEDDING_CACHE_TTL_MS;
|
|
138
|
+
}
|
|
139
|
+
function setEmbeddingCacheTtlForTests2(ttlMs) {
|
|
140
|
+
embeddingCacheTtlMs = Math.max(0, Math.floor(ttlMs));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export { saveEmbedding, saveEmbeddingIfHashMatches, getMemoryEmbedCoverage, getProjectEmbeddings2, peekProjectEmbeddings2, invalidateProject2, invalidateMemory2, resetEmbeddingCacheForTests2, setEmbeddingCacheTtlForTests2 };
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
// src/subagent-telemetry.ts
|
|
2
|
-
import { createHash } from "node:crypto";
|
|
3
|
-
|
|
4
1
|
// ../plugin/src/agents/hidden-agent-registrations.ts
|
|
5
2
|
var HIDDEN_AGENT_DESCRIPTION = "Internal Magic Context maintenance agent. Not for general tasks — do not select for user work.";
|
|
6
3
|
function buildHiddenAgentRegistrations(args) {
|
|
@@ -138,6 +135,7 @@ function buildHiddenAgentRegistrations(args) {
|
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
// src/subagent-telemetry.ts
|
|
138
|
+
import { createHash } from "node:crypto";
|
|
141
139
|
var stepCaps = new Map(buildHiddenAgentRegistrations({
|
|
142
140
|
dreamerPrompt: undefined,
|
|
143
141
|
historianPrompt: undefined,
|