@remnic/core 9.3.651 → 9.3.652

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 (76) hide show
  1. package/dist/access-cli.js +9 -9
  2. package/dist/access-http.d.ts +3 -2
  3. package/dist/access-http.js +10 -10
  4. package/dist/access-mcp.d.ts +3 -2
  5. package/dist/access-mcp.js +9 -9
  6. package/dist/{access-service-DIZRHQ7Q.d.ts → access-service-CdJFd3_b.d.ts} +23 -2
  7. package/dist/access-service.d.ts +3 -2
  8. package/dist/access-service.js +8 -8
  9. package/dist/bootstrap.d.ts +2 -1
  10. package/dist/{chunk-QT4THOLT.js → chunk-2DGQLOOM.js} +1 -1
  11. package/dist/chunk-2DGQLOOM.js.map +1 -0
  12. package/dist/{chunk-SLYD3AH4.js → chunk-5V3TAB7D.js} +176 -4
  13. package/dist/chunk-5V3TAB7D.js.map +1 -0
  14. package/dist/{chunk-FOVPSMGI.js → chunk-7WEB3FLJ.js} +2 -2
  15. package/dist/{chunk-WJK75OCH.js → chunk-GI45G4BK.js} +2 -2
  16. package/dist/{chunk-76QTEJ2Q.js → chunk-JBHXMCYN.js} +2 -2
  17. package/dist/{chunk-4PTKFBST.js → chunk-JVRPJ7D4.js} +126 -26
  18. package/dist/chunk-JVRPJ7D4.js.map +1 -0
  19. package/dist/{chunk-TQUWNX7C.js → chunk-JX2RINDR.js} +2 -2
  20. package/dist/{chunk-RSS2KWN6.js → chunk-MGGNV3H2.js} +2 -2
  21. package/dist/{chunk-I4COC5XW.js → chunk-PYWNNF2I.js} +47 -9
  22. package/dist/chunk-PYWNNF2I.js.map +1 -0
  23. package/dist/{chunk-5WSDHTBO.js → chunk-TCX4WLKK.js} +7 -4
  24. package/dist/chunk-TCX4WLKK.js.map +1 -0
  25. package/dist/{chunk-RKN5J4RO.js → chunk-WSFNYPAT.js} +6 -6
  26. package/dist/{chunk-LFTLXOFX.js → chunk-WTI35CVJ.js} +2 -2
  27. package/dist/{chunk-6UKL6IXM.js → chunk-YM3LR4LS.js} +5 -5
  28. package/dist/{chunk-MF32AL7N.js → chunk-YOVKPOMD.js} +3 -3
  29. package/dist/{cli-BG4ybtJr.d.ts → cli-DDo7Qgs-.d.ts} +2 -2
  30. package/dist/cli.d.ts +4 -3
  31. package/dist/cli.js +13 -13
  32. package/dist/explicit-capture.d.ts +2 -1
  33. package/dist/index.d.ts +5 -4
  34. package/dist/index.js +14 -14
  35. package/dist/mcp-memory-inspector-app.d.ts +3 -2
  36. package/dist/namespaces/migrate.js +8 -8
  37. package/dist/namespaces/search.d.ts +18 -1
  38. package/dist/namespaces/search.js +7 -7
  39. package/dist/operator-toolkit.js +9 -9
  40. package/dist/{orchestrator-CX-oqwJq.d.ts → orchestrator-8fTZsa0y.d.ts} +2 -0
  41. package/dist/orchestrator.d.ts +2 -1
  42. package/dist/orchestrator.js +8 -8
  43. package/dist/qmd.d.ts +2 -1
  44. package/dist/qmd.js +2 -2
  45. package/dist/schemas.d.ts +22 -22
  46. package/dist/search/factory.js +6 -6
  47. package/dist/search/index.js +6 -6
  48. package/dist/search/lancedb-backend.js +2 -2
  49. package/dist/search/meilisearch-backend.js +2 -2
  50. package/dist/search/orama-backend.js +2 -2
  51. package/dist/search/port.d.ts +6 -0
  52. package/dist/search/port.js +1 -1
  53. package/dist/transfer/types.d.ts +12 -12
  54. package/package.json +1 -1
  55. package/src/access-service-health.test.ts +402 -0
  56. package/src/access-service.ts +274 -2
  57. package/src/namespaces/search.test.ts +258 -3
  58. package/src/namespaces/search.ts +184 -30
  59. package/src/orchestrator.ts +11 -1
  60. package/src/qmd.test.ts +102 -0
  61. package/src/qmd.ts +54 -7
  62. package/src/search/port.ts +6 -0
  63. package/dist/chunk-4PTKFBST.js.map +0 -1
  64. package/dist/chunk-5WSDHTBO.js.map +0 -1
  65. package/dist/chunk-I4COC5XW.js.map +0 -1
  66. package/dist/chunk-QT4THOLT.js.map +0 -1
  67. package/dist/chunk-SLYD3AH4.js.map +0 -1
  68. /package/dist/{chunk-FOVPSMGI.js.map → chunk-7WEB3FLJ.js.map} +0 -0
  69. /package/dist/{chunk-WJK75OCH.js.map → chunk-GI45G4BK.js.map} +0 -0
  70. /package/dist/{chunk-76QTEJ2Q.js.map → chunk-JBHXMCYN.js.map} +0 -0
  71. /package/dist/{chunk-TQUWNX7C.js.map → chunk-JX2RINDR.js.map} +0 -0
  72. /package/dist/{chunk-RSS2KWN6.js.map → chunk-MGGNV3H2.js.map} +0 -0
  73. /package/dist/{chunk-RKN5J4RO.js.map → chunk-WSFNYPAT.js.map} +0 -0
  74. /package/dist/{chunk-LFTLXOFX.js.map → chunk-WTI35CVJ.js.map} +0 -0
  75. /package/dist/{chunk-6UKL6IXM.js.map → chunk-YM3LR4LS.js.map} +0 -0
  76. /package/dist/{chunk-MF32AL7N.js.map → chunk-YOVKPOMD.js.map} +0 -0
