memorix 1.9.10 → 1.9.12

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +2 -0
  3. package/README.zh-CN.md +2 -0
  4. package/dist/cli/index.js +767 -211
  5. package/dist/index.js +196 -57
  6. package/dist/maintenance-runner.js +74 -20
  7. package/dist/media-audio-runner.js +74 -20
  8. package/dist/media-video-runner.js +74 -20
  9. package/dist/memcode/index.js +1532 -1002
  10. package/dist/memcode-runtime/CHANGELOG.md +42 -0
  11. package/dist/memcode-runtime/package.json +4 -4
  12. package/dist/sdk.js +194 -55
  13. package/dist/vector-backfill-runner.js +74 -20
  14. package/docs/CONFIGURATION.md +26 -0
  15. package/docs/DEVELOPMENT.md +3 -2
  16. package/docs/INTEGRATIONS.md +2 -0
  17. package/docs/README.md +3 -1
  18. package/docs/ROADMAP-1.9.12-2.0.md +637 -0
  19. package/docs/hooks-architecture.md +5 -0
  20. package/package.json +19 -12
  21. package/plugins/antigravity/memorix/plugin.json +1 -1
  22. package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
  23. package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
  24. package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
  25. package/plugins/copilot/memorix/plugin.json +1 -1
  26. package/plugins/gemini/memorix/gemini-extension.json +1 -1
  27. package/plugins/hermes/memorix/plugin.yaml +1 -1
  28. package/plugins/omp/memorix/package.json +1 -1
  29. package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
  30. package/plugins/pi/memorix/package.json +1 -1
  31. package/server.json +2 -2
  32. package/src/cli/commands/hooks-install.ts +2 -0
  33. package/src/cli/commands/init.ts +6 -2
  34. package/src/cli/commands/integrate.ts +2 -0
  35. package/src/cli/commands/setup.ts +1 -1
  36. package/src/cli/index.ts +2 -2
  37. package/src/cli/tui/ConfigureView.tsx +2 -0
  38. package/src/cli/update-checker.ts +2 -1
  39. package/src/config/dotenv-loader.ts +1 -0
  40. package/src/config/resolved-config.ts +7 -3
  41. package/src/config/yaml-loader.ts +2 -2
  42. package/src/dashboard/server.ts +3 -0
  43. package/src/hooks/installers/index.ts +130 -10
  44. package/src/hooks/lifecycle.ts +4 -9
  45. package/src/hooks/normalizer.ts +6 -1
  46. package/src/hooks/types.ts +3 -1
  47. package/src/llm/provider.ts +2 -1
  48. package/src/memory/observations.ts +11 -0
  49. package/src/memory/session.ts +4 -13
  50. package/src/memory/visibility.ts +8 -2
  51. package/src/multimodal/image-loader.ts +6 -5
  52. package/src/server.ts +8 -4
  53. package/src/store/obs-store.ts +3 -0
  54. package/src/store/orama-store.ts +43 -6
  55. package/src/store/sqlite-store.ts +15 -0
@@ -2038,9 +2038,9 @@ function sharedAgentIds(record80) {
2038
2038
  return [];
2039
2039
  }
2040
2040
  }
