@edihasaj/recall 1.4.0 → 1.4.14

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 (86) hide show
  1. package/README.md +17 -7
  2. package/dist/{chunk-EAFRT7RX.js → chunk-22KM2YEO.js} +7 -2
  3. package/dist/{chunk-EAFRT7RX.js.map → chunk-22KM2YEO.js.map} +1 -1
  4. package/dist/{chunk-PUMEMKGF.js → chunk-47CB7PKL.js} +7 -1
  5. package/dist/{chunk-PUMEMKGF.js.map → chunk-47CB7PKL.js.map} +1 -1
  6. package/dist/{chunk-FHEH6QDU.js → chunk-7Z3CCCS2.js} +6 -1
  7. package/dist/{chunk-FHEH6QDU.js.map → chunk-7Z3CCCS2.js.map} +1 -1
  8. package/dist/chunk-AQOI4FCW.js +23 -0
  9. package/dist/chunk-AQOI4FCW.js.map +1 -0
  10. package/dist/{chunk-JKWK73GY.js → chunk-BWKFROGW.js} +101 -11
  11. package/dist/chunk-BWKFROGW.js.map +1 -0
  12. package/dist/{chunk-JYWURG5T.js → chunk-CYAODQOH.js} +12 -2
  13. package/dist/chunk-CYAODQOH.js.map +1 -0
  14. package/dist/{chunk-UWERS646.js → chunk-DJNJQA7L.js} +8 -4
  15. package/dist/{chunk-UWERS646.js.map → chunk-DJNJQA7L.js.map} +1 -1
  16. package/dist/{chunk-6QFOCUEJ.js → chunk-GGUWKT6I.js} +111 -21
  17. package/dist/chunk-GGUWKT6I.js.map +1 -0
  18. package/dist/{chunk-JO5LRCA2.js → chunk-HFHNPOBW.js} +207 -24
  19. package/dist/chunk-HFHNPOBW.js.map +1 -0
  20. package/dist/{chunk-JSTZKFZR.js → chunk-HRUNR5JJ.js} +14 -9
  21. package/dist/{chunk-JSTZKFZR.js.map → chunk-HRUNR5JJ.js.map} +1 -1
  22. package/dist/{chunk-65XK27KK.js → chunk-HUMJTWWT.js} +81 -161
  23. package/dist/chunk-HUMJTWWT.js.map +1 -0
  24. package/dist/{chunk-53GKSF42.js → chunk-JFUMA4WV.js} +308 -169
  25. package/dist/chunk-JFUMA4WV.js.map +1 -0
  26. package/dist/{chunk-MMYLXICL.js → chunk-KOBZIF2X.js} +8 -4
  27. package/dist/{chunk-MMYLXICL.js.map → chunk-KOBZIF2X.js.map} +1 -1
  28. package/dist/{chunk-7Q5CBVUT.js → chunk-M3ASNCVM.js} +234 -49
  29. package/dist/chunk-M3ASNCVM.js.map +1 -0
  30. package/dist/chunk-Q2KCBLJO.js +594 -0
  31. package/dist/chunk-Q2KCBLJO.js.map +1 -0
  32. package/dist/{chunk-CW3XJDH7.js → chunk-RWEX4VJE.js} +6 -2
  33. package/dist/{chunk-CW3XJDH7.js.map → chunk-RWEX4VJE.js.map} +1 -1
  34. package/dist/{chunk-LUIYWYOT.js → chunk-VSEAVK7X.js} +51 -3
  35. package/dist/chunk-VSEAVK7X.js.map +1 -0
  36. package/dist/{chunk-WZWXYBP6.js → chunk-XCFTE74H.js} +6 -3
  37. package/dist/{chunk-WZWXYBP6.js.map → chunk-XCFTE74H.js.map} +1 -1
  38. package/dist/{cleanup-RHNBHBNP.js → cleanup-YCYA6BJB.js} +11 -10
  39. package/dist/cli.js +648 -793
  40. package/dist/cli.js.map +1 -1
  41. package/dist/codex-trust-Z7LNNRVT.js +74 -0
  42. package/dist/codex-trust-Z7LNNRVT.js.map +1 -0
  43. package/dist/daemon.js +181 -61
  44. package/dist/daemon.js.map +1 -1
  45. package/dist/dispatcher-FP3WS74F.js +22 -0
  46. package/dist/{embeddings-HDNAGCOS.js → embeddings-VZPCFCEY.js} +7 -5
  47. package/dist/ingest-QEKMNVL7.js +20 -0
  48. package/dist/{keychain-5KXUHKMF.js → keychain-2PXI2EGF.js} +3 -3
  49. package/dist/mcp.js +18 -14
  50. package/dist/mcp.js.map +1 -1
  51. package/dist/{memory-value-6JUQEYJZ.js → memory-value-XSPRH6KY.js} +11 -10
  52. package/dist/provenance-GJR7S7VA.js +50 -0
  53. package/dist/provenance-GJR7S7VA.js.map +1 -0
  54. package/dist/quality-TWOC3UMF.js +25 -0
  55. package/dist/retrieval-RW6YBQ6P.js +15 -0
  56. package/dist/{store-5C7ZKKZF.js → store-HIM5US7B.js} +4 -4
  57. package/dist/sync-server.js +5 -2
  58. package/dist/sync-server.js.map +1 -1
  59. package/dist/{tasks-AJ62N26N.js → tasks-TAXJSUKB.js} +11 -10
  60. package/dist/{usage-VQ5LJCNH.js → usage-XMYRFJBJ.js} +7 -4
  61. package/dist/{usage-VQ5LJCNH.js.map → usage-XMYRFJBJ.js.map} +1 -1
  62. package/drizzle/0011_compact_telemetry_dedupe_keys.sql +25 -0
  63. package/drizzle/meta/_journal.json +7 -0
  64. package/package.json +15 -12
  65. package/dist/chunk-53GKSF42.js.map +0 -1
  66. package/dist/chunk-65XK27KK.js.map +0 -1
  67. package/dist/chunk-6QFOCUEJ.js.map +0 -1
  68. package/dist/chunk-7Q5CBVUT.js.map +0 -1
  69. package/dist/chunk-JKWK73GY.js.map +0 -1
  70. package/dist/chunk-JO5LRCA2.js.map +0 -1
  71. package/dist/chunk-LUIYWYOT.js.map +0 -1
  72. package/dist/dispatcher-ON7LNX6X.js +0 -21
  73. package/dist/ingest-MHPMJPUA.js +0 -18
  74. package/dist/quality-HVTIOIXP.js +0 -24
  75. package/dist/retrieval-72EIHKRF.js +0 -13
  76. package/dist/tasks-AJ62N26N.js.map +0 -1
  77. /package/dist/{chunk-JYWURG5T.js.map → cleanup-YCYA6BJB.js.map} +0 -0
  78. /package/dist/{cleanup-RHNBHBNP.js.map → dispatcher-FP3WS74F.js.map} +0 -0
  79. /package/dist/{dispatcher-ON7LNX6X.js.map → embeddings-VZPCFCEY.js.map} +0 -0
  80. /package/dist/{embeddings-HDNAGCOS.js.map → ingest-QEKMNVL7.js.map} +0 -0
  81. /package/dist/{ingest-MHPMJPUA.js.map → keychain-2PXI2EGF.js.map} +0 -0
  82. /package/dist/{keychain-5KXUHKMF.js.map → memory-value-XSPRH6KY.js.map} +0 -0
  83. /package/dist/{memory-value-6JUQEYJZ.js.map → quality-TWOC3UMF.js.map} +0 -0
  84. /package/dist/{quality-HVTIOIXP.js.map → retrieval-RW6YBQ6P.js.map} +0 -0
  85. /package/dist/{retrieval-72EIHKRF.js.map → store-HIM5US7B.js.map} +0 -0
  86. /package/dist/{store-5C7ZKKZF.js.map → tasks-TAXJSUKB.js.map} +0 -0
package/README.md CHANGED
@@ -237,6 +237,8 @@ recall health -r owner/repo
237
237
  recall maintenance quality
238
238
  recall eval value-retrieval --snapshot
239
239
  recall maintenance quality --history
240
+ recall reliability
241
+ recall reliability --canary --real-embeddings
240
242
  recall compile -r owner/repo
241
243
  recall compile -r owner/repo --query "pytest -q" --include-candidates
242
244
  ```
@@ -261,26 +263,34 @@ RECALL_EMBEDDING_DIMS=384
261
263
  RECALL_EMBEDDINGS_DISABLED=true
262
264
  ```
263
265
 
264
- Upgrade note:
265
-
266
- - First launch after the local-embeddings upgrade resets Recall's local DB.
267
- - Recall rescans discovered repos and rebuilds embeddings/indexes in the background.
268
- - Recall.app now surfaces that setup progress while the daemon comes up.
266
+ Windows x64 and ARM64 support local vector retrieval. Native ARM64 uses a
267
+ bundled ARM64 extension; other platforms keep the existing sqlite-vec loader.
268
+ This update preserves existing databases. If the native extension is missing
269
+ or cannot load, Recall keeps lexical retrieval available and reports the
270
+ reason in `/health`. See [storage strategy](docs/storage-strategy.md).
269
271
 
270
272
  Daemon maintenance runs in-process on a timer.
271
273
 
272
274
  Useful env vars:
273
275
 
