@cortexkit/pi-magic-context 0.46.1 → 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 +112 -0
- 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-wv28nczk.js → index-3cgbv47m.js} +354 -38
- 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-r01b1b78.js → index-6pgq5ns2.js} +157 -2454
- package/dist/index-72bdc1bd.js +3591 -0
- package/dist/index-8976mezv.js +209 -0
- package/dist/{index-td885aah.js → index-8y5knskr.js} +98 -231
- package/dist/{index-ykb8kkm3.js → index-98z1c1r0.js} +14599 -22287
- 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-phh7e055.js → index-bgmv2kaf.js} +28 -28
- 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-r7xg4hvw.js +3480 -0
- 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 +6345 -2585
- package/dist/logger-v3dsxdnm.js +19 -0
- package/dist/message-index-bounded-t7vvty76.js +120 -0
- package/dist/{message-time-backfill-4688z1k2.js → message-time-backfill-4ndf7hrq.js} +7 -6
- package/dist/migration-worker.js +24 -16
- package/dist/project-embedding-registry-jy2hmq28.js +85 -0
- package/dist/raw-ordinal-warmup-worker.js +60 -0
- package/dist/{read-session-chunk-tc6yn2pe.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 +36 -16
- package/dist/transformers-node-wasm.js +18415 -18415
- package/package.json +3 -3
- package/dist/index-4vfrjwf6.js +0 -7737
- package/dist/index-xvw8zptx.js +0 -5123
- /package/dist/{index-901ekbga.js → index-5prbx026.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// ../plugin/src/hooks/magic-context/auto-search-worker.ts
|
|
2
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
3
|
+
var port = parentPort;
|
|
4
|
+
if (!port)
|
|
5
|
+
throw new Error("auto-search worker requires a parent port");
|
|
6
|
+
var input = workerData;
|
|
7
|
+
if (input.job === "messages") {
|
|
8
|
+
port.postMessage({ kind: "accepted" });
|
|
9
|
+
}
|
|
10
|
+
var [
|
|
11
|
+
{ ensureMemoryEmbeddings },
|
|
12
|
+
{ getProjectEmbeddings },
|
|
13
|
+
{ getMemoriesByProject },
|
|
14
|
+
{ installProjectEmbeddingSearchBridge },
|
|
15
|
+
{ searchMessageHistory, unifiedSearch },
|
|
16
|
+
{ setEmbeddingSessionBusy },
|
|
17
|
+
{ setHarness },
|
|
18
|
+
{ Database }
|
|
19
|
+
] = await Promise.all([
|
|
20
|
+
import("./embedding-backfill-bnnytehy.js"),
|
|
21
|
+
import("./embedding-cache-7rp4gqzr.js"),
|
|
22
|
+
import("./storage-memory-1z20y55x.js"),
|
|
23
|
+
import("./project-embedding-registry-jy2hmq28.js"),
|
|
24
|
+
import("./search-42szfhwp.js"),
|
|
25
|
+
import("./embedding-activity-ew6dshfd.js"),
|
|
26
|
+
import("./harness-9872e0ym.js"),
|
|
27
|
+
import("./sqlite-3yye76ht.js")
|
|
28
|
+
]);
|
|
29
|
+
setHarness(input.harness);
|
|
30
|
+
setEmbeddingSessionBusy(input.sessionId, input.embeddingHostBusy === true);
|
|
31
|
+
var nextId = 0;
|
|
32
|
+
var pending = new Map;
|
|
33
|
+
var queryDimensions = null;
|
|
34
|
+
var db;
|
|
35
|
+
port.on("message", (reply) => {
|
|
36
|
+
if (reply.embeddingHostBusy !== undefined)
|
|
37
|
+
setEmbeddingSessionBusy(input.sessionId, reply.embeddingHostBusy);
|
|
38
|
+
const vector = reply.result instanceof Float32Array ? reply.result : reply.result?.vector;
|
|
39
|
+
if (vector)
|
|
40
|
+
queryDimensions = vector.length;
|
|
41
|
+
pending.get(reply.id)?.(reply);
|
|
42
|
+
pending.delete(reply.id);
|
|
43
|
+
});
|
|
44
|
+
function request(message) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
const id = ++nextId;
|
|
47
|
+
pending.set(id, (reply) => reply.error ? reject(new Error(reply.error)) : resolve(reply));
|
|
48
|
+
port?.postMessage({ ...message, id });
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (input.snapshot) {
|
|
52
|
+
installProjectEmbeddingSearchBridge(input.snapshot, {
|
|
53
|
+
modelId: input.snapshot.modelId,
|
|
54
|
+
initialize: async () => true,
|
|
55
|
+
isLoaded: () => true,
|
|
56
|
+
dispose: async () => {},
|
|
57
|
+
embed: async (text) => {
|
|
58
|
+
const result = (await request({ kind: "query", text })).result;
|
|
59
|
+
return result instanceof Float32Array ? result : result?.vector ?? null;
|
|
60
|
+
},
|
|
61
|
+
embedBatch: async (texts, _signal, purpose = "passage") => {
|
|
62
|
+
const passage = (await request({ kind: "batch", texts, purpose })).passage;
|
|
63
|
+
const captured = input.snapshot;
|
|
64
|
+
if (!passage || !captured || passage.generation !== captured.generation || passage.modelId !== captured.modelId || passage.providerIdentity !== captured.providerIdentity || passage.runtimeFingerprint !== captured.runtimeFingerprint || !queryDimensions || passage.dimensions !== queryDimensions || passage.vectors.length !== texts.length)
|
|
65
|
+
return texts.map(() => null);
|
|
66
|
+
return passage.vectors.map((vector) => vector && vector.length === queryDimensions && vector.every(Number.isFinite) ? vector : null);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
db = new Database(input.path, input.job === "backfill" ? undefined : { readonly: true });
|
|
71
|
+
db.exec("PRAGMA busy_timeout = 250");
|
|
72
|
+
try {
|
|
73
|
+
if (input.job === "backfill") {
|
|
74
|
+
if (input.snapshot?.enabled && input.snapshot.features.memoryEnabled) {
|
|
75
|
+
await request({ kind: "query", text: input.query });
|
|
76
|
+
if (queryDimensions) {
|
|
77
|
+
const existingEmbeddings = getProjectEmbeddings(db, input.projectPath, input.snapshot.modelId);
|
|
78
|
+
const memories = getMemoriesByProject(db, input.projectPath).filter((memory) => !existingEmbeddings.has(memory.id)).slice(0, 50);
|
|
79
|
+
await ensureMemoryEmbeddings({
|
|
80
|
+
db,
|
|
81
|
+
projectIdentity: input.projectPath,
|
|
82
|
+
memories,
|
|
83
|
+
existingEmbeddings
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
port.postMessage({ kind: "result", results: [] });
|
|
88
|
+
} else if (input.job === "messages") {
|
|
89
|
+
if (!input.messageRequest)
|
|
90
|
+
throw new Error("message search job carries no request");
|
|
91
|
+
const outcome = searchMessageHistory(db, input.messageRequest);
|
|
92
|
+
port.postMessage({ kind: "messages", outcome });
|
|
93
|
+
} else {
|
|
94
|
+
const results = await unifiedSearch(db, input.sessionId, input.projectPath, input.query, {
|
|
95
|
+
...input.options,
|
|
96
|
+
backfillMemoryEmbeddings: false,
|
|
97
|
+
countRetrievals: false,
|
|
98
|
+
measurementDisabled: true,
|
|
99
|
+
embedQuery: async (text) => (await request({ kind: "query", text })).result ?? null,
|
|
100
|
+
isEmbeddingRuntimeEnabled: () => input.embeddingRuntimeEnabled
|
|
101
|
+
});
|
|
102
|
+
port.postMessage({ kind: "result", results });
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
port.postMessage({
|
|
106
|
+
kind: "error",
|
|
107
|
+
error: error instanceof Error ? error.message : String(error)
|
|
108
|
+
});
|
|
109
|
+
} finally {
|
|
110
|
+
db.close();
|
|
111
|
+
port.close();
|
|
112
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setEmbeddingSessionBusy2,
|
|
3
|
+
observeEmbeddingActivity2,
|
|
4
|
+
isEmbeddingHostBusy2
|
|
5
|
+
} from "./index-9p40dgkm.js";
|
|
6
|
+
export {
|
|
7
|
+
isEmbeddingHostBusy2 as isEmbeddingHostBusy,
|
|
8
|
+
observeEmbeddingActivity2 as observeEmbeddingActivity,
|
|
9
|
+
setEmbeddingSessionBusy2 as setEmbeddingSessionBusy
|
|
10
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensureMemoryEmbeddings2
|
|
3
|
+
} from "./index-0am8a7k1.js";
|
|
4
|
+
import"./index-544c0e0x.js";
|
|
5
|
+
import"./index-fm3ksh5e.js";
|
|
6
|
+
import"./index-yhzhdp3m.js";
|
|
7
|
+
import"./index-9p40dgkm.js";
|
|
8
|
+
import"./index-6pgq5ns2.js";
|
|
9
|
+
import"./index-419bndtm.js";
|
|
10
|
+
import"./index-dkx0b1kt.js";
|
|
11
|
+
import"./index-603mt6nm.js";
|
|
12
|
+
import"./index-fp37he9a.js";
|
|
13
|
+
import"./index-bgmv2kaf.js";
|
|
14
|
+
import"./index-3cgbv47m.js";
|
|
15
|
+
import"./index-9xb0axhc.js";
|
|
16
|
+
import"./index-f956htf3.js";
|
|
17
|
+
import"./index-0h2mkab2.js";
|
|
18
|
+
export {
|
|
19
|
+
ensureMemoryEmbeddings2 as ensureMemoryEmbeddings
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getProjectEmbeddings2,
|
|
3
|
+
peekProjectEmbeddings2,
|
|
4
|
+
invalidateProject2,
|
|
5
|
+
invalidateMemory2,
|
|
6
|
+
resetEmbeddingCacheForTests2,
|
|
7
|
+
setEmbeddingCacheTtlForTests2
|
|
8
|
+
} from "./index-yhzhdp3m.js";
|
|
9
|
+
export {
|
|
10
|
+
getProjectEmbeddings2 as getProjectEmbeddings,
|
|
11
|
+
invalidateMemory2 as invalidateMemory,
|
|
12
|
+
invalidateProject2 as invalidateProject,
|
|
13
|
+
peekProjectEmbeddings2 as peekProjectEmbeddings,
|
|
14
|
+
resetEmbeddingCacheForTests2 as resetEmbeddingCacheForTests,
|
|
15
|
+
setEmbeddingCacheTtlForTests2 as setEmbeddingCacheTtlForTests
|
|
16
|
+
};
|
package/dist/embedding-worker.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
setHarness2
|
|
3
|
+
} from "./index-0h2mkab2.js";
|
|
4
|
+
import {
|
|
5
|
+
log2
|
|
6
|
+
} from "./index-f956htf3.js";
|
|
5
7
|
import {
|
|
6
8
|
resolveLocalEmbeddingWorkerRuntime,
|
|
7
9
|
getLocalEmbeddingNativeMemoryStats,
|
|
8
10
|
LocalEmbeddingProvider
|
|
9
|
-
} from "./index-
|
|
10
|
-
import"./index-
|
|
11
|
-
import"./index-
|
|
11
|
+
} from "./index-6pgq5ns2.js";
|
|
12
|
+
import"./index-bgmv2kaf.js";
|
|
13
|
+
import"./index-419bndtm.js";
|
|
14
|
+
import"./index-9xb0axhc.js";
|
|
12
15
|
import {
|
|
13
16
|
setStoragePrivatePermissionEnforcement
|
|
14
17
|
} from "./index-vf38qhee.js";
|
|
15
18
|
|
|
16
19
|
// ../plugin/src/features/magic-context/memory/embedding-worker.ts
|
|
17
20
|
import { parentPort, workerData } from "node:worker_threads";
|
|
18
|
-
|
|
21
|
+
setHarness2(workerData.harness);
|
|
19
22
|
setStoragePrivatePermissionEnforcement(workerData.enforcePrivateStoragePermissions !== false);
|
|
20
23
|
var unsafeNative = workerData.runtimePreference === "native" && resolveLocalEmbeddingWorkerRuntime("native") === "wasm";
|
|
21
24
|
if (unsafeNative)
|
|
22
|
-
|
|
25
|
+
log2("[magic-context] native embedding worker teardown is unsafe on this Bun version; using WASM. Upgrade the host to Bun >=1.4.0 for native inference.");
|
|
23
26
|
var provider = new LocalEmbeddingProvider(workerData.model, workerData.maxInputTokens, workerData.dtype, unsafeNative ? "wasm" : workerData.runtimePreference);
|
|
24
27
|
var queue = Promise.resolve();
|
|
25
28
|
parentPort?.on("message", (request) => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import"./index-
|
|
1
|
+
import"./index-0h2mkab2.js";
|
|
2
|
+
import"./index-f956htf3.js";
|
|
2
3
|
import {
|
|
3
4
|
promptFingerprint,
|
|
4
5
|
readHostSystemPrompt
|
|
5
|
-
} from "./index-
|
|
6
|
+
} from "./index-zrr5t5a7.js";
|
|
6
7
|
|
|
7
8
|
// src/historian-calibration-extension.ts
|
|
8
9
|
import { readFileSync } from "node:fs";
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
3
|
+
LocalEmbeddingProvider
|
|
4
|
+
} from "./index-6pgq5ns2.js";
|
|
5
|
+
import {
|
|
6
|
+
log2
|
|
7
|
+
} from "./index-f956htf3.js";
|
|
8
|
+
import {
|
|
9
|
+
isSynapseEmbeddingTruncated,
|
|
10
|
+
SynapseEmbeddingProvider
|
|
11
|
+
} from "./index-419bndtm.js";
|
|
12
|
+
import {
|
|
13
|
+
OpenAICompatibleEmbeddingProvider,
|
|
14
|
+
getProjectEmbeddingSnapshot2,
|
|
15
|
+
embedBatchForProject2
|
|
16
|
+
} from "./index-544c0e0x.js";
|
|
17
|
+
import {
|
|
18
|
+
isEmbeddingHostBusy2
|
|
19
|
+
} from "./index-9p40dgkm.js";
|
|
20
|
+
import {
|
|
21
|
+
saveEmbeddingIfHashMatches
|
|
22
|
+
} from "./index-yhzhdp3m.js";
|
|
23
|
+
|
|
24
|
+
// ../plugin/src/features/magic-context/memory/cosine-similarity.ts
|
|
25
|
+
function cosineSimilarity(a, b) {
|
|
26
|
+
if (a.length !== b.length) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
let dotProduct = 0;
|
|
30
|
+
let normA = 0;
|
|
31
|
+
let normB = 0;
|
|
32
|
+
for (let index = 0;index < a.length; index++) {
|
|
33
|
+
dotProduct += a[index] * b[index];
|
|
34
|
+
normA += a[index] * a[index];
|
|
35
|
+
normB += b[index] * b[index];
|
|
36
|
+
}
|
|
37
|
+
const denominator = Math.sqrt(normA) * Math.sqrt(normB);
|
|
38
|
+
return denominator === 0 ? 0 : dotProduct / denominator;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ../plugin/src/features/magic-context/memory/embedding.ts
|
|
42
|
+
var DEFAULT_EMBEDDING_CONFIG = {
|
|
43
|
+
provider: "local",
|
|
44
|
+
model: DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
45
|
+
local_runtime: "auto"
|
|
46
|
+
};
|
|
47
|
+
var embeddingConfig = DEFAULT_EMBEDDING_CONFIG;
|
|
48
|
+
var provider = null;
|
|
49
|
+
function createProvider(config) {
|
|
50
|
+
if (config.provider === "off") {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (config.provider === "openai-compatible") {
|
|
54
|
+
return new OpenAICompatibleEmbeddingProvider({
|
|
55
|
+
endpoint: config.endpoint,
|
|
56
|
+
model: config.model,
|
|
57
|
+
apiKey: config.api_key,
|
|
58
|
+
inputType: config.input_type,
|
|
59
|
+
queryInputType: config.query_input_type,
|
|
60
|
+
queryInstruction: config.query_instruction,
|
|
61
|
+
documentPrefix: config.document_prefix,
|
|
62
|
+
truncate: config.truncate,
|
|
63
|
+
maxInputTokens: config.max_input_tokens
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (config.provider === "local") {
|
|
67
|
+
return new LocalEmbeddingProvider(config.model, config.max_input_tokens, config.local_dtype, config.local_runtime);
|
|
68
|
+
}
|
|
69
|
+
if (config.provider === "synapse") {
|
|
70
|
+
const synapse = config;
|
|
71
|
+
return new SynapseEmbeddingProvider({
|
|
72
|
+
connectionFile: synapse.synapse_connection_file ?? "",
|
|
73
|
+
projectRoot: "",
|
|
74
|
+
session: "embedding",
|
|
75
|
+
model: synapse.model,
|
|
76
|
+
fingerprint: synapse.synapse_fingerprint,
|
|
77
|
+
tableEpoch: synapse.synapse_table_epoch,
|
|
78
|
+
dims: synapse.synapse_dims,
|
|
79
|
+
recommendedBatch: synapse.synapse_recommended_batch,
|
|
80
|
+
recommendedTokenBudget: synapse.synapse_recommended_token_budget,
|
|
81
|
+
descriptor: synapse.synapse_descriptor,
|
|
82
|
+
provenance: synapse.synapse_provenance
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
throw new Error("Unknown embedding provider");
|
|
86
|
+
}
|
|
87
|
+
function getOrCreateProvider() {
|
|
88
|
+
if (provider) {
|
|
89
|
+
return provider;
|
|
90
|
+
}
|
|
91
|
+
provider = createProvider(embeddingConfig);
|
|
92
|
+
return provider;
|
|
93
|
+
}
|
|
94
|
+
function isEmbeddingEnabled() {
|
|
95
|
+
return embeddingConfig.provider !== "off";
|
|
96
|
+
}
|
|
97
|
+
async function embedText(text, signal) {
|
|
98
|
+
const currentProvider = getOrCreateProvider();
|
|
99
|
+
if (!currentProvider) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
if (!await currentProvider.initialize()) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const vector = await currentProvider.embed(text, signal);
|
|
106
|
+
return vector && !isSynapseEmbeddingTruncated(vector) ? vector : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ../plugin/src/features/magic-context/memory/embedding-backfill.ts
|
|
110
|
+
async function ensureMemoryEmbeddings2(args) {
|
|
111
|
+
if (isEmbeddingHostBusy2())
|
|
112
|
+
return args.existingEmbeddings;
|
|
113
|
+
const snapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
114
|
+
if (!snapshot?.enabled) {
|
|
115
|
+
return args.existingEmbeddings;
|
|
116
|
+
}
|
|
117
|
+
const missingMemories = args.memories.filter((memory) => !args.existingEmbeddings.has(memory.id));
|
|
118
|
+
if (missingMemories.length === 0) {
|
|
119
|
+
return args.existingEmbeddings;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const result = await embedBatchForProject2(args.projectIdentity, missingMemories.map((memory) => memory.content));
|
|
123
|
+
if (!result) {
|
|
124
|
+
return args.existingEmbeddings;
|
|
125
|
+
}
|
|
126
|
+
const staged = new Map;
|
|
127
|
+
args.db.transaction(() => {
|
|
128
|
+
for (const [index, memory] of missingMemories.entries()) {
|
|
129
|
+
const embedding = result.vectors[index];
|
|
130
|
+
if (!embedding) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const saved = saveEmbeddingIfHashMatches(args.db, memory.id, embedding, result.modelId, memory.normalizedHash);
|
|
134
|
+
if (saved) {
|
|
135
|
+
staged.set(memory.id, { embedding, modelId: result.modelId });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}).immediate();
|
|
139
|
+
const currentSnapshot = getProjectEmbeddingSnapshot2(args.projectIdentity);
|
|
140
|
+
if (!currentSnapshot || currentSnapshot.generation !== result.generation) {
|
|
141
|
+
return args.existingEmbeddings;
|
|
142
|
+
}
|
|
143
|
+
for (const [id, embedding] of staged) {
|
|
144
|
+
args.existingEmbeddings.set(id, embedding);
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
log2("[magic-context] failed to backfill memory embeddings:", error);
|
|
148
|
+
}
|
|
149
|
+
return args.existingEmbeddings;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { cosineSimilarity, isEmbeddingEnabled, embedText, ensureMemoryEmbeddings2 };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ../plugin/src/shared/harness.ts
|
|
2
|
+
var currentHarness = "opencode";
|
|
3
|
+
var harnessLocked = false;
|
|
4
|
+
function setHarness2(value) {
|
|
5
|
+
if (harnessLocked && currentHarness !== value) {
|
|
6
|
+
throw new Error(`Magic Context: harness already locked to "${currentHarness}"; cannot change to "${value}"`);
|
|
7
|
+
}
|
|
8
|
+
currentHarness = value;
|
|
9
|
+
harnessLocked = true;
|
|
10
|
+
}
|
|
11
|
+
function getHarness2() {
|
|
12
|
+
return currentHarness;
|
|
13
|
+
}
|
|
14
|
+
function harnessOwnsOpenCodeStore2(harness = currentHarness) {
|
|
15
|
+
return harness === "opencode" || harness === "opencode2";
|
|
16
|
+
}
|
|
17
|
+
export { setHarness2, getHarness2, harnessOwnsOpenCodeStore2 };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// ../plugin/src/features/magic-context/memory/constants.ts
|
|
2
|
+
var V2_MEMORY_CATEGORIES = [
|
|
3
|
+
"PROJECT_RULES",
|
|
4
|
+
"ARCHITECTURE",
|
|
5
|
+
"CONSTRAINTS",
|
|
6
|
+
"CONFIG_VALUES",
|
|
7
|
+
"NAMING"
|
|
8
|
+
];
|
|
9
|
+
var PROMOTABLE_CATEGORIES = [
|
|
10
|
+
...V2_MEMORY_CATEGORIES,
|
|
11
|
+
"ARCHITECTURE_DECISIONS",
|
|
12
|
+
"CONFIG_DEFAULTS",
|
|
13
|
+
"USER_PREFERENCES",
|
|
14
|
+
"USER_DIRECTIVES",
|
|
15
|
+
"ENVIRONMENT",
|
|
16
|
+
"WORKFLOW_RULES",
|
|
17
|
+
"KNOWN_ISSUES"
|
|
18
|
+
];
|
|
19
|
+
var CATEGORY_PRIORITY = [
|
|
20
|
+
...V2_MEMORY_CATEGORIES,
|
|
21
|
+
"USER_DIRECTIVES",
|
|
22
|
+
"USER_PREFERENCES",
|
|
23
|
+
"CONFIG_DEFAULTS",
|
|
24
|
+
"ARCHITECTURE_DECISIONS",
|
|
25
|
+
"ENVIRONMENT",
|
|
26
|
+
"WORKFLOW_RULES",
|
|
27
|
+
"KNOWN_ISSUES"
|
|
28
|
+
];
|
|
29
|
+
var MEMORY_CATEGORY_ORDER_UNKNOWN = 99;
|
|
30
|
+
var MEMORY_CATEGORY_ORDER_PRIORITY = CATEGORY_PRIORITY.reduce((acc, category, index) => {
|
|
31
|
+
acc[category] = index;
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
var MEMORY_CATEGORY_ORDER_SQL = `CASE category ${CATEGORY_PRIORITY.map((category, index) => `WHEN '${category}' THEN ${index}`).join(" ")} ELSE ${MEMORY_CATEGORY_ORDER_UNKNOWN} END`;
|
|
35
|
+
function getMemoryCategoryOrder(category) {
|
|
36
|
+
return MEMORY_CATEGORY_ORDER_PRIORITY[category] ?? MEMORY_CATEGORY_ORDER_UNKNOWN;
|
|
37
|
+
}
|
|
38
|
+
var CATEGORY_DEFAULT_TTL = {
|
|
39
|
+
WORKFLOW_RULES: 90 * 24 * 60 * 60 * 1000,
|
|
40
|
+
KNOWN_ISSUES: 30 * 24 * 60 * 60 * 1000
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { V2_MEMORY_CATEGORIES, PROMOTABLE_CATEGORIES, CATEGORY_PRIORITY, MEMORY_CATEGORY_ORDER_SQL, getMemoryCategoryOrder, CATEGORY_DEFAULT_TTL };
|