@edihasaj/recall 2.0.6 → 2.0.8

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 (84) hide show
  1. package/README.md +11 -0
  2. package/dist/{chunk-AMKKCXL5.js → chunk-3LL5S473.js} +2 -2
  3. package/dist/{chunk-AR37YSEM.js → chunk-3ZA4YOFN.js} +5 -5
  4. package/dist/{chunk-N235JJB2.js → chunk-4LTGMFHN.js} +3 -3
  5. package/dist/{chunk-PMMGXYBS.js → chunk-6U7YMPBE.js} +2 -2
  6. package/dist/{chunk-QRI6W7FJ.js → chunk-BOUMOPKD.js} +2 -2
  7. package/dist/{chunk-5AM6YJ23.js → chunk-HYDNV5T2.js} +351 -139
  8. package/dist/chunk-HYDNV5T2.js.map +1 -0
  9. package/dist/{chunk-I6FOUVJ6.js → chunk-J3F3CLWL.js} +7 -7
  10. package/dist/{chunk-3MCEP2MO.js → chunk-JSKYG7TC.js} +2 -2
  11. package/dist/{chunk-LZUN3MKB.js → chunk-LOWPEB72.js} +3 -3
  12. package/dist/{chunk-5TFMHIZA.js → chunk-MD2LUEVD.js} +435 -89
  13. package/dist/chunk-MD2LUEVD.js.map +1 -0
  14. package/dist/{chunk-PWF7DAPA.js → chunk-N2ONUBXR.js} +9 -9
  15. package/dist/{chunk-FT3EEFPN.js → chunk-OHWHU653.js} +843 -144
  16. package/dist/chunk-OHWHU653.js.map +1 -0
  17. package/dist/{chunk-7L4PAEIP.js → chunk-PW42PFVO.js} +7 -7
  18. package/dist/{chunk-TKBPDASJ.js → chunk-QKGE74LD.js} +8 -5
  19. package/dist/chunk-QKGE74LD.js.map +1 -0
  20. package/dist/{chunk-X2DPMIBG.js → chunk-QOMNHKYE.js} +2 -2
  21. package/dist/{chunk-D3GBCJFT.js → chunk-RSBIISGE.js} +5 -5
  22. package/dist/{chunk-7MBCHU7J.js → chunk-URQEUH7T.js} +3 -3
  23. package/dist/{chunk-UVP6BVRD.js → chunk-VV2QPDAM.js} +2 -2
  24. package/dist/{chunk-UVP6BVRD.js.map → chunk-VV2QPDAM.js.map} +1 -1
  25. package/dist/{cleanup-MYBUBFDI.js → cleanup-QC7EHMUB.js} +11 -11
  26. package/dist/cli.js +209 -162
  27. package/dist/cli.js.map +1 -1
  28. package/dist/{codex-trust-I4EO6X2D.js → codex-trust-4RI6LCAI.js} +4 -4
  29. package/dist/daemon.js +224 -49
  30. package/dist/daemon.js.map +1 -1
  31. package/dist/dispatcher-XGATH6Q5.js +22 -0
  32. package/dist/{embeddings-RI6JOHF7.js → embeddings-RS3GK3TS.js} +5 -5
  33. package/dist/ingest-RGPV5QYT.js +20 -0
  34. package/dist/{keychain-7XUE3UOM.js → keychain-BRWB5CL5.js} +3 -3
  35. package/dist/mcp.js +15 -15
  36. package/dist/{memory-value-HFKFPQYC.js → memory-value-6KDRPDXE.js} +11 -11
  37. package/dist/{provenance-JY3NQ7DC.js → provenance-NLVTH5ZK.js} +9 -9
  38. package/dist/quality-QPRUXM4B.js +25 -0
  39. package/dist/retrieval-N5FQRL2V.js +15 -0
  40. package/dist/{store-FQ5LZXHU.js → store-DXJJ7VOQ.js} +4 -4
  41. package/dist/sync-server.js +2 -2
  42. package/dist/{tasks-NZK7VQYZ.js → tasks-32RY4KNA.js} +11 -11
  43. package/dist/{usage-KRWQUZ4G.js → usage-3EMXD6MZ.js} +4 -4
  44. package/dist/webui/assets/{GraphPage-DJhwG-72.js → GraphPage-BH_Mch3C.js} +2 -2
  45. package/dist/webui/assets/{GraphPage-DJhwG-72.js.map → GraphPage-BH_Mch3C.js.map} +1 -1
  46. package/dist/webui/assets/{index-Cpn2MjW0.js → index-CPFc-fiv.js} +25 -25
  47. package/dist/webui/assets/index-CPFc-fiv.js.map +1 -0
  48. package/dist/webui/index.html +1 -1
  49. package/package.json +1 -1
  50. package/dist/chunk-5AM6YJ23.js.map +0 -1
  51. package/dist/chunk-5TFMHIZA.js.map +0 -1
  52. package/dist/chunk-FT3EEFPN.js.map +0 -1
  53. package/dist/chunk-TKBPDASJ.js.map +0 -1
  54. package/dist/dispatcher-UMZKX2AK.js +0 -22
  55. package/dist/ingest-M5PRYMU3.js +0 -20
  56. package/dist/quality-NDTZMU34.js +0 -25
  57. package/dist/retrieval-D3BTENJX.js +0 -15
  58. package/dist/webui/assets/index-Cpn2MjW0.js.map +0 -1
  59. /package/dist/{chunk-AMKKCXL5.js.map → chunk-3LL5S473.js.map} +0 -0
  60. /package/dist/{chunk-AR37YSEM.js.map → chunk-3ZA4YOFN.js.map} +0 -0
  61. /package/dist/{chunk-N235JJB2.js.map → chunk-4LTGMFHN.js.map} +0 -0
  62. /package/dist/{chunk-PMMGXYBS.js.map → chunk-6U7YMPBE.js.map} +0 -0
  63. /package/dist/{chunk-QRI6W7FJ.js.map → chunk-BOUMOPKD.js.map} +0 -0
  64. /package/dist/{chunk-I6FOUVJ6.js.map → chunk-J3F3CLWL.js.map} +0 -0
  65. /package/dist/{chunk-3MCEP2MO.js.map → chunk-JSKYG7TC.js.map} +0 -0
  66. /package/dist/{chunk-LZUN3MKB.js.map → chunk-LOWPEB72.js.map} +0 -0
  67. /package/dist/{chunk-PWF7DAPA.js.map → chunk-N2ONUBXR.js.map} +0 -0
  68. /package/dist/{chunk-7L4PAEIP.js.map → chunk-PW42PFVO.js.map} +0 -0
  69. /package/dist/{chunk-X2DPMIBG.js.map → chunk-QOMNHKYE.js.map} +0 -0
  70. /package/dist/{chunk-D3GBCJFT.js.map → chunk-RSBIISGE.js.map} +0 -0
  71. /package/dist/{chunk-7MBCHU7J.js.map → chunk-URQEUH7T.js.map} +0 -0
  72. /package/dist/{cleanup-MYBUBFDI.js.map → cleanup-QC7EHMUB.js.map} +0 -0
  73. /package/dist/{codex-trust-I4EO6X2D.js.map → codex-trust-4RI6LCAI.js.map} +0 -0
  74. /package/dist/{dispatcher-UMZKX2AK.js.map → dispatcher-XGATH6Q5.js.map} +0 -0
  75. /package/dist/{embeddings-RI6JOHF7.js.map → embeddings-RS3GK3TS.js.map} +0 -0
  76. /package/dist/{ingest-M5PRYMU3.js.map → ingest-RGPV5QYT.js.map} +0 -0
  77. /package/dist/{keychain-7XUE3UOM.js.map → keychain-BRWB5CL5.js.map} +0 -0
  78. /package/dist/{memory-value-HFKFPQYC.js.map → memory-value-6KDRPDXE.js.map} +0 -0
  79. /package/dist/{provenance-JY3NQ7DC.js.map → provenance-NLVTH5ZK.js.map} +0 -0
  80. /package/dist/{quality-NDTZMU34.js.map → quality-QPRUXM4B.js.map} +0 -0
  81. /package/dist/{retrieval-D3BTENJX.js.map → retrieval-N5FQRL2V.js.map} +0 -0
  82. /package/dist/{store-FQ5LZXHU.js.map → store-DXJJ7VOQ.js.map} +0 -0
  83. /package/dist/{tasks-NZK7VQYZ.js.map → tasks-32RY4KNA.js.map} +0 -0
  84. /package/dist/{usage-KRWQUZ4G.js.map → usage-3EMXD6MZ.js.map} +0 -0