@@ -0,0 +1,402 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtemp, rm } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import test from "node:test";
6
+
7
+ import { EngramAccessService } from "./access-service.js";
8
+ import { parseConfig } from "./config.js";
9
+ import { namespaceCollectionName } from "./namespaces/search.js";
10
+ import type { Orchestrator } from "./orchestrator.js";
11
+ import type { SearchBackend } from "./search/port.js";
12
+
13
+ function makeQmd(overrides: Partial<SearchBackend> & Record<string, unknown>): SearchBackend {
14
+ return {
15
+ async probe() {
16
+ return false;
17
+ },
18
+ isAvailable() {
19
+ return false;
20
+ },
21
+ debugStatus() {
22
+ return "backend=noop";
23
+ },
24
+ async search() {
25
+ return [];
26
+ },
27
+ async searchGlobal() {
28
+ return [];
29
+ },
30
+ async bm25Search() {
31
+ return [];
32
+ },
33
+ async vectorSearch() {
34
+ return [];
35
+ },
36
+ async hybridSearch() {
37
+ return [];
38
+ },
39
+ async update() {},
40
+ async updateCollection() {},
41
+ async embed() {},
42
+ async embedCollection() {},
43
+ async ensureCollection() {
44
+ return "skipped";
45
+ },
46
+ ...overrides,
47
+ } as SearchBackend;
48
+ }
49
+
50
+ test("health reports active QMD version and collection state", async () => {
51
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-"));
52
+ try {
53
+ const config = parseConfig({
54
+ memoryDir,
55
+ searchBackend: "qmd",
56
+ qmdEnabled: true,
57
+ qmdCollection: "remnic-memory",
58
+ });
59
+ const qmd = makeQmd({
60
+ probe: async () => true,
61
+ isAvailable: () => true,
62
+ debugStatus: () => "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
63
+ checkCollection: async (collection, execution) => {
64
+ assert.equal(collection, "remnic-memory");
65
+ assert.ok(execution?.signal instanceof AbortSignal);
66
+ return "present";
67
+ },
68
+ getVersionStatus: () => ({
69
+ installedVersion: "qmd 2.5.3",
70
+ supportedVersion: "2.5.3",
71
+ supported: true,
72
+ newerThanSupported: false,
73
+ upgradeAvailable: false,
74
+ capabilities: { doctor: true },
75
+ }),
76
+ isDaemonMode: () => false,
77
+ });
78
+ const service = new EngramAccessService({
79
+ config,
80
+ qmd,
81
+ async getStorage() {
82
+ return { dir: memoryDir };
83
+ },
84
+ } as unknown as Orchestrator);
85
+
86
+ const health = await service.health();
87
+
88
+ assert.equal(health.qmdEnabled, true);
89
+ assert.deepEqual(health.qmd, {
90
+ enabled: true,
91
+ active: true,
92
+ degraded: false,
93
+ mode: "cli",
94
+ collection: "remnic-memory",
95
+ collectionState: "present",
96
+ installedVersion: "qmd 2.5.3",
97
+ supportedVersion: "2.5.3",
98
+ supported: true,
99
+ upgradeAvailable: false,
100
+ doctorAvailable: true,
101
+ debugStatus: "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
102
+ });
103
+ } finally {
104
+ await rm(memoryDir, { recursive: true, force: true });
105
+ }
106
+ });
107
+
108
+ test("health marks QMD as degraded when configured search falls back to noop", async () => {
109
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-degraded-"));
110
+ try {
111
+ const config = parseConfig({
112
+ memoryDir,
113
+ searchBackend: "qmd",
114
+ qmdEnabled: true,
115
+ qmdCollection: "remnic-memory",
116
+ });
117
+ const service = new EngramAccessService({
118
+ config,
119
+ qmd: makeQmd({}),
120
+ async getStorage() {
121
+ return { dir: memoryDir };
122
+ },
123
+ } as unknown as Orchestrator);
124
+
125
+ const health = await service.health();
126
+
127
+ assert.equal(health.qmd.active, false);
128
+ assert.equal(health.qmd.degraded, true);
129
+ assert.equal(health.qmd.mode, "fallback");
130
+ assert.equal(health.qmd.collectionState, "unknown");
131
+ assert.equal(health.qmd.debugStatus, "backend=noop");
132
+ } finally {
133
+ await rm(memoryDir, { recursive: true, force: true });
134
+ }
135
+ });
136
+
137
+ test("health marks QMD as degraded when the checked collection is missing", async () => {
138
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-missing-"));
139
+ try {
140
+ const config = parseConfig({
141
+ memoryDir,
142
+ searchBackend: "qmd",
143
+ qmdEnabled: true,
144
+ qmdCollection: "remnic-memory",
145
+ });
146
+ const service = new EngramAccessService({
147
+ config,
148
+ qmd: makeQmd({
149
+ probe: async () => true,
150
+ isAvailable: () => true,
151
+ debugStatus: () => "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
152
+ checkCollection: async () => "missing",
153
+ isDaemonMode: () => false,
154
+ }),
155
+ async getStorage() {
156
+ return { dir: memoryDir };
157
+ },
158
+ } as unknown as Orchestrator);
159
+
160
+ const health = await service.health();
161
+
162
+ assert.equal(health.qmd.collectionState, "missing");
163
+ assert.equal(health.qmd.active, false);
164
+ assert.equal(health.qmd.degraded, true);
165
+ assert.equal(health.qmd.mode, "fallback");
166
+ } finally {
167
+ await rm(memoryDir, { recursive: true, force: true });
168
+ }
169
+ });
170
+
171
+ test("health reports degraded diagnostics when read-only root QMD probe fails", async () => {
172
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-stale-probe-"));
173
+ try {
174
+ const config = parseConfig({
175
+ memoryDir,
176
+ searchBackend: "qmd",
177
+ qmdEnabled: true,
178
+ qmdCollection: "remnic-memory",
179
+ });
180
+ const service = new EngramAccessService({
181
+ config,
182
+ qmd: makeQmd({
183
+ probe: async () => false,
184
+ isAvailable: () => true,
185
+ debugStatus: () => "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
186
+ checkCollection: async () => "present",
187
+ isDaemonMode: () => false,
188
+ }),
189
+ async getStorage() {
190
+ return { dir: memoryDir };
191
+ },
192
+ } as unknown as Orchestrator);
193
+
194
+ const health = await service.health();
195
+
196
+ assert.equal(health.qmd.active, true);
197
+ assert.equal(health.qmd.degraded, true);
198
+ assert.equal(health.qmd.mode, "cli");
199
+ assert.equal(health.qmd.collectionState, "unknown");
200
+ } finally {
201
+ await rm(memoryDir, { recursive: true, force: true });
202
+ }
203
+ });
204
+
205
+ test("health uses read-only root QMD availability checks", async () => {
206
+ const memoryDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-readonly-"));
207
+ try {
208
+ const config = parseConfig({
209
+ memoryDir,
210
+ searchBackend: "qmd",
211
+ qmdEnabled: true,
212
+ qmdCollection: "remnic-memory",
213
+ });
214
+ let checkAvailabilityCalled = false;
215
+ let probeCalled = false;
216
+ const service = new EngramAccessService({
217
+ config,
218
+ qmd: makeQmd({
219
+ probe: async () => {
220
+ probeCalled = true;
221
+ return true;
222
+ },
223
+ checkAvailability: async (execution) => {
224
+ checkAvailabilityCalled = true;
225
+ assert.ok(execution?.signal instanceof AbortSignal);
226
+ return true;
227
+ },
228
+ isAvailable: () => true,
229
+ debugStatus: () => "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
230
+ checkCollection: async () => "present",
231
+ isDaemonMode: () => false,
232
+ }),
233
+ async getStorage() {
234
+ return { dir: memoryDir };
235
+ },
236
+ } as unknown as Orchestrator);
237
+
238
+ const health = await service.health();
239
+
240
+ assert.equal(checkAvailabilityCalled, true);
241
+ assert.equal(probeCalled, false);
242
+ assert.equal(health.qmd.active, true);
243
+ assert.equal(health.qmd.degraded, false);
244
+ } finally {
245
+ await rm(memoryDir, { recursive: true, force: true });
246
+ }
247
+ });
248
+
249
+ test("health reports namespace-scoped QMD backend state", async () => {
250
+ const rootDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-ns-"));
251
+ try {
252
+ const teamDir = path.join(rootDir, "namespaces", "team");
253
+ const config = parseConfig({
254
+ memoryDir: rootDir,
255
+ namespacesEnabled: true,
256
+ defaultNamespace: "default",
257
+ searchBackend: "qmd",
258
+ qmdEnabled: true,
259
+ qmdCollection: "remnic-memory",
260
+ namespacePolicies: [{ name: "team", readPrincipals: [], writePrincipals: [] }],
261
+ });
262
+ const expectedCollection = namespaceCollectionName("remnic-memory", "team", {
263
+ defaultNamespace: "default",
264
+ });
265
+ const service = new EngramAccessService({
266
+ config,
267
+ qmd: makeQmd({}),
268
+ async getStorage(namespace: string) {
269
+ return { dir: namespace === "team" ? teamDir : rootDir };
270
+ },
271
+ async searchHealthForNamespace(namespace: string, execution?: { signal?: AbortSignal }) {
272
+ assert.equal(namespace, "team");
273
+ assert.ok(execution?.signal instanceof AbortSignal);
274
+ return {
275
+ collection: expectedCollection,
276
+ available: true,
277
+ collectionState: "present",
278
+ debugStatus: "cli=true daemon=false cliPath=qmd cliVersion=qmd 2.5.3",
279
+ installedVersion: "qmd 2.5.3",
280
+ supportedVersion: "2.5.3",
281
+ supported: true,
282
+ upgradeAvailable: false,
283
+ doctorAvailable: true,
284
+ daemonMode: false,
285
+ };
286
+ },
287
+ } as unknown as Orchestrator);
288
+
289
+ const health = await service.health("team");
290
+
291
+ assert.equal(health.memoryDir, teamDir);
292
+ assert.equal(health.qmd.active, true);
293
+ assert.equal(health.qmd.degraded, false);
294
+ assert.equal(health.qmd.collection, expectedCollection);
295
+ assert.equal(health.qmd.collectionState, "present");
296
+ assert.equal(health.qmd.installedVersion, "qmd 2.5.3");
297
+ } finally {
298
+ await rm(rootDir, { recursive: true, force: true });
299
+ }
300
+ });
301
+
302
+ test("health marks namespace QMD unknown collection state degraded", async () => {
303
+ const rootDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-ns-unknown-"));
304
+ try {
305
+ const teamDir = path.join(rootDir, "namespaces", "team");
306
+ const config = parseConfig({
307
+ memoryDir: rootDir,
308
+ namespacesEnabled: true,
309
+ defaultNamespace: "default",
310
+ searchBackend: "qmd",
311
+ qmdEnabled: true,
312
+ qmdCollection: "remnic-memory",
313
+ namespacePolicies: [{ name: "team", readPrincipals: [], writePrincipals: [] }],
314
+ });
315
+ const expectedCollection = namespaceCollectionName("remnic-memory", "team", {
316
+ defaultNamespace: "default",
317
+ });
318
+ const service = new EngramAccessService({
319
+ config,
320
+ qmd: makeQmd({}),
321
+ async getStorage(namespace: string) {
322
+ return { dir: namespace === "team" ? teamDir : rootDir };
323
+ },
324
+ async searchHealthForNamespace(namespace: string, execution?: { signal?: AbortSignal }) {
325
+ assert.equal(namespace, "team");
326
+ assert.ok(execution?.signal instanceof AbortSignal);
327
+ return {
328
+ collection: expectedCollection,
329
+ available: true,
330
+ collectionState: "unknown",
331
+ debugStatus: "cli=true collection=unknown",
332
+ installedVersion: "qmd 2.5.3",
333
+ supportedVersion: "2.5.3",
334
+ supported: true,
335
+ upgradeAvailable: false,
336
+ doctorAvailable: true,
337
+ daemonMode: false,
338
+ };
339
+ },
340
+ } as unknown as Orchestrator);
341
+
342
+ const health = await service.health("team");
343
+
344
+ assert.equal(health.memoryDir, teamDir);
345
+ assert.equal(health.qmd.active, true);
346
+ assert.equal(health.qmd.degraded, true);
347
+ assert.equal(health.qmd.collection, expectedCollection);
348
+ assert.equal(health.qmd.collectionState, "unknown");
349
+ assert.equal(health.qmd.mode, "cli");
350
+ } finally {
351
+ await rm(rootDir, { recursive: true, force: true });
352
+ }
353
+ });
354
+
355
+ test("health keeps namespace QMD failures scoped to the namespace", async () => {
356
+ const rootDir = await mkdtemp(path.join(os.tmpdir(), "remnic-health-qmd-ns-fail-"));
357
+ try {
358
+ const teamDir = path.join(rootDir, "namespaces", "team");
359
+ const config = parseConfig({
360
+ memoryDir: rootDir,
361
+ namespacesEnabled: true,
362
+ defaultNamespace: "default",
363
+ searchBackend: "qmd",
364
+ qmdEnabled: true,
365
+ qmdCollection: "remnic-memory",
366
+ namespacePolicies: [{ name: "team", readPrincipals: [], writePrincipals: [] }],
367
+ });
368
+ const expectedCollection = namespaceCollectionName("remnic-memory", "team", {
369
+ defaultNamespace: "default",
370
+ });
371
+ const service = new EngramAccessService({
372
+ config,
373
+ qmd: makeQmd({
374
+ probe: async () => true,
375
+ isAvailable: () => true,
376
+ debugStatus: () => "root-qmd-should-not-leak",
377
+ checkCollection: async () => "present",
378
+ }),
379
+ async getStorage(namespace: string) {
380
+ return { dir: namespace === "team" ? teamDir : rootDir };
381
+ },
382
+ async searchHealthForNamespace() {
383
+ throw new Error(`namespace probe timed out at ${teamDir}/qmd/index.sqlite`);
384
+ },
385
+ } as unknown as Orchestrator);
386
+
387
+ const health = await service.health("team");
388
+
389
+ assert.equal(health.memoryDir, teamDir);
390
+ assert.equal(health.qmd.collection, expectedCollection);
391
+ assert.equal(health.qmd.active, false);
392
+ assert.equal(health.qmd.degraded, true);
393
+ assert.equal(health.qmd.collectionState, "unknown");
394
+ assert.equal(health.qmd.mode, "fallback");
395
+ assert.equal(health.qmd.debugStatus, "backend=namespace-unavailable error=Error");
396
+ assert.doesNotMatch(health.qmd.debugStatus, /root-qmd-should-not-leak/);
397
+ assert.doesNotMatch(health.qmd.debugStatus, /index\.sqlite/);
398
+ assert.doesNotMatch(health.qmd.debugStatus, /remnic-health-qmd-ns-fail/);
399
+ } finally {
400
+ await rm(rootDir, { recursive: true, force: true });
401
+ }
402
+ });
@@ -38,6 +38,7 @@ import {
38
38
  runMemoryGovernance,
39
39
  } from "./maintenance/memory-governance.js";
