memorix 1.10.1 → 1.10.3
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/CHANGELOG.md +34 -0
- package/README.md +3 -1
- package/README.zh-CN.md +3 -1
- package/dist/cli/index.js +810 -379
- package/dist/cli/memcode.js +0 -0
- package/dist/index.js +380 -142
- package/dist/maintenance-runner.js +275 -79
- package/dist/media-audio-runner.js +247 -51
- package/dist/media-video-runner.js +274 -78
- package/dist/memcode-runtime/CHANGELOG.md +34 -0
- package/dist/sdk.js +431 -142
- package/dist/types.d.ts +1 -1
- package/dist/vector-backfill-runner.js +274 -78
- package/docs/CONFIGURATION.md +34 -0
- package/docs/DEVELOPMENT.md +3 -4
- package/docs/INTEGRATIONS.md +1 -1
- package/docs/PERFORMANCE.md +23 -0
- package/docs/README.md +3 -2
- package/docs/ROADMAP-1.9.12-2.0.md +2 -2
- package/docs/SETUP.md +19 -4
- package/package.json +1 -1
- package/plugins/antigravity/memorix/plugin.json +1 -1
- package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
- package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/copilot/memorix/plugin.json +1 -1
- package/plugins/gemini/memorix/gemini-extension.json +1 -1
- package/plugins/hermes/memorix/__init__.py +1 -2
- package/plugins/hermes/memorix/plugin.yaml +1 -1
- package/plugins/omp/memorix/package.json +1 -1
- package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/pi/memorix/package.json +1 -1
- package/server.json +2 -2
- package/src/cli/commands/agent-integrations.ts +1 -1
- package/src/cli/commands/background.ts +1 -1
- package/src/cli/commands/context.ts +3 -2
- package/src/cli/commands/doctor.ts +9 -0
- package/src/cli/commands/explain.ts +3 -2
- package/src/cli/commands/init.ts +6 -2
- package/src/cli/commands/repair.ts +17 -3
- package/src/cli/commands/setup.ts +9 -6
- package/src/cli/commands/uninstall.ts +15 -0
- package/src/cli/tui/App.tsx +9 -16
- package/src/cli/tui/ConfigureView.tsx +2 -0
- package/src/codegraph/auto-context.ts +1 -1
- package/src/codegraph/store.ts +37 -0
- package/src/codegraph/types.ts +3 -0
- package/src/compact/index-format.ts +1 -1
- package/src/config/dotenv-loader.ts +1 -0
- package/src/config/resolved-config.ts +7 -2
- package/src/config/toml-loader.ts +1 -0
- package/src/config/yaml-loader.ts +4 -2
- package/src/dashboard/server.ts +5 -6
- package/src/hooks/handler.ts +0 -1
- package/src/integrations/registry.ts +2 -1
- package/src/knowledge/context-receipt.ts +6 -3
- package/src/llm/provider.ts +2 -1
- package/src/memory/observations.ts +68 -22
- package/src/multimodal/image-loader.ts +2 -2
- package/src/runtime/open-browser.ts +25 -0
- package/src/search/derived-view-receipt.ts +40 -0
- package/src/search/semantic-index.ts +149 -1
- package/src/server.ts +20 -5
- package/src/store/orama-store.ts +59 -19
- package/src/types.ts +1 -1
- package/src/workspace/mcp-adapters/pi.ts +58 -0
- package/plugins/pi/memorix/skills/memorix-git-memory/SKILL.md +0 -26
- package/plugins/pi/memorix/skills/memorix-memory/SKILL.md +0 -51
- package/plugins/pi/memorix/skills/memorix-mini-skills/SKILL.md +0 -31
- package/plugins/pi/memorix/skills/memorix-orchestrate/SKILL.md +0 -28
- package/plugins/pi/memorix/skills/memorix-reasoning/SKILL.md +0 -30
- package/plugins/pi/memorix/skills/memorix-sessions/SKILL.md +0 -25
- package/plugins/pi/memorix/skills/memorix-troubleshooting/SKILL.md +0 -27
|
@@ -2113,7 +2113,8 @@ function getResolvedConfig(options = {}) {
|
|
|
2113
2113
|
const isRequesty = memoryLlmProvider === "requesty";
|
|
2114
2114
|
const isApiRoute = memoryLlmProvider === "apiroute";
|
|
2115
2115
|
const isCheaperInference = memoryLlmProvider === "cheaperinference";
|
|
2116
|
-
const
|
|
2116
|
+
const isRuncrate = memoryLlmProvider === "runcrate";
|
|
2117
|
+
const usesPresetKeyOnly = isAtlasCloud || isRequesty || isApiRoute || isCheaperInference || isRuncrate;
|
|
2117
2118
|
const memoryLlmApiKey = first(
|
|
2118
2119
|
process.env.MEMORIX_LLM_API_KEY,
|
|
2119
2120
|
process.env.MEMORIX_API_KEY,
|
|
@@ -2121,7 +2122,7 @@ function getResolvedConfig(options = {}) {
|
|
|
2121
2122
|
yaml.llm?.apiKey,
|
|
2122
2123
|
legacy.llm?.apiKey,
|
|
2123
2124
|
// Never borrow another provider's credentials for these gateway presets.
|
|
2124
|
-
isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : isCheaperInference ? process.env.CHEAPER_INFERENCE_API_KEY : process.env.OPENAI_API_KEY,
|
|
2125
|
+
isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : isCheaperInference ? process.env.CHEAPER_INFERENCE_API_KEY : isRuncrate ? process.env.RUNCRATE_API_KEY : process.env.OPENAI_API_KEY,
|
|
2125
2126
|
usesPresetKeyOnly ? void 0 : process.env.ANTHROPIC_API_KEY,
|
|
2126
2127
|
usesPresetKeyOnly ? void 0 : openRouterMemoryLlmApiKey
|
|
2127
2128
|
);
|
|
@@ -2192,6 +2193,7 @@ function getResolvedConfig(options = {}) {
|
|
|
2192
2193
|
codegraph: {
|
|
2193
2194
|
excludePatterns: firstArray(toml.codegraph?.exclude_patterns, yaml.codegraph?.excludePatterns),
|
|
2194
2195
|
maxFileBytes: firstNumber(toml.codegraph?.max_file_bytes, yaml.codegraph?.maxFileBytes),
|
|
2196
|
+
autoRefresh: first(toml.codegraph?.auto_refresh, yaml.codegraph?.autoRefresh, "auto"),
|
|
2195
2197
|
externalContext: first(
|
|
2196
2198
|
normalizeExternalContext(process.env.MEMORIX_CODEGRAPH_EXTERNAL_CONTEXT),
|
|
2197
2199
|
toml.codegraph?.external_context,
|
|
@@ -2306,6 +2308,7 @@ function getEnvSourceNames() {
|
|
|
2306
2308
|
"REQUESTY_API_KEY",
|
|
2307
2309
|
"API_ROUTE_API_KEY",
|
|
2308
2310
|
"CHEAPER_INFERENCE_API_KEY",
|
|
2311
|
+
"RUNCRATE_API_KEY",
|
|
2309
2312
|
"ATLASCLOUD_API_KEY"
|
|
2310
2313
|
].filter((name) => process.env[name]);
|
|
2311
2314
|
}
|
|
@@ -3152,6 +3155,7 @@ var init_provider = __esm({
|
|
|
3152
3155
|
requesty: { baseUrl: "https://router.requesty.ai/v1", model: "openai/gpt-4.1-nano" },
|
|
3153
3156
|
apiroute: { baseUrl: "https://global.api-route.com/v1", model: "deepseek-v4.1-flash" },
|
|
3154
3157
|
cheaperinference: { baseUrl: "https://api.cheaperinference.com/v1", model: "gpt-5.4-mini" },
|
|
3158
|
+
runcrate: { baseUrl: "https://api.runcrate.ai/v1", model: "deepseek-ai/DeepSeek-V4.1-Flash" },
|
|
3155
3159
|
atlascloud: { baseUrl: "https://api.atlascloud.ai/v1", model: "deepseek-ai/deepseek-v3.2" },
|
|
3156
3160
|
custom: { baseUrl: "http://localhost:11434/v1", model: "llama3" }
|
|
3157
3161
|
};
|
|
@@ -6374,6 +6378,7 @@ var init_timeout = __esm({
|
|
|
6374
6378
|
|
|
6375
6379
|
// src/search/semantic-index.ts
|
|
6376
6380
|
import { createHash as createHash4 } from "crypto";
|
|
6381
|
+
import { existsSync as existsSync8 } from "fs";
|
|
6377
6382
|
import { createRequire as createRequire3 } from "module";
|
|
6378
6383
|
import path8 from "path";
|
|
6379
6384
|
function createSemanticIndexProfile(provider2) {
|
|
@@ -6472,17 +6477,80 @@ function queueOperation(key, operation) {
|
|
|
6472
6477
|
writeQueues.set(key, run.catch(() => void 0));
|
|
6473
6478
|
return run;
|
|
6474
6479
|
}
|
|
6480
|
+
function positiveEnvInt(name, fallback) {
|
|
6481
|
+
const value = Number.parseInt(process.env[name] ?? "", 10);
|
|
6482
|
+
return Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
6483
|
+
}
|
|
6484
|
+
function semanticWriteBatchSize() {
|
|
6485
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_BATCH_SIZE", DEFAULT_WRITE_BATCH_SIZE);
|
|
6486
|
+
}
|
|
6487
|
+
function semanticWriteFlushMs() {
|
|
6488
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_FLUSH_MS", DEFAULT_WRITE_FLUSH_MS);
|
|
6489
|
+
}
|
|
6490
|
+
function semanticOptimizeEvery() {
|
|
6491
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_OPTIMIZE_EVERY", DEFAULT_OPTIMIZE_EVERY);
|
|
6492
|
+
}
|
|
6493
|
+
function semanticVersionRetentionMs() {
|
|
6494
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_VERSION_RETENTION_MS", DEFAULT_VERSION_RETENTION_MS);
|
|
6495
|
+
}
|
|
6496
|
+
async function optimizeState(state) {
|
|
6497
|
+
if (!state.table || typeof state.table.optimize !== "function") return;
|
|
6498
|
+
await state.table.optimize({
|
|
6499
|
+
cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
|
|
6500
|
+
deleteUnverified: false
|
|
6501
|
+
});
|
|
6502
|
+
}
|
|
6475
6503
|
async function mergeVectors(dataDir, profile, records) {
|
|
6476
6504
|
if (records.length === 0) return;
|
|
6477
6505
|
const state = await getState(dataDir, profile, records);
|
|
6478
6506
|
if (!state?.table) return;
|
|
6479
6507
|
const rows = records.map(toLanceRow);
|
|
6480
6508
|
await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
6509
|
+
const key = stateKey(dataDir, profile);
|
|
6510
|
+
const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
|
|
6511
|
+
if (mutationCount >= semanticOptimizeEvery()) {
|
|
6512
|
+
mutationCounts.set(key, 0);
|
|
6513
|
+
await optimizeState(state).catch(() => void 0);
|
|
6514
|
+
} else {
|
|
6515
|
+
mutationCounts.set(key, mutationCount);
|
|
6516
|
+
}
|
|
6481
6517
|
void ensureSemanticIndex(dataDir, profile);
|
|
6482
6518
|
}
|
|
6519
|
+
function flushPendingVectorBatch(key) {
|
|
6520
|
+
const pending = pendingVectorBatches.get(key);
|
|
6521
|
+
if (!pending) return Promise.resolve();
|
|
6522
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
6523
|
+
pendingVectorBatches.delete(key);
|
|
6524
|
+
const records = [...pending.records.values()];
|
|
6525
|
+
const waiters = pending.waiters.splice(0);
|
|
6526
|
+
return queueOperation(key, () => mergeVectors(pending.dataDir, pending.profile, records)).then(() => waiters.forEach((waiter) => waiter.resolve())).catch((error) => {
|
|
6527
|
+
waiters.forEach((waiter) => waiter.reject(error));
|
|
6528
|
+
});
|
|
6529
|
+
}
|
|
6530
|
+
function upsertSemanticVector(dataDir, profile, record80) {
|
|
6531
|
+
const key = stateKey(dataDir, profile);
|
|
6532
|
+
let pending = pendingVectorBatches.get(key);
|
|
6533
|
+
if (!pending) {
|
|
6534
|
+
pending = { dataDir, profile, records: /* @__PURE__ */ new Map(), waiters: [] };
|
|
6535
|
+
pendingVectorBatches.set(key, pending);
|
|
6536
|
+
}
|
|
6537
|
+
pending.records.set(`${record80.projectId}:${record80.observationId}`, record80);
|
|
6538
|
+
const promise = new Promise((resolve2, reject) => pending.waiters.push({ resolve: resolve2, reject }));
|
|
6539
|
+
if (pending.records.size >= semanticWriteBatchSize()) void flushPendingVectorBatch(key);
|
|
6540
|
+
else if (!pending.timer) pending.timer = setTimeout(() => {
|
|
6541
|
+
void flushPendingVectorBatch(key);
|
|
6542
|
+
}, semanticWriteFlushMs());
|
|
6543
|
+
return promise;
|
|
6544
|
+
}
|
|
6483
6545
|
function upsertSemanticVectors(dataDir, profile, records) {
|
|
6484
6546
|
return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
|
|
6485
6547
|
}
|
|
6548
|
+
async function listSemanticVectorIds(dataDir, profile) {
|
|
6549
|
+
const state = await getState(dataDir, profile);
|
|
6550
|
+
if (!state?.table) return null;
|
|
6551
|
+
const rows = await state.table.query().select(["observation_id"]).toArray();
|
|
6552
|
+
return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
|
|
6553
|
+
}
|
|
6486
6554
|
function resolveIndexThreshold() {
|
|
6487
6555
|
const raw = Number.parseInt(process.env.MEMORIX_SEMANTIC_INDEX_THRESHOLD ?? "", 10);
|
|
6488
6556
|
return Number.isSafeInteger(raw) && raw > 0 ? raw : DEFAULT_INDEX_THRESHOLD;
|
|
@@ -6534,7 +6602,7 @@ async function searchSemanticVectors(options) {
|
|
|
6534
6602
|
distance: Number(row._distance ?? Number.POSITIVE_INFINITY)
|
|
6535
6603
|
})).filter((row) => Number.isFinite(row.distance));
|
|
6536
6604
|
}
|
|
6537
|
-
var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, statePromises, writeQueues, indexBuilds, availability, requireFromHere2;
|
|
6605
|
+
var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, DEFAULT_WRITE_BATCH_SIZE, DEFAULT_WRITE_FLUSH_MS, DEFAULT_OPTIMIZE_EVERY, DEFAULT_VERSION_RETENTION_MS, statePromises, writeQueues, indexBuilds, mutationCounts, pendingVectorBatches, availability, requireFromHere2;
|
|
6538
6606
|
var init_semantic_index = __esm({
|
|
6539
6607
|
"src/search/semantic-index.ts"() {
|
|
6540
6608
|
"use strict";
|
|
@@ -6543,13 +6611,81 @@ var init_semantic_index = __esm({
|
|
|
6543
6611
|
TABLE_PREFIX = "observations_";
|
|
6544
6612
|
DEFAULT_INDEX_THRESHOLD = 1e4;
|
|
6545
6613
|
MAX_INDEX_PARTITIONS = 32;
|
|
6614
|
+
DEFAULT_WRITE_BATCH_SIZE = 100;
|
|
6615
|
+
DEFAULT_WRITE_FLUSH_MS = 50;
|
|
6616
|
+
DEFAULT_OPTIMIZE_EVERY = 20;
|
|
6617
|
+
DEFAULT_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
|
|
6546
6618
|
statePromises = /* @__PURE__ */ new Map();
|
|
6547
6619
|
writeQueues = /* @__PURE__ */ new Map();
|
|
6548
6620
|
indexBuilds = /* @__PURE__ */ new Map();
|
|
6621
|
+
mutationCounts = /* @__PURE__ */ new Map();
|
|
6622
|
+
pendingVectorBatches = /* @__PURE__ */ new Map();
|
|
6549
6623
|
requireFromHere2 = createRequire3(import.meta.url);
|
|
6550
6624
|
}
|
|
6551
6625
|
});
|
|
6552
6626
|
|
|
6627
|
+
// src/memory/secret-filter.ts
|
|
6628
|
+
function applyRedaction(text2) {
|
|
6629
|
+
if (!text2) return text2;
|
|
6630
|
+
let out = text2;
|
|
6631
|
+
out = out.replace(
|
|
6632
|
+
/((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
|
|
6633
|
+
"$1[REDACTED]"
|
|
6634
|
+
);
|
|
6635
|
+
out = out.replace(
|
|
6636
|
+
/(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
|
|
6637
|
+
"$1[REDACTED]"
|
|
6638
|
+
);
|
|
6639
|
+
out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
|
|
6640
|
+
out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
|
|
6641
|
+
out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
|
|
6642
|
+
return out;
|
|
6643
|
+
}
|
|
6644
|
+
function sanitizeCredentials(text2) {
|
|
6645
|
+
return applyRedaction(text2);
|
|
6646
|
+
}
|
|
6647
|
+
var init_secret_filter = __esm({
|
|
6648
|
+
"src/memory/secret-filter.ts"() {
|
|
6649
|
+
"use strict";
|
|
6650
|
+
init_esm_shims();
|
|
6651
|
+
}
|
|
6652
|
+
});
|
|
6653
|
+
|
|
6654
|
+
// src/search/derived-view-receipt.ts
|
|
6655
|
+
function sanitizeDerivedViewFailureReason(reason) {
|
|
6656
|
+
const safe = sanitizeCredentials(reason).replace(/(?:[A-Za-z]:[\\/]|\\\\[^\\/\s]+[\\/]|\/(?:home|Users|tmp|var|private|mnt|workspace|workspaces)\/)[^\s"'<>|]*/gi, "[path]").replace(/\s+/g, " ").trim();
|
|
6657
|
+
return safe.slice(0, 240) || "derived view failed";
|
|
6658
|
+
}
|
|
6659
|
+
function embeddingHealthReceipt(health, embeddingEnabled2) {
|
|
6660
|
+
if (health?.status === "disabled") {
|
|
6661
|
+
return { freshness: "current", rebuildStatus: "disabled" };
|
|
6662
|
+
}
|
|
6663
|
+
if (health?.status === "ready" || embeddingEnabled2) {
|
|
6664
|
+
return { freshness: "current", rebuildStatus: "idle" };
|
|
6665
|
+
}
|
|
6666
|
+
if (health?.status === "degraded") {
|
|
6667
|
+
return {
|
|
6668
|
+
freshness: "stale",
|
|
6669
|
+
rebuildStatus: "failed",
|
|
6670
|
+
...health.failure ? {
|
|
6671
|
+
failureReason: `embedding ${health.failure.kind}; retry in ${health.failure.retryAfterMs}ms`
|
|
6672
|
+
} : { failureReason: "embedding provider degraded" }
|
|
6673
|
+
};
|
|
6674
|
+
}
|
|
6675
|
+
return {
|
|
6676
|
+
freshness: "unknown",
|
|
6677
|
+
rebuildStatus: "unavailable",
|
|
6678
|
+
failureReason: "embedding provider is not initialized"
|
|
6679
|
+
};
|
|
6680
|
+
}
|
|
6681
|
+
var init_derived_view_receipt = __esm({
|
|
6682
|
+
"src/search/derived-view-receipt.ts"() {
|
|
6683
|
+
"use strict";
|
|
6684
|
+
init_esm_shims();
|
|
6685
|
+
init_secret_filter();
|
|
6686
|
+
}
|
|
6687
|
+
});
|
|
6688
|
+
|
|
6553
6689
|
// src/project/aliases.ts
|
|
6554
6690
|
var aliases_exports = {};
|
|
6555
6691
|
__export(aliases_exports, {
|
|
@@ -7158,6 +7294,7 @@ __export(orama_store_exports, {
|
|
|
7158
7294
|
getLastSearchMode: () => getLastSearchMode,
|
|
7159
7295
|
getObservationCount: () => getObservationCount,
|
|
7160
7296
|
getObservationsByIds: () => getObservationsByIds,
|
|
7297
|
+
getPersistentSemanticVectorIds: () => getPersistentSemanticVectorIds,
|
|
7161
7298
|
getSearchDerivedViews: () => getSearchDerivedViews,
|
|
7162
7299
|
getTimeline: () => getTimeline,
|
|
7163
7300
|
getVectorDimensions: () => getVectorDimensions,
|
|
@@ -7170,10 +7307,18 @@ __export(orama_store_exports, {
|
|
|
7170
7307
|
queueSemanticVector: () => queueSemanticVector,
|
|
7171
7308
|
removeObservation: () => removeObservation,
|
|
7172
7309
|
resetDb: () => resetDb,
|
|
7310
|
+
resolveSearchFuzzyTolerance: () => resolveSearchFuzzyTolerance,
|
|
7173
7311
|
searchObservations: () => searchObservations,
|
|
7174
7312
|
updateObservationMetadata: () => updateObservationMetadata
|
|
7175
7313
|
});
|
|
7176
7314
|
import { components, create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
|
|
7315
|
+
function resolveSearchFuzzyTolerance(query, quality) {
|
|
7316
|
+
if (quality === "fast") return void 0;
|
|
7317
|
+
const characters = [...query];
|
|
7318
|
+
const cjkCount = characters.filter((char) => /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/u.test(char)).length;
|
|
7319
|
+
if (characters.length > 0 && cjkCount / characters.length > 0.3) return void 0;
|
|
7320
|
+
return query.length > 6 ? 2 : 1;
|
|
7321
|
+
}
|
|
7177
7322
|
function rememberSearchMode(key, value) {
|
|
7178
7323
|
if (!lastSearchModeByProject.has(key) && lastSearchModeByProject.size >= MAX_SEARCH_MODE_KEYS) {
|
|
7179
7324
|
const oldest = lastSearchModeByProject.keys().next().value;
|
|
@@ -7202,14 +7347,16 @@ function getSearchDerivedViews() {
|
|
|
7202
7347
|
generation,
|
|
7203
7348
|
freshness: "unknown",
|
|
7204
7349
|
rebuildStatus: "unavailable",
|
|
7205
|
-
failureReason:
|
|
7350
|
+
failureReason: sanitizeDerivedViewFailureReason(
|
|
7351
|
+
store.getBackendReason?.() ?? "persistent lexical index unavailable"
|
|
7352
|
+
)
|
|
7206
7353
|
};
|
|
7207
7354
|
}
|
|
7208
7355
|
} catch (error) {
|
|
7209
7356
|
views.fts = {
|
|
7210
7357
|
freshness: "unknown",
|
|
7211
7358
|
rebuildStatus: "failed",
|
|
7212
|
-
failureReason: error instanceof Error ? error.message
|
|
7359
|
+
failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
|
|
7213
7360
|
};
|
|
7214
7361
|
}
|
|
7215
7362
|
} else {
|
|
@@ -7225,18 +7372,12 @@ function getSearchDerivedViews() {
|
|
|
7225
7372
|
rebuildStatus: "unavailable",
|
|
7226
7373
|
failureReason: "Orama index is not initialized"
|
|
7227
7374
|
};
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
}
|
|
7232
|
-
views.embedding = { freshness: "current", rebuildStatus: "idle" };
|
|
7233
|
-
} else {
|
|
7234
|
-
views.embedding = {
|
|
7235
|
-
freshness: "unknown",
|
|
7236
|
-
rebuildStatus: "unavailable",
|
|
7237
|
-
failureReason: "embedding provider is not initialized"
|
|
7238
|
-
};
|
|
7375
|
+
let embeddingHealth;
|
|
7376
|
+
try {
|
|
7377
|
+
embeddingHealth = getEmbeddingRuntimeHealth?.();
|
|
7378
|
+
} catch {
|
|
7239
7379
|
}
|
|
7380
|
+
views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
|
|
7240
7381
|
return views;
|
|
7241
7382
|
}
|
|
7242
7383
|
function rememberSearchDiagnostics(key, value) {
|
|
@@ -7540,12 +7681,16 @@ function getVectorDimensions() {
|
|
|
7540
7681
|
function getActiveSemanticIndexProfile() {
|
|
7541
7682
|
return indexEmbeddingProvider ? createSemanticIndexProfile(indexEmbeddingProvider) : null;
|
|
7542
7683
|
}
|
|
7684
|
+
async function getPersistentSemanticVectorIds(dataDir) {
|
|
7685
|
+
if (!indexEmbeddingProvider) return null;
|
|
7686
|
+
return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
|
|
7687
|
+
}
|
|
7543
7688
|
async function queueSemanticVector(dataDir, record80) {
|
|
7544
7689
|
const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
|
|
7545
7690
|
const profile = provider2 ? createSemanticIndexProfile(provider2) : null;
|
|
7546
7691
|
if (!profile) return;
|
|
7547
7692
|
try {
|
|
7548
|
-
await
|
|
7693
|
+
await upsertSemanticVector(dataDir, profile, record80);
|
|
7549
7694
|
} catch {
|
|
7550
7695
|
}
|
|
7551
7696
|
}
|
|
@@ -7607,6 +7752,7 @@ function isCompatibleCachedVector(vector) {
|
|
|
7607
7752
|
async function attachCachedVectors(database, observations2) {
|
|
7608
7753
|
const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
|
|
7609
7754
|
const semanticProfile = getActiveSemanticIndexProfile();
|
|
7755
|
+
const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
|
|
7610
7756
|
const batchSize = 200;
|
|
7611
7757
|
for (let start = 0; start < observations2.length; start += batchSize) {
|
|
7612
7758
|
const batch = observations2.slice(start, start + batchSize);
|
|
@@ -7617,7 +7763,7 @@ async function attachCachedVectors(database, observations2) {
|
|
|
7617
7763
|
const vector = cachedVectors[index];
|
|
7618
7764
|
if (!isCompatibleCachedVector(vector)) continue;
|
|
7619
7765
|
const observation = batch[index];
|
|
7620
|
-
if (semanticDataDir && semanticProfile) {
|
|
7766
|
+
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
|
|
7621
7767
|
semanticRecords.push({
|
|
7622
7768
|
observationId: observation.id,
|
|
7623
7769
|
projectId: observation.projectId,
|
|
@@ -7818,7 +7964,10 @@ async function searchObservations(options) {
|
|
|
7818
7964
|
// Fuzzy tolerance: allow 1-char typos for short queries, 2 for longer
|
|
7819
7965
|
// Fuzzy matching is useful for ordinary recall, but grows sharply with
|
|
7820
7966
|
// corpus size. The fast profile deliberately uses exact lexical matching.
|
|
7821
|
-
...hasQuery
|
|
7967
|
+
...hasQuery ? (() => {
|
|
7968
|
+
const tolerance = resolveSearchFuzzyTolerance(originalQuery, quality);
|
|
7969
|
+
return tolerance === void 0 ? {} : { tolerance };
|
|
7970
|
+
})() : {}
|
|
7822
7971
|
};
|
|
7823
7972
|
let queryVector = null;
|
|
7824
7973
|
let embeddingProviderForSearch = null;
|
|
@@ -8049,14 +8198,16 @@ async function searchObservations(options) {
|
|
|
8049
8198
|
filesModified: doc.filesModified?.split?.("\n") ?? (Array.isArray(doc.filesModified) ? doc.filesModified : [])
|
|
8050
8199
|
});
|
|
8051
8200
|
}
|
|
8201
|
+
const topScore = Math.max(...intermediate.map((entry) => entry.score));
|
|
8202
|
+
const affinityTieWindow = topScore * 0.92;
|
|
8052
8203
|
intermediate = intermediate.map((entry) => {
|
|
8053
8204
|
const memory = memoryContentMap.get(entry.id);
|
|
8054
8205
|
if (!memory) return entry;
|
|
8055
8206
|
const { score: affinityScore } = calculateProjectAffinity(memory, affinityContext);
|
|
8207
|
+
if (entry.score < affinityTieWindow) return entry;
|
|
8056
8208
|
return {
|
|
8057
8209
|
...entry,
|
|
8058
|
-
score: entry.score * affinityScore
|
|
8059
|
-
// Apply affinity as multiplier
|
|
8210
|
+
score: entry.score * (0.98 + affinityScore * 0.02)
|
|
8060
8211
|
};
|
|
8061
8212
|
});
|
|
8062
8213
|
intermediate.sort((a, b) => b.score - a.score);
|
|
@@ -8390,6 +8541,7 @@ var init_orama_store = __esm({
|
|
|
8390
8541
|
init_mini_skills();
|
|
8391
8542
|
init_visibility();
|
|
8392
8543
|
init_provider2();
|
|
8544
|
+
init_provider2();
|
|
8393
8545
|
init_project_affinity();
|
|
8394
8546
|
init_intent_detector();
|
|
8395
8547
|
init_query_expansion();
|
|
@@ -8397,6 +8549,7 @@ var init_orama_store = __esm({
|
|
|
8397
8549
|
init_timeout();
|
|
8398
8550
|
init_obs_store();
|
|
8399
8551
|
init_semantic_index();
|
|
8552
|
+
init_derived_view_receipt();
|
|
8400
8553
|
db = null;
|
|
8401
8554
|
dbInitPromise = null;
|
|
8402
8555
|
dbGeneration = 0;
|
|
@@ -8521,33 +8674,6 @@ var init_entity_extractor = __esm({
|
|
|
8521
8674
|
}
|
|
8522
8675
|
});
|
|
8523
8676
|
|
|
8524
|
-
// src/memory/secret-filter.ts
|
|
8525
|
-
function applyRedaction(text2) {
|
|
8526
|
-
if (!text2) return text2;
|
|
8527
|
-
let out = text2;
|
|
8528
|
-
out = out.replace(
|
|
8529
|
-
/((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
|
|
8530
|
-
"$1[REDACTED]"
|
|
8531
|
-
);
|
|
8532
|
-
out = out.replace(
|
|
8533
|
-
/(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
|
|
8534
|
-
"$1[REDACTED]"
|
|
8535
|
-
);
|
|
8536
|
-
out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
|
|
8537
|
-
out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
|
|
8538
|
-
out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
|
|
8539
|
-
return out;
|
|
8540
|
-
}
|
|
8541
|
-
function sanitizeCredentials(text2) {
|
|
8542
|
-
return applyRedaction(text2);
|
|
8543
|
-
}
|
|
8544
|
-
var init_secret_filter = __esm({
|
|
8545
|
-
"src/memory/secret-filter.ts"() {
|
|
8546
|
-
"use strict";
|
|
8547
|
-
init_esm_shims();
|
|
8548
|
-
}
|
|
8549
|
-
});
|
|
8550
|
-
|
|
8551
8677
|
// src/runtime/maintenance-jobs.ts
|
|
8552
8678
|
var maintenance_jobs_exports = {};
|
|
8553
8679
|
__export(maintenance_jobs_exports, {
|
|
@@ -9366,7 +9492,7 @@ var init_maintenance_targets = __esm({
|
|
|
9366
9492
|
|
|
9367
9493
|
// src/runtime/isolated-maintenance.ts
|
|
9368
9494
|
import { spawn } from "child_process";
|
|
9369
|
-
import { existsSync as
|
|
9495
|
+
import { existsSync as existsSync9 } from "fs";
|
|
9370
9496
|
import os3 from "os";
|
|
9371
9497
|
import path10 from "path";
|
|
9372
9498
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
@@ -144156,7 +144282,7 @@ __export(video_jobs_exports, {
|
|
|
144156
144282
|
runMiniMaxVideoGenerationJob: () => runMiniMaxVideoGenerationJob
|
|
144157
144283
|
});
|
|
144158
144284
|
import { spawn as spawn2 } from "child_process";
|
|
144159
|
-
import { existsSync as
|
|
144285
|
+
import { existsSync as existsSync10 } from "fs";
|
|
144160
144286
|
import path16 from "path";
|
|
144161
144287
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
144162
144288
|
function safeError2(error) {
|
|
@@ -144404,7 +144530,7 @@ function resolveMediaVideoRunnerPath(moduleUrl = import.meta.url) {
|
|
|
144404
144530
|
}
|
|
144405
144531
|
function launchMediaVideoRunner(request, options = {}) {
|
|
144406
144532
|
const runnerPath = options.runnerPath ?? resolveMediaVideoRunnerPath();
|
|
144407
|
-
if (!
|
|
144533
|
+
if (!existsSync10(runnerPath)) {
|
|
144408
144534
|
return { launched: false, reason: "Media video runner is unavailable until Memorix is built or reinstalled." };
|
|
144409
144535
|
}
|
|
144410
144536
|
try {
|
|
@@ -144449,7 +144575,7 @@ __export(audio_jobs_exports, {
|
|
|
144449
144575
|
transcribeAudio: () => transcribeAudio
|
|
144450
144576
|
});
|
|
144451
144577
|
import { spawn as spawn3 } from "child_process";
|
|
144452
|
-
import { existsSync as
|
|
144578
|
+
import { existsSync as existsSync11 } from "fs";
|
|
144453
144579
|
import path17 from "path";
|
|
144454
144580
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
144455
144581
|
function safeError3(error) {
|
|
@@ -144700,7 +144826,7 @@ function resolveMediaAudioRunnerPath(moduleUrl = import.meta.url) {
|
|
|
144700
144826
|
}
|
|
144701
144827
|
function launchMediaAudioRunner(request, options = {}) {
|
|
144702
144828
|
const runnerPath = options.runnerPath ?? resolveMediaAudioRunnerPath();
|
|
144703
|
-
if (!
|
|
144829
|
+
if (!existsSync11(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
|
|
144704
144830
|
try {
|
|
144705
144831
|
const child = spawn3(process.execPath, [runnerPath, JSON.stringify(request)], {
|
|
144706
144832
|
cwd: request.projectRoot,
|
|
@@ -147109,6 +147235,7 @@ var init_store = __esm({
|
|
|
147109
147235
|
recordCodeStateSnapshot(input) {
|
|
147110
147236
|
const id = randomUUID11();
|
|
147111
147237
|
let snapshot;
|
|
147238
|
+
let compactNeeded = false;
|
|
147112
147239
|
const tx = this.db.transaction(() => {
|
|
147113
147240
|
const previous = this.db.prepare(
|
|
147114
147241
|
"SELECT id, sourceEpoch FROM code_state_snapshots WHERE projectId = ? ORDER BY sourceEpoch DESC LIMIT 1"
|
|
@@ -147152,6 +147279,26 @@ var init_store = __esm({
|
|
|
147152
147279
|
for (const file of snapshotFileRows) {
|
|
147153
147280
|
insertSnapshotFile.run(id, file.projectId, file.id, file.path, file.contentHash);
|
|
147154
147281
|
}
|
|
147282
|
+
const staleSymbolIds = this.db.prepare(
|
|
147283
|
+
"SELECT id FROM code_symbols WHERE projectId = ? AND stale = 1"
|
|
147284
|
+
).all(input.projectId).map((row) => row.id);
|
|
147285
|
+
if (staleSymbolIds.length > 0) {
|
|
147286
|
+
const placeholders = staleSymbolIds.map(() => "?").join(", ");
|
|
147287
|
+
this.db.prepare(
|
|
147288
|
+
`DELETE FROM code_edges WHERE projectId = ? AND (fromSymbolId IN (${placeholders}) OR toSymbolId IN (${placeholders}))`
|
|
147289
|
+
).run(input.projectId, ...staleSymbolIds, ...staleSymbolIds);
|
|
147290
|
+
this.db.prepare("DELETE FROM code_symbols WHERE projectId = ? AND stale = 1").run(input.projectId);
|
|
147291
|
+
compactNeeded = true;
|
|
147292
|
+
}
|
|
147293
|
+
const oldSnapshots = this.db.prepare(
|
|
147294
|
+
"SELECT id FROM code_state_snapshots WHERE projectId = ? ORDER BY sourceEpoch DESC LIMIT -1 OFFSET 2"
|
|
147295
|
+
).all(input.projectId).map((row) => row.id);
|
|
147296
|
+
if (oldSnapshots.length > 0) {
|
|
147297
|
+
const placeholders = oldSnapshots.map(() => "?").join(", ");
|
|
147298
|
+
this.db.prepare(`DELETE FROM code_state_snapshot_files WHERE snapshotId IN (${placeholders})`).run(...oldSnapshots);
|
|
147299
|
+
this.db.prepare(`DELETE FROM code_state_snapshots WHERE id IN (${placeholders})`).run(...oldSnapshots);
|
|
147300
|
+
compactNeeded = true;
|
|
147301
|
+
}
|
|
147155
147302
|
snapshot = {
|
|
147156
147303
|
...input,
|
|
147157
147304
|
id,
|
|
@@ -147160,11 +147307,24 @@ var init_store = __esm({
|
|
|
147160
147307
|
};
|
|
147161
147308
|
});
|
|
147162
147309
|
tx();
|
|
147310
|
+
if (compactNeeded) this.compactStorage();
|
|
147163
147311
|
return snapshot;
|
|
147164
147312
|
}
|
|
147313
|
+
/** Reclaim WAL/free pages after a derived codegraph sweep. */
|
|
147314
|
+
compactStorage() {
|
|
147315
|
+
try {
|
|
147316
|
+
this.db.pragma("wal_checkpoint(TRUNCATE)");
|
|
147317
|
+
} catch {
|
|
147318
|
+
}
|
|
147319
|
+
try {
|
|
147320
|
+
this.db.exec("VACUUM");
|
|
147321
|
+
} catch {
|
|
147322
|
+
}
|
|
147323
|
+
}
|
|
147165
147324
|
status(projectId) {
|
|
147166
147325
|
const files = this.db.prepare(`SELECT COUNT(*) AS count FROM code_files WHERE projectId = ?`).get(projectId).count;
|
|
147167
147326
|
const symbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 0`).get(projectId).count;
|
|
147327
|
+
const staleSymbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 1`).get(projectId).count;
|
|
147168
147328
|
const edges = this.db.prepare(`SELECT COUNT(*) AS count FROM code_edges WHERE projectId = ?`).get(projectId).count;
|
|
147169
147329
|
const refs = this.db.prepare(`SELECT COUNT(*) AS count FROM observation_code_refs WHERE projectId = ?`).get(projectId).count;
|
|
147170
147330
|
const semanticSymbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 0 AND source = 'typescript-compiler'`).get(projectId).count;
|
|
@@ -147172,6 +147332,8 @@ var init_store = __esm({
|
|
|
147172
147332
|
const parserErrors = this.db.prepare(`SELECT COUNT(*) AS count FROM code_files WHERE projectId = ? AND parserError IS NOT NULL`).get(projectId).count;
|
|
147173
147333
|
const latest = this.db.prepare(`SELECT MAX(indexedAt) AS indexedAt FROM code_files WHERE projectId = ?`).get(projectId);
|
|
147174
147334
|
const latestSnapshot = this.latestSnapshot(projectId);
|
|
147335
|
+
const snapshots = this.db.prepare(`SELECT COUNT(*) AS count FROM code_state_snapshots WHERE projectId = ?`).get(projectId).count;
|
|
147336
|
+
const snapshotFiles = this.db.prepare(`SELECT COUNT(*) AS count FROM code_state_snapshot_files WHERE projectId = ?`).get(projectId).count;
|
|
147175
147337
|
return {
|
|
147176
147338
|
provider: "lite",
|
|
147177
147339
|
files,
|
|
@@ -147181,6 +147343,9 @@ var init_store = __esm({
|
|
|
147181
147343
|
semanticSymbols,
|
|
147182
147344
|
semanticEdges,
|
|
147183
147345
|
parserErrors,
|
|
147346
|
+
staleSymbols,
|
|
147347
|
+
snapshots,
|
|
147348
|
+
snapshotFiles,
|
|
147184
147349
|
...latest?.indexedAt ? { indexedAt: latest.indexedAt } : {},
|
|
147185
147350
|
...latestSnapshot ? { latestSnapshot } : {}
|
|
147186
147351
|
};
|
|
@@ -147665,7 +147830,7 @@ __export(lite_provider_exports, {
|
|
|
147665
147830
|
refreshProjectLite: () => refreshProjectLite
|
|
147666
147831
|
});
|
|
147667
147832
|
import { createHash as createHash11 } from "crypto";
|
|
147668
|
-
import { existsSync as
|
|
147833
|
+
import { existsSync as existsSync13, readdirSync as readdirSync2, readFileSync as readFileSync8, statSync as statSync3 } from "fs";
|
|
147669
147834
|
import { join as join4, relative as relative2 } from "path";
|
|
147670
147835
|
function hashText2(text2) {
|
|
147671
147836
|
return createHash11("sha256").update(text2).digest("hex");
|
|
@@ -147683,7 +147848,7 @@ function resolveMaxFileBytes(value) {
|
|
|
147683
147848
|
return Math.max(1, Math.floor(value));
|
|
147684
147849
|
}
|
|
147685
147850
|
function isPythonVirtualenvDir(dir) {
|
|
147686
|
-
return
|
|
147851
|
+
return existsSync13(join4(dir, "pyvenv.cfg"));
|
|
147687
147852
|
}
|
|
147688
147853
|
function walk(root, exclude, maxFiles) {
|
|
147689
147854
|
const out = [];
|
|
@@ -151222,7 +151387,7 @@ __export(vector_backfill_runner_exports, {
|
|
|
151222
151387
|
import { spawn as spawn4 } from "child_process";
|
|
151223
151388
|
import {
|
|
151224
151389
|
closeSync,
|
|
151225
|
-
existsSync as
|
|
151390
|
+
existsSync as existsSync14,
|
|
151226
151391
|
mkdirSync as mkdirSync2,
|
|
151227
151392
|
openSync,
|
|
151228
151393
|
readFileSync as readFileSync9,
|
|
@@ -151350,7 +151515,7 @@ function releaseVectorBackfillLock(lockPath = process.env.MEMORIX_VECTOR_BACKFIL
|
|
|
151350
151515
|
}
|
|
151351
151516
|
function launchDetachedVectorBackfill(request, options = {}) {
|
|
151352
151517
|
const runnerPath = options.runnerPath ?? resolveVectorBackfillRunnerPath();
|
|
151353
|
-
const exists = options.exists ??
|
|
151518
|
+
const exists = options.exists ?? existsSync14;
|
|
151354
151519
|
if (!exists(runnerPath)) return false;
|
|
151355
151520
|
const lock = acquireVectorBackfillLock(request.dataDir, request.projectId, options.lockPath);
|
|
151356
151521
|
if (!lock) return false;
|
|
@@ -151506,10 +151671,22 @@ function resetObservationRuntime() {
|
|
|
151506
151671
|
loadedObservationStore = null;
|
|
151507
151672
|
embeddingWriteMode = "background";
|
|
151508
151673
|
embeddingWorkerProjectRoot = void 0;
|
|
151509
|
-
|
|
151674
|
+
clearVectorMissingIds();
|
|
151510
151675
|
vectorSchemaUpgradePromise = null;
|
|
151511
151676
|
embeddingFailureLogTimestamps.clear();
|
|
151512
151677
|
}
|
|
151678
|
+
function markVectorMissing(observationId2, projectId) {
|
|
151679
|
+
vectorMissingIds.add(observationId2);
|
|
151680
|
+
vectorMissingProjectIds.set(observationId2, projectId);
|
|
151681
|
+
}
|
|
151682
|
+
function clearVectorMissing(observationId2) {
|
|
151683
|
+
vectorMissingIds.delete(observationId2);
|
|
151684
|
+
vectorMissingProjectIds.delete(observationId2);
|
|
151685
|
+
}
|
|
151686
|
+
function clearVectorMissingIds() {
|
|
151687
|
+
vectorMissingIds.clear();
|
|
151688
|
+
vectorMissingProjectIds.clear();
|
|
151689
|
+
}
|
|
151513
151690
|
function logEmbeddingFailureOnce(key, message) {
|
|
151514
151691
|
const now3 = Date.now();
|
|
151515
151692
|
const last = embeddingFailureLogTimestamps.get(key) ?? 0;
|
|
@@ -151629,10 +151806,13 @@ function isVectorCompatibleWithCurrentIndex(embedding) {
|
|
|
151629
151806
|
}
|
|
151630
151807
|
async function upgradeVectorSchemaAfterFirstEmbedding(embedding) {
|
|
151631
151808
|
if (isVectorCompatibleWithCurrentIndex(embedding)) return true;
|
|
151632
|
-
if (
|
|
151809
|
+
if (!embedding.every(Number.isFinite)) return false;
|
|
151633
151810
|
const targetProjectDir = projectDir;
|
|
151634
151811
|
if (!vectorSchemaUpgradePromise) {
|
|
151635
|
-
vectorSchemaUpgradePromise =
|
|
151812
|
+
vectorSchemaUpgradePromise = getDb().then(async () => {
|
|
151813
|
+
if (getVectorDimensions() === null && observations.length > 0) await reindexObservations();
|
|
151814
|
+
return projectDir === targetProjectDir && isVectorCompatibleWithCurrentIndex(embedding);
|
|
151815
|
+
}).catch(() => false).finally(() => {
|
|
151636
151816
|
vectorSchemaUpgradePromise = null;
|
|
151637
151817
|
});
|
|
151638
151818
|
}
|
|
@@ -151672,9 +151852,9 @@ async function initObservations(dir, options = {}) {
|
|
|
151672
151852
|
}
|
|
151673
151853
|
function scheduleObservationEmbedding(input) {
|
|
151674
151854
|
const { observationId: observationId2, projectId, searchableText, doc } = input;
|
|
151675
|
-
|
|
151855
|
+
markVectorMissing(observationId2, projectId);
|
|
151676
151856
|
if (isEmbeddingExplicitlyDisabled()) {
|
|
151677
|
-
|
|
151857
|
+
clearVectorMissing(observationId2);
|
|
151678
151858
|
return;
|
|
151679
151859
|
}
|
|
151680
151860
|
if (embeddingWriteMode === "deferred") {
|
|
@@ -151709,13 +151889,13 @@ function scheduleObservationEmbedding(input) {
|
|
|
151709
151889
|
vector: embedding
|
|
151710
151890
|
});
|
|
151711
151891
|
}
|
|
151712
|
-
|
|
151892
|
+
clearVectorMissing(observationId2);
|
|
151713
151893
|
} catch {
|
|
151714
151894
|
console.error(`[memorix] Embedding index update failed for obs-${observationId2} (kept in backfill queue)`);
|
|
151715
151895
|
queueVectorBackfill(projectId);
|
|
151716
151896
|
}
|
|
151717
151897
|
} else if (isEmbeddingExplicitlyDisabled()) {
|
|
151718
|
-
|
|
151898
|
+
clearVectorMissing(observationId2);
|
|
151719
151899
|
} else {
|
|
151720
151900
|
queueVectorBackfill(projectId);
|
|
151721
151901
|
logEmbeddingFailureOnce(
|
|
@@ -152275,7 +152455,7 @@ async function reindexObservations() {
|
|
|
152275
152455
|
if (observations.length === 0) return 0;
|
|
152276
152456
|
await resetDb();
|
|
152277
152457
|
searchIndexPrepared = false;
|
|
152278
|
-
|
|
152458
|
+
clearVectorMissingIds();
|
|
152279
152459
|
let embeddings = observations.map(() => null);
|
|
152280
152460
|
const provider2 = await getEmbeddingProvider();
|
|
152281
152461
|
const canBatchEmbedAtStartup = provider2 !== null && !provider2.name.startsWith("api-");
|
|
@@ -152340,7 +152520,7 @@ async function reindexObservations() {
|
|
|
152340
152520
|
};
|
|
152341
152521
|
await insertObservation(doc);
|
|
152342
152522
|
if (!compatibleEmbedding && !isEmbeddingExplicitlyDisabled()) {
|
|
152343
|
-
|
|
152523
|
+
markVectorMissing(obs.id, obs.projectId);
|
|
152344
152524
|
}
|
|
152345
152525
|
count2++;
|
|
152346
152526
|
} catch (err) {
|
|
@@ -152357,7 +152537,17 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152357
152537
|
if (!isEmbeddingExplicitlyDisabled()) {
|
|
152358
152538
|
const store = getObservationStore();
|
|
152359
152539
|
const projects = await store.listProjectIds?.() ?? [];
|
|
152360
|
-
|
|
152540
|
+
await getDb({ allowNetworkProbe: false }).catch(() => void 0);
|
|
152541
|
+
const persistedIds = projectDir ? await getPersistentSemanticVectorIds(projectDir).catch(() => null) : null;
|
|
152542
|
+
for (const projectId of projects) {
|
|
152543
|
+
const projectObservations = await store.loadByProject(projectId);
|
|
152544
|
+
for (const observation of projectObservations) {
|
|
152545
|
+
if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
|
|
152546
|
+
}
|
|
152547
|
+
if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
|
|
152548
|
+
queueVectorBackfill(projectId);
|
|
152549
|
+
}
|
|
152550
|
+
}
|
|
152361
152551
|
}
|
|
152362
152552
|
return 0;
|
|
152363
152553
|
}
|
|
@@ -152369,14 +152559,15 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152369
152559
|
return 0;
|
|
152370
152560
|
}
|
|
152371
152561
|
const hydratedProjectDir = projectDir;
|
|
152372
|
-
const queueMissingVectors = () => {
|
|
152373
|
-
if (projectDir !== hydratedProjectDir) return;
|
|
152374
|
-
|
|
152562
|
+
const queueMissingVectors = async () => {
|
|
152563
|
+
if (!hydratedProjectDir || projectDir !== hydratedProjectDir) return;
|
|
152564
|
+
clearVectorMissingIds();
|
|
152375
152565
|
if (!isEmbeddingExplicitlyDisabled()) {
|
|
152566
|
+
const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
|
|
152376
152567
|
const projectsWithMissingVectors = /* @__PURE__ */ new Set();
|
|
152377
152568
|
for (const obs of observations) {
|
|
152378
|
-
if (!hasObservationVector(obs.projectId, obs.id)) {
|
|
152379
|
-
|
|
152569
|
+
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
|
|
152570
|
+
markVectorMissing(obs.id, obs.projectId);
|
|
152380
152571
|
projectsWithMissingVectors.add(obs.projectId);
|
|
152381
152572
|
}
|
|
152382
152573
|
}
|
|
@@ -152385,15 +152576,18 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152385
152576
|
};
|
|
152386
152577
|
const cacheHydration = getDeferredCachedVectorHydration();
|
|
152387
152578
|
if (cacheHydration) {
|
|
152388
|
-
void cacheHydration.
|
|
152579
|
+
void cacheHydration.then(queueMissingVectors, queueMissingVectors).catch(() => void 0);
|
|
152389
152580
|
} else {
|
|
152390
|
-
queueMissingVectors();
|
|
152581
|
+
await queueMissingVectors();
|
|
152391
152582
|
}
|
|
152392
152583
|
searchIndexPrepared = true;
|
|
152393
152584
|
return count2;
|
|
152394
152585
|
}
|
|
152395
152586
|
function getVectorMissingIds(projectId) {
|
|
152396
152587
|
if (!projectId) return [...vectorMissingIds];
|
|
152588
|
+
if (!corpusLoaded) {
|
|
152589
|
+
return [...vectorMissingIds].filter((id) => vectorMissingProjectIds.get(id) === projectId);
|
|
152590
|
+
}
|
|
152397
152591
|
const observationById = new Map(observations.map((observation) => [observation.id, observation]));
|
|
152398
152592
|
return [...vectorMissingIds].filter((id) => observationById.get(id)?.projectId === projectId);
|
|
152399
152593
|
}
|
|
@@ -152431,7 +152625,8 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152431
152625
|
return { attempted: 0, succeeded: 0, failed: 0 };
|
|
152432
152626
|
}
|
|
152433
152627
|
vectorBackfillRunning = true;
|
|
152434
|
-
const
|
|
152628
|
+
const sourceObservations = corpusLoaded ? observations : options.projectId ? await getObservationStore().loadByProject(options.projectId, { status: "active" }) : await getObservationStore().loadAll();
|
|
152629
|
+
const observationById = new Map(sourceObservations.map((observation) => [observation.id, observation]));
|
|
152435
152630
|
const limit2 = Number.isFinite(options.limit) ? Math.max(1, Math.floor(options.limit)) : Number.POSITIVE_INFINITY;
|
|
152436
152631
|
const ids = [...vectorMissingIds].filter((id) => !options.projectId || observationById.get(id)?.projectId === options.projectId).slice(0, limit2);
|
|
152437
152632
|
let succeeded = 0;
|
|
@@ -152444,7 +152639,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152444
152639
|
for (const id of ids) {
|
|
152445
152640
|
const observation = observationById.get(id);
|
|
152446
152641
|
if (!observation) {
|
|
152447
|
-
|
|
152642
|
+
clearVectorMissing(id);
|
|
152448
152643
|
continue;
|
|
152449
152644
|
}
|
|
152450
152645
|
candidates.push({
|
|
@@ -152462,7 +152657,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152462
152657
|
const provider2 = await getEmbeddingProvider();
|
|
152463
152658
|
if (!provider2) {
|
|
152464
152659
|
if (isEmbeddingExplicitlyDisabled()) {
|
|
152465
|
-
for (const candidate of candidates)
|
|
152660
|
+
for (const candidate of candidates) clearVectorMissing(candidate.id);
|
|
152466
152661
|
} else {
|
|
152467
152662
|
recordFailure("embedding provider unavailable");
|
|
152468
152663
|
failed += candidates.length;
|
|
@@ -152539,7 +152734,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152539
152734
|
vector: embedding
|
|
152540
152735
|
});
|
|
152541
152736
|
}
|
|
152542
|
-
|
|
152737
|
+
clearVectorMissing(id);
|
|
152543
152738
|
succeeded++;
|
|
152544
152739
|
} catch (error) {
|
|
152545
152740
|
recordFailure(vectorBackfillError(error));
|
|
@@ -152564,7 +152759,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152564
152759
|
...lastFailure ? { lastError: lastFailure } : {}
|
|
152565
152760
|
};
|
|
152566
152761
|
}
|
|
152567
|
-
var observations, nextId, projectDir, searchIndexPrepared, embeddingWriteMode, embeddingWorkerProjectRoot, corpusLoaded, largeCorpusLazyMode, loadedObservationStore, DEFAULT_ORAMA_HYDRATION_THRESHOLD, vectorMissingIds, vectorBackfillRunning, vectorSchemaUpgradePromise, lastVectorBackfill, embeddingFailureLogTimestamps, EMBEDDING_FAILURE_LOG_COOLDOWN_MS, MAX_EMBEDDING_FAILURE_KEYS;
|
|
152762
|
+
var observations, nextId, projectDir, searchIndexPrepared, embeddingWriteMode, embeddingWorkerProjectRoot, corpusLoaded, largeCorpusLazyMode, loadedObservationStore, DEFAULT_ORAMA_HYDRATION_THRESHOLD, vectorMissingIds, vectorMissingProjectIds, vectorBackfillRunning, vectorSchemaUpgradePromise, lastVectorBackfill, embeddingFailureLogTimestamps, EMBEDDING_FAILURE_LOG_COOLDOWN_MS, MAX_EMBEDDING_FAILURE_KEYS;
|
|
152568
152763
|
var init_observations = __esm({
|
|
152569
152764
|
"src/memory/observations.ts"() {
|
|
152570
152765
|
"use strict";
|
|
@@ -152589,6 +152784,7 @@ var init_observations = __esm({
|
|
|
152589
152784
|
loadedObservationStore = null;
|
|
152590
152785
|
DEFAULT_ORAMA_HYDRATION_THRESHOLD = 1e4;
|
|
152591
152786
|
vectorMissingIds = /* @__PURE__ */ new Set();
|
|
152787
|
+
vectorMissingProjectIds = /* @__PURE__ */ new Map();
|
|
152592
152788
|
vectorBackfillRunning = false;
|
|
152593
152789
|
vectorSchemaUpgradePromise = null;
|
|
152594
152790
|
lastVectorBackfill = null;
|