@cortexkit/opencode-magic-context 0.41.0 → 0.41.1
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/config/schema/magic-context.d.ts +15 -0
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/{conflict-warning-hook-xj1r88a7.js → conflict-warning-hook-rf17b6et.js} +3 -3
- package/dist/{derive-budgets-3xfyphvk.js → derive-budgets-bb7mrpzs.js} +2 -2
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +12 -16
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/context-authority.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-failure.d.ts +1 -1
- package/dist/features/magic-context/memory/embedding-failure.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +12 -2
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-synapse.d.ts +10 -1
- package/dist/features/magic-context/memory/embedding-synapse.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/project-identity.d.ts +4 -0
- package/dist/features/magic-context/memory/project-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/transformers-web-entry.d.ts +2 -0
- package/dist/features/magic-context/memory/transformers-web-entry.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +18 -0
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-ops.d.ts +2 -0
- package/dist/features/magic-context/storage-ops.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/hooks/magic-context/boundary-execution.d.ts +3 -0
- package/dist/hooks/magic-context/boundary-execution.d.ts.map +1 -1
- package/dist/hooks/magic-context/format-embed-failure.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -3
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +3 -0
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-2bykz3bx.js → index-2d4kf2ve.js} +1 -1
- package/dist/{index-b4gv9f7g.js → index-4x691bz5.js} +87 -2
- package/dist/{index-knna83k0.js → index-9j3tx8hy.js} +1 -1
- package/dist/{index-jmwq2wxr.js → index-b9j85d29.js} +1 -1
- package/dist/{index-bf799gbq.js → index-d1mxrd3p.js} +0 -1
- package/dist/{index-w8rkbhn6.js → index-dh0vfghk.js} +318 -143
- package/dist/{index-dmgbar7r.js → index-eq9wr75c.js} +2 -2
- package/dist/{index-26ds03jd.js → index-vnz6jvdc.js} +1 -1
- package/dist/{index-x9dmzyp5.js → index-z893kjyt.js} +3 -3
- package/dist/{index-88za3sz8.js → index-zwjhba2r.js} +3 -3
- package/dist/index.js +366 -148
- package/dist/{model-resolution-jgrkt0z2.js → model-resolution-6w6wzw18.js} +1 -1
- package/dist/plugin/embedding-routing.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{recomp-orchestrator-1w4xj6jt.js → recomp-orchestrator-w7xg48e3.js} +6 -6
- package/dist/{safe-notification-target-p0c0csxw.js → safe-notification-target-2a8py95v.js} +2 -2
- package/dist/{send-session-notification-kn34g7mx.js → send-session-notification-bw7eex6w.js} +3 -3
- package/dist/shared/logger.d.ts.map +1 -1
- package/dist/shared/model-resolution.d.ts.map +1 -1
- package/dist/shared/test-temp-dir.d.ts +40 -0
- package/dist/shared/test-temp-dir.d.ts.map +1 -0
- package/dist/{storage-meta-session-snbzd26z.js → storage-meta-session-gr4zn7sq.js} +3 -3
- package/dist/{task-config-ty08ptc2.js → task-config-gv6s04fp.js} +2 -2
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/transformers-web.js +24570 -0
- package/dist/transformers.node-b1wa0hgx.js +28808 -0
- package/package.json +7 -3
- package/src/config/index.test.ts +9 -4
- package/src/config/schema/magic-context.test.ts +20 -0
- package/src/config/schema/magic-context.ts +8 -0
- package/src/shared/conflict-detector.test.ts +6 -19
- package/src/shared/conflict-fixer.test.ts +5 -8
- package/src/shared/logger.test.ts +135 -40
- package/src/shared/logger.ts +115 -2
- package/src/shared/model-resolution.test.ts +4 -6
- package/src/shared/model-resolution.ts +0 -1
- package/src/shared/test-temp-dir.test.ts +57 -0
- package/src/shared/test-temp-dir.ts +165 -0
- /package/dist/{index-rpgg35ms.js → index-8sseka65.js} +0 -0
|
@@ -2,20 +2,21 @@ import {
|
|
|
2
2
|
deriveTriggerBudget,
|
|
3
3
|
modelSupportsVision,
|
|
4
4
|
shouldEnforcePrivateStoragePermissions
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-2d4kf2ve.js";
|
|
6
6
|
import {
|
|
7
7
|
describeError,
|
|
8
8
|
getErrorMessage,
|
|
9
9
|
sendIgnoredMessage
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-zwjhba2r.js";
|
|
11
11
|
import {
|
|
12
|
+
SESSION_SCOPED_TABLES,
|
|
12
13
|
clearCachedM0M1,
|
|
13
14
|
deleteSessionScopedRows,
|
|
14
15
|
ensureSessionMetaRow,
|
|
15
16
|
logSlowWriteTransaction,
|
|
16
17
|
persistCachedM0,
|
|
17
18
|
updateSessionMeta
|
|
18
|
-
} from "./index-
|
|
19
|
+
} from "./index-z893kjyt.js";
|
|
19
20
|
import {
|
|
20
21
|
modelRefLookupOrder,
|
|
21
22
|
piModelRefToCanonical
|
|
@@ -28,7 +29,7 @@ import {
|
|
|
28
29
|
openCodeDbExists,
|
|
29
30
|
withPrivilegedWriter,
|
|
30
31
|
withReadOnlySessionDb
|
|
31
|
-
} from "./index-
|
|
32
|
+
} from "./index-b9j85d29.js";
|
|
32
33
|
import {
|
|
33
34
|
detectConfigFile
|
|
34
35
|
} from "./index-8mtsfhyg.js";
|
|
@@ -39,7 +40,7 @@ import {
|
|
|
39
40
|
log,
|
|
40
41
|
sanitizeDiagnosticText,
|
|
41
42
|
sessionLog
|
|
42
|
-
} from "./index-
|
|
43
|
+
} from "./index-4x691bz5.js";
|
|
43
44
|
import {
|
|
44
45
|
ensureCortexKitArtifactGitignore,
|
|
45
46
|
getDataDir,
|
|
@@ -1241,7 +1242,7 @@ async function prepareAuthority(args) {
|
|
|
1241
1242
|
if (identities.length > 0) {
|
|
1242
1243
|
args.db.transaction(() => {
|
|
1243
1244
|
for (const identity of identities) {
|
|
1244
|
-
rememberIdentity(args.db, domain, args.projectPath, identity.moduleRowId, identity.sourceRowId);
|
|
1245
|
+
rememberIdentity(args.db, domain, args.projectPath, identity.moduleRowId, identity.sourceRowId, undefined, true);
|
|
1245
1246
|
}
|
|
1246
1247
|
}).immediate();
|
|
1247
1248
|
}
|
|
@@ -1880,11 +1881,16 @@ function applyMirroredNoteCompileFields(args) {
|
|
|
1880
1881
|
return result.changes === 1;
|
|
1881
1882
|
});
|
|
1882
1883
|
}
|
|
1883
|
-
function rememberIdentity(db, domain, moduleProject, moduleRowId, contextRowId, statements) {
|
|
1884
|
+
function rememberIdentity(db, domain, moduleProject, moduleRowId, contextRowId, statements, replaceContextIdentity = domain === "notes") {
|
|
1884
1885
|
const existing = mirrorIdentity(db, domain, moduleProject, moduleRowId, statements);
|
|
1885
|
-
if (existing)
|
|
1886
|
+
if (existing?.context_row_id === contextRowId)
|
|
1886
1887
|
return;
|
|
1887
|
-
if (
|
|
1888
|
+
if (existing) {
|
|
1889
|
+
if (!replaceContextIdentity)
|
|
1890
|
+
return;
|
|
1891
|
+
(statements?.deleteIdentity ?? db.prepare("DELETE FROM mirror_identity WHERE domain = ? AND module_project = ? AND module_row_id = ?")).run(domain, moduleProject, moduleRowId);
|
|
1892
|
+
}
|
|
1893
|
+
if (replaceContextIdentity) {
|
|
1888
1894
|
(statements?.deleteIdentityByContext ?? db.prepare("DELETE FROM mirror_identity WHERE domain = ? AND context_row_id = ?")).run(domain, contextRowId);
|
|
1889
1895
|
}
|
|
1890
1896
|
(statements?.insertIdentity ?? db.prepare("INSERT OR IGNORE INTO mirror_identity(domain, module_project, module_row_id, context_row_id) VALUES (?, ?, ?, ?)")).run(domain, moduleProject, moduleRowId, contextRowId);
|
|
@@ -1899,7 +1905,7 @@ function contextMemoryId(db, domain, moduleProject, row, moduleRowId, statements
|
|
|
1899
1905
|
if (sourceUuid && sourceUuid === localStoreUuid && sourceId >= 0) {
|
|
1900
1906
|
const existing = (statements?.memoryIdByStoreId ?? db.prepare("SELECT id FROM memories WHERE id = ? AND project_path = ?")).get(sourceId, moduleProject);
|
|
1901
1907
|
if (existing?.id !== undefined) {
|
|
1902
|
-
rememberIdentity(db, domain, moduleProject, moduleRowId, existing.id, statements);
|
|
1908
|
+
rememberIdentity(db, domain, moduleProject, moduleRowId, existing.id, statements, true);
|
|
1903
1909
|
return existing.id;
|
|
1904
1910
|
}
|
|
1905
1911
|
}
|
|
@@ -2128,6 +2134,24 @@ function applyMirrorPage(args) {
|
|
|
2128
2134
|
if (page.domain === "memories" && resnapshotStatus !== "complete" && page.rows.some((feed) => feed.op === "tombstone")) {
|
|
2129
2135
|
throw new Error("memory mirror resnapshot must complete before tombstones");
|
|
2130
2136
|
}
|
|
2137
|
+
if (page.domain === "memories") {
|
|
2138
|
+
for (const feed of page.rows) {
|
|
2139
|
+
if (feed.domain !== "memories" || feed.op === "tombstone" || feed.feed_seq <= durableCursor) {
|
|
2140
|
+
continue;
|
|
2141
|
+
}
|
|
2142
|
+
const row = feed.full_row_snapshot;
|
|
2143
|
+
const moduleProject = rowString(row, "project_path");
|
|
2144
|
+
const sourceUuid = rowNullableString(row, "context_store_uuid");
|
|
2145
|
+
const sourceId = rowNumber(row, "context_row_id", -1);
|
|
2146
|
+
if (!moduleProject || !sourceUuid || sourceUuid !== statements.contextStoreUuid || sourceId < 0) {
|
|
2147
|
+
continue;
|
|
2148
|
+
}
|
|
2149
|
+
const existing = statements.memoryIdByStoreId.get(sourceId, moduleProject);
|
|
2150
|
+
if (existing?.id === undefined)
|
|
2151
|
+
continue;
|
|
2152
|
+
rememberIdentity(db, "memories", moduleProject, feed.module_row_id, existing.id, statements, true);
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
2131
2155
|
const touchedProjects = new Set;
|
|
2132
2156
|
for (const feed of page.rows) {
|
|
2133
2157
|
if (feed.domain !== page.domain || feed.feed_seq <= nextCursor)
|
|
@@ -2927,6 +2951,9 @@ function gitRootDirectory(canonical) {
|
|
|
2927
2951
|
return null;
|
|
2928
2952
|
}
|
|
2929
2953
|
}
|
|
2954
|
+
function directoryHasGitMetadata(directory) {
|
|
2955
|
+
return gitRootDirectory(path.resolve(directory)) !== null;
|
|
2956
|
+
}
|
|
2930
2957
|
function resolveProjectIdentityForSession(directory, allowHomeProject = false) {
|
|
2931
2958
|
const canonicalHome = canonicalUserHomeDirectory();
|
|
2932
2959
|
const canonicalDirectory = (() => {
|
|
@@ -9982,6 +10009,16 @@ function persistMessageHistoryOrphanSweepState(db, cursor, lastSweptAt) {
|
|
|
9982
10009
|
cursor_session_id = excluded.cursor_session_id,
|
|
9983
10010
|
last_swept_at = excluded.last_swept_at`).run(cursor, lastSweptAt);
|
|
9984
10011
|
}
|
|
10012
|
+
function getOpenCodeSessionScopedCandidateSourceSql() {
|
|
10013
|
+
return SESSION_SCOPED_TABLES.filter((definition) => definition.harnessScoped === true).map((definition) => {
|
|
10014
|
+
const predicates = ["session_id IS NOT NULL", "harness = 'opencode'"];
|
|
10015
|
+
if (definition.extraPredicate)
|
|
10016
|
+
predicates.push(definition.extraPredicate);
|
|
10017
|
+
return `SELECT session_id FROM ${definition.table} WHERE ${predicates.join(" AND ")}`;
|
|
10018
|
+
}).join(`
|
|
10019
|
+
UNION
|
|
10020
|
+
`);
|
|
10021
|
+
}
|
|
9985
10022
|
function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options = {}) {
|
|
9986
10023
|
const now = options.now ?? Date.now();
|
|
9987
10024
|
const batchSize = Math.max(1, Math.floor(options.batchSize ?? MESSAGE_HISTORY_ORPHAN_SWEEP_BATCH_SIZE));
|
|
@@ -10005,13 +10042,19 @@ function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options
|
|
|
10005
10042
|
}
|
|
10006
10043
|
try {
|
|
10007
10044
|
const cutoff = now - safetyAgeMs;
|
|
10045
|
+
const candidateSourceSql = getOpenCodeSessionScopedCandidateSourceSql();
|
|
10008
10046
|
const candidates = db.prepare(`SELECT session_id
|
|
10009
|
-
FROM
|
|
10010
|
-
WHERE
|
|
10011
|
-
AND
|
|
10012
|
-
|
|
10047
|
+
FROM (${candidateSourceSql}) AS session_candidates
|
|
10048
|
+
WHERE session_id > ?
|
|
10049
|
+
AND NOT EXISTS (
|
|
10050
|
+
SELECT 1
|
|
10051
|
+
FROM message_history_index
|
|
10052
|
+
WHERE message_history_index.session_id = session_candidates.session_id
|
|
10053
|
+
AND message_history_index.harness = 'opencode'
|
|
10054
|
+
AND message_history_index.updated_at > ?
|
|
10055
|
+
)
|
|
10013
10056
|
ORDER BY session_id ASC
|
|
10014
|
-
LIMIT ?`).all(
|
|
10057
|
+
LIMIT ?`).all(cursor, cutoff, batchSize);
|
|
10015
10058
|
const sessionExists = openCodeDb.prepare("SELECT 1 FROM session WHERE id = ? LIMIT 1");
|
|
10016
10059
|
const missingSessionIds = candidates.filter((candidate) => !sessionExists.get(candidate.session_id)).map((candidate) => candidate.session_id);
|
|
10017
10060
|
const nextCursor = candidates.length < batchSize ? "" : candidates[candidates.length - 1]?.session_id ?? cursor;
|
|
@@ -10020,7 +10063,17 @@ function sweepOrphanedOpenCodeMessageIndexes(db, openReadableOpenCodeDb, options
|
|
|
10020
10063
|
let committed = false;
|
|
10021
10064
|
let deleted = 0;
|
|
10022
10065
|
try {
|
|
10023
|
-
const stillEligible = db.prepare(
|
|
10066
|
+
const stillEligible = db.prepare(`SELECT 1
|
|
10067
|
+
FROM (${candidateSourceSql}) AS session_candidates
|
|
10068
|
+
WHERE session_id = ?
|
|
10069
|
+
AND NOT EXISTS (
|
|
10070
|
+
SELECT 1
|
|
10071
|
+
FROM message_history_index
|
|
10072
|
+
WHERE message_history_index.session_id = session_candidates.session_id
|
|
10073
|
+
AND message_history_index.harness = 'opencode'
|
|
10074
|
+
AND message_history_index.updated_at > ?
|
|
10075
|
+
)
|
|
10076
|
+
LIMIT 1`);
|
|
10024
10077
|
const eligibleSessionIds = missingSessionIds.filter((sessionId) => stillEligible.get(sessionId, cutoff));
|
|
10025
10078
|
deleteSessionScopedRows(db, eligibleSessionIds, "opencode");
|
|
10026
10079
|
deleted = eligibleSessionIds.length;
|
|
@@ -11975,6 +12028,7 @@ function markNoteChecked(db, noteId) {
|
|
|
11975
12028
|
// src/features/magic-context/storage-ops.ts
|
|
11976
12029
|
var queuePendingOpStatements = new WeakMap;
|
|
11977
12030
|
var getPendingOpsStatements = new WeakMap;
|
|
12031
|
+
var getPendingOpsCountStatements = new WeakMap;
|
|
11978
12032
|
var clearPendingOpsStatements = new WeakMap;
|
|
11979
12033
|
var removePendingOpStatements = new WeakMap;
|
|
11980
12034
|
function getQueuePendingOpStatement(db) {
|
|
@@ -12035,6 +12089,19 @@ function getPendingOps(db, sessionId) {
|
|
|
12035
12089
|
const rows = getPendingOpsStatement(db).all(sessionId).filter(isPendingOpRow);
|
|
12036
12090
|
return rows.map(toPendingOp).filter((op) => op !== null);
|
|
12037
12091
|
}
|
|
12092
|
+
function getPendingOpsCount(db, sessionId) {
|
|
12093
|
+
try {
|
|
12094
|
+
let statement = getPendingOpsCountStatements.get(db);
|
|
12095
|
+
if (!statement) {
|
|
12096
|
+
statement = db.prepare("SELECT COUNT(*) AS count FROM pending_ops WHERE session_id = ?");
|
|
12097
|
+
getPendingOpsCountStatements.set(db, statement);
|
|
12098
|
+
}
|
|
12099
|
+
const row = statement.get(sessionId);
|
|
12100
|
+
return typeof row?.count === "number" && Number.isFinite(row.count) ? row.count : null;
|
|
12101
|
+
} catch {
|
|
12102
|
+
return null;
|
|
12103
|
+
}
|
|
12104
|
+
}
|
|
12038
12105
|
function clearPendingOps(db, sessionId) {
|
|
12039
12106
|
getClearPendingOpsStatement(db).run(sessionId);
|
|
12040
12107
|
}
|
|
@@ -17209,39 +17276,76 @@ function mapBackfillCandidateRows(rows) {
|
|
|
17209
17276
|
title: row.title
|
|
17210
17277
|
}));
|
|
17211
17278
|
}
|
|
17212
|
-
|
|
17213
|
-
|
|
17214
|
-
|
|
17215
|
-
|
|
17216
|
-
|
|
17217
|
-
|
|
17218
|
-
|
|
17219
|
-
|
|
17220
|
-
c.title AS title
|
|
17221
|
-
FROM compartments c
|
|
17222
|
-
JOIN session_projects sp
|
|
17223
|
-
ON sp.session_id = c.session_id
|
|
17224
|
-
AND sp.harness = c.harness
|
|
17225
|
-
AND sp.project_path = ?
|
|
17226
|
-
WHERE c.session_id = ?
|
|
17227
|
-
AND c.start_message IS NOT NULL
|
|
17228
|
-
AND c.end_message IS NOT NULL
|
|
17229
|
-
AND c.id NOT IN (${placeholders3})
|
|
17230
|
-
AND NOT EXISTS (
|
|
17231
|
-
SELECT 1
|
|
17232
|
-
FROM compartment_chunk_embeddings current
|
|
17233
|
-
WHERE current.compartment_id = c.id
|
|
17234
|
-
AND current.project_path = ?
|
|
17235
|
-
AND current.model_id = ?
|
|
17236
|
-
)
|
|
17237
|
-
ORDER BY c.start_message ASC, c.id ASC
|
|
17238
|
-
LIMIT ?`);
|
|
17239
|
-
const rows2 = stmt2.all(projectPath, sessionId, ...excludeIds, projectPath, modelId, Math.max(1, limit));
|
|
17240
|
-
return mapBackfillCandidateRows(rows2);
|
|
17279
|
+
function classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens) {
|
|
17280
|
+
const canonicalText = buildCanonicalChunkTextFromFts(db, candidate.sessionId, candidate.startMessage, candidate.endMessage) || buildCompartmentSummaryFallbackText(db, candidate.id);
|
|
17281
|
+
const windows = chunkCanonicalText(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
17282
|
+
const existing = getExistingChunkHashes(db, candidate.id, modelId, projectPath);
|
|
17283
|
+
if (windows.some((window) => !existing.has(window.windowIndex)))
|
|
17284
|
+
return "missing";
|
|
17285
|
+
if (existing.size !== windows.length || windows.some((window) => existing.get(window.windowIndex) !== window.chunkHash)) {
|
|
17286
|
+
return "stale";
|
|
17241
17287
|
}
|
|
17242
|
-
|
|
17243
|
-
|
|
17244
|
-
|
|
17288
|
+
return null;
|
|
17289
|
+
}
|
|
17290
|
+
function selectHashIncompleteChunkCandidates(db, projectPath, modelId, candidates, limit, maxInputTokens) {
|
|
17291
|
+
const missing = [];
|
|
17292
|
+
const stale = [];
|
|
17293
|
+
for (const candidate of candidates) {
|
|
17294
|
+
const defect = classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens);
|
|
17295
|
+
if (defect === "missing")
|
|
17296
|
+
missing.push(candidate);
|
|
17297
|
+
else if (defect === "stale")
|
|
17298
|
+
stale.push(candidate);
|
|
17299
|
+
}
|
|
17300
|
+
return [...missing, ...stale].slice(0, limit);
|
|
17301
|
+
}
|
|
17302
|
+
var sessionBackfillCandidateStatements = new WeakMap;
|
|
17303
|
+
function loadUnembeddedSessionChunkCandidates(db, projectPath, sessionId, modelId, limit, excludeIds, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS) {
|
|
17304
|
+
const exclusions = excludeIds && excludeIds.length > 0 ? excludeIds : [];
|
|
17305
|
+
const exclusionSql = exclusions.length > 0 ? `AND c.id NOT IN (${exclusions.map(() => "?").join(", ")})` : "";
|
|
17306
|
+
const stmt = exclusions.length > 0 ? db.prepare(`SELECT c.id AS id,
|
|
17307
|
+
c.session_id AS sessionId,
|
|
17308
|
+
c.start_message AS startMessage,
|
|
17309
|
+
c.end_message AS endMessage,
|
|
17310
|
+
c.title AS title
|
|
17311
|
+
FROM compartments c
|
|
17312
|
+
JOIN session_projects sp
|
|
17313
|
+
ON sp.session_id = c.session_id
|
|
17314
|
+
AND sp.harness = c.harness
|
|
17315
|
+
AND sp.project_path = ?
|
|
17316
|
+
WHERE c.session_id = ?
|
|
17317
|
+
AND c.start_message IS NOT NULL
|
|
17318
|
+
AND c.end_message IS NOT NULL
|
|
17319
|
+
${exclusionSql}
|
|
17320
|
+
ORDER BY c.start_message ASC, c.id ASC`) : (() => {
|
|
17321
|
+
let cached = sessionBackfillCandidateStatements.get(db);
|
|
17322
|
+
if (!cached) {
|
|
17323
|
+
cached = db.prepare(`SELECT c.id AS id,
|
|
17324
|
+
c.session_id AS sessionId,
|
|
17325
|
+
c.start_message AS startMessage,
|
|
17326
|
+
c.end_message AS endMessage,
|
|
17327
|
+
c.title AS title
|
|
17328
|
+
FROM compartments c
|
|
17329
|
+
JOIN session_projects sp
|
|
17330
|
+
ON sp.session_id = c.session_id
|
|
17331
|
+
AND sp.harness = c.harness
|
|
17332
|
+
AND sp.project_path = ?
|
|
17333
|
+
WHERE c.session_id = ?
|
|
17334
|
+
AND c.start_message IS NOT NULL
|
|
17335
|
+
AND c.end_message IS NOT NULL
|
|
17336
|
+
ORDER BY c.start_message ASC, c.id ASC`);
|
|
17337
|
+
sessionBackfillCandidateStatements.set(db, cached);
|
|
17338
|
+
}
|
|
17339
|
+
return cached;
|
|
17340
|
+
})();
|
|
17341
|
+
const rows = stmt.all(projectPath, sessionId, ...exclusions);
|
|
17342
|
+
return selectHashIncompleteChunkCandidates(db, projectPath, modelId, mapBackfillCandidateRows(rows), Math.max(1, limit), maxInputTokens);
|
|
17343
|
+
}
|
|
17344
|
+
function countUnembeddedSessionCompartments(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS) {
|
|
17345
|
+
return loadUnembeddedSessionChunkCandidates(db, projectPath, sessionId, modelId, Number.MAX_SAFE_INTEGER, undefined, maxInputTokens).length;
|
|
17346
|
+
}
|
|
17347
|
+
function countSessionCompartmentEmbedCoverage(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS) {
|
|
17348
|
+
const rows = db.prepare(`SELECT c.id AS id,
|
|
17245
17349
|
c.session_id AS sessionId,
|
|
17246
17350
|
c.start_message AS startMessage,
|
|
17247
17351
|
c.end_message AS endMessage,
|
|
@@ -17254,60 +17358,15 @@ function loadUnembeddedSessionChunkCandidates(db, projectPath, sessionId, modelI
|
|
|
17254
17358
|
WHERE c.session_id = ?
|
|
17255
17359
|
AND c.start_message IS NOT NULL
|
|
17256
17360
|
AND c.end_message IS NOT NULL
|
|
17257
|
-
|
|
17258
|
-
|
|
17259
|
-
|
|
17260
|
-
|
|
17261
|
-
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
ORDER BY c.start_message ASC, c.id ASC
|
|
17265
|
-
LIMIT ?`);
|
|
17266
|
-
sessionBackfillCandidateStatements.set(db, stmt);
|
|
17361
|
+
ORDER BY c.start_message ASC, c.id ASC`).all(projectPath, sessionId);
|
|
17362
|
+
const candidates = mapBackfillCandidateRows(rows);
|
|
17363
|
+
let embedded = 0;
|
|
17364
|
+
for (const candidate of candidates) {
|
|
17365
|
+
if (classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens) === null) {
|
|
17366
|
+
embedded += 1;
|
|
17367
|
+
}
|
|
17267
17368
|
}
|
|
17268
|
-
|
|
17269
|
-
return mapBackfillCandidateRows(rows);
|
|
17270
|
-
}
|
|
17271
|
-
function countUnembeddedSessionCompartments(db, projectPath, sessionId, modelId) {
|
|
17272
|
-
const row = db.prepare(`SELECT COUNT(*) AS n
|
|
17273
|
-
FROM compartments c
|
|
17274
|
-
JOIN session_projects sp
|
|
17275
|
-
ON sp.session_id = c.session_id
|
|
17276
|
-
AND sp.harness = c.harness
|
|
17277
|
-
AND sp.project_path = ?
|
|
17278
|
-
WHERE c.session_id = ?
|
|
17279
|
-
AND c.start_message IS NOT NULL
|
|
17280
|
-
AND c.end_message IS NOT NULL
|
|
17281
|
-
AND NOT EXISTS (
|
|
17282
|
-
SELECT 1
|
|
17283
|
-
FROM compartment_chunk_embeddings current
|
|
17284
|
-
WHERE current.compartment_id = c.id
|
|
17285
|
-
AND current.project_path = ?
|
|
17286
|
-
AND current.model_id = ?
|
|
17287
|
-
)`).get(projectPath, sessionId, projectPath, modelId);
|
|
17288
|
-
return typeof row?.n === "number" ? row.n : 0;
|
|
17289
|
-
}
|
|
17290
|
-
function countSessionCompartmentEmbedCoverage(db, projectPath, sessionId, modelId) {
|
|
17291
|
-
const row = db.prepare(`SELECT
|
|
17292
|
-
COUNT(*) AS total,
|
|
17293
|
-
SUM(CASE WHEN EXISTS (
|
|
17294
|
-
SELECT 1 FROM compartment_chunk_embeddings e
|
|
17295
|
-
WHERE e.compartment_id = c.id
|
|
17296
|
-
AND e.project_path = ?
|
|
17297
|
-
AND e.model_id = ?
|
|
17298
|
-
) THEN 1 ELSE 0 END) AS embedded
|
|
17299
|
-
FROM compartments c
|
|
17300
|
-
JOIN session_projects sp
|
|
17301
|
-
ON sp.session_id = c.session_id
|
|
17302
|
-
AND sp.harness = c.harness
|
|
17303
|
-
AND sp.project_path = ?
|
|
17304
|
-
WHERE c.session_id = ?
|
|
17305
|
-
AND c.start_message IS NOT NULL
|
|
17306
|
-
AND c.end_message IS NOT NULL`).get(projectPath, modelId, projectPath, sessionId);
|
|
17307
|
-
return {
|
|
17308
|
-
total: typeof row?.total === "number" ? row.total : 0,
|
|
17309
|
-
embedded: typeof row?.embedded === "number" ? row.embedded : 0
|
|
17310
|
-
};
|
|
17369
|
+
return { embedded, total: candidates.length };
|
|
17311
17370
|
}
|
|
17312
17371
|
|
|
17313
17372
|
// src/features/magic-context/project-embedding-registry.ts
|
|
@@ -32012,6 +32071,7 @@ var BaseEmbeddingConfigSchema = exports_external.object({
|
|
|
32012
32071
|
query_input_type: exports_external.string().optional().describe("Optional input_type for query (search) embeddings on asymmetric models (e.g. NVIDIA NIM 'query'). When unset, query embeddings use embedding.input_type. Passage/stored content always uses embedding.input_type."),
|
|
32013
32072
|
truncate: exports_external.string().optional().describe("Optional truncate mode sent in the embedding request body (e.g. NVIDIA NIM accepts 'NONE' | 'START' | 'END'). Omitted from the request when unset."),
|
|
32014
32073
|
max_input_tokens: exports_external.number().int().positive().optional().describe("Optional maximum input tokens for chunk embeddings. Defaults conservatively to 512 when omitted."),
|
|
32074
|
+
local_runtime: exports_external.enum(["auto", "native", "wasm"]).default("auto").describe("Local provider only: ONNX runtime selection. 'auto' uses native under Node and uses WASM under Bun versions before 1.4.0, where Bun's NAPI teardown race can panic on quit; native is restored automatically on Bun 1.4.0+. Set 'native' only to prefer speed while accepting that pre-1.4.0 Bun crash risk, or 'wasm' to avoid loading the native addon."),
|
|
32015
32075
|
local_dtype: exports_external.enum([
|
|
32016
32076
|
"auto",
|
|
32017
32077
|
"fp32",
|
|
@@ -32068,6 +32128,7 @@ var EmbeddingConfigSchema = BaseEmbeddingConfigSchema.transform((data) => {
|
|
|
32068
32128
|
return {
|
|
32069
32129
|
provider: "local",
|
|
32070
32130
|
model: data.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
32131
|
+
local_runtime: data.local_runtime,
|
|
32071
32132
|
...data.max_input_tokens ? { max_input_tokens: data.max_input_tokens } : {},
|
|
32072
32133
|
...data.local_dtype ? { local_dtype: data.local_dtype } : {}
|
|
32073
32134
|
};
|
|
@@ -32148,7 +32209,8 @@ var MagicContextConfigSchema = exports_external.object({
|
|
|
32148
32209
|
}).default({ enforce_private_permissions: true }).describe("Storage permission policy. The default keeps session content and memories owner-private. Disabling enforcement is for trusted shared-group storage managed externally; every group member able to read the storage can read all stored session content and memories."),
|
|
32149
32210
|
embedding: EmbeddingConfigSchema.default({
|
|
32150
32211
|
provider: "local",
|
|
32151
|
-
model: DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
32212
|
+
model: DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
32213
|
+
local_runtime: "auto"
|
|
32152
32214
|
}).describe("Embedding provider configuration"),
|
|
32153
32215
|
subc: exports_external.object({
|
|
32154
32216
|
connection_file: exports_external.string().trim().min(1).transform(expandConfigPath).describe("Path to the owner-only subc connection file.")
|
|
@@ -33890,21 +33952,28 @@ var SYNAPSE_DEFAULT_MODEL = "gte-modernbert-base-f16";
|
|
|
33890
33952
|
var SYNAPSE_MAX_INPUT_TOKENS = 8192;
|
|
33891
33953
|
var SYNAPSE_DEFAULT_QUERY_TIMEOUT_MS = 3000;
|
|
33892
33954
|
var SYNAPSE_DEFAULT_BATCH_TIMEOUT_MS = 120000;
|
|
33955
|
+
var SYNAPSE_CERTIFICATION_REFUSAL_REASONS = new Set([
|
|
33956
|
+
"not_certified",
|
|
33957
|
+
"probe_required",
|
|
33958
|
+
"migration_required"
|
|
33959
|
+
]);
|
|
33893
33960
|
|
|
33894
33961
|
class SynapseEmbeddingError extends Error {
|
|
33895
33962
|
code;
|
|
33896
33963
|
retryAfterMs;
|
|
33897
33964
|
permanent;
|
|
33965
|
+
refusalReason;
|
|
33898
33966
|
constructor(code, message, options) {
|
|
33899
33967
|
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
33900
33968
|
this.name = "SynapseEmbeddingError";
|
|
33901
33969
|
this.code = code;
|
|
33902
33970
|
this.permanent = options?.permanent ?? isPermanentSynapseCode(code);
|
|
33903
33971
|
this.retryAfterMs = options?.retryAfterMs ?? (this.permanent ? undefined : 100);
|
|
33972
|
+
this.refusalReason = options?.refusalReason;
|
|
33904
33973
|
}
|
|
33905
33974
|
}
|
|
33906
33975
|
function isPermanentSynapseCode(code) {
|
|
33907
|
-
return code === "artifact_invalid" || code === "substitution_rejected" || code === "not_certified" || code === "probe_required" || code === "idempotency_conflict" || code === "schema_violation";
|
|
33976
|
+
return code === "artifact_invalid" || code === "substitution_rejected" || code === "not_certified" || code === "probe_required" || code === "idempotency_conflict" || code === "schema_violation" || code === "certification_refused" || code === "needs_reauth";
|
|
33908
33977
|
}
|
|
33909
33978
|
function asRecord(value) {
|
|
33910
33979
|
return value !== null && typeof value === "object" ? value : null;
|
|
@@ -33930,11 +33999,21 @@ function readErrorCode(value) {
|
|
|
33930
33999
|
}
|
|
33931
34000
|
return;
|
|
33932
34001
|
}
|
|
34002
|
+
function readCertificationRefusalReason(value) {
|
|
34003
|
+
if (!(value instanceof SubcCallError))
|
|
34004
|
+
return;
|
|
34005
|
+
const detail = value.detail;
|
|
34006
|
+
if (typeof detail === "string")
|
|
34007
|
+
return detail;
|
|
34008
|
+
const record2 = asRecord(detail);
|
|
34009
|
+
return typeof record2?.reason === "string" ? record2.reason : undefined;
|
|
34010
|
+
}
|
|
33933
34011
|
function classifyError(value) {
|
|
33934
34012
|
if (value instanceof SynapseEmbeddingError)
|
|
33935
34013
|
return value;
|
|
33936
34014
|
const code = readErrorCode(value) ?? (value instanceof Error ? value.name : "transport");
|
|
33937
34015
|
const normalized = code.toLowerCase();
|
|
34016
|
+
const refusalReason = readCertificationRefusalReason(value);
|
|
33938
34017
|
let mapped = "transport";
|
|
33939
34018
|
if (normalized.includes("queue_full"))
|
|
33940
34019
|
mapped = "queue_full";
|
|
@@ -33946,12 +34025,16 @@ function classifyError(value) {
|
|
|
33946
34025
|
mapped = "artifact_invalid";
|
|
33947
34026
|
else if (normalized.includes("substitution"))
|
|
33948
34027
|
mapped = "substitution_rejected";
|
|
34028
|
+
else if (normalized === "certification_refused")
|
|
34029
|
+
mapped = "certification_refused";
|
|
33949
34030
|
else if (normalized.includes("not_certified"))
|
|
33950
34031
|
mapped = "not_certified";
|
|
33951
34032
|
else if (normalized.includes("probe_required"))
|
|
33952
34033
|
mapped = "probe_required";
|
|
33953
34034
|
else if (normalized.includes("idempotency_conflict"))
|
|
33954
34035
|
mapped = "idempotency_conflict";
|
|
34036
|
+
else if (normalized.includes("needs_reauth"))
|
|
34037
|
+
mapped = "needs_reauth";
|
|
33955
34038
|
else if (normalized.includes("schema"))
|
|
33956
34039
|
mapped = "schema_violation";
|
|
33957
34040
|
else if (normalized.includes("module_restarted") || normalized.includes("module restarted"))
|
|
@@ -33959,9 +34042,41 @@ function classifyError(value) {
|
|
|
33959
34042
|
const message = value instanceof Error ? value.message : String(value);
|
|
33960
34043
|
return new SynapseEmbeddingError(mapped, message, {
|
|
33961
34044
|
retryAfterMs: readRetryAfter(value) ?? (isPermanentSynapseCode(mapped) ? undefined : 100),
|
|
33962
|
-
cause: value
|
|
34045
|
+
cause: value,
|
|
34046
|
+
refusalReason
|
|
33963
34047
|
});
|
|
33964
34048
|
}
|
|
34049
|
+
function embeddingFailureFor(error51) {
|
|
34050
|
+
const typedReason = error51.refusalReason;
|
|
34051
|
+
if (typedReason !== undefined && SYNAPSE_CERTIFICATION_REFUSAL_REASONS.has(typedReason) || error51.code === "not_certified" || error51.code === "probe_required") {
|
|
34052
|
+
return {
|
|
34053
|
+
class: "certification_refusal",
|
|
34054
|
+
reason: `SYNAPSE certification refused embedding: ${typedReason ?? error51.code}`,
|
|
34055
|
+
retryable: false
|
|
34056
|
+
};
|
|
34057
|
+
}
|
|
34058
|
+
if (error51.code === "certification_refused") {
|
|
34059
|
+
return {
|
|
34060
|
+
class: "certification_refusal",
|
|
34061
|
+
reason: `SYNAPSE certification refused embedding: ${typedReason ?? "unknown reason"}`,
|
|
34062
|
+
retryable: false
|
|
34063
|
+
};
|
|
34064
|
+
}
|
|
34065
|
+
if (typedReason === "needs_reauth" || typedReason === "needs_reauth_expired") {
|
|
34066
|
+
return {
|
|
34067
|
+
class: "credential_required",
|
|
34068
|
+
reason: "SYNAPSE requires reauthentication",
|
|
34069
|
+
retryable: false
|
|
34070
|
+
};
|
|
34071
|
+
}
|
|
34072
|
+
if (error51.code === "substitution_rejected") {
|
|
34073
|
+
return { class: "substitution_rejected", reason: error51.message, retryable: false };
|
|
34074
|
+
}
|
|
34075
|
+
if (error51.code === "schema_violation" || error51.code === "artifact_invalid") {
|
|
34076
|
+
return { class: "invalid_envelope", reason: error51.message, retryable: false };
|
|
34077
|
+
}
|
|
34078
|
+
return { class: "transport_error", reason: error51.message, retryable: !error51.permanent };
|
|
34079
|
+
}
|
|
33965
34080
|
function wait(ms) {
|
|
33966
34081
|
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
33967
34082
|
}
|
|
@@ -34081,6 +34196,7 @@ class SynapseEmbeddingProvider {
|
|
|
34081
34196
|
initialized = false;
|
|
34082
34197
|
initializing = null;
|
|
34083
34198
|
permanentFailure = false;
|
|
34199
|
+
lastFailureReason = null;
|
|
34084
34200
|
batchLimit = 16;
|
|
34085
34201
|
tokenBudget = null;
|
|
34086
34202
|
constructor(options) {
|
|
@@ -34155,9 +34271,11 @@ class SynapseEmbeddingProvider {
|
|
|
34155
34271
|
this.tokenBudget = metadata.recommended_token_budget ?? this.tokenBudget;
|
|
34156
34272
|
}
|
|
34157
34273
|
this.initialized = true;
|
|
34274
|
+
this.recordSuccess();
|
|
34158
34275
|
return true;
|
|
34159
34276
|
} catch (error51) {
|
|
34160
34277
|
const classified = classifyError(error51);
|
|
34278
|
+
this.recordFailure(classified);
|
|
34161
34279
|
if (classified.permanent) {
|
|
34162
34280
|
this.permanentFailure = true;
|
|
34163
34281
|
log(`[magic-context] Synapse lane disabled: ${classified.code}: ${classified.message}`);
|
|
@@ -34184,6 +34302,7 @@ class SynapseEmbeddingProvider {
|
|
|
34184
34302
|
if (!extracted)
|
|
34185
34303
|
throw new SynapseEmbeddingError("schema_violation", "Synapse query returned no vector");
|
|
34186
34304
|
this.validateResponse(extracted.metadata, extracted.vector.length);
|
|
34305
|
+
this.recordSuccess();
|
|
34187
34306
|
return extracted.vector;
|
|
34188
34307
|
} catch (error51) {
|
|
34189
34308
|
this.logCallFailure(error51, "embed.query");
|
|
@@ -34247,6 +34366,7 @@ class SynapseEmbeddingProvider {
|
|
|
34247
34366
|
const vectorArray = Float32Array.from(vector);
|
|
34248
34367
|
this.validateResponse({ ...batchEnvelope, ...item }, vectorArray.length);
|
|
34249
34368
|
output.set(id, vectorArray);
|
|
34369
|
+
this.recordSuccess();
|
|
34250
34370
|
}
|
|
34251
34371
|
} catch (error51) {
|
|
34252
34372
|
const classified = classifyError(error51);
|
|
@@ -34269,6 +34389,9 @@ class SynapseEmbeddingProvider {
|
|
|
34269
34389
|
isLoaded() {
|
|
34270
34390
|
return this.initialized;
|
|
34271
34391
|
}
|
|
34392
|
+
getLastFailureReason() {
|
|
34393
|
+
return this.lastFailureReason;
|
|
34394
|
+
}
|
|
34272
34395
|
requestConstraints(extra) {
|
|
34273
34396
|
const metadata = this.metadata;
|
|
34274
34397
|
if (!metadata)
|
|
@@ -34386,11 +34509,18 @@ class SynapseEmbeddingProvider {
|
|
|
34386
34509
|
}
|
|
34387
34510
|
logCallFailure(error51, operation) {
|
|
34388
34511
|
const classified = classifyError(error51);
|
|
34512
|
+
this.recordFailure(classified);
|
|
34389
34513
|
if (classified.permanent)
|
|
34390
34514
|
this.permanentFailure = true;
|
|
34391
34515
|
const suffix = classified.retryAfterMs === undefined ? "" : ` retry_after_ms=${classified.retryAfterMs}`;
|
|
34392
34516
|
log(`[magic-context] Synapse ${operation} failed: ${classified.code}${suffix}: ${classified.message}`);
|
|
34393
34517
|
}
|
|
34518
|
+
recordFailure(error51) {
|
|
34519
|
+
this.lastFailureReason = embeddingFailureFor(error51);
|
|
34520
|
+
}
|
|
34521
|
+
recordSuccess() {
|
|
34522
|
+
this.lastFailureReason = null;
|
|
34523
|
+
}
|
|
34394
34524
|
}
|
|
34395
34525
|
|
|
34396
34526
|
// src/features/magic-context/memory/embedding-identity.ts
|
|
@@ -34434,6 +34564,32 @@ import { chmodSync as chmodSync2, mkdirSync as mkdirSync3 } from "node:fs";
|
|
|
34434
34564
|
import { open, stat, unlink, writeFile } from "node:fs/promises";
|
|
34435
34565
|
import { dirname as dirname5, join as join6 } from "node:path";
|
|
34436
34566
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
34567
|
+
var BUN_NAPI_TEARDOWN_FIX_VERSION = [1, 4, 0];
|
|
34568
|
+
function currentLocalEmbeddingHost() {
|
|
34569
|
+
const bun = globalThis.Bun;
|
|
34570
|
+
const bunVersion = typeof process !== "undefined" && typeof process.versions?.bun === "string" ? process.versions.bun : undefined;
|
|
34571
|
+
return {
|
|
34572
|
+
isElectron: typeof process !== "undefined" && Boolean(process.versions?.electron),
|
|
34573
|
+
isBun: Boolean(bun) || Boolean(bunVersion),
|
|
34574
|
+
bunVersion
|
|
34575
|
+
};
|
|
34576
|
+
}
|
|
34577
|
+
function bunHasNapiTeardownFix(version2) {
|
|
34578
|
+
const match = version2?.match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);
|
|
34579
|
+
if (!match || match[4])
|
|
34580
|
+
return false;
|
|
34581
|
+
const parsed = [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
34582
|
+
return parsed.some((part) => !Number.isSafeInteger(part)) ? false : parsed[0] > BUN_NAPI_TEARDOWN_FIX_VERSION[0] || parsed[0] === BUN_NAPI_TEARDOWN_FIX_VERSION[0] && (parsed[1] > BUN_NAPI_TEARDOWN_FIX_VERSION[1] || parsed[1] === BUN_NAPI_TEARDOWN_FIX_VERSION[1] && parsed[2] >= BUN_NAPI_TEARDOWN_FIX_VERSION[2]);
|
|
34583
|
+
}
|
|
34584
|
+
function resolveLocalEmbeddingRuntime(preference = "auto", host = currentLocalEmbeddingHost()) {
|
|
34585
|
+
if (preference === "native" || preference === "wasm")
|
|
34586
|
+
return preference;
|
|
34587
|
+
if (host.isElectron)
|
|
34588
|
+
return "electron";
|
|
34589
|
+
if (host.isBun && !bunHasNapiTeardownFix(host.bunVersion))
|
|
34590
|
+
return "wasm";
|
|
34591
|
+
return "native";
|
|
34592
|
+
}
|
|
34437
34593
|
var LOCK_POLL_MS = 150;
|
|
34438
34594
|
var STALE_LOCK_MS = 3 * 60000;
|
|
34439
34595
|
var MAX_LOCK_WAIT_MS = 5 * 60000;
|
|
@@ -34487,20 +34643,21 @@ function startLockHeartbeat(lockPath) {
|
|
|
34487
34643
|
}
|
|
34488
34644
|
var localEmbeddingRuntimeMode = "native";
|
|
34489
34645
|
var wasmRuntimeInjected = false;
|
|
34490
|
-
var
|
|
34646
|
+
var localEmbeddingHostForRuntime = currentLocalEmbeddingHost;
|
|
34491
34647
|
var importWasmOrtForRuntime = async () => {
|
|
34492
|
-
const
|
|
34493
|
-
|
|
34648
|
+
const { createRequire: createRequireFn } = await import("node:module");
|
|
34649
|
+
const requireFn = createRequireFn(import.meta.url);
|
|
34650
|
+
const ortEntry = requireFn.resolve("onnxruntime-web");
|
|
34651
|
+
return {
|
|
34652
|
+
module: await import("onnxruntime-web"),
|
|
34653
|
+
entryPath: ortEntry
|
|
34654
|
+
};
|
|
34494
34655
|
};
|
|
34495
34656
|
var importTransformersForRuntime = async () => {
|
|
34496
|
-
|
|
34497
|
-
return await import(transformersSpec);
|
|
34657
|
+
return await import("./transformers.node-b1wa0hgx.js");
|
|
34498
34658
|
};
|
|
34499
34659
|
var importTransformersWasmFallbackForRuntime = async () => {
|
|
34500
|
-
const
|
|
34501
|
-
const requireFn = createRequireFn(import.meta.url);
|
|
34502
|
-
const nodeEntry = requireFn.resolve("@huggingface/transformers");
|
|
34503
|
-
const webEntry = pathToFileURL2(join6(dirname5(nodeEntry), "transformers.web.js")).href;
|
|
34660
|
+
const webEntry = new URL("./transformers-web.js", import.meta.url).href;
|
|
34504
34661
|
return await import(webEntry);
|
|
34505
34662
|
};
|
|
34506
34663
|
var modelCacheDirForRuntime = () => join6(getMagicContextStorageDir(), "models");
|
|
@@ -34518,17 +34675,9 @@ async function injectWasmOrt() {
|
|
|
34518
34675
|
if (wasmRuntimeInjected)
|
|
34519
34676
|
return true;
|
|
34520
34677
|
try {
|
|
34521
|
-
const ortWeb = await importWasmOrtForRuntime();
|
|
34522
|
-
|
|
34523
|
-
|
|
34524
|
-
const requireFn = createRequireFn(import.meta.url);
|
|
34525
|
-
const mainEntry = requireFn.resolve("onnxruntime-web");
|
|
34526
|
-
const distDir = dirname5(mainEntry);
|
|
34527
|
-
if (ortWeb.env?.wasm) {
|
|
34528
|
-
ortWeb.env.wasm.wasmPaths = `${pathToFileURL2(distDir).href}/`;
|
|
34529
|
-
}
|
|
34530
|
-
} catch (pathError) {
|
|
34531
|
-
log("[magic-context] could not resolve local onnxruntime-web/dist, falling back to default WASM paths:", pathError instanceof Error ? pathError.message : String(pathError));
|
|
34678
|
+
const { module: ortWeb, entryPath } = await importWasmOrtForRuntime();
|
|
34679
|
+
if (ortWeb.env?.wasm) {
|
|
34680
|
+
ortWeb.env.wasm.wasmPaths = `${pathToFileURL2(dirname5(entryPath)).href}/`;
|
|
34532
34681
|
}
|
|
34533
34682
|
globalThis[Symbol.for("onnxruntime")] = ortWeb;
|
|
34534
34683
|
wasmRuntimeInjected = true;
|
|
@@ -34555,10 +34704,18 @@ function disableLocalEmbeddingsAfterRuntimeFailure(detail) {
|
|
|
34555
34704
|
localEmbeddingRuntimeMode = "disabled";
|
|
34556
34705
|
logForRuntime(`[magic-context] local embeddings are disabled because both the onnxruntime-node native binding and the onnxruntime-web (WASM) fallback failed to load. Native failure: ${detail}. Run \`npx @cortexkit/magic-context@latest doctor\` for repair guidance (use \`doctor --force\` to reinstall cached plugin packages), or configure an \`openai-compatible\` embedding HTTP endpoint. Existing memories are unaffected.`);
|
|
34557
34706
|
}
|
|
34558
|
-
async function loadTransformersForLocalEmbedding() {
|
|
34707
|
+
async function loadTransformersForLocalEmbedding(runtimePreference) {
|
|
34559
34708
|
if (localEmbeddingRuntimeMode === "disabled") {
|
|
34560
34709
|
throw new Error("local embedding runtime is disabled");
|
|
34561
34710
|
}
|
|
34711
|
+
const resolvedRuntime = resolveLocalEmbeddingRuntime(runtimePreference, localEmbeddingHostForRuntime());
|
|
34712
|
+
if (resolvedRuntime === "wasm") {
|
|
34713
|
+
if (!await ensureWasmOrtInjected()) {
|
|
34714
|
+
disableLocalEmbeddingsAfterRuntimeFailure("the selected WASM runtime is unavailable");
|
|
34715
|
+
throw new Error("onnxruntime-web failed to load");
|
|
34716
|
+
}
|
|
34717
|
+
return { module: await importTransformersForRuntime(), usesWasm: true };
|
|
34718
|
+
}
|
|
34562
34719
|
if (localEmbeddingRuntimeMode === "wasm") {
|
|
34563
34720
|
if (!await ensureWasmOrtInjected()) {
|
|
34564
34721
|
disableLocalEmbeddingsAfterRuntimeFailure("the previously selected WASM runtime is unavailable");
|
|
@@ -34571,7 +34728,7 @@ async function loadTransformersForLocalEmbedding() {
|
|
|
34571
34728
|
throw wasmError;
|
|
34572
34729
|
}
|
|
34573
34730
|
}
|
|
34574
|
-
const electron =
|
|
34731
|
+
const electron = resolvedRuntime === "electron";
|
|
34575
34732
|
if (electron) {
|
|
34576
34733
|
const wasInjected = wasmRuntimeInjected;
|
|
34577
34734
|
if (await ensureWasmOrtInjected()) {
|
|
@@ -34627,6 +34784,8 @@ function isNativeRuntimeMissingError(error51) {
|
|
|
34627
34784
|
if (code === "ERR_DLOPEN_FAILED" && lower.includes("onnxruntime")) {
|
|
34628
34785
|
return true;
|
|
34629
34786
|
}
|
|
34787
|
+
if (lower.includes('could not load the "sharp" module'))
|
|
34788
|
+
return true;
|
|
34630
34789
|
const mentionsNativeRuntime = lower.includes("onnxruntime-node") || lower.includes("onnxruntime_binding");
|
|
34631
34790
|
if (!mentionsNativeRuntime)
|
|
34632
34791
|
return false;
|
|
@@ -34679,19 +34838,22 @@ class LocalEmbeddingProvider {
|
|
|
34679
34838
|
maxInputTokens;
|
|
34680
34839
|
model;
|
|
34681
34840
|
dtype;
|
|
34841
|
+
runtimePreference;
|
|
34682
34842
|
pipeline = null;
|
|
34683
34843
|
initPromise = null;
|
|
34684
34844
|
inFlight = 0;
|
|
34685
34845
|
disposing = false;
|
|
34686
34846
|
disposePromise = null;
|
|
34687
34847
|
inFlightWaiters = [];
|
|
34688
|
-
constructor(model = DEFAULT_LOCAL_EMBEDDING_MODEL, maxInputTokens = 512, dtype = DEFAULT_LOCAL_DTYPE) {
|
|
34848
|
+
constructor(model = DEFAULT_LOCAL_EMBEDDING_MODEL, maxInputTokens = 512, dtype = DEFAULT_LOCAL_DTYPE, runtimePreference = "auto") {
|
|
34689
34849
|
this.model = model;
|
|
34690
34850
|
this.maxInputTokens = maxInputTokens;
|
|
34691
34851
|
this.dtype = dtype || DEFAULT_LOCAL_DTYPE;
|
|
34852
|
+
this.runtimePreference = runtimePreference;
|
|
34692
34853
|
this.modelId = getEmbeddingProviderIdentity({
|
|
34693
34854
|
provider: "local",
|
|
34694
34855
|
model,
|
|
34856
|
+
local_runtime: runtimePreference,
|
|
34695
34857
|
...dtype && dtype !== DEFAULT_LOCAL_DTYPE ? { local_dtype: dtype } : {}
|
|
34696
34858
|
});
|
|
34697
34859
|
}
|
|
@@ -34714,7 +34876,7 @@ class LocalEmbeddingProvider {
|
|
|
34714
34876
|
if (this.disposing) {
|
|
34715
34877
|
return;
|
|
34716
34878
|
}
|
|
34717
|
-
const { module: transformersModule, usesWasm } = await loadTransformersForLocalEmbedding();
|
|
34879
|
+
const { module: transformersModule, usesWasm } = await loadTransformersForLocalEmbedding(this.runtimePreference);
|
|
34718
34880
|
const env = transformersModule.env;
|
|
34719
34881
|
const LogLevel = transformersModule.LogLevel;
|
|
34720
34882
|
if (LogLevel && "ERROR" in LogLevel) {
|
|
@@ -34782,7 +34944,7 @@ class LocalEmbeddingProvider {
|
|
|
34782
34944
|
if (!localEmbeddingRuntimeIsDisabled() && isNativeRuntimeMissingError(error51)) {
|
|
34783
34945
|
disableLocalEmbeddingsAfterRuntimeFailure(error51 instanceof Error ? error51.message : String(error51));
|
|
34784
34946
|
} else if (!localEmbeddingRuntimeIsDisabled()) {
|
|
34785
|
-
|
|
34947
|
+
logForRuntime("[magic-context] embedding model failed to load:", error51);
|
|
34786
34948
|
}
|
|
34787
34949
|
this.pipeline = null;
|
|
34788
34950
|
} finally {
|
|
@@ -35452,6 +35614,7 @@ function resolveEmbeddingConfig(config2) {
|
|
|
35452
35614
|
return {
|
|
35453
35615
|
provider: "local",
|
|
35454
35616
|
model: config2?.model?.trim() || DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
35617
|
+
local_runtime: config2?.local_runtime ?? "auto",
|
|
35455
35618
|
...config2?.max_input_tokens ? {
|
|
35456
35619
|
max_input_tokens: normalizeCompartmentChunkMaxInputTokens(config2.max_input_tokens)
|
|
35457
35620
|
} : {},
|
|
@@ -35517,7 +35680,7 @@ function createProvider(config2, context) {
|
|
|
35517
35680
|
});
|
|
35518
35681
|
}
|
|
35519
35682
|
if (config2.provider === "local") {
|
|
35520
|
-
return new LocalEmbeddingProvider(config2.model, config2.max_input_tokens, config2.local_dtype);
|
|
35683
|
+
return new LocalEmbeddingProvider(config2.model, config2.max_input_tokens, config2.local_dtype, config2.local_runtime);
|
|
35521
35684
|
}
|
|
35522
35685
|
if (config2.provider === "synapse") {
|
|
35523
35686
|
const synapse = config2;
|
|
@@ -36004,15 +36167,25 @@ function shadowBackfillMissingBase(scope, primaryModelId, shadowModelId, project
|
|
|
36004
36167
|
};
|
|
36005
36168
|
}
|
|
36006
36169
|
return {
|
|
36007
|
-
sql: `SELECT
|
|
36170
|
+
sql: `SELECT cp.compartment_id AS id,
|
|
36171
|
+
MIN(CASE WHEN NOT EXISTS (
|
|
36172
|
+
SELECT 1 FROM compartment_chunk_embeddings same_key
|
|
36173
|
+
WHERE same_key.compartment_id = cp.compartment_id
|
|
36174
|
+
AND same_key.window_index = cp.window_index
|
|
36175
|
+
AND same_key.model_id = ?
|
|
36176
|
+
) THEN 0 ELSE 1 END) AS defect_order
|
|
36008
36177
|
FROM compartment_chunk_embeddings cp
|
|
36009
36178
|
WHERE cp.project_path = ? AND cp.model_id = ?
|
|
36010
36179
|
AND NOT EXISTS (
|
|
36011
|
-
SELECT 1 FROM compartment_chunk_embeddings
|
|
36012
|
-
WHERE
|
|
36013
|
-
|
|
36014
|
-
|
|
36015
|
-
|
|
36180
|
+
SELECT 1 FROM compartment_chunk_embeddings current
|
|
36181
|
+
WHERE current.compartment_id = cp.compartment_id
|
|
36182
|
+
AND current.window_index = cp.window_index
|
|
36183
|
+
AND current.chunk_hash = cp.chunk_hash
|
|
36184
|
+
AND current.model_id = ?
|
|
36185
|
+
)
|
|
36186
|
+
GROUP BY cp.compartment_id`,
|
|
36187
|
+
params: [shadowModelId, projectIdentity, primaryModelId, shadowModelId],
|
|
36188
|
+
orderBy: " ORDER BY defect_order ASC, cp.compartment_id ASC"
|
|
36016
36189
|
};
|
|
36017
36190
|
}
|
|
36018
36191
|
function shadowBackfillMissingIds(db, projectIdentity, scope, primaryModelId, shadowModelId, limit) {
|
|
@@ -36628,7 +36801,8 @@ async function embedSessionCompartmentChunks(db, projectIdentity, sessionId, opt
|
|
|
36628
36801
|
return { status: "disabled", embedded: 0, total: 0 };
|
|
36629
36802
|
}
|
|
36630
36803
|
recordSessionProjectIdentity(db, sessionId, projectIdentity);
|
|
36631
|
-
const
|
|
36804
|
+
const maxInputTokens = getProjectEmbeddingMaxInputTokens(projectIdentity);
|
|
36805
|
+
const total = countUnembeddedSessionCompartments(db, projectIdentity, sessionId, snapshot2.chunkModelId, maxInputTokens);
|
|
36632
36806
|
if (total === 0)
|
|
36633
36807
|
return { status: "nothing", embedded: 0, total: 0 };
|
|
36634
36808
|
const holderId = `session-embed-${randomUUID2()}`;
|
|
@@ -36666,7 +36840,7 @@ async function embedSessionCompartmentChunks(db, projectIdentity, sessionId, opt
|
|
|
36666
36840
|
aborted2 = true;
|
|
36667
36841
|
break;
|
|
36668
36842
|
}
|
|
36669
|
-
const candidates = loadUnembeddedSessionChunkCandidates(db, projectIdentity, sessionId, snapshot2.chunkModelId, batchSize, [...skipIds, ...failedIds]);
|
|
36843
|
+
const candidates = loadUnembeddedSessionChunkCandidates(db, projectIdentity, sessionId, snapshot2.chunkModelId, batchSize, [...skipIds, ...failedIds], maxInputTokens);
|
|
36670
36844
|
if (candidates.length === 0)
|
|
36671
36845
|
break;
|
|
36672
36846
|
const {
|
|
@@ -36711,7 +36885,7 @@ async function embedSessionCompartmentChunks(db, projectIdentity, sessionId, opt
|
|
|
36711
36885
|
if (aborted2)
|
|
36712
36886
|
return { status: "aborted", embedded, total, failed: failedIds.length };
|
|
36713
36887
|
if (providerDown || failedIds.length > 0) {
|
|
36714
|
-
const remaining = Math.max(0, countUnembeddedSessionCompartments(db, projectIdentity, sessionId, snapshot2.chunkModelId) - skipIds.length);
|
|
36888
|
+
const remaining = Math.max(0, countUnembeddedSessionCompartments(db, projectIdentity, sessionId, snapshot2.chunkModelId, maxInputTokens) - skipIds.length);
|
|
36715
36889
|
if (remaining > 0) {
|
|
36716
36890
|
return {
|
|
36717
36891
|
status: "stalled",
|
|
@@ -36737,7 +36911,7 @@ function getEmbeddingCoverageStatus(db, projectIdentity, sessionId) {
|
|
|
36737
36911
|
commits: { embedded: 0, total: 0, gitEnabled: false }
|
|
36738
36912
|
};
|
|
36739
36913
|
}
|
|
36740
|
-
const session = countSessionCompartmentEmbedCoverage(db, projectIdentity, sessionId, snapshot2.chunkModelId);
|
|
36914
|
+
const session = countSessionCompartmentEmbedCoverage(db, projectIdentity, sessionId, snapshot2.chunkModelId, getProjectEmbeddingMaxInputTokens(projectIdentity));
|
|
36741
36915
|
const memories = getMemoryEmbedCoverage(db, projectIdentity, snapshot2.modelId);
|
|
36742
36916
|
const gitEnabled = snapshot2.gitCommitEnabled;
|
|
36743
36917
|
const commits = gitEnabled ? {
|
|
@@ -36876,7 +37050,8 @@ function cosineSimilarity(a, b) {
|
|
|
36876
37050
|
// src/features/magic-context/memory/embedding.ts
|
|
36877
37051
|
var DEFAULT_EMBEDDING_CONFIG = {
|
|
36878
37052
|
provider: "local",
|
|
36879
|
-
model: DEFAULT_LOCAL_EMBEDDING_MODEL
|
|
37053
|
+
model: DEFAULT_LOCAL_EMBEDDING_MODEL,
|
|
37054
|
+
local_runtime: "auto"
|
|
36880
37055
|
};
|
|
36881
37056
|
var embeddingConfig = DEFAULT_EMBEDDING_CONFIG;
|
|
36882
37057
|
var provider = null;
|
|
@@ -36896,7 +37071,7 @@ function createProvider2(config2) {
|
|
|
36896
37071
|
});
|
|
36897
37072
|
}
|
|
36898
37073
|
if (config2.provider === "local") {
|
|
36899
|
-
return new LocalEmbeddingProvider(config2.model, config2.max_input_tokens, config2.local_dtype);
|
|
37074
|
+
return new LocalEmbeddingProvider(config2.model, config2.max_input_tokens, config2.local_dtype, config2.local_runtime);
|
|
36900
37075
|
}
|
|
36901
37076
|
if (config2.provider === "synapse") {
|
|
36902
37077
|
const synapse = config2;
|
|
@@ -47089,4 +47264,4 @@ async function runUpgradeMemoryMigration(ctx, sessionId, migrationDirectory) {
|
|
|
47089
47264
|
}
|
|
47090
47265
|
}
|
|
47091
47266
|
|
|
47092
|
-
export { withContentLanguageDirective, buildPrimaryLanguageDirective, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, resolveLegacyConfigSources, resolveLegacyConfigSourcesForHarness, migrateMagicContextConfigLocations, exports_external, DEFAULT_PROTECTED_TAGS, parseCron, nextOccurrence, nextDueAtMs, promptSurfaceConfigIdentity, resolvePromptSurface, resolveModelConfigOrDefault, DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE, DEFAULT_HISTORIAN_TIMEOUT_MS, DEFAULT_LOCAL_EMBEDDING_MODEL, PER_HARNESS_MIGRATION_INVENTORY, ConfigProfilesSchema, MagicContextConfigSchema, getOpenCodeDbPath, removeMcOwnedCompactionMarkers, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, ProjectIdentityError, resolveProjectIdentityStrict, takeDubiousOwnershipProjectIdentityWarning, resolveProjectIdentity, resolveProjectIdentityForSession, normalizeStoredProjectPath, storedPathBelongsToIdentity, isLinkedGitWorktree, recordSessionProjectIdentity, beginBootQuietPeriod, bootQuietRemainingMs, scheduleAfterBootQuiet, rpcPortDir, rpcPortFilePath, isPidAlive, parseRpcPortFile, observeAuthorityRouting, registerModuleNoteEvaluationBridge, getModuleNoteEvaluationBridge, getContextStoreUuid, ensureContextStoreUuid, getAuthorityManagedMarker, reconcileAuthorityProject, checksumAuthoritySeedRows, prepareAuthority, drainAuthority, getMirrorCursor, applyMirroredNoteCompileFields, applyMirrorPage, pullMemoryMirrorOnce, V2_MEMORY_CATEGORIES, CATEGORY_PRIORITY, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, textMentionsRecentCommit, hasMeaningfulUserText, extractTexts, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, getCurrentToolSetHash, recordToolDefinition, getMeasuredToolDefinitionTokens, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, runSqliteOptimize, openDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, clearRecompStaging, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, isRecord, estimateTrueRawMessageTokens, invalidateTrueRawTokenCache, stripPersistedAssistantText, byteSize, stripTagPrefix, prependTag, isThinkingPart, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, isEditTool, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, setRawMessageProvider, cleanUserText, withRawSessionMessageCache, readRawSessionMessages, primeTailRawMessageCache, primeInMemoryTailRawMessageCache, readRawSessionMessageOrdinalPage, getRawSessionStoredMessageCount, readRawSessionMessagePartsById, readRawSessionMessageOrdinalById, readRawSessionMessageById, readSessionChunk, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessages, indexSingleMessage, indexMessagesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes, recordEmbeddingMeasurement, getMaxM0MutationId, queueMemoryMutation, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationIdForProjects, MAX_EXECUTE_THRESHOLD, escalationBands, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, getEmergencyRecoveryArmedAt, loadPersistedUsage, loadProtectedTailMeta, resetProtectedTailNoEligibleHead, getWrapupInProgressState, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getPersistedReasoningWatermark, setPersistedReasoningWatermark, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, getChannel2NudgeClaim, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, getNoteNudgeAnchors, getAutoSearchHintDecisions, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, pruneAutoSearchHintDecisions, removeNoteNudgeAnchorByMessageId, removeAutoSearchHintDecisionByMessageId, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, setNoteLastReadAt, getHistorianFailureState, clearHistorianFailureState, getOverflowState, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, setPersistedCompactionMarkerState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, removeStrippedPlaceholderId, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, addProcessedImageStrippedIds, getPendingCompactionMarkerState, clearPendingCompactionMarkerStateIf, peekDeferredExecutePending, setDeferredExecutePendingIfAbsent, clearDeferredExecutePendingIfMatches, getSessionsWithPendingMarker, setSessionWorkMetrics, getNotes, addNote, getSessionNotes, getPendingSmartNotes, getReadySmartNotes, updateNote, dismissNote, markNoteReady, markNoteChecked, queuePendingOp, getPendingOps, clearPendingOps, removePendingOp, PRIMER_CANDIDATE_TTL_MS, PRIMER_CANDIDATE_MAX_AGE_MS, primerOccurrenceKey, primerOccurrenceUtcDay, updatePrimerCandidateEmbedding, getPrimerCandidatesByIds, getPrimerCandidatesForPromotion, countPrimerCandidatesForProject, getActivePrimers, createPrimer, updatePrimerSupport, updatePrimerAnswer, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectMemoryEpoch, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, CTX_REDUCE_KEEP, estimateImageTokensFromDataUrl, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchanged, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, toolOutputTokens, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, updateTagDropMode, updateCavemanDepth, updateTagMessageId, deleteTagsByMessageId, getMaxTagNumberBySession, getTagNumberByMessageId, deriveTagLoadFloor, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getMaxDroppedTagNumber, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, createChildSessionWithFence, detectOverflow, resolveFallbackChain, modelBodyField, toModelEntry, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, promptSurfaceHashMaterial, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, extractLatestAssistantText, hasLengthCappedOutput, setKeepSubagents, shouldKeepSubagents, recordChildInvocation, COMPARTMENT_AGENT_SYSTEM_PROMPT, HISTORIAN_EDITOR_SYSTEM_PROMPT, COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT, Priority, AdmissionClass, StaleRouteHandleError, SocketClosedError, SocketTimeoutError, SubcClient, isConsumerReconnectTransient, connectionFileExists, getCompartmentEvents, loadCompartmentChunkEmbeddingsForSearch, cosineSimilarity, SYNAPSE_DEFAULT_MODEL, SynapseEmbeddingProvider, computeNormalizedHash, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitTimeMs, enforceProjectCap, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease, saveEmbeddingIfHashMatches, getProjectEmbeddings, peekProjectEmbeddings, invalidateProject, invalidateMemory, markProjectLoadUntrusted, contentSha256, sweepStaleEmbeddingIdentitiesForProject, registerProjectEmbedding, registerProjectShadowEmbedding, getShadowEmbeddingMeasurementCohort, getPrimaryEmbeddingMeasurementCohort, embedShadowTextForProject, enqueueShadowEmbeddingItems, registerProjectInObservationMode, getProjectEmbeddingSnapshot, embedTextForProject, embedBatchForProject, embedItemsForProject, embedUnembeddedMemoriesForProject, drainCommitBacklogForProject, embedSessionCompartmentChunks, getEmbeddingCoverageStatus, isEmbeddingEnabled, embedText, ensureMemoryEmbeddings, computeCueContentHash, hasMuralCueColumns, getMuralCueState, memoryNeedsCue, setMuralCue, recordMuralCueRejection, hasMemoryShareableColumn, hasMemoryClassifiedAtColumn, getUnclassifiedMemoryIds, ModuleMemoryAuthorityError, insertMemory, insertMemoryIdempotent, getMemoryByHash, getMemoriesByProject, buildWorkspaceMemorySqlFilter, getMemoriesByProjects, getMaxMemoryIdForProjects, readNewMemoriesForM1Union, getMemoryById, getMemoriesByIds, updateMemorySeenCount, updateMemoryRetrievalCount, setMemoryClassification, supersededMemory, mergeMemoryStats, archiveMemory, getMemoryCountsByStatus, sanitizeFtsQuery, searchMemoriesFTS, searchMemoriesFTSUnion, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getMural, BoundedSessionMap, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, incrementalLkgContentDigests, lkgContentDigest, captureSlot, getSlot, dropSlot, noteEntry, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, resetNoteNudgeCooldownOnly, clearNoteNudgeTriggerOnly, MARKER_SUMMARY_TEXT, applyDeferredCompactionMarker, removeCompactionMarkerForSession, checkCompactionMarkerConsistency, resolveMuralWire, extractM0Block, formatDate, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, prepareCompartmentInjection, renderCompartmentInjection, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, injectM0M1, RECOVERY_NO_HEAD_LIMIT, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, runCompartmentAgent, snapRangeToCompartments, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure, isRecompSkip, isRecompComplete, extractRecompReason, contextualizeUpgradeReason, setRecompStarting, setRecompNote, setRecompTerminal, runManagedRecomp, runManagedUpgrade };
|
|
47267
|
+
export { withContentLanguageDirective, buildPrimaryLanguageDirective, cortexKitUserConfigBasePath, cortexKitProjectConfigBasePath, resolveLegacyConfigSources, resolveLegacyConfigSourcesForHarness, migrateMagicContextConfigLocations, exports_external, DEFAULT_PROTECTED_TAGS, parseCron, nextOccurrence, nextDueAtMs, promptSurfaceConfigIdentity, resolvePromptSurface, resolveModelConfigOrDefault, DEFAULT_EXECUTE_THRESHOLD_PERCENTAGE, DEFAULT_HISTORIAN_TIMEOUT_MS, DEFAULT_LOCAL_EMBEDDING_MODEL, PER_HARNESS_MIGRATION_INVENTORY, ConfigProfilesSchema, MagicContextConfigSchema, getOpenCodeDbPath, removeMcOwnedCompactionMarkers, isFailClosedBlockingError, shouldBypassFailClosedBlock, resolveAgentNameFromMessages, createFailClosedController, recordHookInitFailure, clearHookInitFailure, getLastHookInitFailure, ProjectIdentityError, resolveProjectIdentityStrict, takeDubiousOwnershipProjectIdentityWarning, resolveProjectIdentity, directoryHasGitMetadata, resolveProjectIdentityForSession, normalizeStoredProjectPath, storedPathBelongsToIdentity, isLinkedGitWorktree, recordSessionProjectIdentity, beginBootQuietPeriod, bootQuietRemainingMs, scheduleAfterBootQuiet, rpcPortDir, rpcPortFilePath, isPidAlive, parseRpcPortFile, observeAuthorityRouting, registerModuleNoteEvaluationBridge, getModuleNoteEvaluationBridge, getContextStoreUuid, ensureContextStoreUuid, getAuthorityManagedMarker, reconcileAuthorityProject, checksumAuthoritySeedRows, prepareAuthority, drainAuthority, getMirrorCursor, applyMirroredNoteCompileFields, applyMirrorPage, pullMemoryMirrorOnce, V2_MEMORY_CATEGORIES, CATEGORY_PRIORITY, resolveWorkspaceShareCategories, resolveWorkspaceIdentitySet, expandWorkspaceIdentitySetWithAliases, resolveStoredPathWorkspaceIdentity, storedPathBelongsToWorkspace, sourceNameForMemory, computeWorkspaceEpochFingerprint, textMentionsRecentCommit, hasMeaningfulUserText, extractTexts, extractToolCallSummaries, preloadTokenizer, estimateTokens, normalizeText, getCurrentToolSetHash, recordToolDefinition, getMeasuredToolDefinitionTokens, getSchemaFenceRejection, getMigrationOnOpenRefusal, LATEST_SUPPORTED_VERSION, getDatabasePath, getPersistedSchemaVersion, setSqlitePragmaConfig, runSqliteOptimize, openDatabase, openDatabaseAsync, isDatabasePersisted, getDatabasePersistenceError, COMPARTMENT_LEASE_RENEWAL_MS, acquireCompartmentLease, renewCompartmentLease, releaseCompartmentLease, getCompartments, getLastCompartmentEndMessage, getLastCompartmentEndMessageId, clearRecompStaging, isRawCompactionSummaryInfo, extractInMemoryMessageViews, buildInMemoryTailRawMessages, isRecord, estimateTrueRawMessageTokens, invalidateTrueRawTokenCache, stripPersistedAssistantText, byteSize, stripTagPrefix, prependTag, isThinkingPart, isTextPart, isToolPartWithOutput, isFilePart, buildFileSourceContent, isEditTool, partHasCompletedResult, extractToolCallObservation, ToolMutationBatch, createToolDropTarget, setRawMessageProvider, cleanUserText, withRawSessionMessageCache, readRawSessionMessages, primeTailRawMessageCache, primeInMemoryTailRawMessageCache, readRawSessionMessageOrdinalPage, getRawSessionStoredMessageCount, readRawSessionMessagePartsById, readRawSessionMessageOrdinalById, readRawSessionMessageById, readSessionChunk, getMessageIndexSourceIdentity, isMessageIndexSourceCurrent, getLastIndexedOrdinal, getIndexedMessageCorpusSize, getMessageIndexReconciliationStartOrdinal, isMessageIndexReconciledThrough, deleteIndexedMessage, clearIndexedMessages, indexSingleMessage, indexMessagesAfterOrdinal, sweepOrphanedOpenCodeMessageIndexes, recordEmbeddingMeasurement, getMaxM0MutationId, queueMemoryMutation, getMemoryMutationsForRenderByProjects, getMaxMemoryMutationIdForProjects, MAX_EXECUTE_THRESHOLD, escalationBands, isEmergencyRecoveryArmed, isProviderOverflowReconfirmed, getEmergencyRecoveryArmedAt, loadPersistedUsage, loadProtectedTailMeta, resetProtectedTailNoEligibleHead, getWrapupInProgressState, acquireWrapupInProgress, updateWrapupInProgress, releaseWrapupInProgress, resolveCompactionModeRecord, getCompactionModeRecord, setCompactionModeRecord, getPersistedReasoningWatermark, setPersistedReasoningWatermark, clearPersistedReasoningWatermark, getEmergencyInputSample, setEmergencyDropSample, clearEmergencyDropSample, getLastNudgeUndropped, setLastNudgeUndropped, getChannel1NudgeState, setChannel1NudgeState, markChannel1PostReduceGracePending, captureChannel1PostReduceGraceBaseline, getChannel2NudgeState, getChannel2NudgeClaim, setChannel2NudgeState, casChannel2NudgeState, claimChannel2NudgeState, casChannel2NudgeClaim, getPersistedNoteNudge, getNoteNudgeAnchors, getAutoSearchHintDecisions, appendAutoSearchHintDecision, pruneNoteNudgeAnchors, pruneAutoSearchHintDecisions, removeNoteNudgeAnchorByMessageId, removeAutoSearchHintDecisionByMessageId, getPersistedTodoPermissionDenied, setPersistedTodoPermissionDenied, getPersistedTodoSyntheticAnchor, setPersistedTodoSyntheticAnchor, clearPersistedTodoSyntheticAnchor, setNoteLastReadAt, getHistorianFailureState, clearHistorianFailureState, getOverflowState, recordOverflowDetected, recordDetectedContextLimit, clearEmergencyRecovery, clearDetectedContextLimit, getPersistedCompactionMarkerState, setPersistedCompactionMarkerState, getStrippedPlaceholderIds, applyStrippedPlaceholderDelta, removeStrippedPlaceholderId, getMergedReasoningStrippedIds, addMergedReasoningStrippedIds, getTrailingBlankDecisions, addTrailingBlankDecisions, demoteTrailingBlankKeepDecisions, getStaleReduceStrippedIds, addStaleReduceStrippedIds, getProcessedImageStrippedIds, addProcessedImageStrippedIds, getPendingCompactionMarkerState, clearPendingCompactionMarkerStateIf, peekDeferredExecutePending, setDeferredExecutePendingIfAbsent, clearDeferredExecutePendingIfMatches, getSessionsWithPendingMarker, setSessionWorkMetrics, getNotes, addNote, getSessionNotes, getPendingSmartNotes, getReadySmartNotes, updateNote, dismissNote, markNoteReady, markNoteChecked, queuePendingOp, getPendingOps, getPendingOpsCount, clearPendingOps, removePendingOp, PRIMER_CANDIDATE_TTL_MS, PRIMER_CANDIDATE_MAX_AGE_MS, primerOccurrenceKey, primerOccurrenceUtcDay, updatePrimerCandidateEmbedding, getPrimerCandidatesByIds, getPrimerCandidatesForPromotion, countPrimerCandidatesForProject, getActivePrimers, createPrimer, updatePrimerSupport, updatePrimerAnswer, GLOBAL_USER_PROFILE_PROJECT_PATH, getProjectState, bumpProjectMemoryEpoch, bumpProjectUserProfileVersion, saveSourceContent, replaceSourceContent, getSourceContents, CTX_REDUCE_KEEP, estimateImageTokensFromDataUrl, normalizeTodoStateJson, buildSyntheticTodoPart, computeSyntheticCallId, isSyntheticTodoPart, countRealUserMessages, tailHygieneStructuralSignature, sameTailHygieneStructuralSignature, refreshTailHygieneBaseline, effectiveTailHygiene, assertTailHygieneContentUnchanged, CHANNEL1_SENTINEL, CHANNEL1_FLOOR_TOKENS, toolOutputTokens, decideChannel1, evaluateChannel2, reclaimableToolOutputCount, buildChannel2Reminder, buildChannel1Reminder, estimateEmergencyDropReclaimTokens, planEmergencyDrop, getRecentTagOwnerMessageIds, AGE_RECLAIM_MIN_TOKENS, getOldestActiveUnprotectedToolTags, getActiveToolTagsForAgeReclaim, getTriggerTagTokenUpperBound, getActiveTagTokenTotalsByMessage, tagTokenCountIsNull, backfillTagTokenCounts, insertTag, updateTagStatus, updateTagDropMode, updateCavemanDepth, updateTagMessageId, deleteTagsByMessageId, getMaxTagNumberBySession, getTagNumberByMessageId, deriveTagLoadFloor, getTagsBySession, getActiveTagsBySession, getTailHygieneTags, getDroppedTagsBySession, getTagsByNumbers, getMaxDroppedTagNumber, getToolTagNumberByOwner, getNullOwnerToolTag, adoptNullOwnerToolTag, getCandidateToolOwners, pickNearestPriorOwner, createChildSessionWithFence, detectOverflow, resolveFallbackChain, modelBodyField, toModelEntry, promptSyncWithValidatedOutputRetry, normalizeSDKResponse, promptSurfaceHashMaterial, createPromptSurfaceRuntime, createPromptSurfaceGuidanceEpochCache, extractLatestAssistantText, hasLengthCappedOutput, setKeepSubagents, shouldKeepSubagents, recordChildInvocation, COMPARTMENT_AGENT_SYSTEM_PROMPT, HISTORIAN_EDITOR_SYSTEM_PROMPT, COMPARTMENT_STRUCTURAL_SYSTEM_PROMPT, Priority, AdmissionClass, StaleRouteHandleError, SocketClosedError, SocketTimeoutError, SubcClient, isConsumerReconnectTransient, connectionFileExists, getCompartmentEvents, loadCompartmentChunkEmbeddingsForSearch, cosineSimilarity, SYNAPSE_DEFAULT_MODEL, SynapseEmbeddingProvider, computeNormalizedHash, saveCommitEmbedding, loadProjectCommitEmbeddings, loadUnembeddedCommits, countEmbeddedCommits, upsertCommits, getLatestIndexedCommitTimeMs, enforceProjectCap, GIT_SWEEP_LEASE_RENEWAL_MS, acquireGitSweepLease, renewGitSweepLease, markGitSweepSuccessAndRelease, parkGitSweepNonIndexable, releaseGitSweepLease, saveEmbeddingIfHashMatches, getProjectEmbeddings, peekProjectEmbeddings, invalidateProject, invalidateMemory, markProjectLoadUntrusted, contentSha256, sweepStaleEmbeddingIdentitiesForProject, registerProjectEmbedding, registerProjectShadowEmbedding, getShadowEmbeddingMeasurementCohort, getPrimaryEmbeddingMeasurementCohort, embedShadowTextForProject, enqueueShadowEmbeddingItems, registerProjectInObservationMode, getProjectEmbeddingSnapshot, embedTextForProject, embedBatchForProject, embedItemsForProject, embedUnembeddedMemoriesForProject, drainCommitBacklogForProject, embedSessionCompartmentChunks, getEmbeddingCoverageStatus, isEmbeddingEnabled, embedText, ensureMemoryEmbeddings, computeCueContentHash, hasMuralCueColumns, getMuralCueState, memoryNeedsCue, setMuralCue, recordMuralCueRejection, hasMemoryShareableColumn, hasMemoryClassifiedAtColumn, getUnclassifiedMemoryIds, ModuleMemoryAuthorityError, insertMemory, insertMemoryIdempotent, getMemoryByHash, getMemoriesByProject, buildWorkspaceMemorySqlFilter, getMemoriesByProjects, getMaxMemoryIdForProjects, readNewMemoriesForM1Union, getMemoryById, getMemoriesByIds, updateMemorySeenCount, updateMemoryRetrievalCount, setMemoryClassification, supersededMemory, mergeMemoryStats, archiveMemory, getMemoryCountsByStatus, sanitizeFtsQuery, searchMemoriesFTS, searchMemoriesFTSUnion, recordMemoryMapping, recordMemoryVerifications, getUnmappedMemoryIds, clearMemoryVerifications, getMemoryVerifications, resolveGitTopLevel, readGitHead, readGitChangedFilesSince, readGitFileChangeTimesSince, verificationFileExists, normalizeVerificationFiles, USER_MEMORY_CANDIDATE_TTL_MS, insertUserMemoryCandidates, getUserMemoryCandidates, deleteUserMemoryCandidates, pruneExpiredUserMemoryCandidates, insertUserMemory, getActiveUserMemories, updateUserMemoryContent, dismissUserMemory, getMural, BoundedSessionMap, registerLkgPersistence, LKG_SNAPSHOT_ARRAY, LKG_SNAPSHOT_OBJECT, LKG_SNAPSHOT_KEY, LKG_SNAPSHOT_STRING, LKG_SNAPSHOT_NUMBER, LKG_SNAPSHOT_BOOLEAN, LKG_SNAPSHOT_NULL, LKG_SNAPSHOT_UNDEFINED, incrementalLkgContentDigests, lkgContentDigest, captureSlot, getSlot, dropSlot, noteEntry, onNoteTrigger, peekNoteNudgeText, markNoteNudgeDelivered, clearNoteNudgeTriggerAndCooldown, resetNoteNudgeCooldownOnly, clearNoteNudgeTriggerOnly, MARKER_SUMMARY_TEXT, applyDeferredCompactionMarker, removeCompactionMarkerForSession, checkCompactionMarkerConsistency, resolveMuralWire, extractM0Block, formatDate, injectTemporalMarkers, clearInjectionCache, getVisibleMemoryIds, prepareCompartmentInjection, renderCompartmentInjection, mustMaterialize, trimMemoriesToBudgetV2, renderMemoryBlockV2, injectM0M1, RECOVERY_NO_HEAD_LIMIT, resolveOpenCodeProtectedTailBoundary, resolveWrapupProtectedTailBoundary, getRawHistoryEligibility, hasRunnableCompartmentWindow, recordHighPressureNoEligibleHead, runCompartmentAgent, snapRangeToCompartments, getActiveCompartmentRun, markActiveCompartmentRunPublished, registerActiveCompartmentRun, startCompartmentAgent, isRecompFailure, isRecompSkip, isRecompComplete, extractRecompReason, contextualizeUpgradeReason, setRecompStarting, setRecompNote, setRecompTerminal, runManagedRecomp, runManagedUpgrade };
|