memorix 1.10.4 → 1.10.5
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 +26 -0
- package/dist/cli/index.js +418 -74
- package/dist/index.js +227 -55
- package/dist/maintenance-runner.js +225 -53
- package/dist/media-audio-runner.js +225 -53
- package/dist/media-video-runner.js +225 -53
- package/dist/memcode-runtime/CHANGELOG.md +44 -0
- package/dist/sdk.js +242 -56
- package/dist/vector-backfill-runner.js +225 -53
- package/docs/AGENT_OPERATOR_PLAYBOOK.md +7 -0
- package/docs/ARCHITECTURE.md +19 -0
- package/docs/CONFIGURATION.md +2 -0
- package/docs/DEVELOPMENT.md +8 -1
- package/docs/MODULES.md +1 -1
- package/docs/PERFORMANCE.md +7 -0
- package/docs/README.md +3 -1
- package/docs/ROADMAP-1.9.12-2.0.md +1 -1
- 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/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/command-guide.ts +3 -1
- package/src/cli/commands/http-session-stream-watch.ts +138 -0
- package/src/cli/commands/memory.ts +3 -1
- package/src/cli/commands/project-detection-cache.ts +61 -0
- package/src/cli/commands/serve-http.ts +63 -13
- package/src/cli/index.ts +1 -1
- package/src/core/derived-view-registry.ts +33 -0
- package/src/embedding/api-provider.ts +14 -2
- package/src/embedding/ollama-embed.ts +118 -0
- package/src/memory/observations.ts +28 -6
- package/src/search/semantic-index.ts +38 -6
- package/src/store/orama-store.ts +46 -30
package/dist/cli/index.js
CHANGED
|
@@ -3232,7 +3232,7 @@ ${import_picocolors.default.gray(m3)} ${s4}
|
|
|
3232
3232
|
|
|
3233
3233
|
// src/cli/version.ts
|
|
3234
3234
|
function getCliVersion() {
|
|
3235
|
-
return true ? "1.10.
|
|
3235
|
+
return true ? "1.10.5" : pkg.version;
|
|
3236
3236
|
}
|
|
3237
3237
|
var init_version = __esm({
|
|
3238
3238
|
"src/cli/version.ts"() {
|
|
@@ -22889,6 +22889,96 @@ var init_transformers_provider = __esm({
|
|
|
22889
22889
|
}
|
|
22890
22890
|
});
|
|
22891
22891
|
|
|
22892
|
+
// src/embedding/ollama-embed.ts
|
|
22893
|
+
async function routeOllamaEmbedding(url2, body, fetchImpl = fetch, probeOptions) {
|
|
22894
|
+
const parsed = parseUrl(url2);
|
|
22895
|
+
if (!parsed) return { url: url2, body, rewritten: false };
|
|
22896
|
+
const openAIRoute = parsed.pathname.endsWith("/v1/embeddings");
|
|
22897
|
+
const nativeRoute = parsed.pathname.endsWith("/api/embed");
|
|
22898
|
+
if (!openAIRoute && !nativeRoute) return { url: url2, body, rewritten: false };
|
|
22899
|
+
if (!await originServesOllama(parsed.origin, fetchImpl, probeOptions)) return { url: url2, body, rewritten: false };
|
|
22900
|
+
if (nativeRoute) return { url: url2, body, rewritten: true };
|
|
22901
|
+
parsed.pathname = parsed.pathname.replace(/\/v1\/embeddings$/, "/api/embed");
|
|
22902
|
+
return { url: parsed.toString(), body: withEmbeddingKeepAlive(body), rewritten: true };
|
|
22903
|
+
}
|
|
22904
|
+
async function originServesOllama(origin, fetchImpl = fetch, probeOptions) {
|
|
22905
|
+
const cached2 = ollamaOrigins.get(origin);
|
|
22906
|
+
if (cached2 != null) return cached2;
|
|
22907
|
+
if (probeOptions?.signal?.aborted) return false;
|
|
22908
|
+
try {
|
|
22909
|
+
const response = await fetchImpl(`${origin}/api/version`, {
|
|
22910
|
+
method: "GET",
|
|
22911
|
+
signal: buildProbeSignal(probeOptions)
|
|
22912
|
+
});
|
|
22913
|
+
if (!response.ok) {
|
|
22914
|
+
ollamaOrigins.set(origin, false);
|
|
22915
|
+
return false;
|
|
22916
|
+
}
|
|
22917
|
+
const detected = isOllamaVersionPayload(await response.json());
|
|
22918
|
+
ollamaOrigins.set(origin, detected);
|
|
22919
|
+
return detected;
|
|
22920
|
+
} catch (err) {
|
|
22921
|
+
if (isAbortError(err) || probeOptions?.signal?.aborted) return false;
|
|
22922
|
+
ollamaOrigins.set(origin, false);
|
|
22923
|
+
return false;
|
|
22924
|
+
}
|
|
22925
|
+
}
|
|
22926
|
+
function mapOllamaEmbeddingResponse(payload) {
|
|
22927
|
+
if (!payload || typeof payload !== "object") return payload;
|
|
22928
|
+
const record2 = payload;
|
|
22929
|
+
if (Array.isArray(record2.data) || !Array.isArray(record2.embeddings)) return payload;
|
|
22930
|
+
const embeddings = record2.embeddings.filter((item) => Array.isArray(item));
|
|
22931
|
+
return {
|
|
22932
|
+
...record2,
|
|
22933
|
+
object: "list",
|
|
22934
|
+
data: embeddings.map((embedding, index) => ({
|
|
22935
|
+
object: "embedding",
|
|
22936
|
+
index,
|
|
22937
|
+
embedding
|
|
22938
|
+
}))
|
|
22939
|
+
};
|
|
22940
|
+
}
|
|
22941
|
+
function withEmbeddingKeepAlive(body) {
|
|
22942
|
+
if (body.keep_alive != null && body.keep_alive !== "") return body;
|
|
22943
|
+
return { ...body, keep_alive: OLLAMA_EMBED_KEEP_ALIVE };
|
|
22944
|
+
}
|
|
22945
|
+
function isOllamaVersionPayload(payload) {
|
|
22946
|
+
if (!payload || typeof payload !== "object") return false;
|
|
22947
|
+
const version2 = payload.version;
|
|
22948
|
+
return typeof version2 === "string" && /^\d+\.\d+\.\d+/.test(version2);
|
|
22949
|
+
}
|
|
22950
|
+
function parseUrl(url2) {
|
|
22951
|
+
try {
|
|
22952
|
+
return new URL(url2);
|
|
22953
|
+
} catch {
|
|
22954
|
+
return null;
|
|
22955
|
+
}
|
|
22956
|
+
}
|
|
22957
|
+
function buildProbeSignal(probeOptions) {
|
|
22958
|
+
const timeoutMs = Math.max(
|
|
22959
|
+
1,
|
|
22960
|
+
Math.min(
|
|
22961
|
+
typeof probeOptions?.probeTimeoutMs === "number" && Number.isFinite(probeOptions.probeTimeoutMs) ? Math.floor(probeOptions.probeTimeoutMs) : 1e3,
|
|
22962
|
+
6e4
|
|
22963
|
+
)
|
|
22964
|
+
);
|
|
22965
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
22966
|
+
if (probeOptions?.signal) return AbortSignal.any([probeOptions.signal, timeoutSignal]);
|
|
22967
|
+
return timeoutSignal;
|
|
22968
|
+
}
|
|
22969
|
+
function isAbortError(err) {
|
|
22970
|
+
return err instanceof Error && err.name === "AbortError";
|
|
22971
|
+
}
|
|
22972
|
+
var OLLAMA_EMBED_KEEP_ALIVE, ollamaOrigins;
|
|
22973
|
+
var init_ollama_embed = __esm({
|
|
22974
|
+
"src/embedding/ollama-embed.ts"() {
|
|
22975
|
+
"use strict";
|
|
22976
|
+
init_esm_shims();
|
|
22977
|
+
OLLAMA_EMBED_KEEP_ALIVE = "5m";
|
|
22978
|
+
ollamaOrigins = /* @__PURE__ */ new Map();
|
|
22979
|
+
}
|
|
22980
|
+
});
|
|
22981
|
+
|
|
22892
22982
|
// src/embedding/api-provider.ts
|
|
22893
22983
|
var api_provider_exports = {};
|
|
22894
22984
|
__export(api_provider_exports, {
|
|
@@ -23590,8 +23680,18 @@ function parseBatchLimit(error40) {
|
|
|
23590
23680
|
return null;
|
|
23591
23681
|
}
|
|
23592
23682
|
async function fetchWithRetry(url2, apiKey, body, options = {}, attempt = 0, nativeGemini = false) {
|
|
23593
|
-
const controller = new AbortController();
|
|
23594
23683
|
const timeoutMs = typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) ? Math.max(100, Math.min(Math.floor(options.timeoutMs), 6e4)) : 1e4;
|
|
23684
|
+
let rewritten = false;
|
|
23685
|
+
if (!nativeGemini) {
|
|
23686
|
+
const routed = await routeOllamaEmbedding(url2, body, fetch, {
|
|
23687
|
+
signal: options.signal,
|
|
23688
|
+
probeTimeoutMs: Math.min(1e3, timeoutMs)
|
|
23689
|
+
});
|
|
23690
|
+
url2 = routed.url;
|
|
23691
|
+
body = routed.body;
|
|
23692
|
+
rewritten = routed.rewritten;
|
|
23693
|
+
}
|
|
23694
|
+
const controller = new AbortController();
|
|
23595
23695
|
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
23596
23696
|
const signal = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
23597
23697
|
let response;
|
|
@@ -23617,10 +23717,11 @@ async function fetchWithRetry(url2, apiKey, body, options = {}, attempt = 0, nat
|
|
|
23617
23717
|
}
|
|
23618
23718
|
try {
|
|
23619
23719
|
if (response.ok) {
|
|
23620
|
-
|
|
23720
|
+
const payload = await raceWithAbort(
|
|
23621
23721
|
response.json(),
|
|
23622
23722
|
signal
|
|
23623
23723
|
);
|
|
23724
|
+
return rewritten ? mapOllamaEmbeddingResponse(payload) : payload;
|
|
23624
23725
|
}
|
|
23625
23726
|
if (options.retry !== false && (response.status === 429 || response.status >= 500) && attempt < MAX_RETRIES2) {
|
|
23626
23727
|
const delay3 = BASE_DELAY_MS * Math.pow(2, attempt);
|
|
@@ -23697,6 +23798,7 @@ var init_api_provider = __esm({
|
|
|
23697
23798
|
"use strict";
|
|
23698
23799
|
init_esm_shims();
|
|
23699
23800
|
init_provider();
|
|
23801
|
+
init_ollama_embed();
|
|
23700
23802
|
cache3 = /* @__PURE__ */ new Map();
|
|
23701
23803
|
MAX_CACHE_ENTRIES = 2e5;
|
|
23702
23804
|
MAX_CACHE_PAYLOAD_BYTES = 256 * 1024 * 1024;
|
|
@@ -26222,10 +26324,12 @@ __export(semantic_index_exports, {
|
|
|
26222
26324
|
getSemanticIndexStats: () => getSemanticIndexStats,
|
|
26223
26325
|
isSemanticIndexAvailable: () => isSemanticIndexAvailable,
|
|
26224
26326
|
listSemanticVectorIds: () => listSemanticVectorIds,
|
|
26327
|
+
listSemanticVectorKeys: () => listSemanticVectorKeys,
|
|
26225
26328
|
optimizeSemanticIndex: () => optimizeSemanticIndex,
|
|
26226
26329
|
optimizeSemanticIndexes: () => optimizeSemanticIndexes,
|
|
26227
26330
|
resetSemanticIndexRuntime: () => resetSemanticIndexRuntime,
|
|
26228
26331
|
searchSemanticVectors: () => searchSemanticVectors,
|
|
26332
|
+
semanticVectorKey: () => semanticVectorKey,
|
|
26229
26333
|
upsertSemanticVector: () => upsertSemanticVector,
|
|
26230
26334
|
upsertSemanticVectors: () => upsertSemanticVectors
|
|
26231
26335
|
});
|
|
@@ -26290,6 +26394,9 @@ async function openState(dataDir, profile) {
|
|
|
26290
26394
|
const table = names.includes(name) ? await connection.openTable(name) : null;
|
|
26291
26395
|
return { key: stateKey(dataDir, profile), dataDir, profile, connection, table };
|
|
26292
26396
|
}
|
|
26397
|
+
function semanticVectorKey(projectId, observationId2) {
|
|
26398
|
+
return `${projectId}:${Math.trunc(observationId2)}`;
|
|
26399
|
+
}
|
|
26293
26400
|
function toLanceRow(record2) {
|
|
26294
26401
|
return {
|
|
26295
26402
|
observation_id: record2.observationId,
|
|
@@ -26360,7 +26467,7 @@ async function mergeVectors(dataDir, profile, records) {
|
|
|
26360
26467
|
const state = await getState(dataDir, profile, records);
|
|
26361
26468
|
if (!state?.table) return;
|
|
26362
26469
|
const rows = records.map(toLanceRow);
|
|
26363
|
-
await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
26470
|
+
await state.table.mergeInsert(["project_id", "observation_id"]).whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
26364
26471
|
const key = stateKey(dataDir, profile);
|
|
26365
26472
|
const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
|
|
26366
26473
|
if (mutationCount >= semanticOptimizeEvery()) {
|
|
@@ -26400,11 +26507,28 @@ function upsertSemanticVector(dataDir, profile, record2) {
|
|
|
26400
26507
|
function upsertSemanticVectors(dataDir, profile, records) {
|
|
26401
26508
|
return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
|
|
26402
26509
|
}
|
|
26403
|
-
async function
|
|
26510
|
+
async function listSemanticVectorKeys(dataDir, profile) {
|
|
26404
26511
|
const state = await getState(dataDir, profile);
|
|
26405
26512
|
if (!state?.table) return null;
|
|
26406
|
-
const rows = await state.table.query().select(["observation_id"]).toArray();
|
|
26407
|
-
|
|
26513
|
+
const rows = await state.table.query().select(["observation_id", "project_id"]).toArray();
|
|
26514
|
+
const keys = /* @__PURE__ */ new Set();
|
|
26515
|
+
for (const row of rows) {
|
|
26516
|
+
const observationId2 = Number(row.observation_id);
|
|
26517
|
+
const projectId = String(row.project_id ?? "");
|
|
26518
|
+
if (!Number.isSafeInteger(observationId2) || !projectId) continue;
|
|
26519
|
+
keys.add(semanticVectorKey(projectId, observationId2));
|
|
26520
|
+
}
|
|
26521
|
+
return keys;
|
|
26522
|
+
}
|
|
26523
|
+
async function listSemanticVectorIds(dataDir, profile) {
|
|
26524
|
+
const keys = await listSemanticVectorKeys(dataDir, profile);
|
|
26525
|
+
if (!keys) return null;
|
|
26526
|
+
const ids = /* @__PURE__ */ new Set();
|
|
26527
|
+
for (const key of keys) {
|
|
26528
|
+
const observationId2 = Number(key.slice(key.lastIndexOf(":") + 1));
|
|
26529
|
+
if (Number.isSafeInteger(observationId2)) ids.add(observationId2);
|
|
26530
|
+
}
|
|
26531
|
+
return ids;
|
|
26408
26532
|
}
|
|
26409
26533
|
async function getSemanticIndexStats(dataDir, profile) {
|
|
26410
26534
|
const state = await getState(dataDir, profile);
|
|
@@ -26446,11 +26570,13 @@ async function optimizeSemanticIndexes(dataDir) {
|
|
|
26446
26570
|
}
|
|
26447
26571
|
}
|
|
26448
26572
|
}
|
|
26449
|
-
function deleteSemanticVector(dataDir, profile, observationId2) {
|
|
26573
|
+
function deleteSemanticVector(dataDir, profile, observationId2, projectId) {
|
|
26450
26574
|
return queueOperation(stateKey(dataDir, profile), async () => {
|
|
26451
26575
|
const state = await getState(dataDir, profile);
|
|
26452
26576
|
if (!state?.table) return;
|
|
26453
|
-
|
|
26577
|
+
const idFilter = `observation_id = ${Math.trunc(observationId2)}`;
|
|
26578
|
+
const filter = projectId ? `${idFilter} AND project_id = '${escapeSqlString(projectId)}'` : idFilter;
|
|
26579
|
+
await state.table.delete(filter);
|
|
26454
26580
|
});
|
|
26455
26581
|
}
|
|
26456
26582
|
function resolveIndexThreshold() {
|
|
@@ -26701,6 +26827,37 @@ var init_derived_view_receipt = __esm({
|
|
|
26701
26827
|
}
|
|
26702
26828
|
});
|
|
26703
26829
|
|
|
26830
|
+
// src/core/derived-view-registry.ts
|
|
26831
|
+
var DerivedViewRegistry;
|
|
26832
|
+
var init_derived_view_registry = __esm({
|
|
26833
|
+
"src/core/derived-view-registry.ts"() {
|
|
26834
|
+
"use strict";
|
|
26835
|
+
init_esm_shims();
|
|
26836
|
+
DerivedViewRegistry = class {
|
|
26837
|
+
readers = /* @__PURE__ */ new Map();
|
|
26838
|
+
register(name, reader2) {
|
|
26839
|
+
const normalized = name.trim();
|
|
26840
|
+
if (!normalized) throw new Error("Derived view name must not be empty");
|
|
26841
|
+
this.readers.set(normalized, reader2);
|
|
26842
|
+
return () => {
|
|
26843
|
+
if (this.readers.get(normalized) === reader2) this.readers.delete(normalized);
|
|
26844
|
+
};
|
|
26845
|
+
}
|
|
26846
|
+
snapshot() {
|
|
26847
|
+
const result = {};
|
|
26848
|
+
for (const [name, reader2] of this.readers) {
|
|
26849
|
+
try {
|
|
26850
|
+
result[name] = reader2();
|
|
26851
|
+
} catch {
|
|
26852
|
+
result[name] = { state: "degraded", reason: "derived view reader failed" };
|
|
26853
|
+
}
|
|
26854
|
+
}
|
|
26855
|
+
return result;
|
|
26856
|
+
}
|
|
26857
|
+
};
|
|
26858
|
+
}
|
|
26859
|
+
});
|
|
26860
|
+
|
|
26704
26861
|
// src/memory/entity-extractor.ts
|
|
26705
26862
|
function extractEntities(content) {
|
|
26706
26863
|
const result = {
|
|
@@ -37826,7 +37983,7 @@ var init_uuid = __esm({
|
|
|
37826
37983
|
});
|
|
37827
37984
|
|
|
37828
37985
|
// node_modules/openai/internal/errors.mjs
|
|
37829
|
-
function
|
|
37986
|
+
function isAbortError2(err) {
|
|
37830
37987
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
37831
37988
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
37832
37989
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -39006,7 +39163,7 @@ var init_streaming = __esm({
|
|
|
39006
39163
|
}
|
|
39007
39164
|
done = true;
|
|
39008
39165
|
} catch (e5) {
|
|
39009
|
-
if (
|
|
39166
|
+
if (isAbortError2(e5))
|
|
39010
39167
|
return;
|
|
39011
39168
|
throw e5;
|
|
39012
39169
|
} finally {
|
|
@@ -39049,7 +39206,7 @@ var init_streaming = __esm({
|
|
|
39049
39206
|
}
|
|
39050
39207
|
done = true;
|
|
39051
39208
|
} catch (e5) {
|
|
39052
|
-
if (
|
|
39209
|
+
if (isAbortError2(e5))
|
|
39053
39210
|
return;
|
|
39054
39211
|
throw e5;
|
|
39055
39212
|
} finally {
|
|
@@ -45598,7 +45755,7 @@ var init_client = __esm({
|
|
|
45598
45755
|
if (options.signal?.aborted) {
|
|
45599
45756
|
throw new APIUserAbortError();
|
|
45600
45757
|
}
|
|
45601
|
-
const isTimeout =
|
|
45758
|
+
const isTimeout = isAbortError2(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
45602
45759
|
if (retriesRemaining) {
|
|
45603
45760
|
loggerFor(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
45604
45761
|
loggerFor(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails({
|
|
@@ -64698,7 +64855,7 @@ var init_uuid2 = __esm({
|
|
|
64698
64855
|
});
|
|
64699
64856
|
|
|
64700
64857
|
// node_modules/@anthropic-ai/sdk/internal/errors.mjs
|
|
64701
|
-
function
|
|
64858
|
+
function isAbortError3(err) {
|
|
64702
64859
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
64703
64860
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
64704
64861
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -65469,7 +65626,7 @@ var init_streaming3 = __esm({
|
|
|
65469
65626
|
}
|
|
65470
65627
|
done = true;
|
|
65471
65628
|
} catch (e5) {
|
|
65472
|
-
if (
|
|
65629
|
+
if (isAbortError3(e5))
|
|
65473
65630
|
return;
|
|
65474
65631
|
throw e5;
|
|
65475
65632
|
} finally {
|
|
@@ -65512,7 +65669,7 @@ var init_streaming3 = __esm({
|
|
|
65512
65669
|
}
|
|
65513
65670
|
done = true;
|
|
65514
65671
|
} catch (e5) {
|
|
65515
|
-
if (
|
|
65672
|
+
if (isAbortError3(e5))
|
|
65516
65673
|
return;
|
|
65517
65674
|
throw e5;
|
|
65518
65675
|
} finally {
|
|
@@ -67634,7 +67791,7 @@ var init_BetaMessageStream = __esm({
|
|
|
67634
67791
|
_BetaMessageStream_logger.set(this, void 0);
|
|
67635
67792
|
_BetaMessageStream_handleError.set(this, (error40) => {
|
|
67636
67793
|
__classPrivateFieldSet2(this, _BetaMessageStream_errored, true, "f");
|
|
67637
|
-
if (
|
|
67794
|
+
if (isAbortError3(error40)) {
|
|
67638
67795
|
error40 = new APIUserAbortError2();
|
|
67639
67796
|
}
|
|
67640
67797
|
if (error40 instanceof APIUserAbortError2) {
|
|
@@ -70095,7 +70252,7 @@ var init_MessageStream = __esm({
|
|
|
70095
70252
|
_MessageStream_logger.set(this, void 0);
|
|
70096
70253
|
_MessageStream_handleError.set(this, (error40) => {
|
|
70097
70254
|
__classPrivateFieldSet2(this, _MessageStream_errored, true, "f");
|
|
70098
|
-
if (
|
|
70255
|
+
if (isAbortError3(error40)) {
|
|
70099
70256
|
error40 = new APIUserAbortError2();
|
|
70100
70257
|
}
|
|
70101
70258
|
if (error40 instanceof APIUserAbortError2) {
|
|
@@ -71225,7 +71382,7 @@ var init_client2 = __esm({
|
|
|
71225
71382
|
if (options.signal?.aborted) {
|
|
71226
71383
|
throw new APIUserAbortError2();
|
|
71227
71384
|
}
|
|
71228
|
-
const isTimeout =
|
|
71385
|
+
const isTimeout = isAbortError3(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
71229
71386
|
if (retriesRemaining) {
|
|
71230
71387
|
loggerFor2(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
71231
71388
|
loggerFor2(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails2({
|
|
@@ -105733,7 +105890,7 @@ function listDocumentsResponseFromMldev(fromObject) {
|
|
|
105733
105890
|
}
|
|
105734
105891
|
return toObject;
|
|
105735
105892
|
}
|
|
105736
|
-
function
|
|
105893
|
+
function isAbortError4(err) {
|
|
105737
105894
|
return typeof err === "object" && err !== null && // Spec-compliant fetch implementations
|
|
105738
105895
|
("name" in err && err.name === "AbortError" || // Expo fetch
|
|
105739
105896
|
"message" in err && String(err.message).includes("FetchRequestCanceledException"));
|
|
@@ -112947,7 +113104,7 @@ ${underline}`);
|
|
|
112947
113104
|
}
|
|
112948
113105
|
done = true;
|
|
112949
113106
|
} catch (e5) {
|
|
112950
|
-
if (
|
|
113107
|
+
if (isAbortError4(e5))
|
|
112951
113108
|
return yield __await(void 0);
|
|
112952
113109
|
throw e5;
|
|
112953
113110
|
} finally {
|
|
@@ -113022,7 +113179,7 @@ ${underline}`);
|
|
|
113022
113179
|
}
|
|
113023
113180
|
done = true;
|
|
113024
113181
|
} catch (e5) {
|
|
113025
|
-
if (
|
|
113182
|
+
if (isAbortError4(e5))
|
|
113026
113183
|
return yield __await(void 0);
|
|
113027
113184
|
throw e5;
|
|
113028
113185
|
} finally {
|
|
@@ -113398,7 +113555,7 @@ ${underline}`);
|
|
|
113398
113555
|
if ((_d = options.signal) === null || _d === void 0 ? void 0 : _d.aborted) {
|
|
113399
113556
|
throw new APIUserAbortError3();
|
|
113400
113557
|
}
|
|
113401
|
-
const isTimeout =
|
|
113558
|
+
const isTimeout = isAbortError4(response) || /timed? ?out/i.test(String(response) + ("cause" in response ? String(response.cause) : ""));
|
|
113402
113559
|
if (retriesRemaining) {
|
|
113403
113560
|
loggerFor3(this).info(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} - ${retryMessage}`);
|
|
113404
113561
|
loggerFor3(this).debug(`[${requestLogID}] connection ${isTimeout ? "timed out" : "failed"} (${retryMessage})`, formatRequestDetails3({
|
|
@@ -115622,7 +115779,7 @@ function isTimeoutError(err) {
|
|
|
115622
115779
|
const isGenericErr = "code" in err && typeof err.code === "string" && err.code.toLowerCase() === "econnaborted";
|
|
115623
115780
|
return isNative || isLegacyNative || isGenericErr;
|
|
115624
115781
|
}
|
|
115625
|
-
function
|
|
115782
|
+
function isAbortError5(err) {
|
|
115626
115783
|
if (typeof err !== "object" || err == null) {
|
|
115627
115784
|
return false;
|
|
115628
115785
|
}
|
|
@@ -128373,7 +128530,7 @@ var init_sdks = __esm({
|
|
|
128373
128530
|
return response;
|
|
128374
128531
|
}, { config: options.retryConfig, statusCodes: options.retryCodes }).then((r6) => OK(r6), (err) => {
|
|
128375
128532
|
switch (true) {
|
|
128376
|
-
case
|
|
128533
|
+
case isAbortError5(err):
|
|
128377
128534
|
return ERR(new RequestAbortedError("Request aborted by client", {
|
|
128378
128535
|
cause: err
|
|
128379
128536
|
}));
|
|
@@ -186903,13 +187060,17 @@ async function enqueueObservationDerivedWork(tx, observation) {
|
|
|
186903
187060
|
payload: { observationId: observation.id }
|
|
186904
187061
|
});
|
|
186905
187062
|
}
|
|
187063
|
+
await enqueueObservationProjectionWork(tx, observation);
|
|
187064
|
+
return true;
|
|
187065
|
+
}
|
|
187066
|
+
async function enqueueObservationProjectionWork(tx, observation) {
|
|
187067
|
+
if (!tx.enqueueMaintenanceJob) return;
|
|
186906
187068
|
await tx.enqueueMaintenanceJob({
|
|
186907
187069
|
projectId: observation.projectId,
|
|
186908
187070
|
kind: "observation-project",
|
|
186909
187071
|
dedupeKey: "observation-project:" + observation.id,
|
|
186910
187072
|
payload: { observationId: observation.id }
|
|
186911
187073
|
});
|
|
186912
|
-
return true;
|
|
186913
187074
|
}
|
|
186914
187075
|
function isVectorCompatibleWithCurrentIndex(embedding) {
|
|
186915
187076
|
if (!embedding) return false;
|
|
@@ -187443,6 +187604,7 @@ async function updateObservationAdmission(input) {
|
|
|
187443
187604
|
const next = apply(current);
|
|
187444
187605
|
if (!next) return;
|
|
187445
187606
|
await tx.update(next);
|
|
187607
|
+
await enqueueObservationProjectionWork(tx, next);
|
|
187446
187608
|
updated = next;
|
|
187447
187609
|
});
|
|
187448
187610
|
} else {
|
|
@@ -187460,6 +187622,9 @@ async function updateObservationAdmission(input) {
|
|
|
187460
187622
|
});
|
|
187461
187623
|
} catch {
|
|
187462
187624
|
}
|
|
187625
|
+
if (await persistEvidenceCard(updated)) {
|
|
187626
|
+
await acknowledgeObservationProjection(updated);
|
|
187627
|
+
}
|
|
187463
187628
|
if (updated.admissionState === "qualified" && resolveObservationVisibility(updated) === "project") {
|
|
187464
187629
|
queueClaimDerivation(updated);
|
|
187465
187630
|
}
|
|
@@ -187530,10 +187695,17 @@ async function resolveObservations(ids, status = "resolved") {
|
|
|
187530
187695
|
if (projectDir && resolved.length > 0) {
|
|
187531
187696
|
const store2 = getObservationStore();
|
|
187532
187697
|
await store2.atomic(async (tx) => {
|
|
187533
|
-
await Promise.all(changed.map((observation) =>
|
|
187698
|
+
await Promise.all(changed.map(async (observation) => {
|
|
187699
|
+
await tx.update(observation);
|
|
187700
|
+
await enqueueObservationProjectionWork(tx, observation);
|
|
187701
|
+
}));
|
|
187534
187702
|
});
|
|
187535
187703
|
}
|
|
187536
|
-
for (const observation of changed)
|
|
187704
|
+
for (const observation of changed) {
|
|
187705
|
+
if (await persistEvidenceCard(observation)) {
|
|
187706
|
+
await acknowledgeObservationProjection(observation);
|
|
187707
|
+
}
|
|
187708
|
+
}
|
|
187537
187709
|
return { resolved, notFound };
|
|
187538
187710
|
}
|
|
187539
187711
|
function getProjectObservations(projectId) {
|
|
@@ -187686,9 +187858,9 @@ async function prepareSearchIndex(options = {}) {
|
|
|
187686
187858
|
for (const projectId of projects) {
|
|
187687
187859
|
const projectObservations = await store2.loadByProject(projectId);
|
|
187688
187860
|
for (const observation of projectObservations) {
|
|
187689
|
-
if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
|
|
187861
|
+
if (!persistedIds?.has(semanticVectorKey(observation.projectId, observation.id))) markVectorMissing(observation.id, observation.projectId);
|
|
187690
187862
|
}
|
|
187691
|
-
if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
|
|
187863
|
+
if (projectObservations.some((observation) => !persistedIds?.has(semanticVectorKey(observation.projectId, observation.id)))) {
|
|
187692
187864
|
queueVectorBackfill(projectId);
|
|
187693
187865
|
}
|
|
187694
187866
|
}
|
|
@@ -187710,7 +187882,7 @@ async function prepareSearchIndex(options = {}) {
|
|
|
187710
187882
|
const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
|
|
187711
187883
|
const projectsWithMissingVectors = /* @__PURE__ */ new Set();
|
|
187712
187884
|
for (const obs of observations) {
|
|
187713
|
-
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
|
|
187885
|
+
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(semanticVectorKey(obs.projectId, obs.id))) {
|
|
187714
187886
|
markVectorMissing(obs.id, obs.projectId);
|
|
187715
187887
|
projectsWithMissingVectors.add(obs.projectId);
|
|
187716
187888
|
}
|
|
@@ -187914,6 +188086,7 @@ var init_observations = __esm({
|
|
|
187914
188086
|
init_token_budget();
|
|
187915
188087
|
init_entity_extractor();
|
|
187916
188088
|
init_provider();
|
|
188089
|
+
init_semantic_index();
|
|
187917
188090
|
init_secret_filter();
|
|
187918
188091
|
init_lifecycle();
|
|
187919
188092
|
init_visibility();
|
|
@@ -188588,15 +188761,17 @@ function getLastSearchDiagnostics(projectId) {
|
|
|
188588
188761
|
return diagnostics ? { ...diagnostics } : void 0;
|
|
188589
188762
|
}
|
|
188590
188763
|
function getSearchDerivedViews() {
|
|
188591
|
-
|
|
188764
|
+
return searchDerivedViewRegistry.snapshot();
|
|
188765
|
+
}
|
|
188766
|
+
function readFtsDerivedViewReceipt() {
|
|
188592
188767
|
const store2 = getOptionalObservationStore();
|
|
188593
188768
|
if (store2) {
|
|
188594
188769
|
try {
|
|
188595
188770
|
const generation = store2.getGeneration();
|
|
188596
188771
|
if (store2.hasLexicalIndex?.()) {
|
|
188597
|
-
|
|
188772
|
+
return { generation, freshness: "current", rebuildStatus: "idle" };
|
|
188598
188773
|
} else {
|
|
188599
|
-
|
|
188774
|
+
return {
|
|
188600
188775
|
generation,
|
|
188601
188776
|
freshness: "unknown",
|
|
188602
188777
|
rebuildStatus: "unavailable",
|
|
@@ -188606,32 +188781,34 @@ function getSearchDerivedViews() {
|
|
|
188606
188781
|
};
|
|
188607
188782
|
}
|
|
188608
188783
|
} catch (error40) {
|
|
188609
|
-
|
|
188784
|
+
return {
|
|
188610
188785
|
freshness: "unknown",
|
|
188611
188786
|
rebuildStatus: "failed",
|
|
188612
188787
|
failureReason: sanitizeDerivedViewFailureReason(error40 instanceof Error ? error40.message : String(error40))
|
|
188613
188788
|
};
|
|
188614
188789
|
}
|
|
188615
|
-
} else {
|
|
188616
|
-
views.fts = {
|
|
188617
|
-
freshness: "unknown",
|
|
188618
|
-
rebuildStatus: "unavailable",
|
|
188619
|
-
failureReason: "observation store is not initialized"
|
|
188620
|
-
};
|
|
188621
188790
|
}
|
|
188622
|
-
|
|
188791
|
+
return {
|
|
188792
|
+
freshness: "unknown",
|
|
188793
|
+
rebuildStatus: "unavailable",
|
|
188794
|
+
failureReason: "observation store is not initialized"
|
|
188795
|
+
};
|
|
188796
|
+
}
|
|
188797
|
+
function readOramaDerivedViewReceipt() {
|
|
188798
|
+
return db ? { generation: dbGeneration, freshness: "current", rebuildStatus: "idle" } : {
|
|
188623
188799
|
generation: dbGeneration,
|
|
188624
188800
|
freshness: "unknown",
|
|
188625
188801
|
rebuildStatus: "unavailable",
|
|
188626
188802
|
failureReason: "Orama index is not initialized"
|
|
188627
188803
|
};
|
|
188804
|
+
}
|
|
188805
|
+
function readEmbeddingDerivedViewReceipt() {
|
|
188628
188806
|
let embeddingHealth;
|
|
188629
188807
|
try {
|
|
188630
188808
|
embeddingHealth = getEmbeddingRuntimeHealth?.();
|
|
188631
188809
|
} catch {
|
|
188632
188810
|
}
|
|
188633
|
-
|
|
188634
|
-
return views;
|
|
188811
|
+
return embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
|
|
188635
188812
|
}
|
|
188636
188813
|
function rememberSearchDiagnostics(key, value) {
|
|
188637
188814
|
if (!lastSearchDiagnosticsByProject.has(key) && lastSearchDiagnosticsByProject.size >= MAX_SEARCH_MODE_KEYS) {
|
|
@@ -188768,10 +188945,12 @@ async function searchLanceInVectorOrder(options, projectIds, limit2, queryVector
|
|
|
188768
188945
|
const hits = [];
|
|
188769
188946
|
const seen = /* @__PURE__ */ new Set();
|
|
188770
188947
|
for (const hit of vectorHits) {
|
|
188771
|
-
if (
|
|
188772
|
-
|
|
188948
|
+
if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) continue;
|
|
188949
|
+
const key = semanticVectorKey(hit.projectId, hit.observationId);
|
|
188950
|
+
if (seen.has(key)) continue;
|
|
188951
|
+
seen.add(key);
|
|
188773
188952
|
const observation = await store2.getById(hit.observationId);
|
|
188774
|
-
if (!observation) continue;
|
|
188953
|
+
if (!observation || observation.projectId !== hit.projectId) continue;
|
|
188775
188954
|
if (projectIds && !projectIds.includes(observation.projectId)) continue;
|
|
188776
188955
|
if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) continue;
|
|
188777
188956
|
if (options.type && observation.type !== options.type) continue;
|
|
@@ -188817,14 +188996,15 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
188817
188996
|
documents.set(makeEntryKey(hit.document.projectId, hit.document.observationId), hit.document);
|
|
188818
188997
|
}
|
|
188819
188998
|
const vectorObservations = await Promise.all(vectorHits.map(async (hit) => {
|
|
188999
|
+
if (projectIds ? !projectIds.includes(hit.projectId) : options.projectId && hit.projectId !== options.projectId) return null;
|
|
188820
189000
|
const observation = await store2.getById(hit.observationId);
|
|
188821
|
-
if (!observation) return null;
|
|
189001
|
+
if (!observation || observation.projectId !== hit.projectId) return null;
|
|
188822
189002
|
if (projectIds && !projectIds.includes(observation.projectId)) return null;
|
|
188823
189003
|
if (options.status !== "all" && (observation.status ?? "active") !== (options.status ?? "active")) return null;
|
|
188824
189004
|
if (options.type && observation.type !== options.type) return null;
|
|
188825
189005
|
if (options.source && observation.source !== options.source) return null;
|
|
188826
189006
|
addObservation(observation);
|
|
188827
|
-
vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
|
|
189007
|
+
vectorDocumentKeys.set(semanticVectorKey(hit.projectId, hit.observationId), makeEntryKey(observation.projectId, observation.id));
|
|
188828
189008
|
return observation;
|
|
188829
189009
|
}));
|
|
188830
189010
|
const RRF_K = 60;
|
|
@@ -188834,7 +189014,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
188834
189014
|
scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
|
|
188835
189015
|
}
|
|
188836
189016
|
for (const [index, hit] of vectorHits.entries()) {
|
|
188837
|
-
const key = vectorDocumentKeys.get(
|
|
189017
|
+
const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
|
|
189018
|
+
if (!key) continue;
|
|
188838
189019
|
if (!documents.has(key)) continue;
|
|
188839
189020
|
scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
|
|
188840
189021
|
}
|
|
@@ -188847,8 +189028,8 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
|
|
|
188847
189028
|
return {
|
|
188848
189029
|
count: vectorHits.length,
|
|
188849
189030
|
hits: vectorHits.map((hit, index) => {
|
|
188850
|
-
const key = vectorDocumentKeys.get(
|
|
188851
|
-
const document2 = documents.get(key);
|
|
189031
|
+
const key = vectorDocumentKeys.get(semanticVectorKey(hit.projectId, hit.observationId));
|
|
189032
|
+
const document2 = key ? documents.get(key) : void 0;
|
|
188852
189033
|
return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
|
|
188853
189034
|
}).filter((hit) => hit !== null).slice(0, limit2)
|
|
188854
189035
|
};
|
|
@@ -188979,7 +189160,7 @@ function getActiveSemanticIndexProfile() {
|
|
|
188979
189160
|
}
|
|
188980
189161
|
async function getPersistentSemanticVectorIds(dataDir) {
|
|
188981
189162
|
if (!indexEmbeddingProvider) return null;
|
|
188982
|
-
return
|
|
189163
|
+
return listSemanticVectorKeys(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
|
|
188983
189164
|
}
|
|
188984
189165
|
async function queueSemanticVector(dataDir, record2) {
|
|
188985
189166
|
const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
|
|
@@ -189048,7 +189229,7 @@ function isCompatibleCachedVector(vector) {
|
|
|
189048
189229
|
async function attachCachedVectors(database, observations2) {
|
|
189049
189230
|
const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
|
|
189050
189231
|
const semanticProfile = getActiveSemanticIndexProfile();
|
|
189051
|
-
const persistedSemanticIds = semanticDataDir && semanticProfile ? await
|
|
189232
|
+
const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorKeys(semanticDataDir, semanticProfile).catch(() => null) : null;
|
|
189052
189233
|
const batchSize = 200;
|
|
189053
189234
|
for (let start = 0; start < observations2.length; start += batchSize) {
|
|
189054
189235
|
const batch = observations2.slice(start, start + batchSize);
|
|
@@ -189059,7 +189240,7 @@ async function attachCachedVectors(database, observations2) {
|
|
|
189059
189240
|
const vector = cachedVectors[index];
|
|
189060
189241
|
if (!isCompatibleCachedVector(vector)) continue;
|
|
189061
189242
|
const observation = batch[index];
|
|
189062
|
-
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
|
|
189243
|
+
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(semanticVectorKey(observation.projectId, observation.id))) {
|
|
189063
189244
|
semanticRecords.push({
|
|
189064
189245
|
observationId: observation.id,
|
|
189065
189246
|
projectId: observation.projectId,
|
|
@@ -189849,7 +190030,7 @@ function formatTime(isoDate) {
|
|
|
189849
190030
|
return isoDate;
|
|
189850
190031
|
}
|
|
189851
190032
|
}
|
|
189852
|
-
var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
|
|
190033
|
+
var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, lastSearchDiagnosticsByProject, searchDerivedViewRegistry, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
|
|
189853
190034
|
var init_orama_store = __esm({
|
|
189854
190035
|
"src/store/orama-store.ts"() {
|
|
189855
190036
|
"use strict";
|
|
@@ -189872,6 +190053,7 @@ var init_orama_store = __esm({
|
|
|
189872
190053
|
init_retrieval_contracts();
|
|
189873
190054
|
init_semantic_index();
|
|
189874
190055
|
init_derived_view_receipt();
|
|
190056
|
+
init_derived_view_registry();
|
|
189875
190057
|
db = null;
|
|
189876
190058
|
dbInitPromise = null;
|
|
189877
190059
|
dbGeneration = 0;
|
|
@@ -189883,8 +190065,12 @@ var init_orama_store = __esm({
|
|
|
189883
190065
|
CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
|
|
189884
190066
|
lastSearchModeByProject = /* @__PURE__ */ new Map();
|
|
189885
190067
|
lastSearchDiagnosticsByProject = /* @__PURE__ */ new Map();
|
|
190068
|
+
searchDerivedViewRegistry = new DerivedViewRegistry();
|
|
189886
190069
|
SEARCH_MODE_DEFAULT_KEY = "__global__";
|
|
189887
190070
|
MAX_SEARCH_MODE_KEYS = 4096;
|
|
190071
|
+
searchDerivedViewRegistry.register("fts", readFtsDerivedViewReceipt);
|
|
190072
|
+
searchDerivedViewRegistry.register("orama", readOramaDerivedViewReceipt);
|
|
190073
|
+
searchDerivedViewRegistry.register("embedding", readEmbeddingDerivedViewReceipt);
|
|
189888
190074
|
COMMAND_LOG_TITLE2 = /^(Ran:|Command:|Executed:)\s/i;
|
|
189889
190075
|
COMMAND_STYLE_TITLE = /(\bfindstr\b|\bSelect-String\b|\bGet-Content\b|\bnpx\s+vitest\b|\bnpx\s+tsc\b|\b2>&1\b)/i;
|
|
189890
190076
|
COMMAND_LIKE_QUERY2 = /\b(git|npm|npx|pnpm|yarn|node|bash|powershell|curl|memorix)\b/i;
|
|
@@ -193590,7 +193776,9 @@ function printMemoryUsage() {
|
|
|
193590
193776
|
console.log("Usage:");
|
|
193591
193777
|
console.log(' memorix memory search --query "timeout bug" [--limit 10] [--quality fast|balanced|thorough]');
|
|
193592
193778
|
console.log(" memorix memory recent [--limit 10]");
|
|
193593
|
-
console.log(' memorix memory store --text "..." [--title "..."] [--type discovery] [--visibility project|personal|team]');
|
|
193779
|
+
console.log(' memorix memory store --text "..." [--title "..."] [--type discovery] [--entity <name>] [--topic-key <key>] [--facts a,b] [--files a,b] [--concepts a,b] [--visibility project|personal|team]');
|
|
193780
|
+
console.log(" The same project and the same --topic-key update the existing observation and return upserted: true.");
|
|
193781
|
+
console.log(" memorix remember does not forward --entity or --topic-key.");
|
|
193594
193782
|
console.log(' memorix memory suggest-topic-key --type decision --title "..."');
|
|
193595
193783
|
console.log(" memorix memory detail --id 42");
|
|
193596
193784
|
console.log(" memorix memory detail obs:42@org/project");
|
|
@@ -210773,7 +210961,7 @@ var init_tool_profile = __esm({
|
|
|
210773
210961
|
function getMcpServerInfo() {
|
|
210774
210962
|
return {
|
|
210775
210963
|
name: "memorix",
|
|
210776
|
-
version: true ? "1.10.
|
|
210964
|
+
version: true ? "1.10.5" : "1.0.1"
|
|
210777
210965
|
};
|
|
210778
210966
|
}
|
|
210779
210967
|
function createMcpDiscoverResult(capabilities, serverInfo) {
|
|
@@ -273265,6 +273453,124 @@ var init_port = __esm({
|
|
|
273265
273453
|
}
|
|
273266
273454
|
});
|
|
273267
273455
|
|
|
273456
|
+
// src/cli/commands/http-session-stream-watch.ts
|
|
273457
|
+
function parseSessionDisconnectGraceMs(raw) {
|
|
273458
|
+
const value = raw?.trim();
|
|
273459
|
+
if (!value) return DEFAULT_SESSION_DISCONNECT_GRACE_MS;
|
|
273460
|
+
const parsed = Number(value);
|
|
273461
|
+
if (!Number.isFinite(parsed) || parsed < 0 || parsed > 2147483647) return DEFAULT_SESSION_DISCONNECT_GRACE_MS;
|
|
273462
|
+
return Math.floor(parsed);
|
|
273463
|
+
}
|
|
273464
|
+
function createSessionStreamWatch(options) {
|
|
273465
|
+
const now3 = options.now ?? Date.now;
|
|
273466
|
+
const setTimer = options.setTimer ?? ((callback, ms2) => setTimeout(callback, ms2));
|
|
273467
|
+
const clearTimer = options.clearTimer ?? ((handle) => clearTimeout(handle));
|
|
273468
|
+
const openStreams = /* @__PURE__ */ new Map();
|
|
273469
|
+
const closedStreams = /* @__PURE__ */ new Set();
|
|
273470
|
+
const pending = /* @__PURE__ */ new Map();
|
|
273471
|
+
function cancel(sessionId) {
|
|
273472
|
+
const handle = pending.get(sessionId);
|
|
273473
|
+
if (!handle) return;
|
|
273474
|
+
clearTimer(handle);
|
|
273475
|
+
pending.delete(sessionId);
|
|
273476
|
+
}
|
|
273477
|
+
return {
|
|
273478
|
+
streamOpened(sessionId) {
|
|
273479
|
+
if (options.graceMs === 0) return;
|
|
273480
|
+
cancel(sessionId);
|
|
273481
|
+
openStreams.set(sessionId, (openStreams.get(sessionId) ?? 0) + 1);
|
|
273482
|
+
},
|
|
273483
|
+
streamClosed(sessionId, wasStream) {
|
|
273484
|
+
if (!openStreams.has(sessionId)) return;
|
|
273485
|
+
if (wasStream) closedStreams.add(sessionId);
|
|
273486
|
+
const remaining = Math.max(0, (openStreams.get(sessionId) ?? 0) - 1);
|
|
273487
|
+
if (remaining > 0) {
|
|
273488
|
+
openStreams.set(sessionId, remaining);
|
|
273489
|
+
return;
|
|
273490
|
+
}
|
|
273491
|
+
openStreams.delete(sessionId);
|
|
273492
|
+
const hadStream = closedStreams.delete(sessionId);
|
|
273493
|
+
if (!hadStream || options.graceMs === 0) return;
|
|
273494
|
+
if (options.getLastActivity(sessionId) === void 0) return;
|
|
273495
|
+
cancel(sessionId);
|
|
273496
|
+
const closedAt = now3();
|
|
273497
|
+
const check2 = () => {
|
|
273498
|
+
pending.delete(sessionId);
|
|
273499
|
+
if ((openStreams.get(sessionId) ?? 0) > 0) return;
|
|
273500
|
+
const lastActivity = options.getLastActivity(sessionId);
|
|
273501
|
+
if (lastActivity === void 0) return;
|
|
273502
|
+
if (lastActivity > closedAt) return;
|
|
273503
|
+
if (options.isBusy?.(sessionId)) {
|
|
273504
|
+
const next = setTimer(check2, options.graceMs);
|
|
273505
|
+
next.unref?.();
|
|
273506
|
+
pending.set(sessionId, next);
|
|
273507
|
+
return;
|
|
273508
|
+
}
|
|
273509
|
+
options.onAbandoned(sessionId);
|
|
273510
|
+
};
|
|
273511
|
+
const handle = setTimer(check2, options.graceMs);
|
|
273512
|
+
handle.unref?.();
|
|
273513
|
+
pending.set(sessionId, handle);
|
|
273514
|
+
},
|
|
273515
|
+
forget(sessionId) {
|
|
273516
|
+
cancel(sessionId);
|
|
273517
|
+
openStreams.delete(sessionId);
|
|
273518
|
+
closedStreams.delete(sessionId);
|
|
273519
|
+
},
|
|
273520
|
+
dispose() {
|
|
273521
|
+
for (const handle of pending.values()) clearTimer(handle);
|
|
273522
|
+
pending.clear();
|
|
273523
|
+
openStreams.clear();
|
|
273524
|
+
closedStreams.clear();
|
|
273525
|
+
},
|
|
273526
|
+
pendingCount() {
|
|
273527
|
+
return pending.size;
|
|
273528
|
+
}
|
|
273529
|
+
};
|
|
273530
|
+
}
|
|
273531
|
+
var DEFAULT_SESSION_DISCONNECT_GRACE_MS;
|
|
273532
|
+
var init_http_session_stream_watch = __esm({
|
|
273533
|
+
"src/cli/commands/http-session-stream-watch.ts"() {
|
|
273534
|
+
"use strict";
|
|
273535
|
+
init_esm_shims();
|
|
273536
|
+
DEFAULT_SESSION_DISCONNECT_GRACE_MS = 2 * 60 * 1e3;
|
|
273537
|
+
}
|
|
273538
|
+
});
|
|
273539
|
+
|
|
273540
|
+
// src/cli/commands/project-detection-cache.ts
|
|
273541
|
+
function createCachedProjectDetector(detect, options = {}) {
|
|
273542
|
+
const ttlMs = options.ttlMs ?? DEFAULT_PROJECT_DETECTION_CACHE_TTL_MS;
|
|
273543
|
+
const maxEntries = options.maxEntries ?? MAX_PROJECT_DETECTION_CACHE_ENTRIES;
|
|
273544
|
+
const now3 = options.now ?? Date.now;
|
|
273545
|
+
const cache5 = /* @__PURE__ */ new Map();
|
|
273546
|
+
const cached2 = ((root) => {
|
|
273547
|
+
const at2 = now3();
|
|
273548
|
+
const hit = cache5.get(root);
|
|
273549
|
+
if (hit && hit.expiresAt > at2) return hit.project;
|
|
273550
|
+
const project = detect(root);
|
|
273551
|
+
cache5.delete(root);
|
|
273552
|
+
cache5.set(root, { project, expiresAt: at2 + ttlMs });
|
|
273553
|
+
while (cache5.size > maxEntries) {
|
|
273554
|
+
const oldest = cache5.keys().next().value;
|
|
273555
|
+
if (oldest === void 0) break;
|
|
273556
|
+
cache5.delete(oldest);
|
|
273557
|
+
}
|
|
273558
|
+
return project;
|
|
273559
|
+
});
|
|
273560
|
+
cached2.clear = () => cache5.clear();
|
|
273561
|
+
cached2.size = () => cache5.size;
|
|
273562
|
+
return cached2;
|
|
273563
|
+
}
|
|
273564
|
+
var DEFAULT_PROJECT_DETECTION_CACHE_TTL_MS, MAX_PROJECT_DETECTION_CACHE_ENTRIES;
|
|
273565
|
+
var init_project_detection_cache = __esm({
|
|
273566
|
+
"src/cli/commands/project-detection-cache.ts"() {
|
|
273567
|
+
"use strict";
|
|
273568
|
+
init_esm_shims();
|
|
273569
|
+
DEFAULT_PROJECT_DETECTION_CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
273570
|
+
MAX_PROJECT_DETECTION_CACHE_ENTRIES = 256;
|
|
273571
|
+
}
|
|
273572
|
+
});
|
|
273573
|
+
|
|
273268
273574
|
// node_modules/@hono/node-server/dist/constants-BLSFu_RU.mjs
|
|
273269
273575
|
var X_ALREADY_SENT;
|
|
273270
273576
|
var init_constants_BLSFu_RU = __esm({
|
|
@@ -275694,6 +276000,8 @@ var init_serve_http = __esm({
|
|
|
275694
276000
|
init_mcp_discovery();
|
|
275695
276001
|
init_port();
|
|
275696
276002
|
init_mcp_root_path();
|
|
276003
|
+
init_http_session_stream_watch();
|
|
276004
|
+
init_project_detection_cache();
|
|
275697
276005
|
DEFAULT_SESSION_TIMEOUT_MS = 12 * 60 * 60 * 1e3;
|
|
275698
276006
|
EXPIRED_SESSION_TTL_MS = 10 * 60 * 1e3;
|
|
275699
276007
|
DEFAULT_HTTP_BODY_LIMIT_BYTES = 10 * 1024 * 1024;
|
|
@@ -275802,6 +276110,7 @@ var init_serve_http = __esm({
|
|
|
275802
276110
|
console.error(`[memorix] HTTP transport starting on ${host}:${port}`);
|
|
275803
276111
|
console.error(`[memorix] Project root: ${projectRoot}`);
|
|
275804
276112
|
const sessionTimeoutMs = parseSessionTimeoutMs(process.env.MEMORIX_SESSION_TIMEOUT_MS);
|
|
276113
|
+
const sessionDisconnectGraceMs = parseSessionDisconnectGraceMs(process.env.MEMORIX_SESSION_DISCONNECT_GRACE_MS);
|
|
275805
276114
|
const httpBodyLimitBytes = parseHttpBodyLimit(process.env.MEMORIX_HTTP_MAX_BODY_BYTES);
|
|
275806
276115
|
const maxHttpSessions = parseMaxHttpSessions(process.env.MEMORIX_MAX_HTTP_SESSIONS);
|
|
275807
276116
|
const eventLoopDelay = monitorEventLoopDelay({ resolution: 20 });
|
|
@@ -275809,6 +276118,9 @@ var init_serve_http = __esm({
|
|
|
275809
276118
|
console.error(
|
|
275810
276119
|
sessionTimeoutMs === 0 ? "[memorix] HTTP session idle timeout: disabled" : `[memorix] HTTP session idle timeout: ${Math.round(sessionTimeoutMs / 6e4)}min (${sessionTimeoutMs}ms)`
|
|
275811
276120
|
);
|
|
276121
|
+
console.error(
|
|
276122
|
+
sessionDisconnectGraceMs === 0 ? "[memorix] HTTP session disconnect cleanup: disabled" : `[memorix] HTTP session disconnect cleanup: ${Math.round(sessionDisconnectGraceMs / 1e3)}s after the client stream closes`
|
|
276123
|
+
);
|
|
275812
276124
|
console.error(`[memorix] HTTP session limit: ${maxHttpSessions}`);
|
|
275813
276125
|
const teamStoreCache = /* @__PURE__ */ new Map();
|
|
275814
276126
|
const teamStoreLeases = /* @__PURE__ */ new Map();
|
|
@@ -275850,9 +276162,10 @@ var init_serve_http = __esm({
|
|
|
275850
276162
|
const statelessBindingStore = new McpBindingStore2();
|
|
275851
276163
|
await statelessBindingStore.init(controlPlaneBaseDir);
|
|
275852
276164
|
const modernRuntimePool = new ModernMcpRuntimePool2(MAX_STORE_CACHE_ENTRIES);
|
|
276165
|
+
const detectRequestProject = createCachedProjectDetector(detectorMod.detectProject);
|
|
275853
276166
|
async function resolveModernDataDir(root, persisted) {
|
|
275854
276167
|
if (persisted?.dataDir) return persisted.dataDir;
|
|
275855
|
-
const detected =
|
|
276168
|
+
const detected = detectRequestProject(root);
|
|
275856
276169
|
return detected ? persistMod.getProjectDataDir(detected.id) : controlPlaneBaseDir;
|
|
275857
276170
|
}
|
|
275858
276171
|
const modernMcpHandler = createMcpHandler(async ({ requestInfo }) => {
|
|
@@ -275862,7 +276175,7 @@ var init_serve_http = __esm({
|
|
|
275862
276175
|
const root = persisted?.projectRoot ?? requestedRoot ?? projectRoot;
|
|
275863
276176
|
const dataDir = await resolveModernDataDir(root, persisted);
|
|
275864
276177
|
const binding = persisted ?? (() => {
|
|
275865
|
-
const detected =
|
|
276178
|
+
const detected = detectRequestProject(root);
|
|
275866
276179
|
if (!detected) return void 0;
|
|
275867
276180
|
const existing = statelessBindingStore.findByProjectRoot(detected.rootPath);
|
|
275868
276181
|
return existing ? statelessBindingStore.touch(existing.handleId) ?? existing : void 0;
|
|
@@ -275921,7 +276234,28 @@ ${stack}` : ""}`);
|
|
|
275921
276234
|
const sessions = /* @__PURE__ */ new Map();
|
|
275922
276235
|
let pendingSessionInitializations = 0;
|
|
275923
276236
|
const sessionLastActivity = /* @__PURE__ */ new Map();
|
|
276237
|
+
const sessionActiveRequests = /* @__PURE__ */ new Map();
|
|
275924
276238
|
const expiredSessions = /* @__PURE__ */ new Map();
|
|
276239
|
+
function expireSession(sid, reason) {
|
|
276240
|
+
const state = sessions.get(sid);
|
|
276241
|
+
if (!state) return;
|
|
276242
|
+
console.error(`[memorix] Session ${sid.slice(0, 8)}\u2026 ${reason}, closing`);
|
|
276243
|
+
expiredSessions.set(sid, Date.now() + EXPIRED_SESSION_TTL_MS);
|
|
276244
|
+
sessionStreamWatch.forget(sid);
|
|
276245
|
+
sessions.delete(sid);
|
|
276246
|
+
sessionLastActivity.delete(sid);
|
|
276247
|
+
state.transport.close().catch(() => {
|
|
276248
|
+
});
|
|
276249
|
+
}
|
|
276250
|
+
const sessionStreamWatch = createSessionStreamWatch({
|
|
276251
|
+
graceMs: sessionDisconnectGraceMs,
|
|
276252
|
+
getLastActivity: (sid) => sessions.has(sid) ? sessionLastActivity.get(sid) ?? 0 : void 0,
|
|
276253
|
+
isBusy: (sid) => (sessionActiveRequests.get(sid) ?? 0) > 0,
|
|
276254
|
+
onAbandoned: (sid) => expireSession(
|
|
276255
|
+
sid,
|
|
276256
|
+
`client stream closed ${Math.round(sessionDisconnectGraceMs / 1e3)}s ago with no further request`
|
|
276257
|
+
)
|
|
276258
|
+
});
|
|
275925
276259
|
let suppressedProbeCount = 0;
|
|
275926
276260
|
let lastProbeSummaryTime = Date.now();
|
|
275927
276261
|
const PROBE_SUMMARY_INTERVAL_MS = 6e4;
|
|
@@ -276078,7 +276412,7 @@ ${stack}` : ""}`);
|
|
|
276078
276412
|
}
|
|
276079
276413
|
if (!handleId) {
|
|
276080
276414
|
const requestedRoot = typeof req.headers["mcp-project-root"] === "string" ? req.headers["mcp-project-root"] : projectRoot;
|
|
276081
|
-
const detected =
|
|
276415
|
+
const detected = detectRequestProject(requestedRoot);
|
|
276082
276416
|
if (detected) {
|
|
276083
276417
|
const bindingDataDir = await persistMod.getProjectDataDir(detected.id);
|
|
276084
276418
|
const binding = statelessBindingStore.findByProjectRoot(detected.rootPath) ?? statelessBindingStore.create({
|
|
@@ -276096,10 +276430,17 @@ ${stack}` : ""}`);
|
|
|
276096
276430
|
sessionLastActivity.set(sessionId, Date.now());
|
|
276097
276431
|
patchMcpResponse(res);
|
|
276098
276432
|
const session = sessions.get(sessionId);
|
|
276099
|
-
|
|
276100
|
-
|
|
276101
|
-
await
|
|
276102
|
-
|
|
276433
|
+
sessionActiveRequests.set(sessionId, (sessionActiveRequests.get(sessionId) ?? 0) + 1);
|
|
276434
|
+
try {
|
|
276435
|
+
await withBusinessRuntimeQueue2(async () => {
|
|
276436
|
+
await session.activateProjectRuntime();
|
|
276437
|
+
await session.transport.handleRequest(req, res, body);
|
|
276438
|
+
});
|
|
276439
|
+
} finally {
|
|
276440
|
+
const remaining = (sessionActiveRequests.get(sessionId) ?? 1) - 1;
|
|
276441
|
+
if (remaining > 0) sessionActiveRequests.set(sessionId, remaining);
|
|
276442
|
+
else sessionActiveRequests.delete(sessionId);
|
|
276443
|
+
}
|
|
276103
276444
|
return;
|
|
276104
276445
|
}
|
|
276105
276446
|
if (sessionId) {
|
|
@@ -276157,6 +276498,7 @@ ${stack}` : ""}`);
|
|
|
276157
276498
|
}
|
|
276158
276499
|
sessions.delete(sid);
|
|
276159
276500
|
sessionLastActivity.delete(sid);
|
|
276501
|
+
sessionStreamWatch.forget(sid);
|
|
276160
276502
|
}
|
|
276161
276503
|
handleTransportClose();
|
|
276162
276504
|
for (const lease of sessionLeases) lease.release();
|
|
@@ -276269,6 +276611,8 @@ ${stack}` : ""}`);
|
|
|
276269
276611
|
sendUnknownSession(res, sessionId);
|
|
276270
276612
|
return;
|
|
276271
276613
|
}
|
|
276614
|
+
sessionStreamWatch.streamOpened(sessionId);
|
|
276615
|
+
res.once("close", () => sessionStreamWatch.streamClosed(sessionId, res.statusCode === 200));
|
|
276272
276616
|
await sessions.get(sessionId).transport.handleRequest(req, res);
|
|
276273
276617
|
}
|
|
276274
276618
|
async function handleDelete(req, res) {
|
|
@@ -277331,15 +277675,10 @@ ${stack}` : ""}`);
|
|
|
277331
277675
|
evictIdleDatabases2(MAX_STORE_CACHE_ENTRIES);
|
|
277332
277676
|
void modernRuntimePool.evictIdle();
|
|
277333
277677
|
if (SESSION_TIMEOUT_MS === 0) return;
|
|
277334
|
-
for (const
|
|
277678
|
+
for (const sid of sessions.keys()) {
|
|
277335
277679
|
const lastActive = sessionLastActivity.get(sid) ?? 0;
|
|
277336
277680
|
if (now3 - lastActive > SESSION_TIMEOUT_MS) {
|
|
277337
|
-
|
|
277338
|
-
expiredSessions.set(sid, now3 + EXPIRED_SESSION_TTL_MS);
|
|
277339
|
-
state.transport.close().catch(() => {
|
|
277340
|
-
});
|
|
277341
|
-
sessions.delete(sid);
|
|
277342
|
-
sessionLastActivity.delete(sid);
|
|
277681
|
+
expireSession(sid, `timed out (idle ${Math.round((now3 - lastActive) / 6e4)}min)`);
|
|
277343
277682
|
}
|
|
277344
277683
|
}
|
|
277345
277684
|
}, 6e4);
|
|
@@ -277377,6 +277716,7 @@ ${stack}` : ""}`);
|
|
|
277377
277716
|
dashboardStoreLeases.clear();
|
|
277378
277717
|
for (const lease of teamStoreLeases.values()) lease.release();
|
|
277379
277718
|
teamStoreLeases.clear();
|
|
277719
|
+
sessionStreamWatch.dispose();
|
|
277380
277720
|
for (const [sid, state] of sessions) {
|
|
277381
277721
|
try {
|
|
277382
277722
|
await state.transport.close();
|
|
@@ -277437,6 +277777,8 @@ ${stack}` : ""}`);
|
|
|
277437
277777
|
});
|
|
277438
277778
|
_testing2 = {
|
|
277439
277779
|
DEFAULT_SESSION_TIMEOUT_MS,
|
|
277780
|
+
DEFAULT_SESSION_DISCONNECT_GRACE_MS,
|
|
277781
|
+
parseSessionDisconnectGraceMs,
|
|
277440
277782
|
DEFAULT_HTTP_BODY_LIMIT_BYTES,
|
|
277441
277783
|
MAX_HTTP_BODY_LIMIT_BYTES,
|
|
277442
277784
|
MIN_HTTP_BODY_LIMIT_BYTES,
|
|
@@ -295414,7 +295756,7 @@ var GUIDES = {
|
|
|
295414
295756
|
summary: "Store, search, inspect, resolve, consolidate, and promote project memory.",
|
|
295415
295757
|
usage: [
|
|
295416
295758
|
'memorix memory search --query "timeout regression" [--limit 10]',
|
|
295417
|
-
'memorix memory store --text "..." [--title "..."] [--visibility project|personal|team]',
|
|
295759
|
+
'memorix memory store --text "..." [--title "..."] [--type discovery] [--entity <name>] [--topic-key <key>] [--facts a,b] [--files a,b] [--concepts a,b] [--visibility project|personal|team]',
|
|
295418
295760
|
"memorix memory detail --id 42",
|
|
295419
295761
|
"memorix memory recent [--limit 10]",
|
|
295420
295762
|
"memorix memory resolve --ids 42,43 [--status resolved|archived]",
|
|
@@ -295428,6 +295770,8 @@ var GUIDES = {
|
|
|
295428
295770
|
],
|
|
295429
295771
|
notes: [
|
|
295430
295772
|
"Personal and team visibility require `memorix identity join` or `memorix identity use` first.",
|
|
295773
|
+
"The same project and the same --topic-key update the existing observation and return upserted: true. A missing key creates a new observation. Lookup uses only the project selected by --cwd.",
|
|
295774
|
+
"memorix remember does not forward --entity or --topic-key. Topic-key upsert uses memorix memory store.",
|
|
295431
295775
|
"Candidates never enter a task Workset. Only manual or user-confirmed `user + portable` memory may cross local projects."
|
|
295432
295776
|
]
|
|
295433
295777
|
},
|
|
@@ -295819,7 +296163,7 @@ var main2 = defineCommand({
|
|
|
295819
296163
|
}
|
|
295820
296164
|
})),
|
|
295821
296165
|
remember: () => Promise.resolve(defineCommand({
|
|
295822
|
-
meta: { name: "remember", description:
|
|
296166
|
+
meta: { name: "remember", description: 'Shortcut for `memorix memory store`. Does not forward --entity or --topic-key. Topic-key upsert: memorix memory store --entity <name> --topic-key <key> --title "..." --text "..."' },
|
|
295823
296167
|
args: {
|
|
295824
296168
|
text: { type: "positional", description: "Text to remember", required: true },
|
|
295825
296169
|
title: { type: "string", description: "Optional observation title" },
|