@@ -9,16 +9,16 @@ import {
9
9
  processCorrection,
10
10
  redactSensitiveValue,
11
11
  seedScannedConfidence
12
- } from "./chunk-5TFMHIZA.js";
12
+ } from "./chunk-MD2LUEVD.js";
13
13
  import {
14
14
  recordInjectionValueEvents,
15
15
  recordMemoryInjections,
16
16
  recordOutcomeValueEvent,
17
17
  resolveMemoryInjectionOutcome
18
- } from "./chunk-7L4PAEIP.js";
18
+ } from "./chunk-PW42PFVO.js";
19
19
  import {
20
20
  textMatchScore
21
- } from "./chunk-AMKKCXL5.js";
21
+ } from "./chunk-3LL5S473.js";
22
22
  import {
23
23
  activityEventDedupeKey,
24
24
  confirmMemory,
@@ -38,11 +38,11 @@ import {
38
38
  rejectMemory,
39
39
  setMemoryNote,
40
40
  statusFromConfidence
41
- } from "./chunk-I6FOUVJ6.js";
41
+ } from "./chunk-J3F3CLWL.js";
42
42
  import {
43
43
  asc,
44
44
  desc
45
- } from "./chunk-7MBCHU7J.js";
45
+ } from "./chunk-URQEUH7T.js";
46
46
  import {
47
47
  BACKGROUND_INDEX_BATCH_SIZE,
48
48
  CONFIDENCE,
@@ -67,11 +67,11 @@ import {
67
67
  resolveProvider,
68
68
  retrievalText,
69
69
  tagActivitySource
70
- } from "./chunk-TKBPDASJ.js";
70
+ } from "./chunk-QKGE74LD.js";
71
71
  import {
72
72
  hasProviderConfigured,
73
73
  init_keychain
74
- } from "./chunk-X2DPMIBG.js";
74
+ } from "./chunk-QOMNHKYE.js";
75
75
  import {
76
76
  Column,
77
77
  Columns,
@@ -121,6 +121,7 @@ import {
121
121
  mapUpdateSet,
122
122
  memories,
123
123
  memoryEntities,
124
+ memoryInjections,
124
125
  memoryMaintenanceTasks,
125
126
  memoryValueEvents,
126
127
  ne,
@@ -135,10 +136,10 @@ import {
135
136
  policyRules,
136
137
  schema_exports,
137
138
  sql
138
- } from "./chunk-QRI6W7FJ.js";
139
+ } from "./chunk-BOUMOPKD.js";
139
140
  import {
140
141
  init_define_RECALL_BUILD_INFO
141
- } from "./chunk-UVP6BVRD.js";
142
+ } from "./chunk-VV2QPDAM.js";
142
143
 