274
276
  ```bash
275
- RECALL_MAINTENANCE_INTERVAL_SECONDS=300
276
- RECALL_ACTIVITY_RETENTION_DAYS=90
277
+ RECALL_MAINTENANCE_INTERVAL_SECONDS=3600
278
+ RECALL_ACTIVITY_RETENTION_DAYS=30
277
279
  RECALL_FEEDBACK_RETENTION_DAYS=180
278
280
  RECALL_SIGNAL_RETENTION_DAYS=180
279
281
  RECALL_SQLITE_VACUUM_ENABLED=true
280
282
  RECALL_SQLITE_VACUUM_MIN_FREE_PAGES=100
281
283
  RECALL_SQLITE_VACUUM_MIN_FREE_RATIO=0.1
284
+ RECALL_CANDIDATE_UNCONFIRMED_DAYS=30
285
+ RECALL_RELIABILITY_PROBE_ENABLED=true
286
+ RECALL_RELIABILITY_PROBE_INTERVAL_SECONDS=86400
287
+ RECALL_RELIABILITY_PROBE_REAL_EMBEDDINGS=true
282
288
  ```
283
289
 
290
+ `recall reliability` separates compiler selection, hook emission, observed use,
291
+ and resolved outcomes. The daily probe checks the live database, newest backup,
292
+ and a disposable real-vector canary. See [Reliability and uncertainty](docs/reliability.md).
293
+
284
294
  Inspect rolled-up session history:
285
295
 