40
40
  import { runProcedureMining } from "./procedural/procedure-miner.js";
41
+ import { displayErrorDetail } from "./runtime/better-sqlite.js";
41
42
  import type { PatternReinforcementResult } from "./maintenance/pattern-reinforcement.js";
42
43
  import type { LiveConnectorsRunSummary } from "./live-connectors-runner.js";
43
44
  import type { WearablesService } from "./wearables/service.js";
@@ -279,10 +280,32 @@ export interface EngramAccessHealthResponse {
279
280
  defaultNamespace: string;
280
281
  searchBackend: string;
281
282
  qmdEnabled: boolean;
283
+ qmd: EngramAccessQmdHealthResponse;
282
284
  nativeKnowledgeEnabled: boolean;
283
285
  projectionAvailable: boolean;
284
286
  }
285
287
 
288
+ export type EngramAccessQmdCollectionState =
289
+ | "present"
290
+ | "missing"
291
+ | "unknown"
292
+ | "skipped";
293
+
294
+ export interface EngramAccessQmdHealthResponse {
295
+ enabled: boolean;
296
+ active: boolean;
297
+ degraded: boolean;
298
+ mode: "cli" | "daemon" | "fallback" | "disabled" | "not-selected";
299
+ collection: string;
300
+ collectionState: EngramAccessQmdCollectionState;
301
+ installedVersion: string | null;
302
+ supportedVersion: string | null;
303
+ supported: boolean | null;
304
+ upgradeAvailable: boolean | null;
305
+ doctorAvailable: boolean | null;
306
+ debugStatus: string;
307
+ }
308
+
286
309
  export interface EngramAccessRecallRequest {
287
310
  query: string;
288
311
  sessionKey?: string;
@@ -2412,6 +2435,8 @@ export class EngramAccessService {
2412
2435
  async health(namespace?: string): Promise<EngramAccessHealthResponse> {
2413
2436
  const resolvedNamespace = this.resolveNamespace(namespace);
2414
2437
  const storage = await this.orchestrator.getStorage(resolvedNamespace);
2438
+ const searchBackend = this.orchestrator.config.searchBackend ?? "qmd";
2439
+ const qmdEnabled = this.orchestrator.config.qmdEnabled === true;
2415
2440
  let projectionAvailable = false;
2416
2441
  try {
2417
2442
  await stat(getMemoryProjectionPath(storage.dir));
@@ -2425,13 +2450,260 @@ export class EngramAccessService {
2425
2450
  memoryDir: storage.dir,
2426
2451
  namespacesEnabled: this.orchestrator.config.namespacesEnabled === true,
2427
2452
  defaultNamespace: this.orchestrator.config.defaultNamespace,
2428
- searchBackend: this.orchestrator.config.searchBackend ?? "qmd",
2429
- qmdEnabled: this.orchestrator.config.qmdEnabled === true,
2453
+ searchBackend,
2454
+ qmdEnabled,
2455
+ qmd: await this.qmdHealth(
2456
+ searchBackend,
2457
+ qmdEnabled,
2458
+ resolvedNamespace,
2459
+ this.qmdCollectionForHealth(resolvedNamespace, storage.dir),
2460
+ ),
2430
2461
  nativeKnowledgeEnabled: this.orchestrator.config.nativeKnowledge?.enabled === true,
2431
2462
  projectionAvailable,
2432
2463
  };
2433
2464
  }
2434
2465
 
2466
+ private qmdCollectionForHealth(namespace: string, storageDir: string): string {
2467
+ if (this.orchestrator.config.namespacesEnabled !== true) {
2468
+ return this.orchestrator.config.qmdCollection;
2469
+ }
2470
+
2471
+ const useLegacyDefaultCollection =
2472
+ namespace === this.orchestrator.config.defaultNamespace &&
2473
+ storageDir === this.orchestrator.config.memoryDir;
2474
+ return namespaceCollectionName(this.orchestrator.config.qmdCollection, namespace, {
2475
+ defaultNamespace: this.orchestrator.config.defaultNamespace,
2476
+ useLegacyDefaultCollection,
2477
+ });
2478
+ }
2479
+
2480
+ private async qmdHealth(
2481
+ searchBackend: string,
2482
+ qmdEnabled: boolean,
2483
+ namespace: string,
2484
+ collection: string,
2485
+ ): Promise<EngramAccessQmdHealthResponse> {
2486
+ if (searchBackend !== "qmd" || !qmdEnabled) {
2487
+ return {
2488
+ enabled: qmdEnabled,
2489
+ active: false,
2490
+ degraded: false,
2491
+ mode: searchBackend !== "qmd" ? "not-selected" : "disabled",
2492
+ collection,
2493
+ collectionState: "skipped",
2494
+ installedVersion: null,
2495
+ supportedVersion: null,
2496
+ supported: null,
2497
+ upgradeAvailable: null,
2498
+ doctorAvailable: null,
2499
+ debugStatus: searchBackend !== "qmd" ? `backend=${searchBackend}` : "backend=disabled",
2500
+ };
2501
+ }
2502
+
2503
+ if (this.orchestrator.config.namespacesEnabled === true) {
2504
+ const namespaceHealth = await this.namespaceQmdHealth(searchBackend, qmdEnabled, namespace, collection);
2505
+ if (namespaceHealth) return namespaceHealth;
2506
+ }
2507
+
2508
+ const qmd = this.orchestrator.qmd;
2509
+ if (!qmd) {
2510
+ return {
2511
+ enabled: true,
2512
+ active: false,
2513
+ degraded: true,
2514
+ mode: "fallback",
2515
+ collection,
2516
+ collectionState: "unknown",
2517
+ installedVersion: null,
2518
+ supportedVersion: null,
2519
+ supported: null,
2520
+ upgradeAvailable: null,
2521
+ doctorAvailable: null,
2522
+ debugStatus: "backend=unavailable",
2523
+ };
2524
+ }
2525
+ const diagnosticAvailable = await this.qmdProbeAvailable(searchBackend, qmdEnabled);
2526
+ const operationalAvailable = diagnosticAvailable || qmd.isAvailable();
2527
+ const collectionState = diagnosticAvailable
2528
+ ? await this.qmdCollectionState(searchBackend, qmdEnabled, collection)
2529
+ : "unknown";
2530
+ const active = operationalAvailable && collectionState !== "missing";
2531
+ const degraded =
2532
+ searchBackend === "qmd" &&
2533
+ qmdEnabled &&
2534
+ (!active || !diagnosticAvailable || collectionState === "unknown");
2535
+ const debugStatus = qmd.debugStatus();
2536
+ const versionStatus =
2537
+ "getVersionStatus" in qmd && typeof qmd.getVersionStatus === "function"
2538
+ ? qmd.getVersionStatus()
2539
+ : null;
2540
+ const daemonMode =
2541
+ "isDaemonMode" in qmd && typeof qmd.isDaemonMode === "function"
2542
+ ? qmd.isDaemonMode() === true
2543
+ : false;
2544
+ const mode =
2545
+ searchBackend !== "qmd"
2546
+ ? "not-selected"
2547
+ : !qmdEnabled
2548
+ ? "disabled"
2549
+ : !active
2550
+ ? "fallback"
2551
+ : daemonMode
2552
+ ? "daemon"
2553
+ : "cli";
2554
+
2555
+ return {
2556
+ enabled: qmdEnabled,
2557
+ active,
2558
+ degraded,
2559
+ mode,
2560
+ collection,
2561
+ collectionState,
2562
+ installedVersion: versionStatus?.installedVersion ?? null,
2563
+ supportedVersion: versionStatus?.supportedVersion ?? null,
2564
+ supported: versionStatus?.supported ?? null,
2565
+ upgradeAvailable: versionStatus?.upgradeAvailable ?? null,
2566
+ doctorAvailable: versionStatus?.capabilities?.doctor ?? null,
2567
+ debugStatus,
2568
+ };
2569
+ }
2570
+
2571
+ private async namespaceQmdHealth(
2572
+ searchBackend: string,
2573
+ qmdEnabled: boolean,
2574
+ namespace: string,
2575
+ fallbackCollection: string,
2576
+ ): Promise<EngramAccessQmdHealthResponse | null> {
2577
+ if (searchBackend !== "qmd" || !qmdEnabled) return null;
2578
+ const searchHealthForNamespace = (
2579
+ this.orchestrator as Orchestrator & {
2580
+ searchHealthForNamespace?: (
2581
+ namespace: string,
2582
+ execution?: { signal?: AbortSignal },
2583
+ ) => Promise<{
2584
+ collection: string;
2585
+ available: boolean;
2586
+ collectionState: EngramAccessQmdCollectionState;
2587
+ debugStatus: string;
2588
+ installedVersion: string | null;
2589
+ supportedVersion: string | null;
2590
+ supported: boolean | null;
2591
+ upgradeAvailable: boolean | null;
2592
+ doctorAvailable: boolean | null;
2593
+ daemonMode: boolean | null;
2594
+ }>;
2595
+ }
2596
+ ).searchHealthForNamespace;
2597
+ if (typeof searchHealthForNamespace !== "function") return null;
2598
+
2599
+ const controller = new AbortController();
2600
+ const timer = setTimeout(() => controller.abort(), 2_000);
2601
+ timer.unref?.();
2602
+ try {
2603
+ const health = await searchHealthForNamespace.call(this.orchestrator, namespace, {
2604
+ signal: controller.signal,
2605
+ });
2606
+ const active = health.available && health.collectionState !== "missing";
2607
+ const degraded = !active || health.collectionState === "unknown";
2608
+ const mode =
2609
+ !active
2610
+ ? "fallback"
2611
+ : health.daemonMode === true
2612
+ ? "daemon"
2613
+ : "cli";
2614
+
2615
+ return {
2616
+ enabled: true,
2617
+ active,
2618
+ degraded,
2619
+ mode,
2620
+ collection: health.collection || fallbackCollection,
2621
+ collectionState: health.collectionState,
2622
+ installedVersion: health.installedVersion,
2623
+ supportedVersion: health.supportedVersion,
2624
+ supported: health.supported,
2625
+ upgradeAvailable: health.upgradeAvailable,
2626
+ doctorAvailable: health.doctorAvailable,
2627
+ debugStatus: health.debugStatus,
2628
+ };
2629
+ } catch (error) {
2630
+ const detail = displayErrorDetail(error) || "unknown";
2631
+ return {
2632
+ enabled: true,
2633
+ active: false,
2634
+ degraded: true,
2635
+ mode: "fallback",
2636
+ collection: fallbackCollection,
2637
+ collectionState: "unknown",
2638
+ installedVersion: null,
2639
+ supportedVersion: null,
2640
+ supported: null,
2641
+ upgradeAvailable: null,
2642
+ doctorAvailable: null,
2643
+ debugStatus: `backend=namespace-unavailable error=${detail}`,
2644
+ };
2645
+ } finally {
2646
+ clearTimeout(timer);
2647
+ }
2648
+ }
2649
+
2650
+ private async qmdCollectionState(
2651
+ searchBackend: string,
2652
+ qmdEnabled: boolean,
2653
+ collection: string,
2654
+ ): Promise<EngramAccessQmdCollectionState> {
2655
+ if (searchBackend !== "qmd" || !qmdEnabled) return "skipped";
2656
+ const qmd = this.orchestrator.qmd;
2657
+ if (!qmd.isAvailable()) return "unknown";
2658
+ if (!qmd.checkCollection) return "skipped";
2659
+
2660
+ const controller = new AbortController();
2661
+ const timer = setTimeout(() => controller.abort(), 2_000);
2662
+ timer.unref?.();
2663
+ try {
2664
+ return await qmd.checkCollection(collection, {
2665
+ signal: controller.signal,
2666
+ });
2667
+ } catch {
2668
+ return "unknown";
2669
+ } finally {
2670
+ clearTimeout(timer);
2671
+ }
2672
+ }
2673
+
2674
+ private async qmdProbeAvailable(
2675
+ searchBackend: string,
2676
+ qmdEnabled: boolean,
2677
+ ): Promise<boolean> {
2678
+ if (searchBackend !== "qmd" || !qmdEnabled) return false;
2679
+ const qmd = this.orchestrator.qmd;
2680
+ if (!qmd) return false;
2681
+
2682
+ const controller = new AbortController();
2683
+ const timer = setTimeout(() => controller.abort(), 2_000);
2684
+ timer.unref?.();
2685
+ try {
2686
+ return await new Promise<boolean>((resolve) => {
2687
+ const onAbort = () => {
2688
+ controller.signal.removeEventListener("abort", onAbort);
2689
+ resolve(false);
2690
+ };
2691
+ controller.signal.addEventListener("abort", onAbort, { once: true });
2692
+ const probe =
2693
+ typeof qmd.checkAvailability === "function"
2694
+ ? qmd.checkAvailability({ signal: controller.signal })
2695
+ : qmd.probe();
2696
+ probe
2697
+ .then(resolve, () => resolve(false))
2698
+ .finally(() => {
2699
+ controller.signal.removeEventListener("abort", onAbort);
2700
+ });
2701
+ });
2702
+ } finally {
2703
+ clearTimeout(timer);
2704
+ }
2705
+ }
2706
+
2435
2707
  async actionConfidence(
2436
2708
  request: EngramAccessActionConfidenceRequest = {},
2437
2709
  ): Promise<EngramAccessActionConfidenceResponse> {