143
144
  // src/db/client.ts
144
145
  init_define_RECALL_BUILD_INFO();
@@ -1709,7 +1710,7 @@ var SQLiteSelectQueryBuilderBase = class extends TypedQueryBuilder {
1709
1710
  const baseTableName = this.tableName;
1710
1711
  const tableName = getTableLikeName(table);
1711
1712
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
1712
- if (typeof tableName === "string" && this.config.joins?.some((join4) => join4.alias === tableName)) {
1713
+ if (typeof tableName === "string" && this.config.joins?.some((join5) => join5.alias === tableName)) {
1713
1714
  throw new Error(`Alias "${tableName}" is already used in this query`);
1714
1715
  }
1715
1716
  if (!this.isPartialSelect) {
@@ -2569,7 +2570,7 @@ var SQLiteUpdateBase = class extends QueryPromise {
2569
2570
  createJoin(joinType) {
2570
2571
  return (table, on) => {
2571
2572
  const tableName = getTableLikeName(table);
2572
- if (typeof tableName === "string" && this.config.joins.some((join4) => join4.alias === tableName)) {
2573
+ if (typeof tableName === "string" && this.config.joins.some((join5) => join5.alias === tableName)) {
2573
2574
  throw new Error(`Alias "${tableName}" is already used in this query`);
2574
2575
  }
2575
2576
  if (typeof on === "function") {
@@ -4346,12 +4347,131 @@ function makeGotcha(text, repo, file) {
4346
4347
 
4347
4348
  // src/repo/discovery.ts
4348
4349
  init_define_RECALL_BUILD_INFO();
4349
- import { existsSync as existsSync3, readdirSync } from "fs";
4350
+ import { existsSync as existsSync4, readdirSync } from "fs";
4350
4351
  import { execFileSync as execFileSync2 } from "child_process";
4351
- import { join as join3, resolve } from "path";
4352
+ import { join as join4, resolve as resolve2 } from "path";
4353
+
4354
+ // src/repo/git-root.ts
4355
+ init_define_RECALL_BUILD_INFO();
4356
+ import { existsSync as existsSync3, readFileSync, realpathSync, statSync as statSync2 } from "fs";
4357
+ import { homedir } from "os";
4358
+ import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
4359
+ var MAX_WALK_DEPTH = 64;
4360
+ var TEMP_RE = /\/(?:private\/)?(?:var\/folders\/[^/]+\/[^/]+\/T|tmp)(?:\/|$)/;
4361
+ var HOME_RE = /^\/(?:Users|home)\/[^/]+$/;
4362
+ function safeRealpath(path) {
4363
+ try {
4364
+ return realpathSync(path);
4365
+ } catch {
4366
+ return null;
4367
+ }
4368
+ }
4369
+ function isDirectory(path) {
4370
+ try {
4371
+ return statSync2(path).isDirectory();
4372
+ } catch {
4373
+ return false;
4374
+ }
4375
+ }
4376
+ function isFile(path) {
4377
+ try {
4378
+ return statSync2(path).isFile();
4379
+ } catch {
4380
+ return false;
4381
+ }
4382
+ }
4383
+ function readTrimmed(path) {
4384
+ try {
4385
+ return readFileSync(path, "utf-8").trim();
4386
+ } catch {
4387
+ return null;
4388
+ }
4389
+ }
4390
+ function resolveCommonDir(gitDir) {
4391
+ const pointer = readTrimmed(join3(gitDir, "commondir"));
4392
+ if (!pointer) return gitDir;
4393
+ const common = isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
4394
+ return safeRealpath(common) ?? common;
4395
+ }
4396
+ function resolveGitEntry(root, entry) {
4397
+ if (isDirectory(entry)) {
4398
+ const gitDir2 = safeRealpath(entry) ?? entry;
4399
+ return { gitDir: gitDir2, commonDir: resolveCommonDir(gitDir2) };
4400
+ }
4401
+ if (!isFile(entry)) return null;
4402
+ const match = readTrimmed(entry)?.match(/^gitdir:\s*(.+)$/m);
4403
+ if (!match) return null;
4404
+ const target = match[1].trim();
4405
+ const gitDirRaw = isAbsolute(target) ? target : resolve(root, target);
4406
+ if (!isDirectory(gitDirRaw)) return null;
4407
+ const gitDir = safeRealpath(gitDirRaw) ?? gitDirRaw;
4408
+ return { gitDir, commonDir: resolveCommonDir(gitDir) };
4409
+ }
4410
+ function findGitRoot(startPath) {
4411
+ const real = safeRealpath(startPath);
4412
+ if (!real) return null;
4413
+ let current = isDirectory(real) ? real : dirname2(real);
4414
+ for (let depth = 0; depth < MAX_WALK_DEPTH; depth += 1) {
4415
+ const entry = join3(current, ".git");
4416
+ if (existsSync3(entry)) {
4417
+ const resolved = resolveGitEntry(current, entry);
4418
+ if (resolved) return { root: current, ...resolved };
4419
+ }
4420
+ const parent = dirname2(current);
4421
+ if (parent === current) return null;
4422
+ current = parent;
4423
+ }
4424
+ return null;
4425
+ }
4426
+ function isInsideGitWorkTree(path) {
4427
+ return findGitRoot(path) !== null;
4428
+ }
4429
+ function parseRemoteUrl(config, remoteName) {
4430
+ let inRemote = false;
4431
+ for (const rawLine of config.split(/\r?\n/)) {
4432
+ const line = rawLine.trim();
4433
+ if (line.length === 0 || line.startsWith("#") || line.startsWith(";")) continue;
4434
+ const section = line.match(/^\[([^\]]+)\]$/);
4435
+ if (section) {
4436
+ const named = section[1].trim().match(/^remote\s+"(.+)"$/);
4437
+ inRemote = Boolean(named && named[1] === remoteName);
4438
+ continue;
4439
+ }
4440
+ if (!inRemote) continue;
4441
+ const url = line.match(/^url\s*=\s*(.+)$/);
4442
+ if (url) return url[1].trim().replace(/^"(.*)"$/, "$1");
4443
+ }
4444
+ return null;
4445
+ }
4446
+ function readOriginUrl(info) {
4447
+ const candidates = info.gitDir === info.commonDir ? [join3(info.gitDir, "config")] : [join3(info.gitDir, "config.worktree"), join3(info.gitDir, "config"), join3(info.commonDir, "config")];
4448
+ for (const file of candidates) {
4449
+ const content = readTrimmed(file);
4450
+ if (!content) continue;
4451
+ const url = parseRemoteUrl(content, "origin");
4452
+ if (url) return url;
4453
+ }
4454
+ return null;
4455
+ }
4456
+ function normalizeSlashes(path) {
4457
+ return path.replace(/\\/g, "/").replace(/\/+$/, "") || "/";
4458
+ }
4459
+ function isUnscopedSessionPath(repoPath) {
4460
+ const normalized = normalizeSlashes(repoPath.trim());
4461
+ if (normalized.length === 0) return true;
4462
+ if (TEMP_RE.test(normalized)) return !isInsideGitWorkTree(normalized);
4463
+ if (existsSync3(normalized)) return !isInsideGitWorkTree(normalized);
4464
+ if (normalized === "/" || HOME_RE.test(normalized)) return true;
4465
+ if (normalized === normalizeSlashes(process.env.HOME ?? homedir())) return true;
4466
+ if (/\/Projects$/i.test(normalized)) return true;
4467
+ if (/\/(?:Library|Applications)(?:\/|$)/.test(normalized)) return true;
4468
+ return false;
4469
+ }
4470
+
4471
+ // src/repo/discovery.ts
4352
4472
  var repoPathCache = /* @__PURE__ */ new Map();
4353
4473
  function runGit(args) {
4354
- const binaries = ["git", ...process.platform === "darwin" && existsSync3("/opt/homebrew/bin/git") ? ["/opt/homebrew/bin/git"] : []];
4474
+ const binaries = ["git", ...process.platform === "darwin" && existsSync4("/opt/homebrew/bin/git") ? ["/opt/homebrew/bin/git"] : []];
4355
4475
  let failure;
4356
4476
  for (const binary of binaries) {
4357
4477
  try {
@@ -4459,6 +4579,13 @@ function refreshKnownRepoScan(db, repo, repoPathHint) {
4459
4579
  function inferRepoSlugFromPath(repoPath) {
4460
4580
  const root = normalizeRepoPathHint(repoPath);
4461
4581
  if (!root) return null;
4582
+ const info = findGitRoot(root);
4583
+ const configured = info ? readOriginUrl(info) : null;
4584
+ const fromConfig = configured ? extractRepoSlugFromRemote2(configured) : null;
4585
+ if (fromConfig) return fromConfig;
4586
+ if (process.env.RECALL_DISTRIBUTION === "mac-app-store") {
4587
+ return root.split("/").at(-1) ?? null;
4588
+ }
4462
4589
  try {
4463
4590
  const remote = runGit(["-C", root, "remote", "get-url", "origin"]);
4464
4591
  return extractRepoSlugFromRemote2(remote);
@@ -4499,32 +4626,34 @@ function normalizeRepoSlug(repo) {
4499
4626
  function normalizeRepoPathHint(repoPath) {
4500
4627
  if (!repoPath) return null;
4501
4628
  const expanded = repoPath.trim().replace(/^~(?=\/)/, process.env.HOME ?? "~");
4629
+ if (process.env.RECALL_DISTRIBUTION === "mac-app-store") {
4630
+ return findGitRoot(resolve2(expanded))?.root ?? null;
4631
+ }
4502
4632
  try {
4503
4633
  const root = runGit(["-C", expanded, "rev-parse", "--show-toplevel"]);
4504
4634
  return root || null;
4505
4635
  } catch {
4506
- const resolved = resolve(expanded);
4507
- return existsSync3(join3(resolved, ".git")) ? resolved : null;
4636
+ return findGitRoot(resolve2(expanded))?.root ?? null;
4508
4637
  }
4509
4638
  }
4510
4639
  function getDefaultSearchRoots() {
4511
4640
  const configured = process.env.RECALL_REPO_ROOTS?.split(",").map((value) => value.trim()).filter(Boolean);
4512
4641
  if (configured?.length) return configured;
4513
4642
  const home = process.env.HOME ?? process.cwd();
4514
- return [join3(home, "Projects")];
4643
+ return [join4(home, "Projects")];
4515
4644
  }
4516
4645
  function collectCandidateRepos(searchRoots) {
4517
4646
  const seen = /* @__PURE__ */ new Set();
4518
4647
  const repos = [];
4519
4648
  for (const root of searchRoots) {
4520
- walkRepos(resolve(root), 4, seen, repos);
4649
+ walkRepos(resolve2(root), 4, seen, repos);
4521
4650
  }
4522
4651
  return repos;
4523
4652
  }
4524
4653
  function walkRepos(dir, depthRemaining, seen, repos) {
4525
- if (depthRemaining < 0 || seen.has(dir) || !existsSync3(dir)) return;
4654
+ if (depthRemaining < 0 || seen.has(dir) || !existsSync4(dir)) return;
4526
4655
  seen.add(dir);
4527
- if (existsSync3(join3(dir, ".git"))) {
4656
+ if (existsSync4(join4(dir, ".git"))) {
4528
4657
  repos.push(dir);
4529
4658
  return;
4530
4659
  }
@@ -4537,7 +4666,7 @@ function walkRepos(dir, depthRemaining, seen, repos) {
4537
4666
  for (const entry of entries) {
4538
4667
  if (!entry.isDirectory()) continue;
4539
4668
  if (SKIP_DIRS.has(entry.name)) continue;
4540
- walkRepos(join3(dir, entry.name), depthRemaining - 1, seen, repos);
4669
+ walkRepos(join4(dir, entry.name), depthRemaining - 1, seen, repos);
4541
4670
  }
4542
4671
  }
4543
4672
 
@@ -4652,6 +4781,119 @@ function endSessionLifecycle(db, input) {
4652
4781
  };
4653
4782
  }
4654
4783
 
4784
+ // src/mcp/fallback.ts
4785
+ init_define_RECALL_BUILD_INFO();
4786
+ function attachNote(db, ids, affects) {
4787
+ if (!affects?.trim()) return;
4788
+ for (const id of ids) {
4789
+ if (!getMemory(db, id)?.note) setMemoryNote(db, id, affects);
4790
+ }
4791
+ }
4792
+ async function captureCorrectionFallback(db, input, source) {
4793
+ const sessionId = input.session_id ?? `${source}-capture`;
4794
+ const { ids, pendingTaskId, blockedByRejectedExemplar } = await processCorrection(db, input.text, {
4795
+ sessionId,
4796
+ repo: input.repo,
4797
+ path: input.path,
4798
+ agent: input.agent,
4799
+ prev_assistant_turn: input.prev_assistant_turn,
4800
+ recent_tool_calls: input.recent_tool_calls,
4801
+ force_semantic_capture: true,
4802
+ affects: input.affects
4803
+ });
4804
+ attachNote(db, ids, input.affects);
4805
+ createActivityEvent(db, {
4806
+ session_id: sessionId,
4807
+ repo: input.repo ?? null,
4808
+ path: input.path ?? null,
4809
+ source,
4810
+ event_type: "correction",
4811
+ memory_ids: ids,
4812
+ request: {
4813
+ agent: input.agent ?? null,
4814
+ prev_assistant_turn: input.prev_assistant_turn ?? null,
4815
+ recent_tool_calls: normalizeRecentToolCalls(input.recent_tool_calls),
4816
+ text: input.text
4817
+ },
4818
+ result: {
4819
+ created: ids,
4820
+ created_count: ids.length,
4821
+ pending_task_id: pendingTaskId ?? null
4822
+ }
4823
+ });
4824
+ return {
4825
+ ids,
4826
+ session_id: sessionId,
4827
+ pendingTaskId,
4828
+ blockedByRejectedExemplar
4829
+ };
4830
+ }
4831
+ function signalOutcomeFallback(db, input, source) {
4832
+ const feedbackId = recordFeedback(
4833
+ db,
4834
+ input.memory_id,
4835
+ input.session_id,
4836
+ input.injected ?? true,
4837
+ input.outcome
4838
+ );
4839
+ resolveMemoryInjectionOutcome(db, input.memory_id, input.session_id, input.outcome);
4840
+ recordOutcomeValueEvent(db, {
4841
+ memory_id: input.memory_id,
4842
+ session_id: input.session_id,
4843
+ injected: input.injected ?? true,
4844
+ outcome: input.outcome,
4845
+ feedback_id: feedbackId,
4846
+ context: input.context,
4847
+ source
4848
+ });
4849
+ const memory = getMemory(db, input.memory_id);
4850
+ createActivityEvent(db, {
4851
+ session_id: input.session_id,
4852
+ repo: memory?.repo ?? null,
4853
+ path: memory?.path_scope ?? null,
4854
+ source,
4855
+ event_type: "feedback",
4856
+ memory_ids: [input.memory_id],
4857
+ request: {
4858
+ context: input.context ?? null,
4859
+ injected: input.injected ?? true,
4860
+ outcome: input.outcome
4861
+ },
4862
+ result: {
4863
+ feedback_id: feedbackId
4864
+ }
4865
+ });
4866
+ return {
4867
+ feedback_id: feedbackId
4868
+ };
4869
+ }
4870
+ function sessionEndFallback(db, input) {
4871
+ const result = endSessionLifecycle(db, {
4872
+ session_id: input.session_id,
4873
+ client: input.agent ?? "mcp",
4874
+ repo: input.repo ?? null,
4875
+ repo_path: input.repo_path ?? null,
4876
+ path: input.path ?? null,
4877
+ payload: {
4878
+ ended_at: (/* @__PURE__ */ new Date()).toISOString(),
4879
+ turn_count: input.turn_count ?? null
4880
+ }
4881
+ });
4882
+ return {
4883
+ session_id: result.session_id,
4884
+ repo: result.repo
4885
+ };
4886
+ }
4887
+ function normalizeRecentToolCalls(toolCalls) {
4888
+ if (!toolCalls) return [];
4889
+ return toolCalls.map((toolCall) => ({
4890
+ name: toolCall.name,
4891
+ path: toolCall.path,
4892
+ input_summary: toolCall.input_summary,
4893
+ exit_code: toolCall.exit_code
4894
+ }));
4895
+ }
4896
+
4655
4897
  // src/history/snippets.ts
4656
4898
  init_define_RECALL_BUILD_INFO();
4657
4899
  import { randomUUID as randomUUID2 } from "crypto";
@@ -5326,7 +5568,7 @@ async function callJudge(db, query, memories4) {
5326
5568
  json_output: true,
5327
5569
  task_kind: "relevance_judge"
5328
5570
  }).then((result) => parseGrades(result.text, memories4));
5329
- const timeout = new Promise((resolve2) => setTimeout(() => resolve2(null), timeoutMs()).unref());
5571
+ const timeout = new Promise((resolve3) => setTimeout(() => resolve3(null), timeoutMs()).unref());
5330
5572
  return Promise.race([call.catch(() => null), timeout]);
5331
5573
  }
5332
5574
  async function judgeRelevance(db, query, memories4) {
@@ -6128,9 +6370,9 @@ function formatMetricsReport(metrics) {
6128
6370
 
6129
6371
  // src/eval/retrieval.ts
6130
6372
  init_define_RECALL_BUILD_INFO();
6131
- import { readFileSync } from "fs";
6373
+ import { readFileSync as readFileSync2 } from "fs";
6132
6374
  function loadRetrievalEvalFile(path) {
6133
- return RetrievalEvalFile.parse(JSON.parse(readFileSync(path, "utf8")));
6375
+ return RetrievalEvalFile.parse(JSON.parse(readFileSync2(path, "utf8")));
6134
6376
  }
6135
6377
  async function runRetrievalEval(db, input, options = {}) {
6136
6378
  const providers = options.providers?.length ? options.providers : ["current"];
@@ -6677,6 +6919,67 @@ function rowToPolicy(row) {
6677
6919
 
6678
6920
  // src/pruning/pruner.ts
6679
6921
  init_define_RECALL_BUILD_INFO();
6922
+
6923
+ // src/pruning/loop-activity.ts
6924
+ init_define_RECALL_BUILD_INFO();
6925
+ var DAY_MS = 864e5;
6926
+ function repoCondition(db, repo) {
6927
+ if (!repo) return void 0;
6928
+ return inArray(memoryInjections.repo, memoryRepoAliases(db, repo));
6929
+ }
6930
+ function isInjectionLoopAlive(db, query) {
6931
+ const row = db.select({ id: memoryInjections.id }).from(memoryInjections).where(and(gte(memoryInjections.injected_at, query.sinceIso), repoCondition(db, query.repo))).limit(1).get();
6932
+ return Boolean(row);
6933
+ }
6934
+ function defaultMaxGapDays(windowDays) {
6935
+ return Math.min(7, Math.max(1, Math.floor(windowDays / 2)));
6936
+ }
6937
+ function isInjectionLoopCovering(db, query) {
6938
+ const startMs = Date.parse(query.sinceIso);
6939
+ const endMs = Date.parse(query.untilIso);
6940
+ if (!Number.isFinite(startMs) || !Number.isFinite(endMs)) return false;
6941
+ if (endMs <= startMs) return true;
6942
+ if (!isInjectionLoopAlive(db, query)) return false;
6943
+ const windowDays = (endMs - startMs) / DAY_MS;
6944
+ const maxGapMs = (query.maxGapDays ?? defaultMaxGapDays(windowDays)) * DAY_MS;
6945
+ const days = db.select({
6946
+ first: sql`min(${memoryInjections.injected_at})`,
6947
+ last: sql`max(${memoryInjections.injected_at})`
6948
+ }).from(memoryInjections).where(and(
6949
+ gte(memoryInjections.injected_at, query.sinceIso),
6950
+ lte(memoryInjections.injected_at, query.untilIso),
6951
+ repoCondition(db, query.repo)
6952
+ )).groupBy(sql`substr(${memoryInjections.injected_at}, 1, 10)`).orderBy(sql`substr(${memoryInjections.injected_at}, 1, 10)`).all();
6953
+ if (days.length === 0) return false;
6954
+ let previous = startMs;
6955
+ for (const day of days) {
6956
+ if (Date.parse(day.first) - previous > maxGapMs) return false;
6957
+ previous = Date.parse(day.last);
6958
+ }
6959
+ return endMs - previous <= maxGapMs;
6960
+ }
6961
+ function createLoopCoverageCache(db) {
6962
+ const cache2 = /* @__PURE__ */ new Map();
6963
+ return (repo, sinceIso, untilIso) => {
6964
+ const key = `${repo ?? "\0any"}|${sinceIso}|${untilIso}`;
6965
+ let covered = cache2.get(key);
6966
+ if (covered === void 0) {
6967
+ covered = isInjectionLoopCovering(db, { repo, sinceIso, untilIso });
6968
+ cache2.set(key, covered);
6969
+ }
6970
+ return covered;
6971
+ };
6972
+ }
6973
+ function loopRepoForMemory(memory) {
6974
+ return memory.scope === "global" ? null : memory.repo;
6975
+ }
6976
+ function loadInjectedMemoryIds(db) {
6977
+ return new Set(
6978
+ db.selectDistinct({ memory_id: memoryInjections.memory_id }).from(memoryInjections).all().map((row) => row.memory_id)
6979
+ );
6980
+ }
6981
+
6982
+ // src/pruning/pruner.ts
6680
6983
  var DEFAULT_CONFIG2 = {
6681
6984
  candidate_unconfirmed_days: 30,
6682
6985
  stale_days: 90,
@@ -6694,23 +6997,34 @@ function pruneMemories(db, config = {}) {
6694
6997
  const dayMs = 864e5;
6695
6998
  const result = {
6696
6999
  unconfirmed_archived: [],
7000
+ unconfirmed_skipped_loop_inactive: [],
6697
7001
  stale_archived: [],
7002
+ stale_skipped_loop_inactive: [],
6698
7003
  rejected_pruned: [],
6699
7004
  transient_pruned: [],
6700
7005
  unhealthy_demoted: [],
6701
7006
  total: 0
6702
7007
  };
7008
+ const nowIso = new Date(now2).toISOString();
7009
+ const loopCovered = createLoopCoverageCache(db);
6703
7010
  const unconfirmedCutoff = new Date(
6704
7011
  now2 - cfg.candidate_unconfirmed_days * dayMs
6705
7012
  ).toISOString();
7013
+ const selected = loadInjectedMemoryIds(db);
6706
7014
  const unconfirmed = queryMemories(db, {
6707
7015
  repo: cfg.repo,
6708
7016
  status: "candidate",
6709
7017
  auto_inject: true
6710
7018
  }).filter(
6711
- (mem) => mem.created_at < unconfirmedCutoff && mem.repetition_count < 2 && mem.injection_count === 0
7019
+ (mem) => mem.created_at < unconfirmedCutoff && mem.repetition_count < 2 && mem.injection_count === 0 && !selected.has(mem.id)
6712
7020
  );
7021
+ const skippedLoopInactive = /* @__PURE__ */ new Set();
6713
7022
  for (const mem of unconfirmed) {
7023
+ if (!loopCovered(loopRepoForMemory(mem), unconfirmedCutoff, nowIso)) {
7024
+ result.unconfirmed_skipped_loop_inactive.push(mem.id);
7025
+ skippedLoopInactive.add(mem.id);
7026
+ continue;
7027
+ }
6714
7028
  if (!cfg.dry_run) {
6715
7029
  db.update(memories).set({ auto_inject: false, updated_at: (/* @__PURE__ */ new Date()).toISOString() }).where(eq(memories.id, mem.id)).run();
6716
7030
  recordAudit(
@@ -6730,8 +7044,13 @@ function pruneMemories(db, config = {}) {
6730
7044
  }).filter((mem) => mem.status !== "rejected" && mem.status !== "transient");
6731
7045
  for (const mem of staleCandidates) {
6732
7046
  if (result.unconfirmed_archived.includes(mem.id)) continue;
7047
+ if (skippedLoopInactive.has(mem.id)) continue;
6733
7048
  const lastActivity = mem.last_validated_at ?? mem.last_injected_at ?? mem.updated_at;
6734
7049
  if (lastActivity < staleCutoff && mem.auto_inject) {
7050
+ if (mem.status === "candidate" && !loopCovered(loopRepoForMemory(mem), staleCutoff, nowIso)) {
7051
+ result.stale_skipped_loop_inactive.push(mem.id);
7052
+ continue;
7053
+ }
6735
7054
  if (!cfg.dry_run) {
6736
7055
  db.update(memories).set({ auto_inject: false, updated_at: (/* @__PURE__ */ new Date()).toISOString() }).where(eq(memories.id, mem.id)).run();
6737
7056
  recordAudit(
@@ -6822,7 +7141,9 @@ function formatPruneReport(result, dryRun) {
6822
7141
  `${prefix}Prune Report`,
6823
7142
  ``,
6824
7143
  `Unconfirmed archived:${String(result.unconfirmed_archived.length).padStart(5)}`,
7144
+ `Unconfirmed skipped (loop inactive): ${result.unconfirmed_skipped_loop_inactive?.length ?? 0}`,
6825
7145
  `Stale archived: ${result.stale_archived.length}`,
7146
+ `Stale skipped (loop inactive): ${result.stale_skipped_loop_inactive?.length ?? 0}`,
6826
7147
  `Rejected pruned: ${result.rejected_pruned.length}`,
6827
7148
  `Transient pruned: ${result.transient_pruned.length}`,
6828
7149
  `Unhealthy demoted: ${result.unhealthy_demoted.length}`,
@@ -6843,119 +7164,6 @@ function formatPruneReport(result, dryRun) {
6843
7164
  return lines.join("\n");
6844
7165
  }
6845
7166
 
6846
- // src/mcp/fallback.ts
6847
- init_define_RECALL_BUILD_INFO();
6848
- function attachNote(db, ids, affects) {
6849
- if (!affects?.trim()) return;
6850
- for (const id of ids) {
6851
- if (!getMemory(db, id)?.note) setMemoryNote(db, id, affects);
6852
- }
6853
- }
6854
- async function captureCorrectionFallback(db, input, source) {
6855
- const sessionId = input.session_id ?? `${source}-capture`;
6856
- const { ids, pendingTaskId, blockedByRejectedExemplar } = await processCorrection(db, input.text, {
6857
- sessionId,
6858
- repo: input.repo,
6859
- path: input.path,
6860
- agent: input.agent,
6861
- prev_assistant_turn: input.prev_assistant_turn,
6862
- recent_tool_calls: input.recent_tool_calls,
6863
- force_semantic_capture: true,
6864
- affects: input.affects
6865
- });
6866
- attachNote(db, ids, input.affects);
6867
- createActivityEvent(db, {
6868
- session_id: sessionId,
6869
- repo: input.repo ?? null,
6870
- path: input.path ?? null,
6871
- source,
6872
- event_type: "correction",
6873
- memory_ids: ids,
6874
- request: {
6875
- agent: input.agent ?? null,
6876
- prev_assistant_turn: input.prev_assistant_turn ?? null,
6877
- recent_tool_calls: normalizeRecentToolCalls(input.recent_tool_calls),
6878
- text: input.text
6879
- },
6880
- result: {
6881
- created: ids,
6882
- created_count: ids.length,
6883
- pending_task_id: pendingTaskId ?? null
6884
- }
6885
- });
6886
- return {
6887
- ids,
6888
- session_id: sessionId,
6889
- pendingTaskId,
6890
- blockedByRejectedExemplar
6891
- };
6892
- }
6893
- function signalOutcomeFallback(db, input, source) {
6894
- const feedbackId = recordFeedback(
6895
- db,
6896
- input.memory_id,
6897
- input.session_id,
6898
- input.injected ?? true,
6899
- input.outcome
6900
- );
6901
- resolveMemoryInjectionOutcome(db, input.memory_id, input.session_id, input.outcome);
6902
- recordOutcomeValueEvent(db, {
6903
- memory_id: input.memory_id,
6904
- session_id: input.session_id,
6905
- injected: input.injected ?? true,
6906
- outcome: input.outcome,
6907
- feedback_id: feedbackId,
6908
- context: input.context,
6909
- source
6910
- });
6911
- const memory = getMemory(db, input.memory_id);
6912
- createActivityEvent(db, {
6913
- session_id: input.session_id,
6914
- repo: memory?.repo ?? null,
6915
- path: memory?.path_scope ?? null,
6916
- source,
6917
- event_type: "feedback",
6918
- memory_ids: [input.memory_id],
6919
- request: {
6920
- context: input.context ?? null,
6921
- injected: input.injected ?? true,
6922
- outcome: input.outcome
6923
- },
6924
- result: {
6925
- feedback_id: feedbackId
6926
- }
6927
- });
6928
- return {
6929
- feedback_id: feedbackId
6930
- };
6931
- }
6932
- function sessionEndFallback(db, input) {
6933
- const result = endSessionLifecycle(db, {
6934
- session_id: input.session_id,
6935
- client: input.agent ?? "mcp",
6936
- repo: input.repo ?? null,
6937
- repo_path: input.repo_path ?? null,
6938
- path: input.path ?? null,
6939
- payload: {
6940
- ended_at: (/* @__PURE__ */ new Date()).toISOString(),
6941
- turn_count: input.turn_count ?? null
6942
- }
6943
- });
6944
- return {
6945
- session_id: result.session_id,
6946
- repo: result.repo
6947
- };
6948
- }
6949
- function normalizeRecentToolCalls(toolCalls) {
6950
- if (!toolCalls) return [];
6951
- return toolCalls.map((toolCall) => ({
6952
- name: toolCall.name,
6953
- path: toolCall.path,
6954
- input_summary: toolCall.input_summary,
6955
- exit_code: toolCall.exit_code
6956
- }));
6957
- }
6958
-
6959
7167
  export {
6960
7168
  RECALL_DB_USER_VERSION,
6961
7169
  getDbPath,
@@ -6968,6 +7176,7 @@ export {
6968
7176
  listActivityEvents,
6969
7177
  listActivitySessions,
6970
7178
  scanAndStore,
7179
+ isUnscopedSessionPath,
6971
7180
  ensureRepoBootstrapped,
6972
7181
  resolveLocalRepoPath,
6973
7182
  inferRepoSlugFromPath,
@@ -7013,7 +7222,10 @@ export {
7013
7222
  requestApproval,
7014
7223
  resolveApproval,
7015
7224
  listPendingApprovals,
7225
+ createLoopCoverageCache,
7226
+ loopRepoForMemory,
7227
+ loadInjectedMemoryIds,
7016
7228
  pruneMemories,
7017
7229
  formatPruneReport
7018
7230
  };
7019
- //# sourceMappingURL=chunk-5AM6YJ23.js.map
7231
+ //# sourceMappingURL=chunk-HYDNV5T2.js.map