2041
- function canReadObservation(record80, reader) {
2041
+ function canReadObservation(record80, reader, allowedProjectIds) {
2042
2042
  if (!reader) return true;
2043
- const sameProject = reader.projectId === record80.projectId;
2043
+ const sameProject = allowedProjectIds ? allowedProjectIds.includes(record80.projectId) : reader.projectId === record80.projectId;
2044
2044
  const visibility = resolveObservationVisibility(record80);
2045
2045
  if (visibility === "project") return !reader.projectId || sameProject;
2046
2046
  if (!sameProject || !reader.agentId) return false;
@@ -2406,15 +2406,16 @@ function getResolvedConfig(options = {}) {
2406
2406
  const openRouterMemoryLlmApiKey = isOpenRouterMemoryLane(memoryLlmProvider, memoryLlmBaseUrl) ? process.env.OPENROUTER_API_KEY : void 0;
2407
2407
  const isAtlasCloud = memoryLlmProvider === "atlascloud";
2408
2408
  const isRequesty = memoryLlmProvider === "requesty";
2409
- const usesPresetKeyOnly = isAtlasCloud || isRequesty;
2409
+ const isApiRoute = memoryLlmProvider === "apiroute";
2410
+ const usesPresetKeyOnly = isAtlasCloud || isRequesty || isApiRoute;
2410
2411
  const memoryLlmApiKey = first(
2411
2412
  process.env.MEMORIX_LLM_API_KEY,
2412
2413
  process.env.MEMORIX_API_KEY,
2413
2414
  toml.memory?.llm?.api_key,
2414
2415
  yaml.llm?.apiKey,
2415
2416
  legacy.llm?.apiKey,
2416
- // Never borrow another provider's credentials for the Atlas Cloud or Requesty presets.
2417
- isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : process.env.OPENAI_API_KEY,
2417
+ // Never borrow another provider's credentials for these gateway presets.
2418
+ isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : process.env.OPENAI_API_KEY,
2418
2419
  usesPresetKeyOnly ? void 0 : process.env.ANTHROPIC_API_KEY,
2419
2420
  usesPresetKeyOnly ? void 0 : openRouterMemoryLlmApiKey
2420
2421
  );
@@ -2597,6 +2598,7 @@ function getEnvSourceNames() {
2597
2598
  "MEMORIX_CODEGRAPH_EXTERNAL_TIMEOUT_MS",
2598
2599
  "OPENROUTER_API_KEY",
2599
2600
  "REQUESTY_API_KEY",
2601
+ "API_ROUTE_API_KEY",
2600
2602
  "ATLASCLOUD_API_KEY"
2601
2603
  ].filter((name) => process.env[name]);
2602
2604
  }
@@ -5590,6 +5592,7 @@ var init_provider2 = __esm({
5590
5592
  anthropic: { baseUrl: "https://api.anthropic.com/v1", model: "claude-3-5-haiku-latest" },
5591
5593
  openrouter: { baseUrl: "https://openrouter.ai/api/v1", model: "openai/gpt-4.1-nano" },
5592
5594
  requesty: { baseUrl: "https://router.requesty.ai/v1", model: "openai/gpt-4.1-nano" },
5595
+ apiroute: { baseUrl: "https://global.api-route.com/v1", model: "deepseek-v4.1-flash" },
5593
5596
  atlascloud: { baseUrl: "https://api.atlascloud.ai/v1", model: "deepseek-ai/deepseek-v3.2" },
5594
5597
  custom: { baseUrl: "http://localhost:11434/v1", model: "llama3" }
5595
5598
  };
@@ -6084,6 +6087,19 @@ var init_sqlite_store = __esm({
6084
6087
  async listProjectIds() {
6085
6088
  return this.db.prepare("SELECT DISTINCT projectId FROM observations ORDER BY projectId").all().map((row) => row.projectId).filter((projectId) => Boolean(projectId));
6086
6089
  }
6090
+ async migrateProjectIds(aliasIds, canonicalId) {
6091
+ const sourceIds = [...new Set(aliasIds.filter((projectId) => projectId && projectId !== canonicalId))];
6092
+ if (sourceIds.length === 0) return 0;
6093
+ return retrySqliteBusy(async () => {
6094
+ const placeholders = sourceIds.map(() => "?").join(", ");
6095
+ const result = this.db.prepare(
6096
+ `UPDATE observations SET projectId = ? WHERE projectId IN (${placeholders})`
6097
+ ).run(canonicalId, ...sourceIds);
6098
+ const migrated = Number(result.changes ?? 0);
6099
+ if (migrated > 0) this.bumpGeneration();
6100
+ return migrated;
6101
+ }, "Migrate observation project IDs");
6102
+ }
6087
6103
  async searchLexical(options) {
6088
6104
  return searchObservationLexically(this.db, options).map((hit) => ({
6089
6105
  observation: rowToObs(hit.row),
@@ -7129,6 +7145,7 @@ var orama_store_exports = {};
7129
7145
  __export(orama_store_exports, {
7130
7146
  _classifyQueryTier: () => classifyQueryTier,
7131
7147
  batchGenerateEmbeddings: () => batchGenerateEmbeddings,
7148
+ createSearchTokenizer: () => createSearchTokenizer,
7132
7149
  generateEmbedding: () => generateEmbedding,
7133
7150
  generateEmbeddingInput: () => generateEmbeddingInput,
7134
7151
  getActiveSemanticIndexProfile: () => getActiveSemanticIndexProfile,
@@ -7151,7 +7168,7 @@ __export(orama_store_exports, {
7151
7168
  searchObservations: () => searchObservations,
7152
7169
  updateObservationMetadata: () => updateObservationMetadata
7153
7170
  });
7154
- import { create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
7171
+ import { components, create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
7155
7172
  function rememberSearchMode(key, value) {
7156
7173
  if (!lastSearchModeByProject.has(key) && lastSearchModeByProject.size >= MAX_SEARCH_MODE_KEYS) {
7157
7174
  const oldest = lastSearchModeByProject.keys().next().value;
@@ -7170,6 +7187,26 @@ function getOptionalObservationStore() {
7170
7187
  return null;
7171
7188
  }
7172
7189
  }
7190
+ function createSearchTokenizer() {
7191
+ const defaultTokenizer = components.tokenizer.createTokenizer({ language: "english" });
7192
+ return {
7193
+ language: defaultTokenizer.language,
7194
+ normalizationCache: defaultTokenizer.normalizationCache,
7195
+ tokenize(raw, language, prop, withCache = true) {
7196
+ const defaultTokens = defaultTokenizer.tokenize(raw, language, prop, withCache);
7197
+ const cjkTokens = [];
7198
+ const normalized = raw.normalize("NFKC").toLowerCase();
7199
+ for (const match2 of normalized.matchAll(CJK_RUN)) {
7200
+ const characters = Array.from(match2[0]);
7201
+ cjkTokens.push(...characters);
7202
+ for (let index = 0; index + 1 < characters.length; index++) {
7203
+ cjkTokens.push(`${characters[index]}${characters[index + 1]}`);
7204
+ }
7205
+ }
7206
+ return [.../* @__PURE__ */ new Set([...defaultTokens, ...cjkTokens])];
7207
+ }
7208
+ };
7209
+ }
7173
7210
  async function shouldUsePersistentSearch(projectIds, projectId) {
7174
7211
  const store = getOptionalObservationStore();
7175
7212
  if (!store?.hasLexicalIndex?.()) return false;
@@ -7270,6 +7307,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7270
7307
  const lexical = await searchPersistentLexically(options, projectIds, limit2);
7271
7308
  const store = getObservationStore();
7272
7309
  const documents = /* @__PURE__ */ new Map();
7310
+ const vectorDocumentKeys = /* @__PURE__ */ new Map();
7273
7311
  const addObservation = (observation) => {
7274
7312
  const document2 = observationToSearchDocument(observation);
7275
7313
  documents.set(makeEntryKey(document2.projectId, document2.observationId), document2);
@@ -7285,6 +7323,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7285
7323
  if (options.type && observation.type !== options.type) return null;
7286
7324
  if (options.source && observation.source !== options.source) return null;
7287
7325
  addObservation(observation);
7326
+ vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
7288
7327
  return observation;
7289
7328
  }));
7290
7329
  const RRF_K = 60;
@@ -7294,7 +7333,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7294
7333
  scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
7295
7334
  }
7296
7335
  for (const [index, hit] of vectorHits.entries()) {
7297
- const key = makeEntryKey(hit.projectId, hit.observationId);
7336
+ const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
7298
7337
  if (!documents.has(key)) continue;
7299
7338
  scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
7300
7339
  }
@@ -7307,12 +7346,13 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
7307
7346
  return {
7308
7347
  count: vectorHits.length,
7309
7348
  hits: vectorHits.map((hit, index) => {
7310
- const key = makeEntryKey(hit.projectId, hit.observationId);
7349
+ const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
7311
7350
  const document2 = documents.get(key);
7312
7351
  return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
7313
7352
  }).filter((hit) => hit !== null).slice(0, limit2)
7314
7353
  };
7315
7354
  }
7355
+ if (hits.length === 0) return null;
7316
7356
  return { count: hits.length, hits };
7317
7357
  } catch {
7318
7358
  return null;
@@ -7387,7 +7427,10 @@ async function initializeDb(options, generation) {
7387
7427
  };
7388
7428
  const dims = nextEmbeddingDimensions ?? 384;
7389
7429
  const schema = nextEmbeddingEnabled ? { ...baseSchema, embedding: `vector[${dims}]` } : baseSchema;
7390
- const nextDb = await create({ schema });
7430
+ const nextDb = await create({
7431
+ schema,
7432
+ components: { tokenizer: createSearchTokenizer() }
7433
+ });
7391
7434
  if (generation !== dbGeneration) {
7392
7435
  return getDb(options);
7393
7436
  }
@@ -7821,7 +7864,7 @@ async function searchObservations(options) {
7821
7864
  if (!projectIds) return true;
7822
7865
  const doc = hit.document;
7823
7866
  return projectIds.includes(doc.projectId);
7824
- }).filter((hit) => canReadObservation(hit.document, options.reader)).filter((hit) => {
7867
+ }).filter((hit) => canReadObservation(hit.document, options.reader, projectIds ?? void 0)).filter((hit) => {
7825
7868
  if (statusFilter === "all") return true;
7826
7869
  const doc = hit.document;
7827
7870
  return (doc.status || "active") === statusFilter;
@@ -8087,7 +8130,7 @@ async function searchObservations(options) {
8087
8130
  let entries = intermediate.map(({ rawTime: _, _isCommandLog: _c, ...rest }) => rest);
8088
8131
  for (const hit of results.hits) {
8089
8132
  const doc = hit.document;
8090
- if (canReadObservation(doc, options.reader)) rememberObservationDoc(doc);
8133
+ if (canReadObservation(doc, options.reader, projectIds ?? void 0)) rememberObservationDoc(doc);
8091
8134
  }
8092
8135
  if (hasQuery && originalQuery) {
8093
8136
  const queryLower = originalQuery.toLowerCase();
@@ -8245,7 +8288,7 @@ function formatTime(isoDate) {
8245
8288
  return isoDate;
8246
8289
  }
8247
8290
  }
8248
- var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, lastSearchModeByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
8291
+ var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, CJK_RUN, lastSearchModeByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
8249
8292
  var init_orama_store = __esm({
8250
8293
  "src/store/orama-store.ts"() {
8251
8294
  "use strict";
@@ -8269,6 +8312,7 @@ var init_orama_store = __esm({
8269
8312
  indexEmbeddingProvider = null;
8270
8313
  deferredCachedVectorHydration = null;
8271
8314
  NON_CJK_HYBRID_SIMILARITY = 0.45;
8315
+ CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
8272
8316
  lastSearchModeByProject = /* @__PURE__ */ new Map();
8273
8317
  SEARCH_MODE_DEFAULT_KEY = "__global__";
8274
8318
  MAX_SEARCH_MODE_KEYS = 4096;
@@ -71819,16 +71863,16 @@ var require_pluggable_auth_handler = __commonJS({
71819
71863
  * spaces are between quotation marks.
71820
71864
  */
71821
71865
  static parseCommand(command) {
71822
- const components = command.match(/(?:[^\s"]+|"[^"]*")+/g);
71823
- if (!components) {
71866
+ const components2 = command.match(/(?:[^\s"]+|"[^"]*")+/g);
71867
+ if (!components2) {
71824
71868
  throw new Error(`Provided command: "${command}" could not be parsed.`);
71825
71869
  }
71826
- for (let i2 = 0; i2 < components.length; i2++) {
71827
- if (components[i2][0] === '"' && components[i2].slice(-1) === '"') {
71828
- components[i2] = components[i2].slice(1, -1);
71870
+ for (let i2 = 0; i2 < components2.length; i2++) {
71871
+ if (components2[i2][0] === '"' && components2[i2].slice(-1) === '"') {
71872
+ components2[i2] = components2[i2].slice(1, -1);
71829
71873
  }
71830
71874
  }
71831
- return components;
71875
+ return components2;
71832
71876
  }
71833
71877
  };
71834
71878
  exports.PluggableAuthHandler = PluggableAuthHandler;
@@ -151954,6 +151998,16 @@ function getProjectObservations(projectId) {
151954
151998
  async function migrateProjectIds(aliasIds, canonicalId) {
151955
151999
  const nonCanonical = new Set(aliasIds.filter((id) => id !== canonicalId));
151956
152000
  if (nonCanonical.size === 0) return 0;
152001
+ const store = projectDir ? getObservationStore() : null;
152002
+ if (store?.migrateProjectIds) {
152003
+ const migrated2 = await store.migrateProjectIds(aliasIds, canonicalId);
152004
+ if (migrated2 > 0 && corpusLoaded) {
152005
+ for (const observation of observations) {
152006
+ if (nonCanonical.has(observation.projectId)) observation.projectId = canonicalId;
152007
+ }
152008
+ }
152009
+ return migrated2;
152010
+ }
151957
152011
  let migrated = 0;
151958
152012
  const changed = [];
151959
152013
  for (const obs of observations) {
@@ -151964,8 +152018,8 @@ async function migrateProjectIds(aliasIds, canonicalId) {
151964
152018
  }
151965
152019
  }
151966
152020
  if (migrated > 0 && projectDir) {
151967
- const store = getObservationStore();
151968
- await store.atomic(async (tx) => {
152021
+ const store2 = getObservationStore();
152022
+ await store2.atomic(async (tx) => {
151969
152023
  await Promise.all(changed.map((observation) => tx.update(observation)));
151970
152024
  });
151971
152025
  }