286
296
  ```bash
@@ -8,12 +8,17 @@ import {
8
8
  memoryEntities,
9
9
  or,
10
10
  sql
11
- } from "./chunk-LUIYWYOT.js";
11
+ } from "./chunk-VSEAVK7X.js";
12
+ import {
13
+ init_define_RECALL_BUILD_INFO
14
+ } from "./chunk-CYAODQOH.js";
12
15
 
13
16
  // src/graph/store.ts
17
+ init_define_RECALL_BUILD_INFO();
14
18
  import { randomUUID } from "crypto";
15
19
 
16
20
  // src/graph/normalize.ts
21
+ init_define_RECALL_BUILD_INFO();
17
22
  function normalizeName(kind, raw) {
18
23
  const trimmed = raw.trim();
19
24
  switch (kind) {
@@ -285,4 +290,4 @@ export {
285
290
  countRelations,
286
291
  clearGraph
287
292
  };
288
- //# sourceMappingURL=chunk-EAFRT7RX.js.map
293
+ //# sourceMappingURL=chunk-22KM2YEO.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/graph/store.ts","../src/graph/normalize.ts"],"sourcesContent":["/**\n * Read/write layer for the knowledge graph tables. Pure DB operations —\n * no LLM calls, no business logic — so they're safe to call from any\n * code path (capture hook, dispatcher, scan, MCP tool).\n */\nimport { randomUUID } from \"node:crypto\";\nimport { and, eq, inArray, like, or, sql } from \"drizzle-orm\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { entities, entityRelations, memoryEntities } from \"../db/schema.js\";\nimport { normalizeName, type EntityKind } from \"./normalize.js\";\n\nexport type RelationType =\n | \"uses\"\n | \"replaces\"\n | \"conflicts_with\"\n | \"tested_by\"\n | \"depends_on\"\n | \"references\"\n | \"part_of\";\n\nexport interface EntityRow {\n id: string;\n kind: EntityKind;\n name: string;\n normalized_name: string;\n repo: string | null;\n description: string | null;\n mention_count: number;\n first_seen_memory_id: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface EntityRelationRow {\n id: string;\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id: string | null;\n confidence: number;\n created_at: string;\n}\n\nexport interface UpsertEntityInput {\n kind: EntityKind;\n name: string;\n repo?: string | null;\n description?: string | null;\n first_seen_memory_id?: string | null;\n}\n\n/**\n * Insert or look up an entity by (kind, normalized_name, repo). Returns the\n * canonical row. Increments mention_count on every call so we can rank\n * entities by how often the codebase mentions them.\n */\nexport function upsertEntity(db: RecallDb, input: UpsertEntityInput): EntityRow {\n const normalized = normalizeName(input.kind, input.name);\n const repo = input.repo ?? null;\n const now = new Date().toISOString();\n\n const existing = findEntityByNormalized(db, input.kind, normalized, repo);\n if (existing) {\n db.update(entities)\n .set({\n mention_count: existing.mention_count + 1,\n updated_at: now,\n // Backfill description / first_seen if not previously set.\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n })\n .where(eq(entities.id, existing.id))\n .run();\n return {\n ...existing,\n mention_count: existing.mention_count + 1,\n updated_at: now,\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n };\n }\n\n const id = randomUUID();\n db.insert(entities)\n .values({\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n mention_count: 1,\n created_at: now,\n updated_at: now,\n })\n .run();\n return {\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n mention_count: 1,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n created_at: now,\n updated_at: now,\n };\n}\n\nexport function findEntityByNormalized(\n db: RecallDb,\n kind: EntityKind,\n normalized: string,\n repo: string | null,\n): EntityRow | null {\n const row = db\n .select()\n .from(entities)\n .where(\n and(\n eq(entities.kind, kind),\n eq(entities.normalized_name, normalized),\n repo === null\n ? sql`${entities.repo} IS NULL`\n : eq(entities.repo, repo),\n ),\n )\n .get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport function getEntity(db: RecallDb, id: string): EntityRow | null {\n const row = db.select().from(entities).where(eq(entities.id, id)).get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport interface ListEntitiesOptions {\n repo?: string;\n kind?: EntityKind;\n search?: string;\n limit?: number;\n offset?: number;\n}\n\nexport function listEntities(db: RecallDb, opts: ListEntitiesOptions = {}): EntityRow[] {\n const conditions = [] as Array<ReturnType<typeof eq> | ReturnType<typeof or>>;\n if (opts.repo) conditions.push(eq(entities.repo, opts.repo));\n if (opts.kind) conditions.push(eq(entities.kind, opts.kind));\n if (opts.search) {\n // Push the contains-match into SQL so LIMIT applies post-filter; the\n // previous in-memory filter only saw the top-N by mention_count and\n // missed long-tail matches entirely.\n const needle = `%${opts.search.toLowerCase()}%`;\n conditions.push(\n or(\n like(entities.normalized_name, needle),\n like(sql`lower(${entities.name})`, needle),\n )!,\n );\n }\n const where = conditions.length === 1 ? conditions[0] : conditions.length > 1 ? and(...conditions) : undefined;\n const builder = where\n ? db.select().from(entities).where(where)\n : db.select().from(entities);\n return builder\n .orderBy(sql`${entities.mention_count} DESC`)\n .limit(opts.limit ?? 200)\n .offset(opts.offset ?? 0)\n .all() as EntityRow[];\n}\n\nexport interface LinkMemoryEntityInput {\n memory_id: string;\n entity_id: string;\n source: \"heuristic\" | \"llm\" | \"manual\";\n weight?: number;\n}\n\n/** Idempotent: links a memory to an entity, no-op if the edge already exists. */\nexport function linkMemoryToEntity(db: RecallDb, input: LinkMemoryEntityInput): void {\n const existing = db\n .select({ id: memoryEntities.id })\n .from(memoryEntities)\n .where(\n and(\n eq(memoryEntities.memory_id, input.memory_id),\n eq(memoryEntities.entity_id, input.entity_id),\n ),\n )\n .get();\n if (existing) return;\n db.insert(memoryEntities)\n .values({\n id: randomUUID(),\n memory_id: input.memory_id,\n entity_id: input.entity_id,\n source: input.source,\n weight: input.weight ?? 1,\n created_at: new Date().toISOString(),\n })\n .run();\n}\n\nexport function listEntitiesForMemory(db: RecallDb, memoryId: string): EntityRow[] {\n return db\n .select({\n id: entities.id,\n kind: entities.kind,\n name: entities.name,\n normalized_name: entities.normalized_name,\n repo: entities.repo,\n description: entities.description,\n mention_count: entities.mention_count,\n first_seen_memory_id: entities.first_seen_memory_id,\n created_at: entities.created_at,\n updated_at: entities.updated_at,\n })\n .from(memoryEntities)\n .innerJoin(entities, eq(entities.id, memoryEntities.entity_id))\n .where(eq(memoryEntities.memory_id, memoryId))\n .all() as EntityRow[];\n}\n\nexport function listMemoryIdsForEntity(db: RecallDb, entityId: string): string[] {\n const rows = db\n .select({ memory_id: memoryEntities.memory_id })\n .from(memoryEntities)\n .where(eq(memoryEntities.entity_id, entityId))\n .all();\n return rows.map((r) => r.memory_id);\n}\n\nexport interface UpsertRelationInput {\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id?: string | null;\n confidence?: number;\n}\n\n/** Idempotent on (source, target, relation_type, source_memory_id). */\nexport function upsertRelation(db: RecallDb, input: UpsertRelationInput): EntityRelationRow {\n const sourceMem = input.source_memory_id ?? null;\n const existing = db\n .select()\n .from(entityRelations)\n .where(\n and(\n eq(entityRelations.source_entity_id, input.source_entity_id),\n eq(entityRelations.target_entity_id, input.target_entity_id),\n eq(entityRelations.relation_type, input.relation_type),\n sourceMem === null\n ? sql`${entityRelations.source_memory_id} IS NULL`\n : eq(entityRelations.source_memory_id, sourceMem),\n ),\n )\n .get() as EntityRelationRow | undefined;\n if (existing) {\n if (input.confidence !== undefined && input.confidence > existing.confidence) {\n db.update(entityRelations)\n .set({ confidence: input.confidence })\n .where(eq(entityRelations.id, existing.id))\n .run();\n return { ...existing, confidence: input.confidence };\n }\n return existing;\n }\n const id = randomUUID();\n const now = new Date().toISOString();\n db.insert(entityRelations)\n .values({\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n })\n .run();\n return {\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n };\n}\n\nexport function neighborsOf(\n db: RecallDb,\n entityId: string,\n options: { hops?: number; relationTypes?: RelationType[] } = {},\n): { entities: EntityRow[]; relations: EntityRelationRow[] } {\n const maxHops = Math.max(1, Math.min(5, options.hops ?? 1));\n const visited = new Set<string>([entityId]);\n let frontier = [entityId];\n const collectedRelations = new Map<string, EntityRelationRow>();\n\n for (let hop = 0; hop < maxHops; hop++) {\n if (frontier.length === 0) break;\n const next: string[] = [];\n const relationFilter = options.relationTypes;\n const outgoing = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.source_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.source_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n const incoming = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.target_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.target_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n\n for (const rel of [...outgoing, ...incoming]) {\n collectedRelations.set(rel.id, rel);\n for (const candidate of [rel.source_entity_id, rel.target_entity_id]) {\n if (!visited.has(candidate)) {\n visited.add(candidate);\n next.push(candidate);\n }\n }\n }\n frontier = next;\n }\n\n const entityRows = visited.size === 0\n ? []\n : (db\n .select()\n .from(entities)\n .where(inArray(entities.id, Array.from(visited)))\n .all() as EntityRow[]);\n\n return {\n entities: entityRows,\n relations: Array.from(collectedRelations.values()),\n };\n}\n\n/**\n * List every relation in the graph, optionally restricted to relations\n * whose source AND target entities both belong to the given repo. Used by\n * the WebUI to render the whole graph at once (no seed required).\n */\nexport function listAllRelations(\n db: RecallDb,\n opts: { repo?: string; limit?: number } = {},\n): EntityRelationRow[] {\n const limit = Math.min(Math.max(opts.limit ?? 2000, 1), 10_000);\n if (!opts.repo) {\n return db\n .select()\n .from(entityRelations)\n .limit(limit)\n .all() as EntityRelationRow[];\n }\n // Filter both endpoints to entities in the repo. Two-step: collect ids,\n // then pick relations whose endpoints are both inside that set.\n const repoEntityIds = db\n .select({ id: entities.id })\n .from(entities)\n .where(eq(entities.repo, opts.repo))\n .all()\n .map((r) => r.id);\n if (repoEntityIds.length === 0) return [];\n const idSet = new Set(repoEntityIds);\n const all = db\n .select()\n .from(entityRelations)\n .where(\n and(\n inArray(entityRelations.source_entity_id, repoEntityIds),\n inArray(entityRelations.target_entity_id, repoEntityIds),\n ),\n )\n .limit(limit)\n .all() as EntityRelationRow[];\n return all.filter(\n (r) => idSet.has(r.source_entity_id) && idSet.has(r.target_entity_id),\n );\n}\n\nexport function countEntities(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entities)\n .get();\n return Number(row?.c ?? 0);\n}\n\nexport function countRelations(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entityRelations)\n .get();\n return Number(row?.c ?? 0);\n}\n\n/**\n * Wipe all graph state (entities, relations, and memory→entity links). Used\n * by `graph backfill --rebuild` to regenerate the graph from scratch under\n * the current extraction rules, dropping entities that older/looser rules\n * produced (e.g. generic `pnpm build` command nodes).\n */\nexport function clearGraph(db: RecallDb): void {\n db.delete(memoryEntities).run();\n db.delete(entityRelations).run();\n db.delete(entities).run();\n}\n","/**\n * Canonical-form helpers for entity dedup. Two entities with the same\n * (kind, normalizedName, repo) collapse into one node.\n *\n * Normalization rules are conservative on purpose — we'd rather have a\n * duplicate than merge two semantically distinct things. Aggressive\n * merging belongs in a maintenance pass that can be reviewed.\n */\n\nexport type EntityKind =\n | \"file\"\n | \"function\"\n | \"library\"\n | \"tool\"\n | \"concept\"\n | \"repo_path\"\n | \"command\"\n | \"url\";\n\nexport function normalizeName(kind: EntityKind, raw: string): string {\n const trimmed = raw.trim();\n switch (kind) {\n case \"file\":\n case \"repo_path\":\n // Posix-style paths, no leading slash, no trailing slash.\n return trimmed\n .replace(/\\\\/g, \"/\")\n .replace(/^[./]+/, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n case \"function\":\n // foo() / Class.method / obj.method — keep the dotted form, drop parens/args.\n return trimmed\n .replace(/\\(.*\\)/, \"\")\n .replace(/\\s+/g, \"\")\n .toLowerCase();\n case \"library\":\n case \"tool\":\n case \"command\":\n // package names / CLI names: lowercase, strip @scope leading-only if present\n // but keep `@scope/name` distinct from `name`.\n return trimmed.toLowerCase();\n case \"url\":\n try {\n const u = new URL(trimmed);\n return `${u.hostname.toLowerCase()}${u.pathname.replace(/\\/+$/, \"\")}`;\n } catch {\n return trimmed.toLowerCase();\n }\n case \"concept\":\n default:\n return trimmed.toLowerCase().replace(/\\s+/g, \" \");\n }\n}\n\nexport function isPlausibleEntityName(kind: EntityKind, name: string): boolean {\n const n = name.trim();\n if (n.length === 0 || n.length > 200) return false;\n // Filter common false positives that look like identifiers but aren't.\n if (/^[0-9]+$/.test(n)) return false;\n if (kind === \"concept\" && n.split(/\\s+/).length > 8) return false;\n // Single-letter \"library\" tokens are almost always noise.\n if ((kind === \"library\" || kind === \"tool\") && n.length < 2) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;AAKA,SAAS,kBAAkB;;;ACcpB,SAAS,cAAc,MAAkB,KAAqB;AACnE,QAAM,UAAU,IAAI,KAAK;AACzB,UAAQ,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,IAAI,SAAS,GAAG,CAAC,EAC1B,KAAK,QAAQ,EACb,MAAM,GAAG,SAAS,MAAM,KAAK,IAAI,CAAC,EAClC,IAAI,EACJ,IAAI,CAAC,MAAM,EAAE,EAAE;AAClB,MAAI,cAAc,WAAW,EAAG,QAAO,CAAC;AACxC,QAAM,QAAQ,IAAI,IAAI,aAAa;AACnC,QAAM,MAAM,GACT,OAAO,EACP,KAAK,eAAe,EACpB;AAAA,IACC;AAAA,MACE,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,MACvD,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,IACzD;AAAA,EACF,EACC,MAAM,KAAK,EACX,IAAI;AACP,SAAO,IAAI;AAAA,IACT,CAAC,MAAM,MAAM,IAAI,EAAE,gBAAgB,KAAK,MAAM,IAAI,EAAE,gBAAgB;AAAA,EACtE;AACF;AAEO,SAAS,cAAc,IAAsB;AAClD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,QAAQ,EACb,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAEO,SAAS,eAAe,IAAsB;AACnD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,eAAe,EACpB,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAQO,SAAS,WAAW,IAAoB;AAC7C,KAAG,OAAO,cAAc,EAAE,IAAI;AAC9B,KAAG,OAAO,eAAe,EAAE,IAAI;AAC/B,KAAG,OAAO,QAAQ,EAAE,IAAI;AAC1B;","names":[]}
1
+ {"version":3,"sources":["../src/graph/store.ts","../src/graph/normalize.ts"],"sourcesContent":["/**\n * Read/write layer for the knowledge graph tables. Pure DB operations —\n * no LLM calls, no business logic — so they're safe to call from any\n * code path (capture hook, dispatcher, scan, MCP tool).\n */\nimport { randomUUID } from \"node:crypto\";\nimport { and, eq, inArray, like, or, sql } from \"drizzle-orm\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { entities, entityRelations, memoryEntities } from \"../db/schema.js\";\nimport { normalizeName, type EntityKind } from \"./normalize.js\";\n\nexport type RelationType =\n | \"uses\"\n | \"replaces\"\n | \"conflicts_with\"\n | \"tested_by\"\n | \"depends_on\"\n | \"references\"\n | \"part_of\";\n\nexport interface EntityRow {\n id: string;\n kind: EntityKind;\n name: string;\n normalized_name: string;\n repo: string | null;\n description: string | null;\n mention_count: number;\n first_seen_memory_id: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface EntityRelationRow {\n id: string;\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id: string | null;\n confidence: number;\n created_at: string;\n}\n\nexport interface UpsertEntityInput {\n kind: EntityKind;\n name: string;\n repo?: string | null;\n description?: string | null;\n first_seen_memory_id?: string | null;\n}\n\n/**\n * Insert or look up an entity by (kind, normalized_name, repo). Returns the\n * canonical row. Increments mention_count on every call so we can rank\n * entities by how often the codebase mentions them.\n */\nexport function upsertEntity(db: RecallDb, input: UpsertEntityInput): EntityRow {\n const normalized = normalizeName(input.kind, input.name);\n const repo = input.repo ?? null;\n const now = new Date().toISOString();\n\n const existing = findEntityByNormalized(db, input.kind, normalized, repo);\n if (existing) {\n db.update(entities)\n .set({\n mention_count: existing.mention_count + 1,\n updated_at: now,\n // Backfill description / first_seen if not previously set.\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n })\n .where(eq(entities.id, existing.id))\n .run();\n return {\n ...existing,\n mention_count: existing.mention_count + 1,\n updated_at: now,\n description: existing.description ?? input.description ?? null,\n first_seen_memory_id: existing.first_seen_memory_id ?? input.first_seen_memory_id ?? null,\n };\n }\n\n const id = randomUUID();\n db.insert(entities)\n .values({\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n mention_count: 1,\n created_at: now,\n updated_at: now,\n })\n .run();\n return {\n id,\n kind: input.kind,\n name: input.name.trim(),\n normalized_name: normalized,\n repo,\n description: input.description ?? null,\n mention_count: 1,\n first_seen_memory_id: input.first_seen_memory_id ?? null,\n created_at: now,\n updated_at: now,\n };\n}\n\nexport function findEntityByNormalized(\n db: RecallDb,\n kind: EntityKind,\n normalized: string,\n repo: string | null,\n): EntityRow | null {\n const row = db\n .select()\n .from(entities)\n .where(\n and(\n eq(entities.kind, kind),\n eq(entities.normalized_name, normalized),\n repo === null\n ? sql`${entities.repo} IS NULL`\n : eq(entities.repo, repo),\n ),\n )\n .get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport function getEntity(db: RecallDb, id: string): EntityRow | null {\n const row = db.select().from(entities).where(eq(entities.id, id)).get();\n return (row as EntityRow | undefined) ?? null;\n}\n\nexport interface ListEntitiesOptions {\n repo?: string;\n kind?: EntityKind;\n search?: string;\n limit?: number;\n offset?: number;\n}\n\nexport function listEntities(db: RecallDb, opts: ListEntitiesOptions = {}): EntityRow[] {\n const conditions = [] as Array<ReturnType<typeof eq> | ReturnType<typeof or>>;\n if (opts.repo) conditions.push(eq(entities.repo, opts.repo));\n if (opts.kind) conditions.push(eq(entities.kind, opts.kind));\n if (opts.search) {\n // Push the contains-match into SQL so LIMIT applies post-filter; the\n // previous in-memory filter only saw the top-N by mention_count and\n // missed long-tail matches entirely.\n const needle = `%${opts.search.toLowerCase()}%`;\n conditions.push(\n or(\n like(entities.normalized_name, needle),\n like(sql`lower(${entities.name})`, needle),\n )!,\n );\n }\n const where = conditions.length === 1 ? conditions[0] : conditions.length > 1 ? and(...conditions) : undefined;\n const builder = where\n ? db.select().from(entities).where(where)\n : db.select().from(entities);\n return builder\n .orderBy(sql`${entities.mention_count} DESC`)\n .limit(opts.limit ?? 200)\n .offset(opts.offset ?? 0)\n .all() as EntityRow[];\n}\n\nexport interface LinkMemoryEntityInput {\n memory_id: string;\n entity_id: string;\n source: \"heuristic\" | \"llm\" | \"manual\";\n weight?: number;\n}\n\n/** Idempotent: links a memory to an entity, no-op if the edge already exists. */\nexport function linkMemoryToEntity(db: RecallDb, input: LinkMemoryEntityInput): void {\n const existing = db\n .select({ id: memoryEntities.id })\n .from(memoryEntities)\n .where(\n and(\n eq(memoryEntities.memory_id, input.memory_id),\n eq(memoryEntities.entity_id, input.entity_id),\n ),\n )\n .get();\n if (existing) return;\n db.insert(memoryEntities)\n .values({\n id: randomUUID(),\n memory_id: input.memory_id,\n entity_id: input.entity_id,\n source: input.source,\n weight: input.weight ?? 1,\n created_at: new Date().toISOString(),\n })\n .run();\n}\n\nexport function listEntitiesForMemory(db: RecallDb, memoryId: string): EntityRow[] {\n return db\n .select({\n id: entities.id,\n kind: entities.kind,\n name: entities.name,\n normalized_name: entities.normalized_name,\n repo: entities.repo,\n description: entities.description,\n mention_count: entities.mention_count,\n first_seen_memory_id: entities.first_seen_memory_id,\n created_at: entities.created_at,\n updated_at: entities.updated_at,\n })\n .from(memoryEntities)\n .innerJoin(entities, eq(entities.id, memoryEntities.entity_id))\n .where(eq(memoryEntities.memory_id, memoryId))\n .all() as EntityRow[];\n}\n\nexport function listMemoryIdsForEntity(db: RecallDb, entityId: string): string[] {\n const rows = db\n .select({ memory_id: memoryEntities.memory_id })\n .from(memoryEntities)\n .where(eq(memoryEntities.entity_id, entityId))\n .all();\n return rows.map((r) => r.memory_id);\n}\n\nexport interface UpsertRelationInput {\n source_entity_id: string;\n target_entity_id: string;\n relation_type: RelationType;\n source_memory_id?: string | null;\n confidence?: number;\n}\n\n/** Idempotent on (source, target, relation_type, source_memory_id). */\nexport function upsertRelation(db: RecallDb, input: UpsertRelationInput): EntityRelationRow {\n const sourceMem = input.source_memory_id ?? null;\n const existing = db\n .select()\n .from(entityRelations)\n .where(\n and(\n eq(entityRelations.source_entity_id, input.source_entity_id),\n eq(entityRelations.target_entity_id, input.target_entity_id),\n eq(entityRelations.relation_type, input.relation_type),\n sourceMem === null\n ? sql`${entityRelations.source_memory_id} IS NULL`\n : eq(entityRelations.source_memory_id, sourceMem),\n ),\n )\n .get() as EntityRelationRow | undefined;\n if (existing) {\n if (input.confidence !== undefined && input.confidence > existing.confidence) {\n db.update(entityRelations)\n .set({ confidence: input.confidence })\n .where(eq(entityRelations.id, existing.id))\n .run();\n return { ...existing, confidence: input.confidence };\n }\n return existing;\n }\n const id = randomUUID();\n const now = new Date().toISOString();\n db.insert(entityRelations)\n .values({\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n })\n .run();\n return {\n id,\n source_entity_id: input.source_entity_id,\n target_entity_id: input.target_entity_id,\n relation_type: input.relation_type,\n source_memory_id: sourceMem,\n confidence: input.confidence ?? 0.6,\n created_at: now,\n };\n}\n\nexport function neighborsOf(\n db: RecallDb,\n entityId: string,\n options: { hops?: number; relationTypes?: RelationType[] } = {},\n): { entities: EntityRow[]; relations: EntityRelationRow[] } {\n const maxHops = Math.max(1, Math.min(5, options.hops ?? 1));\n const visited = new Set<string>([entityId]);\n let frontier = [entityId];\n const collectedRelations = new Map<string, EntityRelationRow>();\n\n for (let hop = 0; hop < maxHops; hop++) {\n if (frontier.length === 0) break;\n const next: string[] = [];\n const relationFilter = options.relationTypes;\n const outgoing = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.source_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.source_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n const incoming = db\n .select()\n .from(entityRelations)\n .where(\n relationFilter && relationFilter.length > 0\n ? and(\n inArray(entityRelations.target_entity_id, frontier),\n inArray(entityRelations.relation_type, relationFilter),\n )\n : inArray(entityRelations.target_entity_id, frontier),\n )\n .all() as EntityRelationRow[];\n\n for (const rel of [...outgoing, ...incoming]) {\n collectedRelations.set(rel.id, rel);\n for (const candidate of [rel.source_entity_id, rel.target_entity_id]) {\n if (!visited.has(candidate)) {\n visited.add(candidate);\n next.push(candidate);\n }\n }\n }\n frontier = next;\n }\n\n const entityRows = visited.size === 0\n ? []\n : (db\n .select()\n .from(entities)\n .where(inArray(entities.id, Array.from(visited)))\n .all() as EntityRow[]);\n\n return {\n entities: entityRows,\n relations: Array.from(collectedRelations.values()),\n };\n}\n\n/**\n * List every relation in the graph, optionally restricted to relations\n * whose source AND target entities both belong to the given repo. Used by\n * the WebUI to render the whole graph at once (no seed required).\n */\nexport function listAllRelations(\n db: RecallDb,\n opts: { repo?: string; limit?: number } = {},\n): EntityRelationRow[] {\n const limit = Math.min(Math.max(opts.limit ?? 2000, 1), 10_000);\n if (!opts.repo) {\n return db\n .select()\n .from(entityRelations)\n .limit(limit)\n .all() as EntityRelationRow[];\n }\n // Filter both endpoints to entities in the repo. Two-step: collect ids,\n // then pick relations whose endpoints are both inside that set.\n const repoEntityIds = db\n .select({ id: entities.id })\n .from(entities)\n .where(eq(entities.repo, opts.repo))\n .all()\n .map((r) => r.id);\n if (repoEntityIds.length === 0) return [];\n const idSet = new Set(repoEntityIds);\n const all = db\n .select()\n .from(entityRelations)\n .where(\n and(\n inArray(entityRelations.source_entity_id, repoEntityIds),\n inArray(entityRelations.target_entity_id, repoEntityIds),\n ),\n )\n .limit(limit)\n .all() as EntityRelationRow[];\n return all.filter(\n (r) => idSet.has(r.source_entity_id) && idSet.has(r.target_entity_id),\n );\n}\n\nexport function countEntities(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entities)\n .get();\n return Number(row?.c ?? 0);\n}\n\nexport function countRelations(db: RecallDb): number {\n const row = db\n .select({ c: sql<number>`count(*)` })\n .from(entityRelations)\n .get();\n return Number(row?.c ?? 0);\n}\n\n/**\n * Wipe all graph state (entities, relations, and memory→entity links). Used\n * by `graph backfill --rebuild` to regenerate the graph from scratch under\n * the current extraction rules, dropping entities that older/looser rules\n * produced (e.g. generic `pnpm build` command nodes).\n */\nexport function clearGraph(db: RecallDb): void {\n db.delete(memoryEntities).run();\n db.delete(entityRelations).run();\n db.delete(entities).run();\n}\n","/**\n * Canonical-form helpers for entity dedup. Two entities with the same\n * (kind, normalizedName, repo) collapse into one node.\n *\n * Normalization rules are conservative on purpose — we'd rather have a\n * duplicate than merge two semantically distinct things. Aggressive\n * merging belongs in a maintenance pass that can be reviewed.\n */\n\nexport type EntityKind =\n | \"file\"\n | \"function\"\n | \"library\"\n | \"tool\"\n | \"concept\"\n | \"repo_path\"\n | \"command\"\n | \"url\";\n\nexport function normalizeName(kind: EntityKind, raw: string): string {\n const trimmed = raw.trim();\n switch (kind) {\n case \"file\":\n case \"repo_path\":\n // Posix-style paths, no leading slash, no trailing slash.\n return trimmed\n .replace(/\\\\/g, \"/\")\n .replace(/^[./]+/, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n case \"function\":\n // foo() / Class.method / obj.method — keep the dotted form, drop parens/args.\n return trimmed\n .replace(/\\(.*\\)/, \"\")\n .replace(/\\s+/g, \"\")\n .toLowerCase();\n case \"library\":\n case \"tool\":\n case \"command\":\n // package names / CLI names: lowercase, strip @scope leading-only if present\n // but keep `@scope/name` distinct from `name`.\n return trimmed.toLowerCase();\n case \"url\":\n try {\n const u = new URL(trimmed);\n return `${u.hostname.toLowerCase()}${u.pathname.replace(/\\/+$/, \"\")}`;\n } catch {\n return trimmed.toLowerCase();\n }\n case \"concept\":\n default:\n return trimmed.toLowerCase().replace(/\\s+/g, \" \");\n }\n}\n\nexport function isPlausibleEntityName(kind: EntityKind, name: string): boolean {\n const n = name.trim();\n if (n.length === 0 || n.length > 200) return false;\n // Filter common false positives that look like identifiers but aren't.\n if (/^[0-9]+$/.test(n)) return false;\n if (kind === \"concept\" && n.split(/\\s+/).length > 8) return false;\n // Single-letter \"library\" tokens are almost always noise.\n if ((kind === \"library\" || kind === \"tool\") && n.length < 2) return false;\n return true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAKA,SAAS,kBAA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,KAAK,eAAe,EACpB,MAAM,KAAK,EACX,IAAI;AAAA,EACT;AAGA,QAAM,gBAAgB,GACnB,OAAO,EAAE,IAAI,SAAS,GAAG,CAAC,EAC1B,KAAK,QAAQ,EACb,MAAM,GAAG,SAAS,MAAM,KAAK,IAAI,CAAC,EAClC,IAAI,EACJ,IAAI,CAAC,MAAM,EAAE,EAAE;AAClB,MAAI,cAAc,WAAW,EAAG,QAAO,CAAC;AACxC,QAAM,QAAQ,IAAI,IAAI,aAAa;AACnC,QAAM,MAAM,GACT,OAAO,EACP,KAAK,eAAe,EACpB;AAAA,IACC;AAAA,MACE,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,MACvD,QAAQ,gBAAgB,kBAAkB,aAAa;AAAA,IACzD;AAAA,EACF,EACC,MAAM,KAAK,EACX,IAAI;AACP,SAAO,IAAI;AAAA,IACT,CAAC,MAAM,MAAM,IAAI,EAAE,gBAAgB,KAAK,MAAM,IAAI,EAAE,gBAAgB;AAAA,EACtE;AACF;AAEO,SAAS,cAAc,IAAsB;AAClD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,QAAQ,EACb,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAEO,SAAS,eAAe,IAAsB;AACnD,QAAM,MAAM,GACT,OAAO,EAAE,GAAG,cAAsB,CAAC,EACnC,KAAK,eAAe,EACpB,IAAI;AACP,SAAO,OAAO,KAAK,KAAK,CAAC;AAC3B;AAQO,SAAS,WAAW,IAAoB;AAC7C,KAAG,OAAO,cAAc,EAAE,IAAI;AAC9B,KAAG,OAAO,eAAe,EAAE,IAAI;AAC/B,KAAG,OAAO,QAAQ,EAAE,IAAI;AAC1B;","names":[]}
@@ -1,4 +1,9 @@
1
+ import {
2
+ init_define_RECALL_BUILD_INFO
3
+ } from "./chunk-CYAODQOH.js";
4
+
1
5
  // src/observability/sentry.ts
6
+ init_define_RECALL_BUILD_INFO();
2
7
  import * as Sentry from "@sentry/node";
3
8
  var initialized = false;
4
9
  function initSentry() {
@@ -21,9 +26,10 @@ function initSentry() {
21
26
  }
22
27
 
23
28
  // src/observability/instrument.ts
29
+ init_define_RECALL_BUILD_INFO();
24
30
  initSentry();
25
31
 
26
32
  export {
27
33
  Sentry
28
34
  };
29
- //# sourceMappingURL=chunk-PUMEMKGF.js.map
35
+ //# sourceMappingURL=chunk-47CB7PKL.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/observability/sentry.ts","../src/observability/instrument.ts"],"sourcesContent":["/**\n * Optional, opt-in Sentry error reporting.\n *\n * Errors and crashes only — no performance tracing, no profiling, no session\n * replay, no default PII. The DSN comes exclusively from the `SENTRY_DSN`\n * environment variable; when it is empty or unset, {@link initSentry} is a hard\n * no-op and `Sentry.init` is never called, so the SDK sends nothing off-box.\n *\n * Recall is public OSS: community installs never phone home unless the operator\n * explicitly sets `SENTRY_DSN`. The DSN is intentionally NOT baked into source.\n *\n * The `@sentry/node` SDK installs its own `onUncaughtException` /\n * `onUnhandledRejection` handlers by default once initialized, so unhandled\n * crashes in a long-running process (daemon, sync server, MCP server) are\n * captured automatically.\n */\n\nimport * as Sentry from \"@sentry/node\";\n\nlet initialized = false;\n\n/**\n * Initialize Sentry iff `SENTRY_DSN` is set. Safe (and cheap) to call once at\n * each entrypoint's first side-effect. Returns whether Sentry was initialized.\n */\nexport function initSentry(): boolean {\n if (initialized) return true;\n\n const dsn = process.env.SENTRY_DSN?.trim();\n // Hard no-op without a DSN — the critical OSS guarantee. No init, no network.\n if (!dsn) return false;\n\n const environment =\n process.env.RECALL_ENV?.trim() ||\n process.env.NODE_ENV?.trim() ||\n \"production\";\n\n Sentry.init({\n dsn,\n environment,\n // Errors/crashes only — no performance traffic.\n tracesSampleRate: 0,\n // No profiling, no replay: keep only the error integrations.\n profilesSampleRate: 0,\n // Don't attach client IP, cookies, or any user identity.\n sendDefaultPii: false,\n });\n\n initialized = true;\n return true;\n}\n\nexport { Sentry };\n","/**\n * Side-effecting Sentry bootstrap.\n *\n * Import this FIRST — before any other module — at each long-running or\n * user-facing entrypoint so Sentry (if, and only if, `SENTRY_DSN` is set)\n * installs its error handlers before any other code runs:\n *\n * import \"./observability/instrument.js\";\n *\n * With `SENTRY_DSN` unset this is a hard no-op: no init, no network. See\n * {@link ./sentry.ts} for the full opt-in contract.\n */\n\nimport { initSentry } from \"./sentry.js\";\n\ninitSentry();\n"],"mappings":";AAiBA,YAAY,YAAY;AAExB,IAAI,cAAc;AAMX,SAAS,aAAsB;AACpC,MAAI,YAAa,QAAO;AAExB,QAAM,MAAM,QAAQ,IAAI,YAAY,KAAK;AAEzC,MAAI,CAAC,IAAK,QAAO;AAEjB,QAAM,cACJ,QAAQ,IAAI,YAAY,KAAK,KAC7B,QAAQ,IAAI,UAAU,KAAK,KAC3B;AAEF,EAAO,YAAK;AAAA,IACV;AAAA,IACA;AAAA;AAAA,IAEA,kBAAkB;AAAA;AAAA,IAElB,oBAAoB;AAAA;AAAA,IAEpB,gBAAgB;AAAA,EAClB,CAAC;AAED,gBAAc;AACd,SAAO;AACT;;;ACnCA,WAAW;","names":[]}
1
+ {"version":3,"sources":["../src/observability/sentry.ts","../src/observability/instrument.ts"],"sourcesContent":["/**\n * Optional, opt-in Sentry error reporting.\n *\n * Errors and crashes only — no performance tracing, no profiling, no session\n * replay, no default PII. The DSN comes exclusively from the `SENTRY_DSN`\n * environment variable; when it is empty or unset, {@link initSentry} is a hard\n * no-op and `Sentry.init` is never called, so the SDK sends nothing off-box.\n *\n * Recall is public OSS: community installs never phone home unless the operator\n * explicitly sets `SENTRY_DSN`. The DSN is intentionally NOT baked into source.\n *\n * The `@sentry/node` SDK installs its own `onUncaughtException` /\n * `onUnhandledRejection` handlers by default once initialized, so unhandled\n * crashes in a long-running process (daemon, sync server, MCP server) are\n * captured automatically.\n */\n\nimport * as Sentry from \"@sentry/node\";\n\nlet initialized = false;\n\n/**\n * Initialize Sentry iff `SENTRY_DSN` is set. Safe (and cheap) to call once at\n * each entrypoint's first side-effect. Returns whether Sentry was initialized.\n */\nexport function initSentry(): boolean {\n if (initialized) return true;\n\n const dsn = process.env.SENTRY_DSN?.trim();\n // Hard no-op without a DSN — the critical OSS guarantee. No init, no network.\n if (!dsn) return false;\n\n const environment =\n process.env.RECALL_ENV?.trim() ||\n process.env.NODE_ENV?.trim() ||\n \"production\";\n\n Sentry.init({\n dsn,\n environment,\n // Errors/crashes only — no performance traffic.\n tracesSampleRate: 0,\n // No profiling, no replay: keep only the error integrations.\n profilesSampleRate: 0,\n // Don't attach client IP, cookies, or any user identity.\n sendDefaultPii: false,\n });\n\n initialized = true;\n return true;\n}\n\nexport { Sentry };\n","/**\n * Side-effecting Sentry bootstrap.\n *\n * Import this FIRST — before any other module — at each long-running or\n * user-facing entrypoint so Sentry (if, and only if, `SENTRY_DSN` is set)\n * installs its error handlers before any other code runs:\n *\n * import \"./observability/instrument.js\";\n *\n * With `SENTRY_DSN` unset this is a hard no-op: no init, no network. See\n * {@link ./sentry.ts} for the full opt-in contract.\n */\n\nimport { initSentry } from \"./sentry.js\";\n\ninitSentry();\n"],"mappings":";;;;;AAAA;AAiBA,YAAY,YAAY;AAExB,IAAI,cAAc;AAMX,SAAS,aAAsB;AACpC,MAAI,YAAa,QAAO;AAExB,QAAM,MAAM,QAAQ,IAAI,YAAY,KAAK;AAEzC,MAAI,CAAC,IAAK,QAAO;AAEjB,QAAM,cACJ,QAAQ,IAAI,YAAY,KAAK,KAC7B,QAAQ,IAAI,UAAU,KAAK,KAC3B;AAEF,EAAO,YAAK;AAAA,IACV;AAAA,IACA;AAAA;AAAA,IAEA,kBAAkB;AAAA;AAAA,IAElB,oBAAoB;AAAA;AAAA,IAEpB,gBAAgB;AAAA,EAClB,CAAC;AAED,gBAAc;AACd,SAAO;AACT;;;AClDA;AAeA,WAAW;","names":[]}
@@ -1,4 +1,9 @@
1
+ import {
2
+ init_define_RECALL_BUILD_INFO
3
+ } from "./chunk-CYAODQOH.js";
4
+
1
5
  // src/text/match.ts
6
+ init_define_RECALL_BUILD_INFO();
2
7
  var STOP_WORDS = /* @__PURE__ */ new Set([
3
8
  "a",
4
9
  "an",
@@ -111,4 +116,4 @@ export {
111
116
  textMatchScore,
112
117
  matchTokens
113
118
  };
114
- //# sourceMappingURL=chunk-FHEH6QDU.js.map
119
+ //# sourceMappingURL=chunk-7Z3CCCS2.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/text/match.ts"],"sourcesContent":["const STOP_WORDS = new Set([\n \"a\",\n \"an\",\n \"and\",\n \"always\",\n \"are\",\n \"as\",\n \"at\",\n \"be\",\n \"by\",\n \"call\",\n \"do\",\n \"for\",\n \"from\",\n \"i\",\n \"in\",\n \"import\",\n \"instead\",\n \"is\",\n \"it\",\n \"its\",\n \"just\",\n \"must\",\n \"of\",\n \"on\",\n \"only\",\n \"or\",\n \"our\",\n \"please\",\n \"required\",\n \"run\",\n \"should\",\n \"that\",\n \"the\",\n \"this\",\n \"to\",\n \"use\",\n \"we\",\n \"with\",\n \"you\",\n \"your\",\n]);\n\nconst NEGATION_WORDS = new Set([\n \"avoid\",\n \"dont\",\n \"forbid\",\n \"forbidden\",\n \"never\",\n \"no\",\n \"not\",\n \"stop\",\n]);\n\nexport interface TextMatchScore {\n score: number;\n jaccard: number;\n containment: number;\n intersection: number;\n left_tokens: string[];\n right_tokens: string[];\n}\n\nexport function textMatches(left: string, right: string, threshold: number): boolean {\n return textMatchScore(left, right).score >= threshold;\n}\n\nexport function textMatchScore(left: string, right: string): TextMatchScore {\n const leftTokens = matchTokens(left);\n const rightTokens = matchTokens(right);\n if (leftTokens.length === 0 || rightTokens.length === 0) {\n return {\n score: 0,\n jaccard: 0,\n containment: 0,\n intersection: 0,\n left_tokens: leftTokens,\n right_tokens: rightTokens,\n };\n }\n\n const leftSet = new Set(leftTokens);\n const rightSet = new Set(rightTokens);\n const intersection = [...leftSet].filter((token) => rightSet.has(token)).length;\n const union = new Set([...leftSet, ...rightSet]).size;\n const jaccard = union === 0 ? 0 : intersection / union;\n const smaller = Math.min(leftSet.size, rightSet.size);\n const containment = smaller === 0 ? 0 : intersection / smaller;\n const containmentWeight = smaller < 2 ? 0 : smaller === 2 ? 0.75 : 0.9;\n // Short tool/product queries are common (\"uv\", \"pnpm\", \"shotport\").\n // A one-token side is normally too weak for correction matching, but when\n // that whole distinctive token occurs on the other side it is exactly the\n // user's retrieval intent. Sentence-to-sentence one-token overlap remains\n // unboosted because neither side collapses to one content token.\n const exactSingleTokenScore =\n intersection === 1 &&\n smaller === 1 &&\n ![\"not\"].includes([...leftSet].find((token) => rightSet.has(token)) ?? \"\")\n ? 0.7\n : 0;\n const score = Math.max(jaccard, containment * containmentWeight, exactSingleTokenScore);\n\n return {\n score,\n jaccard,\n containment,\n intersection,\n left_tokens: [...leftSet],\n right_tokens: [...rightSet],\n };\n}\n\nexport function matchTokens(text: string): string[] {\n return text\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .replace(/\\bdo\\s+not\\b/g, \" not \")\n .replace(/\\bdon['’]?t\\b/g, \" dont \")\n .split(/[^a-z0-9]+/)\n .map(normalizeToken)\n .filter((token) => token.length > 1 && !STOP_WORDS.has(token));\n}\n\nfunction normalizeToken(token: string): string {\n if (NEGATION_WORDS.has(token)) return \"not\";\n if ([\"dependencies\", \"dependency\", \"packages\"].includes(token)) return \"package\";\n if (token === \"manager\" || token === \"management\") return \"manage\";\n if (/^es\\d+$/.test(token)) return \"es\";\n if (token === \"ran\" || token === \"running\" || token === \"runs\") return \"run\";\n if (token === \"using\" || token === \"used\" || token === \"uses\") return \"use\";\n if (token.endsWith(\"ies\") && token.length > 4) return `${token.slice(0, -3)}y`;\n if (/(?:ches|shes|sses|xes|zes)$/.test(token) && token.length > 4) {\n return token.slice(0, -2);\n }\n if (token.endsWith(\"ing\") && token.length > 5) return token.slice(0, -3);\n if (token.endsWith(\"ed\") && token.length > 4) return token.slice(0, -2);\n if (token.endsWith(\"s\") && token.length > 3) return token.slice(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GAAG,EAAE,CAAC;AAC3E,MAAI,8BAA8B,KAAK,KAAK,KAAK,MAAM,SAAS,GAAG;AACjE,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,MAAI,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACvE,MAAI,MAAM,SAAS,IAAI,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACtE,MAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACrE,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/text/match.ts"],"sourcesContent":["const STOP_WORDS = new Set([\n \"a\",\n \"an\",\n \"and\",\n \"always\",\n \"are\",\n \"as\",\n \"at\",\n \"be\",\n \"by\",\n \"call\",\n \"do\",\n \"for\",\n \"from\",\n \"i\",\n \"in\",\n \"import\",\n \"instead\",\n \"is\",\n \"it\",\n \"its\",\n \"just\",\n \"must\",\n \"of\",\n \"on\",\n \"only\",\n \"or\",\n \"our\",\n \"please\",\n \"required\",\n \"run\",\n \"should\",\n \"that\",\n \"the\",\n \"this\",\n \"to\",\n \"use\",\n \"we\",\n \"with\",\n \"you\",\n \"your\",\n]);\n\nconst NEGATION_WORDS = new Set([\n \"avoid\",\n \"dont\",\n \"forbid\",\n \"forbidden\",\n \"never\",\n \"no\",\n \"not\",\n \"stop\",\n]);\n\nexport interface TextMatchScore {\n score: number;\n jaccard: number;\n containment: number;\n intersection: number;\n left_tokens: string[];\n right_tokens: string[];\n}\n\nexport function textMatches(left: string, right: string, threshold: number): boolean {\n return textMatchScore(left, right).score >= threshold;\n}\n\nexport function textMatchScore(left: string, right: string): TextMatchScore {\n const leftTokens = matchTokens(left);\n const rightTokens = matchTokens(right);\n if (leftTokens.length === 0 || rightTokens.length === 0) {\n return {\n score: 0,\n jaccard: 0,\n containment: 0,\n intersection: 0,\n left_tokens: leftTokens,\n right_tokens: rightTokens,\n };\n }\n\n const leftSet = new Set(leftTokens);\n const rightSet = new Set(rightTokens);\n const intersection = [...leftSet].filter((token) => rightSet.has(token)).length;\n const union = new Set([...leftSet, ...rightSet]).size;\n const jaccard = union === 0 ? 0 : intersection / union;\n const smaller = Math.min(leftSet.size, rightSet.size);\n const containment = smaller === 0 ? 0 : intersection / smaller;\n const containmentWeight = smaller < 2 ? 0 : smaller === 2 ? 0.75 : 0.9;\n // Short tool/product queries are common (\"uv\", \"pnpm\", \"shotport\").\n // A one-token side is normally too weak for correction matching, but when\n // that whole distinctive token occurs on the other side it is exactly the\n // user's retrieval intent. Sentence-to-sentence one-token overlap remains\n // unboosted because neither side collapses to one content token.\n const exactSingleTokenScore =\n intersection === 1 &&\n smaller === 1 &&\n ![\"not\"].includes([...leftSet].find((token) => rightSet.has(token)) ?? \"\")\n ? 0.7\n : 0;\n const score = Math.max(jaccard, containment * containmentWeight, exactSingleTokenScore);\n\n return {\n score,\n jaccard,\n containment,\n intersection,\n left_tokens: [...leftSet],\n right_tokens: [...rightSet],\n };\n}\n\nexport function matchTokens(text: string): string[] {\n return text\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .toLowerCase()\n .replace(/\\bdo\\s+not\\b/g, \" not \")\n .replace(/\\bdon['’]?t\\b/g, \" dont \")\n .split(/[^a-z0-9]+/)\n .map(normalizeToken)\n .filter((token) => token.length > 1 && !STOP_WORDS.has(token));\n}\n\nfunction normalizeToken(token: string): string {\n if (NEGATION_WORDS.has(token)) return \"not\";\n if ([\"dependencies\", \"dependency\", \"packages\"].includes(token)) return \"package\";\n if (token === \"manager\" || token === \"management\") return \"manage\";\n if (/^es\\d+$/.test(token)) return \"es\";\n if (token === \"ran\" || token === \"running\" || token === \"runs\") return \"run\";\n if (token === \"using\" || token === \"used\" || token === \"uses\") return \"use\";\n if (token.endsWith(\"ies\") && token.length > 4) return `${token.slice(0, -3)}y`;\n if (/(?:ches|shes|sses|xes|zes)$/.test(token) && token.length > 4) {\n return token.slice(0, -2);\n }\n if (token.endsWith(\"ing\") && token.length > 5) return token.slice(0, -3);\n if (token.endsWith(\"ed\") && token.length > 4) return token.slice(0, -2);\n if (token.endsWith(\"s\") && token.length > 3) return token.slice(0, -1);\n return token;\n}\n"],"mappings":";;;;;AAAA;AAAA,IAAM,aAAa,oBAAI,IAAI;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,iBAAiB,oBAAI,IAAI;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAWM,SAAS,YAAY,MAAc,OAAe,WAA4B;AACnF,SAAO,eAAe,MAAM,KAAK,EAAE,SAAS;AAC9C;AAEO,SAAS,eAAe,MAAc,OAA+B;AAC1E,QAAM,aAAa,YAAY,IAAI;AACnC,QAAM,cAAc,YAAY,KAAK;AACrC,MAAI,WAAW,WAAW,KAAK,YAAY,WAAW,GAAG;AACvD,WAAO;AAAA,MACL,OAAO;AAAA,MACP,SAAS;AAAA,MACT,aAAa;AAAA,MACb,cAAc;AAAA,MACd,aAAa;AAAA,MACb,cAAc;AAAA,IAChB;AAAA,EACF;AAEA,QAAM,UAAU,IAAI,IAAI,UAAU;AAClC,QAAM,WAAW,IAAI,IAAI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S,UAAU,aAAa,UAAU,OAAQ,QAAO;AACvE,MAAI,UAAU,WAAW,UAAU,UAAU,UAAU,OAAQ,QAAO;AACtE,MAAI,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,EAAG,QAAO,GAAG,MAAM,MAAM,GAAG,EAAE,CAAC;AAC3E,MAAI,8BAA8B,KAAK,KAAK,KAAK,MAAM,SAAS,GAAG;AACjE,WAAO,MAAM,MAAM,GAAG,EAAE;AAAA,EAC1B;AACA,MAAI,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACvE,MAAI,MAAM,SAAS,IAAI,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACtE,MAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,EAAG,QAAO,MAAM,MAAM,GAAG,EAAE;AACrE,SAAO;AACT;","names":[]}
@@ -0,0 +1,23 @@
1
+ import {
2
+ init_define_RECALL_BUILD_INFO
3
+ } from "./chunk-CYAODQOH.js";
4
+
5
+ // src/security/object.ts
6
+ init_define_RECALL_BUILD_INFO();
7
+ function defineOwn(target, key, value) {
8
+ Object.defineProperty(target, key, {
9
+ configurable: true,
10
+ enumerable: true,
11
+ value,
12
+ writable: true
13
+ });
14
+ }
15
+ function deleteOwn(target, key) {
16
+ Reflect.deleteProperty(target, key);
17
+ }
18
+
19
+ export {
20
+ defineOwn,
21
+ deleteOwn
22
+ };
23
+ //# sourceMappingURL=chunk-AQOI4FCW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/security/object.ts"],"sourcesContent":["export function defineOwn<T>(\n target: Record<string, T>,\n key: string,\n value: T,\n): void {\n Object.defineProperty(target, key, {\n configurable: true,\n enumerable: true,\n value,\n writable: true,\n });\n}\n\nexport function deleteOwn(\n target: Record<string, unknown>,\n key: string,\n): void {\n Reflect.deleteProperty(target, key);\n}\n"],"mappings":";;;;;AAAA;AAAO,SAAS,UACd,QACA,KACA,OACM;AACN,SAAO,eAAe,QAAQ,KAAK;AAAA,IACjC,cAAc;AAAA,IACd,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,EACZ,CAAC;AACH;AAEO,SAAS,UACd,QACA,KACM;AACN,UAAQ,eAAe,QAAQ,GAAG;AACpC;","names":[]}
@@ -2,19 +2,65 @@ import {
2
2
  getProviderConfig,
3
3
  hasProviderConfigured,
4
4
  init_keychain
5
- } from "./chunk-WZWXYBP6.js";
5
+ } from "./chunk-XCFTE74H.js";
6
6
  import {
7
7
  eq,
8
8
  inArray,
9
9
  llmUsage,
10
10
  memories,
11
11
  memoryEmbeddings
12
- } from "./chunk-LUIYWYOT.js";
12
+ } from "./chunk-VSEAVK7X.js";
13
+ import {
14
+ init_define_RECALL_BUILD_INFO
15
+ } from "./chunk-CYAODQOH.js";
13
16
 
14
17
  // src/embeddings/embeddings.ts
18
+ init_define_RECALL_BUILD_INFO();
15
19
  import { createHash as createHash2 } from "crypto";
16
20
 
21
+ // src/vector/native-extension.ts
22
+ init_define_RECALL_BUILD_INFO();
23
+ import { createRequire } from "module";
24
+ import Database from "better-sqlite3";
25
+ import * as upstream from "sqlite-vec";
26
+ var require2 = createRequire(import.meta.url);
27
+ var windowsChecked = false;
28
+ var windowsPath;
29
+ var windowsError;
30
+ function needsWindowsArmExtension() {
31
+ return process.platform === "win32" && process.arch === "arm64";
32
+ }
33
+ function getLoadablePath2() {
34
+ if (!needsWindowsArmExtension()) return upstream.getLoadablePath();
35
+ if (!windowsChecked) {
36
+ try {
37
+ const extension = require2("@photostructure/sqlite-vec");
38
+ windowsPath = extension.getLoadablePath();
39
+ const probe = new Database(":memory:");
40
+ try {
41
+ probe.loadExtension(windowsPath);
42
+ probe.prepare("select vec_version()").get();
43
+ } finally {
44
+ probe.close();
45
+ }
46
+ } catch (error) {
47
+ windowsError = error instanceof Error ? error : new Error(String(error));
48
+ }
49
+ windowsChecked = true;
50
+ }
51
+ if (windowsError) throw windowsError;
52
+ return windowsPath;
53
+ }
54
+ function load2(db) {
55
+ if (!needsWindowsArmExtension()) {
56
+ upstream.load(db);
57
+ return;
58
+ }
59
+ db.loadExtension(getLoadablePath2());
60
+ }
61
+
17
62
  // src/types.ts
63
+ init_define_RECALL_BUILD_INFO();
18
64
  import { z } from "zod";
19
65
  var MemoryStatus = z.enum([
20
66
  "transient",
@@ -438,6 +484,7 @@ var Contradiction = z.object({
438
484
  });
439
485
  var PruneConfig = z.object({
440
486
  repo: z.string().optional(),
487
+ candidate_unconfirmed_days: z.number().default(30),
441
488
  stale_days: z.number().default(90),
442
489
  rejected_retention_days: z.number().default(30),
443
490
  transient_retention_days: z.number().default(7),
@@ -472,6 +519,7 @@ var AuditEntry = z.object({
472
519
  });
473
520
 
474
521
  // src/embeddings/cache.ts
522
+ init_define_RECALL_BUILD_INFO();
475
523
  import { existsSync, mkdirSync, readdirSync, statSync } from "fs";
476
524
  import { homedir } from "os";
477
525
  import { join } from "path";
@@ -506,7 +554,11 @@ function formatBytes(bytes) {
506
554
  return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
507
555
  }
508
556
 
557
+ // src/embeddings/providers/index.ts
558
+ init_define_RECALL_BUILD_INFO();
559
+
509
560
  // src/embeddings/providers/all-minilm-l6-v2.ts
561
+ init_define_RECALL_BUILD_INFO();
510
562
  import { pipeline } from "@huggingface/transformers";
511
563
  var MINILM_MODEL = "Xenova/all-MiniLM-L6-v2";
512
564
  var MINILM_DIMENSIONS = 384;
@@ -586,6 +638,7 @@ function createAllMiniLmL6V2Provider(config) {
586
638
  }
587
639
 
588
640
  // src/embeddings/providers/bge-small-en-v1.5.ts
641
+ init_define_RECALL_BUILD_INFO();
589
642
  import { pipeline as pipeline2 } from "@huggingface/transformers";
590
643
  var BGE_MODEL = "Xenova/bge-small-en-v1.5";
591
644
  var BGE_DIMENSIONS = 384;
@@ -665,6 +718,7 @@ function createBgeSmallEnV15Provider(config) {
665
718
  }
666
719
 
667
720
  // src/embeddings/providers/multilingual-e5.ts
721
+ init_define_RECALL_BUILD_INFO();
668
722
  import { pipeline as pipeline3 } from "@huggingface/transformers";
669
723
  var MULTILINGUAL_E5_MODEL = "Xenova/multilingual-e5-small";
670
724
  var MULTILINGUAL_E5_NATIVE_DIMENSIONS = 384;
@@ -753,6 +807,7 @@ function createMultilingualE5Provider(config) {
753
807
  }
754
808
 
755
809
  // src/embeddings/providers/nomic.ts
810
+ init_define_RECALL_BUILD_INFO();
756
811
  import { layer_norm, pipeline as pipeline4 } from "@huggingface/transformers";
757
812
  var NOMIC_MODEL = "nomic-ai/nomic-embed-text-v1.5";
758
813
  var NOMIC_NATIVE_DIMENSIONS = 768;
@@ -859,9 +914,10 @@ function resolveProvider(config) {
859
914
  }
860
915
 
861
916
  // src/vector/sqlite-vec.ts
862
- import * as sqliteVec from "sqlite-vec";
917
+ init_define_RECALL_BUILD_INFO();
863
918
 
864
919
  // src/embeddings/responsive-batches.ts
920
+ init_define_RECALL_BUILD_INFO();
865
921
  var BACKGROUND_EMBEDDING_BATCH_SIZE = 1;
866
922
  var BACKGROUND_INDEX_BATCH_SIZE = 32;
867
923
  function yieldToEventLoop() {
@@ -893,7 +949,7 @@ function hasMemoryVecIndex(db) {
893
949
  function ensureSqliteVecLoaded(db) {
894
950
  const sqlite = getSqlite(db);
895
951
  if (loadedClients.has(sqlite)) return;
896
- sqliteVec.load(sqlite);
952
+ load2(sqlite);
897
953
  loadedClients.add(sqlite);
898
954
  }
899
955
  function getMemoryVecDimension(rows) {
@@ -928,6 +984,7 @@ function ensureMemoryVecIndex(db, dimensions) {
928
984
  `);
929
985
  }
930
986
  function dropMemoryVecIndex(db) {
987
+ if (!hasMemoryVecIndex(db)) return;
931
988
  ensureSqliteVecLoaded(db);
932
989
  getSqlite(db).exec(`drop table if exists ${VEC_MEMORY_INDEX};`);
933
990
  }
@@ -954,8 +1011,8 @@ function upsertMemoryVecRow(db, memory, embeddingRow) {
954
1011
  );
955
1012
  }
956
1013
  function removeMemoryVecRow(db, memoryId, config) {
957
- ensureSqliteVecLoaded(db);
958
1014
  if (!hasMemoryVecIndex(db)) return;
1015
+ ensureSqliteVecLoaded(db);
959
1016
  getSqlite(db).prepare(`delete from ${VEC_MEMORY_INDEX} where memory_id = ?`).run(memoryId);
960
1017
  }
961
1018
  function rebuildMemoryVecIndex(db, config, options = {}) {
@@ -1121,7 +1178,11 @@ function searchMemoryVecIndex(db, queryEmbedding, options = {}) {
1121
1178
  `).all(queryEmbedding, limit);
1122
1179
  }
1123
1180
 
1181
+ // src/vector/sqlite-fts.ts
1182
+ init_define_RECALL_BUILD_INFO();
1183
+
1124
1184
  // src/vector/synonyms.ts
1185
+ init_define_RECALL_BUILD_INFO();
1125
1186
  import { readFileSync, existsSync as existsSync2 } from "fs";
1126
1187
 
1127
1188
  // src/data/synonyms.en.json
@@ -1570,11 +1631,13 @@ function searchMemoryFtsIndex(db, query, options = {}) {
1570
1631
  }
1571
1632
 
1572
1633
  // src/embeddings/hyde.ts
1634
+ init_define_RECALL_BUILD_INFO();
1573
1635
  import { createHash } from "crypto";
1574
1636
  import { mkdirSync as mkdirSync2 } from "fs";
1575
1637
  import { dirname as dirname2 } from "path";
1576
1638
 
1577
1639
  // src/llm/client.ts
1640
+ init_define_RECALL_BUILD_INFO();
1578
1641
  init_keychain();
1579
1642
  import { randomUUID } from "crypto";
1580
1643
  var LlmCredentialError = class extends Error {
@@ -1812,6 +1875,7 @@ async function safeText(response) {
1812
1875
  init_keychain();
1813
1876
 
1814
1877
  // src/security/atomic-file.ts
1878
+ init_define_RECALL_BUILD_INFO();
1815
1879
  import {
1816
1880
  closeSync,
1817
1881
  constants,
@@ -1959,6 +2023,7 @@ async function generateHydeText(db, query) {
1959
2023
  }
1960
2024
 
1961
2025
  // src/embeddings/reranker.ts
2026
+ init_define_RECALL_BUILD_INFO();
1962
2027
  import { mkdirSync as mkdirSync3 } from "fs";
1963
2028
  import { join as join3 } from "path";
1964
2029
  import {
@@ -2031,7 +2096,7 @@ var EMBEDDING_DEFAULTS = {
2031
2096
  }
2032
2097
  };
2033
2098
  function loadEmbeddingConfigFromEnv() {
2034
- if (process.env.RECALL_EMBEDDINGS_DISABLED === "true") return null;
2099
+ if (getEmbeddingUnavailableReason()) return null;
2035
2100
  const requested = process.env.RECALL_EMBEDDING_PROVIDER;
2036
2101
  const provider = requested === "multilingual-e5" ? "multilingual-e5" : requested === "bge-small-en-v1.5" ? "bge-small-en-v1.5" : requested === "all-MiniLM-L6-v2" ? "all-MiniLM-L6-v2" : "nomic";
2037
2102
  const defaults = EMBEDDING_DEFAULTS[provider];
@@ -2043,6 +2108,15 @@ function loadEmbeddingConfigFromEnv() {
2043
2108
  similarity_threshold: parseFloat(process.env.RECALL_SIMILARITY_THRESHOLD ?? "0.8")
2044
2109
  };
2045
2110
  }
2111
+ function getEmbeddingUnavailableReason() {
2112
+ if (process.env.RECALL_EMBEDDINGS_DISABLED === "true") return "Disabled by configuration";
2113
+ try {
2114
+ getLoadablePath2();
2115
+ return null;
2116
+ } catch (error) {
2117
+ return `Native vector extension unavailable; lexical retrieval remains enabled: ${error instanceof Error ? error.message : String(error)}`;
2118
+ }
2119
+ }
2046
2120
  function getEmbeddingModelInfo(config = loadEmbeddingConfigFromEnv()) {
2047
2121
  if (!config) return null;
2048
2122
  const provider = resolveProvider(config);
@@ -2248,8 +2322,22 @@ async function bootstrapEmbeddings(db, config, options = {}) {
2248
2322
  return total;
2249
2323
  }
2250
2324
  function verifyEmbeddings(db, config, options = {}) {
2251
- const rows = db.select().from(memories).all();
2252
- const embeddingRows = db.select().from(memoryEmbeddings).all();
2325
+ const rows = db.select({
2326
+ id: memories.id,
2327
+ repo: memories.repo,
2328
+ text: memories.text,
2329
+ status: memories.status,
2330
+ confidence: memories.confidence,
2331
+ source: memories.source
2332
+ }).from(memories).all();
2333
+ const embeddingRows = db.select({
2334
+ memory_id: memoryEmbeddings.memory_id,
2335
+ model: memoryEmbeddings.model,
2336
+ embedding_dimensions: memoryEmbeddings.embedding_dimensions,
2337
+ index_dimensions: memoryEmbeddings.index_dimensions,
2338
+ version: memoryEmbeddings.version,
2339
+ content_hash: memoryEmbeddings.content_hash
2340
+ }).from(memoryEmbeddings).all();
2253
2341
  const embeddingById = new Map(embeddingRows.map((row) => [row.memory_id, row]));
2254
2342
  let eligible = 0;
2255
2343
  let stale = 0;
@@ -2445,9 +2533,9 @@ async function findSemanticDuplicates(db, text, config, threshold, options = {})
2445
2533
  }
2446
2534
  return duplicates.sort((a, b) => b.similarity - a.similarity).slice(0, options.limit ?? 10);
2447
2535
  }
2448
- async function findSimilarRejectedExemplar(db, text, config, threshold) {
2536
+ async function findSimilarRejectedExemplar(db, text, config, threshold, isEligible) {
2449
2537
  const queryEmbedding = await generateEmbedding(text, config, "query");
2450
- const rejectedRows = db.select().from(memories).where(eq(memories.status, "rejected")).all().filter((row) => row.source === "user_correction" || row.source === "user_reported_review");
2538
+ const rejectedRows = db.select().from(memories).where(eq(memories.status, "rejected")).all().filter((row) => row.source === "user_correction" || row.source === "user_reported_review").filter((row) => isEligible ? isEligible(row.id) : true);
2451
2539
  if (rejectedRows.length === 0) return null;
2452
2540
  const embeddingsById = new Map(
2453
2541
  db.select().from(memoryEmbeddings).all().map((row) => [row.memory_id, row])
@@ -2495,6 +2583,7 @@ function rowToMemory(row) {
2495
2583
 
2496
2584
  export {
2497
2585
  getEmbeddingCacheRoot,
2586
+ load2 as load,
2498
2587
  tagActivitySource,
2499
2588
  CONFIDENCE,
2500
2589
  PROMOTION,
@@ -2511,6 +2600,7 @@ export {
2511
2600
  readUtf8FileIfExists,
2512
2601
  atomicWriteUtf8File,
2513
2602
  loadEmbeddingConfigFromEnv,
2603
+ getEmbeddingUnavailableReason,
2514
2604
  getEmbeddingModelInfo,
2515
2605
  ensureEmbeddingProviderReady,
2516
2606
  projectEmbeddingToIndex,
@@ -2532,4 +2622,4 @@ export {
2532
2622
  findSemanticDuplicates,
2533
2623
  findSimilarRejectedExemplar
2534
2624
  };
2535
- //# sourceMappingURL=chunk-JKWK73GY.js.map
2625
+ //# sourceMappingURL=chunk-BWKFROGW.js.map