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
package/dist/sdk.js CHANGED
@@ -81,9 +81,9 @@ function sharedAgentIds(record80) {
81
81
  return [];
82
82
  }
83
83
  }
84
- function canReadObservation(record80, reader2) {
84
+ function canReadObservation(record80, reader2, allowedProjectIds) {
85
85
  if (!reader2) return true;
86
- const sameProject = reader2.projectId === record80.projectId;
86
+ const sameProject = allowedProjectIds ? allowedProjectIds.includes(record80.projectId) : reader2.projectId === record80.projectId;
87
87
  const visibility = resolveObservationVisibility(record80);
88
88
  if (visibility === "project") return !reader2.projectId || sameProject;
89
89
  if (!sameProject || !reader2.agentId) return false;
@@ -3869,15 +3869,16 @@ function getResolvedConfig(options = {}) {
3869
3869
  const openRouterMemoryLlmApiKey = isOpenRouterMemoryLane(memoryLlmProvider, memoryLlmBaseUrl) ? process.env.OPENROUTER_API_KEY : void 0;
3870
3870
  const isAtlasCloud = memoryLlmProvider === "atlascloud";
3871
3871
  const isRequesty = memoryLlmProvider === "requesty";
3872
- const usesPresetKeyOnly = isAtlasCloud || isRequesty;
3872
+ const isApiRoute = memoryLlmProvider === "apiroute";
3873
+ const usesPresetKeyOnly = isAtlasCloud || isRequesty || isApiRoute;
3873
3874
  const memoryLlmApiKey = first(
3874
3875
  process.env.MEMORIX_LLM_API_KEY,
3875
3876
  process.env.MEMORIX_API_KEY,
3876
3877
  toml.memory?.llm?.api_key,
3877
3878
  yaml.llm?.apiKey,
3878
3879
  legacy.llm?.apiKey,
3879
- // Never borrow another provider's credentials for the Atlas Cloud or Requesty presets.
3880
- isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : process.env.OPENAI_API_KEY,
3880
+ // Never borrow another provider's credentials for these gateway presets.
3881
+ isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : process.env.OPENAI_API_KEY,
3881
3882
  usesPresetKeyOnly ? void 0 : process.env.ANTHROPIC_API_KEY,
3882
3883
  usesPresetKeyOnly ? void 0 : openRouterMemoryLlmApiKey
3883
3884
  );
@@ -4060,6 +4061,7 @@ function getEnvSourceNames() {
4060
4061
  "MEMORIX_CODEGRAPH_EXTERNAL_TIMEOUT_MS",
4061
4062
  "OPENROUTER_API_KEY",
4062
4063
  "REQUESTY_API_KEY",
4064
+ "API_ROUTE_API_KEY",
4063
4065
  "ATLASCLOUD_API_KEY"
4064
4066
  ].filter((name) => process.env[name]);
4065
4067
  }
@@ -7053,6 +7055,7 @@ var init_provider2 = __esm({
7053
7055
  anthropic: { baseUrl: "https://api.anthropic.com/v1", model: "claude-3-5-haiku-latest" },
7054
7056
  openrouter: { baseUrl: "https://openrouter.ai/api/v1", model: "openai/gpt-4.1-nano" },
7055
7057
  requesty: { baseUrl: "https://router.requesty.ai/v1", model: "openai/gpt-4.1-nano" },
7058
+ apiroute: { baseUrl: "https://global.api-route.com/v1", model: "deepseek-v4.1-flash" },
7056
7059
  atlascloud: { baseUrl: "https://api.atlascloud.ai/v1", model: "deepseek-ai/deepseek-v3.2" },
7057
7060
  custom: { baseUrl: "http://localhost:11434/v1", model: "llama3" }
7058
7061
  };
@@ -7547,6 +7550,19 @@ var init_sqlite_store = __esm({
7547
7550
  async listProjectIds() {
7548
7551
  return this.db.prepare("SELECT DISTINCT projectId FROM observations ORDER BY projectId").all().map((row) => row.projectId).filter((projectId) => Boolean(projectId));
7549
7552
  }
7553
+ async migrateProjectIds(aliasIds, canonicalId) {
7554
+ const sourceIds = [...new Set(aliasIds.filter((projectId) => projectId && projectId !== canonicalId))];
7555
+ if (sourceIds.length === 0) return 0;
7556
+ return retrySqliteBusy(async () => {
7557
+ const placeholders = sourceIds.map(() => "?").join(", ");
7558
+ const result = this.db.prepare(
7559
+ `UPDATE observations SET projectId = ? WHERE projectId IN (${placeholders})`
7560
+ ).run(canonicalId, ...sourceIds);
7561
+ const migrated = Number(result.changes ?? 0);
7562
+ if (migrated > 0) this.bumpGeneration();
7563
+ return migrated;
7564
+ }, "Migrate observation project IDs");
7565
+ }
7550
7566
  async searchLexical(options) {
7551
7567
  return searchObservationLexically(this.db, options).map((hit) => ({
7552
7568
  observation: rowToObs(hit.row),
@@ -8650,6 +8666,7 @@ var orama_store_exports = {};
8650
8666
  __export(orama_store_exports, {
8651
8667
  _classifyQueryTier: () => classifyQueryTier,
8652
8668
  batchGenerateEmbeddings: () => batchGenerateEmbeddings,
8669
+ createSearchTokenizer: () => createSearchTokenizer,
8653
8670
  generateEmbedding: () => generateEmbedding,
8654
8671
  generateEmbeddingInput: () => generateEmbeddingInput,
8655
8672
  getActiveSemanticIndexProfile: () => getActiveSemanticIndexProfile,
@@ -8672,7 +8689,7 @@ __export(orama_store_exports, {
8672
8689
  searchObservations: () => searchObservations,
8673
8690
  updateObservationMetadata: () => updateObservationMetadata
8674
8691
  });
8675
- import { create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
8692
+ import { components, create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
8676
8693
  function rememberSearchMode(key, value) {
8677
8694
  if (!lastSearchModeByProject.has(key) && lastSearchModeByProject.size >= MAX_SEARCH_MODE_KEYS) {
8678
8695
  const oldest = lastSearchModeByProject.keys().next().value;
@@ -8691,6 +8708,26 @@ function getOptionalObservationStore() {
8691
8708
  return null;
8692
8709
  }
8693
8710
  }
8711
+ function createSearchTokenizer() {
8712
+ const defaultTokenizer = components.tokenizer.createTokenizer({ language: "english" });
8713
+ return {
8714
+ language: defaultTokenizer.language,
8715
+ normalizationCache: defaultTokenizer.normalizationCache,
8716
+ tokenize(raw, language, prop, withCache = true) {
8717
+ const defaultTokens = defaultTokenizer.tokenize(raw, language, prop, withCache);
8718
+ const cjkTokens = [];
8719
+ const normalized = raw.normalize("NFKC").toLowerCase();
8720
+ for (const match2 of normalized.matchAll(CJK_RUN)) {
8721
+ const characters = Array.from(match2[0]);
8722
+ cjkTokens.push(...characters);
8723
+ for (let index = 0; index + 1 < characters.length; index++) {
8724
+ cjkTokens.push(`${characters[index]}${characters[index + 1]}`);
8725
+ }
8726
+ }
8727
+ return [.../* @__PURE__ */ new Set([...defaultTokens, ...cjkTokens])];
8728
+ }
8729
+ };
8730
+ }
8694
8731
  async function shouldUsePersistentSearch(projectIds, projectId) {
8695
8732
  const store = getOptionalObservationStore();
8696
8733
  if (!store?.hasLexicalIndex?.()) return false;
@@ -8791,6 +8828,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
8791
8828
  const lexical = await searchPersistentLexically(options, projectIds, limit2);
8792
8829
  const store = getObservationStore();
8793
8830
  const documents = /* @__PURE__ */ new Map();
8831
+ const vectorDocumentKeys = /* @__PURE__ */ new Map();
8794
8832
  const addObservation = (observation) => {
8795
8833
  const document2 = observationToSearchDocument(observation);
8796
8834
  documents.set(makeEntryKey(document2.projectId, document2.observationId), document2);
@@ -8806,6 +8844,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
8806
8844
  if (options.type && observation.type !== options.type) return null;
8807
8845
  if (options.source && observation.source !== options.source) return null;
8808
8846
  addObservation(observation);
8847
+ vectorDocumentKeys.set(hit.observationId, makeEntryKey(observation.projectId, observation.id));
8809
8848
  return observation;
8810
8849
  }));
8811
8850
  const RRF_K = 60;
@@ -8815,7 +8854,7 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
8815
8854
  scores.set(key, (scores.get(key) ?? 0) + 0.6 / (RRF_K + index + 1));
8816
8855
  }
8817
8856
  for (const [index, hit] of vectorHits.entries()) {
8818
- const key = makeEntryKey(hit.projectId, hit.observationId);
8857
+ const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
8819
8858
  if (!documents.has(key)) continue;
8820
8859
  scores.set(key, (scores.get(key) ?? 0) + 0.4 / (RRF_K + index + 1));
8821
8860
  }
@@ -8828,12 +8867,13 @@ async function searchPersistentSemantically(options, projectIds, limit2, queryVe
8828
8867
  return {
8829
8868
  count: vectorHits.length,
8830
8869
  hits: vectorHits.map((hit, index) => {
8831
- const key = makeEntryKey(hit.projectId, hit.observationId);
8870
+ const key = vectorDocumentKeys.get(hit.observationId) ?? makeEntryKey(hit.projectId, hit.observationId);
8832
8871
  const document2 = documents.get(key);
8833
8872
  return document2 ? { id: document2.id, score: 0.4 / (RRF_K + index + 1), document: document2 } : null;
8834
8873
  }).filter((hit) => hit !== null).slice(0, limit2)
8835
8874
  };
8836
8875
  }
8876
+ if (hits.length === 0) return null;
8837
8877
  return { count: hits.length, hits };
8838
8878
  } catch {
8839
8879
  return null;
@@ -8908,7 +8948,10 @@ async function initializeDb(options, generation) {
8908
8948
  };
8909
8949
  const dims = nextEmbeddingDimensions ?? 384;
8910
8950
  const schema = nextEmbeddingEnabled ? { ...baseSchema, embedding: `vector[${dims}]` } : baseSchema;
8911
- const nextDb = await create({ schema });
8951
+ const nextDb = await create({
8952
+ schema,
8953
+ components: { tokenizer: createSearchTokenizer() }
8954
+ });
8912
8955
  if (generation !== dbGeneration) {
8913
8956
  return getDb(options);
8914
8957
  }
@@ -9342,7 +9385,7 @@ async function searchObservations(options) {
9342
9385
  if (!projectIds) return true;
9343
9386
  const doc = hit.document;
9344
9387
  return projectIds.includes(doc.projectId);
9345
- }).filter((hit) => canReadObservation(hit.document, options.reader)).filter((hit) => {
9388
+ }).filter((hit) => canReadObservation(hit.document, options.reader, projectIds ?? void 0)).filter((hit) => {
9346
9389
  if (statusFilter === "all") return true;
9347
9390
  const doc = hit.document;
9348
9391
  return (doc.status || "active") === statusFilter;
@@ -9608,7 +9651,7 @@ async function searchObservations(options) {
9608
9651
  let entries = intermediate.map(({ rawTime: _, _isCommandLog: _c, ...rest }) => rest);
9609
9652
  for (const hit of results.hits) {
9610
9653
  const doc = hit.document;
9611
- if (canReadObservation(doc, options.reader)) rememberObservationDoc(doc);
9654
+ if (canReadObservation(doc, options.reader, projectIds ?? void 0)) rememberObservationDoc(doc);
9612
9655
  }
9613
9656
  if (hasQuery && originalQuery) {
9614
9657
  const queryLower = originalQuery.toLowerCase();
@@ -9766,7 +9809,7 @@ function formatTime(isoDate) {
9766
9809
  return isoDate;
9767
9810
  }
9768
9811
  }
9769
- var db, dbInitPromise, dbGeneration, embeddingEnabled, embeddingDimensions, indexEmbeddingProvider, deferredCachedVectorHydration, NON_CJK_HYBRID_SIMILARITY, lastSearchModeByProject, SEARCH_MODE_DEFAULT_KEY, MAX_SEARCH_MODE_KEYS, COMMAND_LOG_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
9812
+ 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_TITLE2, COMMAND_STYLE_TITLE, COMMAND_LIKE_QUERY2, COMMAND_INTENT_QUERY, NATURAL_LANGUAGE_MARKERS;
9770
9813
  var init_orama_store = __esm({
9771
9814
  "src/store/orama-store.ts"() {
9772
9815
  "use strict";
@@ -9790,6 +9833,7 @@ var init_orama_store = __esm({
9790
9833
  indexEmbeddingProvider = null;
9791
9834
  deferredCachedVectorHydration = null;
9792
9835
  NON_CJK_HYBRID_SIMILARITY = 0.45;
9836
+ CJK_RUN = /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]+/gu;
9793
9837
  lastSearchModeByProject = /* @__PURE__ */ new Map();
9794
9838
  SEARCH_MODE_DEFAULT_KEY = "__global__";
9795
9839
  MAX_SEARCH_MODE_KEYS = 4096;
@@ -73729,16 +73773,16 @@ var require_pluggable_auth_handler = __commonJS({
73729
73773
  * spaces are between quotation marks.
73730
73774
  */
73731
73775
  static parseCommand(command) {
73732
- const components = command.match(/(?:[^\s"]+|"[^"]*")+/g);
73733
- if (!components) {
73776
+ const components2 = command.match(/(?:[^\s"]+|"[^"]*")+/g);
73777
+ if (!components2) {
73734
73778
  throw new Error(`Provided command: "${command}" could not be parsed.`);
73735
73779
  }
73736
- for (let i2 = 0; i2 < components.length; i2++) {
73737
- if (components[i2][0] === '"' && components[i2].slice(-1) === '"') {
73738
- components[i2] = components[i2].slice(1, -1);
73780
+ for (let i2 = 0; i2 < components2.length; i2++) {
73781
+ if (components2[i2][0] === '"' && components2[i2].slice(-1) === '"') {
73782
+ components2[i2] = components2[i2].slice(1, -1);
73739
73783
  }
73740
73784
  }
73741
- return components;
73785
+ return components2;
73742
73786
  }
73743
73787
  };
73744
73788
  exports.PluggableAuthHandler = PluggableAuthHandler;
@@ -154361,6 +154405,16 @@ function getProjectObservations(projectId) {
154361
154405
  async function migrateProjectIds(aliasIds, canonicalId) {
154362
154406
  const nonCanonical = new Set(aliasIds.filter((id) => id !== canonicalId));
154363
154407
  if (nonCanonical.size === 0) return 0;
154408
+ const store = projectDir ? getObservationStore() : null;
154409
+ if (store?.migrateProjectIds) {
154410
+ const migrated2 = await store.migrateProjectIds(aliasIds, canonicalId);
154411
+ if (migrated2 > 0 && corpusLoaded) {
154412
+ for (const observation of observations) {
154413
+ if (nonCanonical.has(observation.projectId)) observation.projectId = canonicalId;
154414
+ }
154415
+ }
154416
+ return migrated2;
154417
+ }
154364
154418
  let migrated = 0;
154365
154419
  const changed = [];
154366
154420
  for (const obs of observations) {
@@ -154371,8 +154425,8 @@ async function migrateProjectIds(aliasIds, canonicalId) {
154371
154425
  }
154372
154426
  }
154373
154427
  if (migrated > 0 && projectDir) {
154374
- const store = getObservationStore();
154375
- await store.atomic(async (tx) => {
154428
+ const store2 = getObservationStore();
154429
+ await store2.atomic(async (tx) => {
154376
154430
  await Promise.all(changed.map((observation) => tx.update(observation)));
154377
154431
  });
154378
154432
  }
@@ -156573,7 +156627,7 @@ async function getSessionContext(projectDir2, projectId, limit2 = 3, reader2) {
156573
156627
  lines.push("## Key Project Memories");
156574
156628
  lines.push("*Durable working context \u2014 explicit decisions, gotchas, and discoveries.*");
156575
156629
  for (const obs of l2Obs) {
156576
- const emoji = TYPE_EMOJI[obs.type] ?? "[PIN]";
156630
+ const emoji = OBSERVATION_ICONS[obs.type] ?? "[PIN]";
156577
156631
  const fact = obs.facts?.[0] ? ` \u2014 ${redactCredentials(obs.facts[0])}` : "";
156578
156632
  lines.push(`${emoji} ${redactCredentials(obs.title)}${fact}`);
156579
156633
  }
@@ -156621,11 +156675,12 @@ async function getActiveSession(projectDir2, projectId) {
156621
156675
  const sessions = await loadAliasActiveSessions(aliasSet);
156622
156676
  return sessions.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime())[0] ?? null;
156623
156677
  }
156624
- var PRIORITY_TYPES, RESUME_TYPES, TYPE_EMOJI, TYPE_WEIGHTS2, NOISE_PATTERNS2, COMMAND_TRACE_PATTERNS, SYSTEM_SELF_PATTERNS, SESSION_RESUME_OBSERVATION_LIMIT, SESSION_CONTEXT_OBSERVATION_LIMIT, AUTO_RESUME_SUMMARY_LIMIT, AUTO_RESUME_TITLE_LIMIT;
156678
+ var PRIORITY_TYPES, RESUME_TYPES, TYPE_WEIGHTS2, NOISE_PATTERNS2, COMMAND_TRACE_PATTERNS, SYSTEM_SELF_PATTERNS, SESSION_RESUME_OBSERVATION_LIMIT, SESSION_CONTEXT_OBSERVATION_LIMIT, AUTO_RESUME_SUMMARY_LIMIT, AUTO_RESUME_TITLE_LIMIT;
156625
156679
  var init_session = __esm({
156626
156680
  "src/memory/session.ts"() {
156627
156681
  "use strict";
156628
156682
  init_esm_shims();
156683
+ init_types();
156629
156684
  init_admission();
156630
156685
  init_disclosure_policy();
156631
156686
  init_aliases();
@@ -156653,18 +156708,6 @@ var init_session = __esm({
156653
156708
  "what-changed",
156654
156709
  "reasoning"
156655
156710
  ]);
156656
- TYPE_EMOJI = {
156657
- "gotcha": "[DISCOVERY]",
156658
- "decision": "[WHY]",
156659
- "problem-solution": "[FIX]",
156660
- "trade-off": "[TRADEOFF]",
156661
- "discovery": "[DISCOVERY]",
156662
- "how-it-works": "[INFO]",
156663
- "what-changed": "[CHANGE]",
156664
- "why-it-exists": "[DECISION]",
156665
- "session-request": "[SESSION]",
156666
- "probe": "[PROBE]"
156667
- };
156668
156711
  TYPE_WEIGHTS2 = {
156669
156712
  "gotcha": 6,
156670
156713
  "decision": 5.5,
@@ -163584,7 +163627,8 @@ async function handleApi(req, res, dataDir, projectId, projectName, baseDir, pro
163584
163627
  "OPENAI_API_KEY",
163585
163628
  "ANTHROPIC_API_KEY",
163586
163629
  ...resolved.memory.llm.provider === "openrouter" || resolved.memory.llm.baseUrl?.includes("openrouter.ai") ? ["OPENROUTER_API_KEY"] : [],
163587
- ...resolved.memory.llm.provider === "requesty" ? ["REQUESTY_API_KEY"] : []
163630
+ ...resolved.memory.llm.provider === "requesty" ? ["REQUESTY_API_KEY"] : [],
163631
+ ...resolved.memory.llm.provider === "apiroute" ? ["API_ROUTE_API_KEY"] : []
163588
163632
  ];
163589
163633
  if (llmKey) {
163590
163634
  const src = resolveDashboardKeySource({ value: llmKey, envKeys: memoryKeyEnv, configSource });
@@ -165109,12 +165153,13 @@ __export(image_loader_exports, {
165109
165153
  analyzeImage: () => analyzeImage
165110
165154
  });
165111
165155
  async function callVisionLLM(systemPrompt, imageBase64, mimeType) {
165112
- const apiKey = getLLMApiKey();
165156
+ const config = getLLMConfig();
165157
+ const apiKey = config?.apiKey ?? getLLMApiKey();
165113
165158
  if (!apiKey) {
165114
165159
  throw new Error("No LLM API key configured for image analysis.");
165115
165160
  }
165116
- const baseUrl = normalizeOpenAICompatibleBaseUrl(getLLMBaseUrl("https://api.openai.com/v1"));
165117
- const model = getLLMModel("gpt-4o");
165161
+ const baseUrl = normalizeOpenAICompatibleBaseUrl(config?.baseUrl ?? getLLMBaseUrl("https://api.openai.com/v1"));
165162
+ const model = config?.model ?? getLLMModel("gpt-4o");
165118
165163
  const response = await fetch(`${baseUrl}/chat/completions`, {
165119
165164
  method: "POST",
165120
165165
  headers: {
@@ -165169,7 +165214,7 @@ async function analyzeImage(input) {
165169
165214
  const config = getLLMConfig();
165170
165215
  if (!OPENAI_COMPATIBLE_PROVIDERS.has(config.provider)) {
165171
165216
  throw new Error(
165172
- `Image analysis requires an OpenAI-compatible provider (openai, openrouter, requesty, or custom). Current provider "${config.provider}" uses a different API shape. Set MEMORIX_LLM_PROVIDER=openai or configure an OpenAI-compatible base URL.`
165217
+ `Image analysis requires an OpenAI-compatible provider (openai, openrouter, requesty, apiroute, or custom). Current provider "${config.provider}" uses a different API shape. Set MEMORIX_LLM_PROVIDER=openai or configure an OpenAI-compatible base URL.`
165173
165218
  );
165174
165219
  }
165175
165220
  const bytes = decodeBase64ImagePayload(input.base64, MAX_VISION_IMAGE_BYTES);
@@ -165208,7 +165253,7 @@ var init_image_loader = __esm({
165208
165253
  init_provider2();
165209
165254
  init_secret_filter();
165210
165255
  init_image_payload();
165211
- OPENAI_COMPATIBLE_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openrouter", "requesty", "custom"]);
165256
+ OPENAI_COMPATIBLE_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openrouter", "requesty", "apiroute", "custom"]);
165212
165257
  MAX_VISION_PROMPT_CHARS = 12e3;
165213
165258
  MAX_VISION_DESCRIPTION_CHARS = 12e3;
165214
165259
  MAX_VISION_LABELS = 50;
@@ -165638,6 +165683,26 @@ function generateClaudeConfig() {
165638
165683
  }
165639
165684
  };
165640
165685
  }
165686
+ function generateQwenConfig() {
165687
+ const cmd = `${resolveHookCommand()} hook --agent qwen`;
165688
+ const hookEntry = {
165689
+ type: "command",
165690
+ command: cmd,
165691
+ timeout: 10
165692
+ };
165693
+ return {
165694
+ hooks: {
165695
+ SessionStart: [{ hooks: [hookEntry] }],
165696
+ SessionEnd: [{ hooks: [hookEntry] }],
165697
+ PostToolUse: [{ hooks: [hookEntry] }],
165698
+ PostToolUseFailure: [{ hooks: [hookEntry] }],
165699
+ UserPromptSubmit: [{ hooks: [hookEntry] }],
165700
+ PreCompact: [{ hooks: [hookEntry] }],
165701
+ PostCompact: [{ hooks: [hookEntry] }],
165702
+ Stop: [{ hooks: [hookEntry] }]
165703
+ }
165704
+ };
165705
+ }
165641
165706
  function generateGrokConfig() {
165642
165707
  const cmd = `${resolveHookCommand()} hook --agent grok`;
165643
165708
  const hookEntry = {
@@ -165668,7 +165733,13 @@ function isMemorixGrokCommand(value) {
165668
165733
  function isMemorixGrokHook(value) {
165669
165734
  return isJsonRecord(value) && value.type === "command" && isMemorixGrokCommand(value.command);
165670
165735
  }
165671
- function mergeGrokHookConfig(existing, generated) {
165736
+ function isMemorixQwenCommand(value) {
165737
+ return value === "memorix hook --agent qwen" || value === "memorix.cmd hook --agent qwen";
165738
+ }
165739
+ function isMemorixQwenHook(value) {
165740
+ return isJsonRecord(value) && value.type === "command" && isMemorixQwenCommand(value.command);
165741
+ }
165742
+ function mergeCommandHookConfig(existing, generated, isOwnedHook) {
165672
165743
  const merged = { ...existing };
165673
165744
  const existingHooks = isJsonRecord(existing.hooks) ? { ...existing.hooks } : {};
165674
165745
  const generatedHooks = isJsonRecord(generated.hooks) ? generated.hooks : {};
@@ -165676,7 +165747,7 @@ function mergeGrokHookConfig(existing, generated) {
165676
165747
  const currentGroups = Array.isArray(existingHooks[event]) ? existingHooks[event] : [];
165677
165748
  const preservedGroups = currentGroups.flatMap((group) => {
165678
165749
  if (!isJsonRecord(group) || !Array.isArray(group.hooks)) return [group];
165679
- const preservedHooks = group.hooks.filter((hook) => !isMemorixGrokHook(hook));
165750
+ const preservedHooks = group.hooks.filter((hook) => !isOwnedHook(hook));
165680
165751
  if (preservedHooks.length === 0) return [];
165681
165752
  return [{ ...group, hooks: preservedHooks }];
165682
165753
  });
@@ -165685,7 +165756,13 @@ function mergeGrokHookConfig(existing, generated) {
165685
165756
  merged.hooks = existingHooks;
165686
165757
  return merged;
165687
165758
  }
165688
- function removeMemorixGrokHooks(config) {
165759
+ function mergeGrokHookConfig(existing, generated) {
165760
+ return mergeCommandHookConfig(existing, generated, isMemorixGrokHook);
165761
+ }
165762
+ function mergeQwenHookConfig(existing, generated) {
165763
+ return mergeCommandHookConfig(existing, generated, isMemorixQwenHook);
165764
+ }
165765
+ function removeCommandHooks(config, isOwnedHook) {
165689
165766
  const cleaned = { ...config };
165690
165767
  const hooks = isJsonRecord(config.hooks) ? { ...config.hooks } : null;
165691
165768
  if (!hooks) return cleaned;
@@ -165693,7 +165770,7 @@ function removeMemorixGrokHooks(config) {
165693
165770
  if (!Array.isArray(groups)) continue;
165694
165771
  const preservedGroups = groups.flatMap((group) => {
165695
165772
  if (!isJsonRecord(group) || !Array.isArray(group.hooks)) return [group];
165696
- const preservedHooks = group.hooks.filter((hook) => !isMemorixGrokHook(hook));
165773
+ const preservedHooks = group.hooks.filter((hook) => !isOwnedHook(hook));
165697
165774
  if (preservedHooks.length === 0) return [];
165698
165775
  return [{ ...group, hooks: preservedHooks }];
165699
165776
  });
@@ -165704,6 +165781,12 @@ function removeMemorixGrokHooks(config) {
165704
165781
  else delete cleaned.hooks;
165705
165782
  return cleaned;
165706
165783
  }
165784
+ function removeMemorixGrokHooks(config) {
165785
+ return removeCommandHooks(config, isMemorixGrokHook);
165786
+ }
165787
+ function removeMemorixQwenHooks(config) {
165788
+ return removeCommandHooks(config, isMemorixQwenHook);
165789
+ }
165707
165790
  async function readGrokHookConfig(configPath) {
165708
165791
  let content;
165709
165792
  try {
@@ -165722,6 +165805,24 @@ async function readGrokHookConfig(configPath) {
165722
165805
  throw new Error(`Cannot safely update Grok hook config ${configPath}: ${reason}`);
165723
165806
  }
165724
165807
  }
165808
+ async function readQwenHookConfig(configPath) {
165809
+ let content;
165810
+ try {
165811
+ content = await fs21.readFile(configPath, "utf-8");
165812
+ } catch (error) {
165813
+ if (error.code === "ENOENT") return {};
165814
+ throw error;
165815
+ }
165816
+ if (!content.trim()) return {};
165817
+ try {
165818
+ const parsed = JSON.parse(content);
165819
+ if (!isJsonRecord(parsed)) throw new Error("top-level value must be an object");
165820
+ return parsed;
165821
+ } catch (error) {
165822
+ const reason = error instanceof Error ? error.message : String(error);
165823
+ throw new Error(`Cannot safely update Qwen hook config ${configPath}: ${reason}`);
165824
+ }
165825
+ }
165725
165826
  function generateCopilotConfig() {
165726
165827
  const cmd = `${resolveHookCommand()} hook`;
165727
165828
  const hasPwsh = detectPwsh();
@@ -166336,6 +166437,8 @@ function getProjectConfigPath(agent, projectRoot) {
166336
166437
  switch (agent) {
166337
166438
  case "claude":
166338
166439
  return path34.join(projectRoot, ".claude", "settings.local.json");
166440
+ case "qwen":
166441
+ return path34.join(projectRoot, ".qwen", "settings.json");
166339
166442
  case "copilot":
166340
166443
  return path34.join(projectRoot, ".github", "hooks", "memorix.json");
166341
166444
  case "windsurf":
@@ -166377,6 +166480,8 @@ function getGlobalConfigPath(agent) {
166377
166480
  switch (agent) {
166378
166481
  case "claude":
166379
166482
  return path34.join(home, ".claude", "settings.json");
166483
+ case "qwen":
166484
+ return path34.join(home, ".qwen", "settings.json");
166380
166485
  case "copilot":
166381
166486
  return "";
166382
166487
  case "windsurf":
@@ -166418,6 +166523,8 @@ function getAgentRulesPath(agent, root, global2 = false) {
166418
166523
  return path34.join(root, ".cursor", "rules", "memorix.mdc");
166419
166524
  case "claude":
166420
166525
  return path34.join(root, ".claude", "CLAUDE.md");
166526
+ case "qwen":
166527
+ return path34.join(root, ".qwen", "QWEN.md");
166421
166528
  case "codex":
166422
166529
  return path34.join(root, ".codex", "AGENTS.md");
166423
166530
  case "kiro":
@@ -166446,6 +166553,8 @@ function getAgentRulesPath(agent, root, global2 = false) {
166446
166553
  return path34.join(root, ".cursor", "rules", "memorix.mdc");
166447
166554
  case "claude":
166448
166555
  return path34.join(root, "CLAUDE.md");
166556
+ case "qwen":
166557
+ return path34.join(root, "QWEN.md");
166449
166558
  case "copilot":
166450
166559
  return path34.join(root, ".github", "copilot-instructions.md");
166451
166560
  case "codex":
@@ -166522,6 +166631,12 @@ async function detectInstalledAgents() {
166522
166631
  agents.push("grok");
166523
166632
  } catch {
166524
166633
  }
166634
+ const qwenDir = path34.join(home, ".qwen");
166635
+ try {
166636
+ await fs21.access(qwenDir);
166637
+ agents.push("qwen");
166638
+ } catch {
166639
+ }
166525
166640
  const codexDir = path34.join(home, ".codex");
166526
166641
  try {
166527
166642
  await fs21.access(codexDir);
@@ -166605,10 +166720,10 @@ async function installHooks(agent, projectRoot, global2 = false) {
166605
166720
  const { access: access3, unlink: unlink3 } = await import("fs/promises");
166606
166721
  await access3(entry.path);
166607
166722
  const basename5 = path34.basename(entry.path);
166608
- if (basename5 === "AGENTS.md" || basename5 === "GEMINI.md" || basename5 === "CONTEXT.md") {
166723
+ if (basename5 === "AGENTS.md" || basename5 === "GEMINI.md" || basename5 === "QWEN.md" || basename5 === "CONTEXT.md") {
166609
166724
  continue;
166610
166725
  }
166611
- if (agent === "grok" && path34.resolve(entry.path) === path34.resolve(configPath)) {
166726
+ if ((agent === "grok" || agent === "qwen") && path34.resolve(entry.path) === path34.resolve(configPath)) {
166612
166727
  continue;
166613
166728
  }
166614
166729
  await unlink3(entry.path);
@@ -166623,6 +166738,9 @@ async function installHooks(agent, projectRoot, global2 = false) {
166623
166738
  case "claude":
166624
166739
  generated = generateClaudeConfig();
166625
166740
  break;
166741
+ case "qwen":
166742
+ generated = generateQwenConfig();
166743
+ break;
166626
166744
  case "grok":
166627
166745
  generated = generateGrokConfig();
166628
166746
  break;
@@ -166729,6 +166847,15 @@ async function installHooks(agent, projectRoot, global2 = false) {
166729
166847
  await recordFile2(projectRoot, "hook", configPath, agent);
166730
166848
  } catch {
166731
166849
  }
166850
+ } else if (agent === "qwen") {
166851
+ const existing = await readQwenHookConfig(configPath);
166852
+ const merged = mergeQwenHookConfig(existing, generated);
166853
+ await fs21.writeFile(configPath, JSON.stringify(merged, null, 2), "utf-8");
166854
+ try {
166855
+ const { recordFile: recordFile2 } = await Promise.resolve().then(() => (init_audit(), audit_exports));
166856
+ await recordFile2(projectRoot, "hook", configPath, agent);
166857
+ } catch {
166858
+ }
166732
166859
  } else if (agent === "kiro") {
166733
166860
  const hookFiles = generateKiroHookFiles();
166734
166861
  const hooksDir = path34.join(path34.dirname(configPath));
@@ -166792,6 +166919,9 @@ async function installHooks(agent, projectRoot, global2 = false) {
166792
166919
  case "claude":
166793
166920
  events.push("session_start", "post_tool", "user_prompt", "pre_compact", "session_end");
166794
166921
  break;
166922
+ case "qwen":
166923
+ events.push("session_start", "session_end", "user_prompt", "post_tool", "pre_compact", "post_compact");
166924
+ break;
166795
166925
  case "copilot":
166796
166926
  events.push("session_start", "session_end", "user_prompt", "post_tool");
166797
166927
  break;
@@ -166833,7 +166963,7 @@ async function installAgentRules(agent, projectRoot, global2 = false) {
166833
166963
  const rulesPath = getAgentRulesPath(agent, rulesRoot, global2);
166834
166964
  try {
166835
166965
  await fs21.mkdir(path34.dirname(rulesPath), { recursive: true });
166836
- if (agent === "claude" || agent === "codex" || agent === "opencode" || agent === "antigravity" || agent === "gemini-cli" || agent === "dsh" || agent === "grok") {
166966
+ if (agent === "claude" || agent === "qwen" || agent === "codex" || agent === "opencode" || agent === "antigravity" || agent === "gemini-cli" || agent === "dsh" || agent === "grok") {
166837
166967
  try {
166838
166968
  const existing = await fs21.readFile(rulesPath, "utf-8");
166839
166969
  await fs21.writeFile(rulesPath, mergeMemorixRulesContent(existing, rulesContent), "utf-8");
@@ -167011,6 +167141,15 @@ async function uninstallHooks(agent, projectRoot, global2 = false) {
167011
167141
  await fs21.writeFile(configPath, JSON.stringify(cleaned, null, 2), "utf-8");
167012
167142
  }
167013
167143
  success = true;
167144
+ } else if (agent === "qwen") {
167145
+ const config = await readQwenHookConfig(configPath);
167146
+ const cleaned = removeMemorixQwenHooks(config);
167147
+ if (Object.keys(cleaned).length === 0) {
167148
+ await fs21.unlink(configPath);
167149
+ } else {
167150
+ await fs21.writeFile(configPath, JSON.stringify(cleaned, null, 2), "utf-8");
167151
+ }
167152
+ success = true;
167014
167153
  } else if (agent === "kiro" || agent === "opencode") {
167015
167154
  await fs21.unlink(configPath);
167016
167155
  success = true;
@@ -167034,13 +167173,13 @@ async function uninstallHooks(agent, projectRoot, global2 = false) {
167034
167173
  const agentFiles = prevFiles.filter((e2) => e2.agent === agent);
167035
167174
  for (const entry of agentFiles) {
167036
167175
  try {
167037
- if (agent === "grok" && path34.resolve(entry.path) === path34.resolve(configPath)) {
167176
+ if ((agent === "grok" || agent === "qwen") && path34.resolve(entry.path) === path34.resolve(configPath)) {
167038
167177
  await removeFile2(projectRoot, entry.path);
167039
167178
  auditCleaned = true;
167040
167179
  continue;
167041
167180
  }
167042
167181
  const basename5 = path34.basename(entry.path);
167043
- if (basename5 === "AGENTS.md" || basename5 === "GEMINI.md" || basename5 === "CONTEXT.md") {
167182
+ if (basename5 === "AGENTS.md" || basename5 === "GEMINI.md" || basename5 === "QWEN.md" || basename5 === "CONTEXT.md") {
167044
167183
  try {
167045
167184
  const content = await fs21.readFile(entry.path, "utf-8");
167046
167185
  const memorixStart = content.indexOf("# Memorix");
@@ -167099,7 +167238,7 @@ async function uninstallHooks(agent, projectRoot, global2 = false) {
167099
167238
  }
167100
167239
  async function getHookStatus(projectRoot) {
167101
167240
  const results = [];
167102
- const agents = ["claude", "copilot", "windsurf", "cursor", "kiro", "codex", "antigravity", "gemini-cli", "opencode", "pi", "trae", "grok"];
167241
+ const agents = ["claude", "qwen", "copilot", "windsurf", "cursor", "kiro", "codex", "antigravity", "gemini-cli", "opencode", "pi", "trae", "grok"];
167103
167242
  for (const agent of agents) {
167104
167243
  const projectPath = getProjectConfigPath(agent, projectRoot);
167105
167244
  const globalPath = getGlobalConfigPath(agent);
@@ -171057,7 +171196,7 @@ var MCP_SERVER_INFO_META_KEY = "io.modelcontextprotocol/serverInfo";
171057
171196
  function getMcpServerInfo() {
171058
171197
  return {
171059
171198
  name: "memorix",
171060
- version: true ? "1.9.10" : "1.0.1"
171199
+ version: true ? "1.9.12" : "1.0.1"
171061
171200
  };
171062
171201
  }
171063
171202
  function createMcpDiscoverResult(capabilities, serverInfo) {
@@ -171331,8 +171470,8 @@ async function createMemorixServer(cwd, existingServer, sharedTeam, options = {}
171331
171470
  if (!lightweightUnresolvedSession && !deferProjectRuntimeInit) {
171332
171471
  try {
171333
171472
  const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
171334
- const allObs = getAllObservations2();
171335
- const observedIds = [...new Set(allObs.map((o) => o.projectId))];
171473
+ const store = getObservationStore();
171474
+ const observedIds = store.listProjectIds ? await store.listProjectIds() : [...new Set(getAllObservations2().map((o) => o.projectId))];
171336
171475
  const merged = await autoMergeByBaseName(observedIds);
171337
171476
  if (merged > 0) {
171338
171477
  console.error(`[memorix] Auto-merged ${merged} alias group(s) by base name`);
@@ -171373,8 +171512,8 @@ async function createMemorixServer(cwd, existingServer, sharedTeam, options = {}
171373
171512
  try {
171374
171513
  const { getAllObservations: getAllObservations2 } = await Promise.resolve().then(() => (init_observations(), observations_exports));
171375
171514
  await initObservations(projectDir2);
171376
- const allObs = getAllObservations2();
171377
- const observedIds = [...new Set(allObs.map((o) => o.projectId))];
171515
+ const store = getObservationStore();
171516
+ const observedIds = store.listProjectIds ? await store.listProjectIds() : [...new Set(getAllObservations2().map((o) => o.projectId))];
171378
171517
  const merged = await autoMergeByBaseName(observedIds);
171379
171518
  if (merged > 0) {
171380
171519
  console.error(`[memorix] Auto-merged ${merged} alias group(s) by base name`);