@edihasaj/recall 0.6.2 → 0.6.4

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.
@@ -20,7 +20,7 @@ import {
20
20
 
21
21
  // src/maintenance/tasks.ts
22
22
  import { and as and4, desc as desc2, eq as eq11, gt, inArray as inArray3, lt, or, isNull, sql as sql3 } from "drizzle-orm";
23
- import { randomUUID as randomUUID8 } from "crypto";
23
+ import { randomUUID as randomUUID7 } from "crypto";
24
24
  import { z as z2 } from "zod";
25
25
 
26
26
  // src/embeddings/embeddings.ts
@@ -998,9 +998,9 @@ function shouldIndexLexically(memory) {
998
998
  return memory.status !== "rejected" && memory.status !== "transient";
999
999
  }
1000
1000
  function buildFtsQuery(query) {
1001
- const tokens = query.match(/[A-Za-z0-9_.:/-]+/g)?.map((token) => token.replace(/"/g, '""')).filter(Boolean) ?? [];
1002
- if (tokens.length === 0) return null;
1003
- return tokens.map((token) => `"${token}"`).join(" ");
1001
+ const tokens2 = query.match(/[A-Za-z0-9_.:/-]+/g)?.map((token) => token.replace(/"/g, '""')).filter(Boolean) ?? [];
1002
+ if (tokens2.length === 0) return null;
1003
+ return tokens2.map((token) => `"${token}"`).join(" ");
1004
1004
  }
1005
1005
  function ensureMemoryFtsIndex(db) {
1006
1006
  const sqlite = getSqlite2(db);
@@ -1548,7 +1548,7 @@ function rowToMemory(row) {
1548
1548
 
1549
1549
  // src/maintenance/appliers.ts
1550
1550
  import { eq as eq10 } from "drizzle-orm";
1551
- import { randomUUID as randomUUID7 } from "crypto";
1551
+ import { randomUUID as randomUUID6 } from "crypto";
1552
1552
 
1553
1553
  // src/models/memory.ts
1554
1554
  import { eq as eq4, and, gte, inArray, like, sql } from "drizzle-orm";
@@ -2845,16 +2845,16 @@ function formatDispatchReport(report) {
2845
2845
  lines.push("", "## Outcomes");
2846
2846
  for (const o of report.outcomes) {
2847
2847
  const cost = o.cost_usd != null ? ` $${o.cost_usd.toFixed(4)}` : "";
2848
- const tokens = o.prompt_tokens != null ? ` tokens=${(o.prompt_tokens ?? 0) + (o.completion_tokens ?? 0)}` : "";
2848
+ const tokens2 = o.prompt_tokens != null ? ` tokens=${(o.prompt_tokens ?? 0) + (o.completion_tokens ?? 0)}` : "";
2849
2849
  const reason = o.reason ? ` \u2014 ${o.reason}` : "";
2850
- lines.push(` ${o.task_id.slice(0, 8)} ${o.kind.padEnd(20)} ${o.status.padEnd(10)}${tokens}${cost}${reason}`);
2850
+ lines.push(` ${o.task_id.slice(0, 8)} ${o.kind.padEnd(20)} ${o.status.padEnd(10)}${tokens2}${cost}${reason}`);
2851
2851
  }
2852
2852
  }
2853
2853
  return lines.join("\n");
2854
2854
  }
2855
2855
 
2856
2856
  // src/capture/correction.ts
2857
- import { randomUUID as randomUUID6 } from "crypto";
2857
+ import { createHash as createHash2 } from "crypto";
2858
2858
 
2859
2859
  // src/capture/scope.ts
2860
2860
  import { execSync } from "child_process";
@@ -3994,6 +3994,32 @@ function truncate(s, n) {
3994
3994
  return s.slice(0, n - 1) + "\u2026";
3995
3995
  }
3996
3996
 
3997
+ // src/security/redaction.ts
3998
+ var SECRET_PATTERNS = [
3999
+ [/\b(Authorization\s*:\s*Bearer\s+)[^\s"'\\]+/gi, "$1[REDACTED]"],
4000
+ [/\b(api-key\s*:\s*)[^\s"'\\]+/gi, "$1[REDACTED]"],
4001
+ [/\b((?:OPENAI|ANTHROPIC|AZURE|RECALL|AWS|GITHUB|GH|NPM|PYPI|SLACK|STRIPE|DATABASE)[A-Z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD)\s*=\s*)(?:"[^"]*"|'[^']*'|[^\s"'\\]+)/gi, "$1[REDACTED]"],
4002
+ [/\b(--(?:api-?key|token|secret|password)\s+)(?:"[^"]*"|'[^']*'|[^\s"'\\]+)/gi, "$1[REDACTED]"],
4003
+ [/\b(sk-[A-Za-z0-9_-]{12,})\b/g, "[REDACTED]"],
4004
+ [/\b(gh[pousr]_[A-Za-z0-9_]{12,})\b/g, "[REDACTED]"]
4005
+ ];
4006
+ function redactSensitiveText(text) {
4007
+ return SECRET_PATTERNS.reduce(
4008
+ (current, [pattern, replacement]) => current.replace(pattern, replacement),
4009
+ text
4010
+ );
4011
+ }
4012
+ function redactSensitiveValue(value) {
4013
+ if (typeof value === "string") return redactSensitiveText(value);
4014
+ if (Array.isArray(value)) return value.map(redactSensitiveValue);
4015
+ if (!value || typeof value !== "object") return value;
4016
+ const out = {};
4017
+ for (const [key, entry] of Object.entries(value)) {
4018
+ out[key] = redactSensitiveValue(entry);
4019
+ }
4020
+ return out;
4021
+ }
4022
+
3997
4023
  // src/capture/correction.ts
3998
4024
  var NEGATION_REPLACEMENT = /\b(?:not|don't|do not|never|stop)\s+(?:use|do|run|call|import)\s+(.+?)[\s,;.]+(?:use|do|run|call|import|instead)\s+(.+)/i;
3999
4025
  var EXPLICIT_RULE = /\b(always|never|must|required|forbidden|don't ever)\b\s+(.+)/i;
@@ -4182,8 +4208,9 @@ function isDurableDecision(segment, first, second) {
4182
4208
  return DURABLE_DECISION_HINT.test(haystack);
4183
4209
  }
4184
4210
  async function processCorrection(db, text, ctx) {
4211
+ text = redactSensitiveText(text);
4185
4212
  if (process.env.RECALL_LLM_CAPTURE_DISABLED !== "true" && hasAnyLlmProvider() && isPromptWorthLLM(text)) {
4186
- const promptId = `prompt:${ctx.sessionId}:${Date.now()}:${randomUUID6().slice(0, 8)}`;
4213
+ const promptId = stablePromptId(ctx.sessionId, ctx.repo, text);
4187
4214
  const taskId = enqueueExtractRulesFromPrompt(db, {
4188
4215
  prompt_id: promptId,
4189
4216
  raw_prompt: text,
@@ -4290,6 +4317,10 @@ async function processCorrection(db, text, ctx) {
4290
4317
  }
4291
4318
  return ids;
4292
4319
  }
4320
+ function stablePromptId(sessionId, repo, text) {
4321
+ const hash = createHash2("sha256").update(`${sessionId}${repo ?? ""}${normalizeDedupeText(text)}`).digest("hex").slice(0, 16);
4322
+ return `prompt:${sessionId}:${hash}`;
4323
+ }
4293
4324
  function maybePromoteGroupCandidate(db, candidateId) {
4294
4325
  const candidate = getMemory(db, candidateId);
4295
4326
  if (!candidate || candidate.status !== "candidate") return;
@@ -4337,6 +4368,7 @@ function extractContextPath(text) {
4337
4368
  return match?.[1];
4338
4369
  }
4339
4370
  async function processReviewFeedback(db, feedback, ctx) {
4371
+ feedback = redactSensitiveText(feedback);
4340
4372
  const profile = getRepoQualityProfile(db, ctx.repo);
4341
4373
  const evidence = {
4342
4374
  type: "review_feedback",
@@ -4643,7 +4675,7 @@ function applySummarizeSession(db, task, result) {
4643
4675
  const payload = task.payload;
4644
4676
  const sessionId = payload.session_id;
4645
4677
  if (!sessionId) throw new ApplyError("payload missing session_id", "invalid-state");
4646
- const id = randomUUID7();
4678
+ const id = randomUUID6();
4647
4679
  const now = (/* @__PURE__ */ new Date()).toISOString();
4648
4680
  db.insert(historySnippets).values({
4649
4681
  id,
@@ -4661,7 +4693,7 @@ function applySynthesizeRepo(db, task, result) {
4661
4693
  const payload = task.payload;
4662
4694
  const repo = payload.repo;
4663
4695
  if (!repo) throw new ApplyError("payload missing repo", "invalid-state");
4664
- const id = randomUUID7();
4696
+ const id = randomUUID6();
4665
4697
  const now = (/* @__PURE__ */ new Date()).toISOString();
4666
4698
  db.insert(historySnippets).values({
4667
4699
  id,
@@ -4733,20 +4765,37 @@ function applyExtractRulesFromPrompt(db, task, result) {
4733
4765
  }
4734
4766
  function existsSimilar(db, repo, rule) {
4735
4767
  if (!repo) return false;
4736
- const candidates = queryMemories(db, { repo: repo ?? void 0, type: rule.type }).filter((memory) => memory.status !== "rejected");
4768
+ const ruleIsHighRisk = rule.is_destructive_risky || isHighRiskRule(rule.text);
4769
+ const candidates = queryMemories(db, {
4770
+ repo: repo ?? void 0,
4771
+ ...ruleIsHighRisk ? {} : { type: rule.type }
4772
+ }).filter((memory) => memory.status !== "rejected");
4737
4773
  const normalized = rule.text.toLowerCase().trim();
4738
4774
  return candidates.some((memory) => {
4739
4775
  if (memory.text.toLowerCase().trim() === normalized) return true;
4776
+ if (ruleIsHighRisk && isHighRiskRule(memory.text)) {
4777
+ return containmentOverlap(memory.text, rule.text) >= 0.65;
4778
+ }
4740
4779
  return jaccard(memory.text, rule.text) >= 0.85;
4741
4780
  });
4742
4781
  }
4743
4782
  function jaccard(a, b) {
4744
- const wordsA = new Set(a.toLowerCase().split(/\s+/));
4745
- const wordsB = new Set(b.toLowerCase().split(/\s+/));
4783
+ const wordsA = new Set(tokens(a));
4784
+ const wordsB = new Set(tokens(b));
4746
4785
  const intersection = [...wordsA].filter((w) => wordsB.has(w));
4747
4786
  const union = /* @__PURE__ */ new Set([...wordsA, ...wordsB]);
4748
4787
  return union.size === 0 ? 0 : intersection.length / union.size;
4749
4788
  }
4789
+ function containmentOverlap(a, b) {
4790
+ const wordsA = new Set(tokens(a));
4791
+ const wordsB = new Set(tokens(b));
4792
+ const intersection = [...wordsA].filter((w) => wordsB.has(w));
4793
+ const smaller = Math.min(wordsA.size, wordsB.size);
4794
+ return smaller === 0 ? 0 : intersection.length / smaller;
4795
+ }
4796
+ function tokens(text) {
4797
+ return text.toLowerCase().match(/[a-z0-9.]+/g) ?? [];
4798
+ }
4750
4799
  function applyTaskResult(db, task, result) {
4751
4800
  switch (task.kind) {
4752
4801
  case "verify_capture":
@@ -4831,7 +4880,7 @@ function hasActiveTaskForTarget(db, kind, target) {
4831
4880
  }
4832
4881
  function insertTaskIdempotent(db, input) {
4833
4882
  if (hasActiveTaskForTarget(db, input.kind, input.target)) return null;
4834
- const id = randomUUID8();
4883
+ const id = randomUUID7();
4835
4884
  db.insert(memoryMaintenanceTasks).values({
4836
4885
  id,
4837
4886
  kind: input.kind,
@@ -5511,10 +5560,12 @@ export {
5511
5560
  revertCleanupRun,
5512
5561
  listCleanupRuns,
5513
5562
  formatCleanupReport,
5563
+ redactSensitiveText,
5564
+ redactSensitiveValue,
5514
5565
  isTriggerTemplateRule,
5515
5566
  isHighRiskRule,
5516
5567
  detectCorrections,
5517
5568
  processCorrection,
5518
5569
  processReviewFeedback
5519
5570
  };
5520
- //# sourceMappingURL=chunk-32CTFWA6.js.map
5571
+ //# sourceMappingURL=chunk-LFWG3CBM.js.map