@edihasaj/recall 1.3.1 → 1.4.1
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.
- package/dist/{chunk-ZXLAD4CS.js → chunk-4UHRAQFG.js} +47 -16
- package/dist/{chunk-ZXLAD4CS.js.map → chunk-4UHRAQFG.js.map} +1 -1
- package/dist/{chunk-427VWTG6.js → chunk-7CFX774S.js} +9 -9
- package/dist/{chunk-VP25EEOH.js → chunk-AFD43EOE.js} +2 -2
- package/dist/{chunk-6FE2IKPF.js → chunk-LWY4Z626.js} +3 -3
- package/dist/{chunk-FUDWE6KW.js → chunk-NAYFAUSM.js} +149 -10
- package/dist/chunk-NAYFAUSM.js.map +1 -0
- package/dist/{chunk-ZPAXZDWJ.js → chunk-T274LVWB.js} +107 -21
- package/dist/chunk-T274LVWB.js.map +1 -0
- package/dist/{chunk-THX57BL4.js → chunk-TA4WSV6A.js} +114 -184
- package/dist/chunk-TA4WSV6A.js.map +1 -0
- package/dist/{chunk-JKWK73GY.js → chunk-ZBQGZCFL.js} +3 -3
- package/dist/chunk-ZBQGZCFL.js.map +1 -0
- package/dist/{chunk-MPWXWBSG.js → chunk-ZXCKMEJA.js} +7 -7
- package/dist/{cleanup-PE3BFDMV.js → cleanup-RTL2UETA.js} +4 -4
- package/dist/cli.js +34 -32
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +20 -18
- package/dist/daemon.js.map +1 -1
- package/dist/{dispatcher-YCWDNYU3.js → dispatcher-PP5OKOLS.js} +4 -4
- package/dist/{embeddings-HDNAGCOS.js → embeddings-MILTROKW.js} +2 -2
- package/dist/{ingest-LZXTAMEZ.js → ingest-HEXVIAL6.js} +4 -3
- package/dist/mcp.js +8 -8
- package/dist/{memory-value-L4VZNKK5.js → memory-value-WXI2Q6TO.js} +4 -4
- package/dist/{quality-MEI6N7IW.js → quality-VKQUCL66.js} +5 -5
- package/dist/{retrieval-WDZXSBKB.js → retrieval-4MEIABHC.js} +5 -4
- package/dist/{tasks-6EJMXJQV.js → tasks-7SE6VHSQ.js} +4 -4
- package/package.json +1 -1
- package/dist/chunk-FUDWE6KW.js.map +0 -1
- package/dist/chunk-JKWK73GY.js.map +0 -1
- package/dist/chunk-THX57BL4.js.map +0 -1
- package/dist/chunk-ZPAXZDWJ.js.map +0 -1
- /package/dist/{chunk-427VWTG6.js.map → chunk-7CFX774S.js.map} +0 -0
- /package/dist/{chunk-VP25EEOH.js.map → chunk-AFD43EOE.js.map} +0 -0
- /package/dist/{chunk-6FE2IKPF.js.map → chunk-LWY4Z626.js.map} +0 -0
- /package/dist/{chunk-MPWXWBSG.js.map → chunk-ZXCKMEJA.js.map} +0 -0
- /package/dist/{cleanup-PE3BFDMV.js.map → cleanup-RTL2UETA.js.map} +0 -0
- /package/dist/{dispatcher-YCWDNYU3.js.map → dispatcher-PP5OKOLS.js.map} +0 -0
- /package/dist/{embeddings-HDNAGCOS.js.map → embeddings-MILTROKW.js.map} +0 -0
- /package/dist/{ingest-LZXTAMEZ.js.map → ingest-HEXVIAL6.js.map} +0 -0
- /package/dist/{memory-value-L4VZNKK5.js.map → memory-value-WXI2Q6TO.js.map} +0 -0
- /package/dist/{quality-MEI6N7IW.js.map → quality-VKQUCL66.js.map} +0 -0
- /package/dist/{retrieval-WDZXSBKB.js.map → retrieval-4MEIABHC.js.map} +0 -0
- /package/dist/{tasks-6EJMXJQV.js.map → tasks-7SE6VHSQ.js.map} +0 -0
|
@@ -2,9 +2,6 @@ import {
|
|
|
2
2
|
matchTokens,
|
|
3
3
|
textMatchScore
|
|
4
4
|
} from "./chunk-FHEH6QDU.js";
|
|
5
|
-
import {
|
|
6
|
-
desc
|
|
7
|
-
} from "./chunk-CW3XJDH7.js";
|
|
8
5
|
import {
|
|
9
6
|
appendEvidence,
|
|
10
7
|
countDistinctCorrectionSessions,
|
|
@@ -12,16 +9,20 @@ import {
|
|
|
12
9
|
defineOwn,
|
|
13
10
|
demoteMemory,
|
|
14
11
|
getMemory,
|
|
15
|
-
getMemoryFeedback,
|
|
16
12
|
incrementMemoryRepetition,
|
|
17
13
|
listMemories,
|
|
18
14
|
memoryDedupeKey,
|
|
19
15
|
normalizeDedupeText,
|
|
20
16
|
promoteMemory,
|
|
21
17
|
queryMemories,
|
|
18
|
+
recordAudit,
|
|
19
|
+
recordAuditWithSnapshot,
|
|
22
20
|
restoreAutoInject,
|
|
23
21
|
updateMemoryCaptureContext
|
|
24
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-NAYFAUSM.js";
|
|
23
|
+
import {
|
|
24
|
+
desc
|
|
25
|
+
} from "./chunk-CW3XJDH7.js";
|
|
25
26
|
import {
|
|
26
27
|
CONFIDENCE,
|
|
27
28
|
LlmCredentialError,
|
|
@@ -31,7 +32,7 @@ import {
|
|
|
31
32
|
findSimilarRejectedExemplar,
|
|
32
33
|
loadEmbeddingConfigFromEnv,
|
|
33
34
|
queueMemoryEmbeddingSync
|
|
34
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-ZBQGZCFL.js";
|
|
35
36
|
import {
|
|
36
37
|
hasProviderConfigured,
|
|
37
38
|
init_keychain
|
|
@@ -59,123 +60,11 @@ import {
|
|
|
59
60
|
} from "./chunk-LUIYWYOT.js";
|
|
60
61
|
|
|
61
62
|
// src/maintenance/tasks.ts
|
|
62
|
-
import { randomUUID as
|
|
63
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
63
64
|
import { z } from "zod";
|
|
64
65
|
|
|
65
66
|
// src/maintenance/appliers.ts
|
|
66
|
-
import { randomUUID as
|
|
67
|
-
|
|
68
|
-
// src/audit/trail.ts
|
|
69
|
-
import { randomUUID } from "crypto";
|
|
70
|
-
function recordAudit(db, memoryId, action, actor, reason, beforeSnapshot, afterSnapshot) {
|
|
71
|
-
const id = randomUUID();
|
|
72
|
-
if (afterSnapshot === void 0) {
|
|
73
|
-
const mem = getMemory(db, memoryId);
|
|
74
|
-
if (mem) {
|
|
75
|
-
afterSnapshot = JSON.stringify(mem);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
db.insert(auditTrail).values({
|
|
79
|
-
id,
|
|
80
|
-
memory_id: memoryId,
|
|
81
|
-
action,
|
|
82
|
-
actor,
|
|
83
|
-
before_snapshot: beforeSnapshot ?? null,
|
|
84
|
-
after_snapshot: afterSnapshot ?? null,
|
|
85
|
-
reason: reason ?? null,
|
|
86
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
87
|
-
}).run();
|
|
88
|
-
return id;
|
|
89
|
-
}
|
|
90
|
-
function recordAuditWithSnapshot(db, memoryId, action, actor, reason, before, after) {
|
|
91
|
-
return recordAudit(
|
|
92
|
-
db,
|
|
93
|
-
memoryId,
|
|
94
|
-
action,
|
|
95
|
-
actor,
|
|
96
|
-
reason,
|
|
97
|
-
before ? JSON.stringify(before) : null,
|
|
98
|
-
after ? JSON.stringify(after) : null
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
function getAuditTrail(db, memoryId) {
|
|
102
|
-
return db.select().from(auditTrail).where(eq(auditTrail.memory_id, memoryId)).orderBy(desc(auditTrail.timestamp)).all().map(rowToAudit);
|
|
103
|
-
}
|
|
104
|
-
function getRecentAudit(db, limit = 50) {
|
|
105
|
-
return db.select().from(auditTrail).orderBy(desc(auditTrail.timestamp)).limit(limit).all().map(rowToAudit);
|
|
106
|
-
}
|
|
107
|
-
function diffSnapshots(before, after) {
|
|
108
|
-
if (!before || !after) return [];
|
|
109
|
-
const a = JSON.parse(before);
|
|
110
|
-
const b = JSON.parse(after);
|
|
111
|
-
const diffs = [];
|
|
112
|
-
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
113
|
-
for (const key of keys) {
|
|
114
|
-
if (key === "evidence" || key === "embedding") continue;
|
|
115
|
-
const va = JSON.stringify(a[key]);
|
|
116
|
-
const vb = JSON.stringify(b[key]);
|
|
117
|
-
if (va !== vb) {
|
|
118
|
-
diffs.push({ field: key, before: a[key], after: b[key] });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return diffs;
|
|
122
|
-
}
|
|
123
|
-
function rollbackMemory(db, memoryId, auditEntryId, actor) {
|
|
124
|
-
const entry = db.select().from(auditTrail).where(eq(auditTrail.id, auditEntryId)).get();
|
|
125
|
-
if (!entry) return false;
|
|
126
|
-
const snapshot = entry.before_snapshot;
|
|
127
|
-
if (!snapshot) return false;
|
|
128
|
-
const beforeRollback = getMemory(db, memoryId);
|
|
129
|
-
const restored = JSON.parse(snapshot);
|
|
130
|
-
db.update(memories).set({
|
|
131
|
-
text: restored.text,
|
|
132
|
-
type: restored.type,
|
|
133
|
-
scope: restored.scope,
|
|
134
|
-
path_scope: restored.path_scope,
|
|
135
|
-
status: restored.status,
|
|
136
|
-
confidence: restored.confidence,
|
|
137
|
-
source: restored.source,
|
|
138
|
-
evidence: restored.evidence,
|
|
139
|
-
capture_context: restored.capture_context,
|
|
140
|
-
repetition_count: restored.repetition_count,
|
|
141
|
-
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
142
|
-
}).where(eq(memories.id, memoryId)).run();
|
|
143
|
-
queueMemoryEmbeddingSync(db, memoryId);
|
|
144
|
-
recordAuditWithSnapshot(
|
|
145
|
-
db,
|
|
146
|
-
memoryId,
|
|
147
|
-
"rolled_back",
|
|
148
|
-
actor,
|
|
149
|
-
`Rolled back to state from ${entry.timestamp}`,
|
|
150
|
-
beforeRollback ?? null,
|
|
151
|
-
getMemory(db, memoryId) ?? null
|
|
152
|
-
);
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
function formatAuditTrail(entries) {
|
|
156
|
-
if (entries.length === 0) return "No audit entries.";
|
|
157
|
-
const lines = ["# Audit Trail", ""];
|
|
158
|
-
for (const e of entries) {
|
|
159
|
-
const diffs = diffSnapshots(e.before_snapshot, e.after_snapshot);
|
|
160
|
-
const diffStr = diffs.length > 0 ? ` [${diffs.map((d) => `${d.field}: ${JSON.stringify(d.before)} \u2192 ${JSON.stringify(d.after)}`).join(", ")}]` : "";
|
|
161
|
-
lines.push(
|
|
162
|
-
`${e.timestamp.slice(0, 19)} ${e.action.padEnd(22)} by ${e.actor}${e.reason ? ` \u2014 ${e.reason}` : ""}${diffStr}`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return lines.join("\n");
|
|
166
|
-
}
|
|
167
|
-
function rowToAudit(row) {
|
|
168
|
-
return {
|
|
169
|
-
id: row.id,
|
|
170
|
-
memory_id: row.memory_id,
|
|
171
|
-
action: row.action,
|
|
172
|
-
actor: row.actor,
|
|
173
|
-
before_snapshot: row.before_snapshot,
|
|
174
|
-
after_snapshot: row.after_snapshot,
|
|
175
|
-
reason: row.reason,
|
|
176
|
-
timestamp: row.timestamp
|
|
177
|
-
};
|
|
178
|
-
}
|
|
67
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
179
68
|
|
|
180
69
|
// src/health/scoring.ts
|
|
181
70
|
var WEIGHTS = {
|
|
@@ -614,6 +503,10 @@ function buildExtractRulesFromPromptPrompt(task) {
|
|
|
614
503
|
" (a) Imperative \u2014 telling the agent what to always/never do, or what to prefer.",
|
|
615
504
|
" (b) Durable \u2014 the user expects it to apply across future sessions, not just this one task.",
|
|
616
505
|
" (c) Specific \u2014 concrete enough that an agent can follow it without further clarification.",
|
|
506
|
+
"Judge durability from MEANING and conversational context in whatever language the user used; never require magic keywords or a special syntax. Habitual behavior, standing preferences, defaults, and repo/team conventions can be durable even without words equivalent to 'always' or 'never'.",
|
|
507
|
+
"Current-task authorization is NOT durable memory: 'don't commit', 'do not push', 'no commit/push', 'work in the existing worktree', and semantic equivalents in any language normally apply only to the live task. Explicit persistence wording is strong evidence, but not required when the meaning clearly describes an ongoing policy.",
|
|
508
|
+
"For every returned rule set durability='durable'|'ephemeral'|'ambiguous' and durability_evidence to an exact short quote from USER PROMPT in its original language that supports the judgment. Return only durable rules; the other labels are accepted defensively but will be discarded.",
|
|
509
|
+
"Do not return scope='session'. Session-only instructions remain in conversation context and must not enter the persistent memory store.",
|
|
617
510
|
"Recognize rules in ANY natural language (English, Spanish, French, German, Italian, Portuguese, Russian, Chinese, Japanese, Albanian, Turkish, Arabic, \u2026). When the source is non-English, return the cleaned rule TEXT in English so memories are searchable across sessions.",
|
|
618
511
|
"REJECT (return empty list):",
|
|
619
512
|
" \u2022 Questions ('should we use X?'), one-off task requests ('please fix this bug now'), narration ('I never use X' as description of past behavior), code paste, error logs, transcripts.",
|
|
@@ -638,7 +531,7 @@ function buildExtractRulesFromPromptPrompt(task) {
|
|
|
638
531
|
`USER PROMPT:`,
|
|
639
532
|
JSON.stringify(payload.raw_prompt ?? ""),
|
|
640
533
|
"",
|
|
641
|
-
'Return JSON: {"rules": [{"text": string, "type": "rule"|"decision"|"review_pattern"|"command"|"gotcha", "scope": "session"|"path"|"repo"|"team"|"global", "path_scope": string|null, "confidence": number, "is_destructive_risky": boolean, "rationale": string}], "dropped_reason": string?}',
|
|
534
|
+
'Return JSON: {"rules": [{"text": string, "type": "rule"|"decision"|"review_pattern"|"command"|"gotcha", "scope": "session"|"path"|"repo"|"team"|"global", "path_scope": string|null, "confidence": number, "durability": "durable"|"ephemeral"|"ambiguous", "durability_evidence": string|null, "is_destructive_risky": boolean, "rationale": string}], "dropped_reason": string?}',
|
|
642
535
|
'When the prompt contains no durable rule, return {"rules": []} with a brief dropped_reason.'
|
|
643
536
|
].join("\n");
|
|
644
537
|
return { system, user, max_output_tokens: 1600 };
|
|
@@ -1042,10 +935,10 @@ function inferFromGitOwnership(filePath, repoPath) {
|
|
|
1042
935
|
}
|
|
1043
936
|
|
|
1044
937
|
// src/maintenance/cleanup.ts
|
|
1045
|
-
import { randomUUID as
|
|
938
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1046
939
|
|
|
1047
940
|
// src/contradictions/detector.ts
|
|
1048
|
-
import { randomUUID
|
|
941
|
+
import { randomUUID } from "crypto";
|
|
1049
942
|
function countContradictionCandidates(db, repo) {
|
|
1050
943
|
const conditions = [inArray(memories.status, ["active", "candidate"])];
|
|
1051
944
|
if (repo) conditions.push(eq(memories.repo, repo));
|
|
@@ -1073,7 +966,7 @@ function detectContradictions(db, repo) {
|
|
|
1073
966
|
)
|
|
1074
967
|
).get();
|
|
1075
968
|
if (!existing) {
|
|
1076
|
-
const id =
|
|
969
|
+
const id = randomUUID();
|
|
1077
970
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
1078
971
|
db.insert(contradictions).values({
|
|
1079
972
|
id,
|
|
@@ -1276,6 +1169,47 @@ var INJECTION_ARTIFACT_RE = new RegExp(
|
|
|
1276
1169
|
"i"
|
|
1277
1170
|
);
|
|
1278
1171
|
var EPHEMERAL_TASK_CONTEXT_RE = /(?:^\s*\/goal\b|pause for (?:the )?user\b|this is task def(?:inition)?:|key details\s+description\s+(?:goal|background)\b|link to jira ticket|what(?:'|’)s changed\?|this article lists the tools we use for development|required software on node)/i;
|
|
1172
|
+
var OPERATIONAL_REPORT_MARKERS = [
|
|
1173
|
+
/(?:^|\n)\s*(?:✏️|❓|✅|❌)\s*(?:review|test|checkout)\s*:/iu,
|
|
1174
|
+
/\bTouch-map\s*:/i,
|
|
1175
|
+
/\b\d+\/\d+ gates passed\b/i,
|
|
1176
|
+
/\b(?:gates|checkout) skipped\b/i,
|
|
1177
|
+
/\bUsage Error\s*:/i,
|
|
1178
|
+
/\b(?:no provider review|verdict from gates only)\b/i,
|
|
1179
|
+
/\bLocal review only for this repo\b/i
|
|
1180
|
+
];
|
|
1181
|
+
function looksLikePastedOperationalReport(text) {
|
|
1182
|
+
if (text.length < 500 || !text.includes("\n")) return false;
|
|
1183
|
+
const leadingRequest = text.split(/\r?\n\s*\r?\n/, 1)[0] ?? "";
|
|
1184
|
+
if (DURABLE_INTENT_MARKER_RE.test(leadingRequest)) return false;
|
|
1185
|
+
const markerCount = OPERATIONAL_REPORT_MARKERS.reduce(
|
|
1186
|
+
(count, marker) => count + (marker.test(text) ? 1 : 0),
|
|
1187
|
+
0
|
|
1188
|
+
);
|
|
1189
|
+
return markerCount >= 2;
|
|
1190
|
+
}
|
|
1191
|
+
var DURABLE_INTENT_MARKER_RE = /\b(?:always|never|from now on|going forward|henceforth|every time|whenever|by default|make (?:this|it) a rule|remember this|save this|for this repo|for this project|repo-wide|project-wide|across (?:all )?(?:repos|projects)|globally|everywhere)\b/i;
|
|
1192
|
+
var GENERIC_CHANGE_CONTROL_RE = new RegExp(
|
|
1193
|
+
[
|
|
1194
|
+
"(?:do\\s+not|don't|no)\\s+(?:commit|push)(?:\\s*(?:\\/|or|and)\\s*(?:commit|push))?(?:\\s+(?:any\\s+)?(?:changes?|work|anything|repository\\s+changes?|from\\s+this\\s+worktree))?",
|
|
1195
|
+
"without\\s+(?:committing|pushing)(?:\\s+or\\s+(?:committing|pushing))?"
|
|
1196
|
+
].join("|"),
|
|
1197
|
+
"i"
|
|
1198
|
+
);
|
|
1199
|
+
function changeControlClauses(text) {
|
|
1200
|
+
return text.split(/(?:\r?\n|[.!?;])+/).map((clause) => clause.trim()).filter((clause) => /\b(?:commit|push|committing|pushing)\b/i.test(clause));
|
|
1201
|
+
}
|
|
1202
|
+
function isEphemeralTaskConstraint(ruleText, rawPrompt) {
|
|
1203
|
+
if (!GENERIC_CHANGE_CONTROL_RE.test(ruleText)) return false;
|
|
1204
|
+
if (/\b(?:secret|credential|token|private key|\.env|config(?:uration)?|generated file|lockfile)s?\b/i.test(ruleText)) {
|
|
1205
|
+
return false;
|
|
1206
|
+
}
|
|
1207
|
+
const sourceClauses = changeControlClauses(rawPrompt);
|
|
1208
|
+
if (sourceClauses.length === 0) return false;
|
|
1209
|
+
const matchingClauses = sourceClauses.filter((clause) => GENERIC_CHANGE_CONTROL_RE.test(clause));
|
|
1210
|
+
if (matchingClauses.length === 0) return false;
|
|
1211
|
+
return matchingClauses.every((clause) => !DURABLE_INTENT_MARKER_RE.test(clause));
|
|
1212
|
+
}
|
|
1279
1213
|
var LLM_WORKER_PROMPT_RE = /(?:^\s*you are (?:the|an?)\s+[^\n]{0,80}?\b(?:worker|judge|extractor|summari[sz]er|compactor|classifier|grader|scorer|labeler)\b|\bfor a personal agent runtime\b|\breturn json only\b[^\n]{0,60}\bno (?:markdown|prose)\b)/i;
|
|
1280
1214
|
var CODEX_INTERNAL_PROMPT_RE = /(?:^\s*generate a title and a git branch name for a coding agent\b|^\s*#\s*overview\s+generate\s+0\s+to\s+3\s+hyperpersonalized suggestions for what this user can do with codex\b|^\s*you are an expert at upholding safety and compliance standards for codex ambient suggestions\b|^\s*you are the implementation worker for one isolated git worktree\b|^\s*you are reviewing github pull request\b[^\n]*\bon behalf of the maintainer\b|^\s*#\s*github issue workorder\s*:|^\s*continue the previous coding task using user-provided context only\b)/i;
|
|
1281
1215
|
function looksLikeQuestionContext(text) {
|
|
@@ -1292,7 +1226,7 @@ function looksLikeQuestionContext(text) {
|
|
|
1292
1226
|
return /\?\s*$/.test(text.trim()) || /(?:^|[.!?]\s+)(?:how|why|what|where|which|who|can|could|should|would|do|does|did|is|are|was|were|have|has)\b/i.test(text);
|
|
1293
1227
|
}
|
|
1294
1228
|
function isNonUserCaptureContext(text) {
|
|
1295
|
-
return SYSTEM_SCAFFOLD_RE.test(text) || NON_USER_CONTEXT_RE.test(text) || INJECTION_ARTIFACT_RE.test(text) || EPHEMERAL_TASK_CONTEXT_RE.test(text) || LLM_WORKER_PROMPT_RE.test(text) || CODEX_INTERNAL_PROMPT_RE.test(text) || looksLikeQuestionContext(text);
|
|
1229
|
+
return SYSTEM_SCAFFOLD_RE.test(text) || NON_USER_CONTEXT_RE.test(text) || INJECTION_ARTIFACT_RE.test(text) || EPHEMERAL_TASK_CONTEXT_RE.test(text) || looksLikePastedOperationalReport(text) || LLM_WORKER_PROMPT_RE.test(text) || CODEX_INTERNAL_PROMPT_RE.test(text) || looksLikeQuestionContext(text);
|
|
1296
1230
|
}
|
|
1297
1231
|
|
|
1298
1232
|
// src/scanner/signal.ts
|
|
@@ -1415,7 +1349,7 @@ var SUPPRESS_INJECTION_FLOOR = 50;
|
|
|
1415
1349
|
var GLOBALIZE_REPO_FLOOR = 3;
|
|
1416
1350
|
var DEFAULT_ACTOR = "maintenance:cleanup";
|
|
1417
1351
|
function runDeterministicCleanup(db, opts = { dryRun: true }) {
|
|
1418
|
-
const runId =
|
|
1352
|
+
const runId = randomUUID2();
|
|
1419
1353
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1420
1354
|
const plan = [];
|
|
1421
1355
|
if (!opts.only || opts.only === "dedupe_exact_merge") {
|
|
@@ -1630,7 +1564,7 @@ function applyDedupeExact(db, runId, plan) {
|
|
|
1630
1564
|
after ?? null
|
|
1631
1565
|
);
|
|
1632
1566
|
db.insert(maintenanceCleanupLog).values({
|
|
1633
|
-
id:
|
|
1567
|
+
id: randomUUID2(),
|
|
1634
1568
|
run_id: runId,
|
|
1635
1569
|
action: "dedupe_exact_merge",
|
|
1636
1570
|
memory_id: loser.id,
|
|
@@ -1826,7 +1760,7 @@ function applyRejectFragment(db, runId, plan) {
|
|
|
1826
1760
|
after ?? null
|
|
1827
1761
|
);
|
|
1828
1762
|
db.insert(maintenanceCleanupLog).values({
|
|
1829
|
-
id:
|
|
1763
|
+
id: randomUUID2(),
|
|
1830
1764
|
run_id: runId,
|
|
1831
1765
|
action: "reject_fragment_candidate",
|
|
1832
1766
|
memory_id: plan.memory_id,
|
|
@@ -1870,7 +1804,7 @@ function applyRejectTestFixtureRepo(db, runId, plan) {
|
|
|
1870
1804
|
after ?? null
|
|
1871
1805
|
);
|
|
1872
1806
|
db.insert(maintenanceCleanupLog).values({
|
|
1873
|
-
id:
|
|
1807
|
+
id: randomUUID2(),
|
|
1874
1808
|
run_id: runId,
|
|
1875
1809
|
action: "reject_test_fixture_repo",
|
|
1876
1810
|
memory_id: plan.memory_id,
|
|
@@ -1939,7 +1873,7 @@ function applyRejectInvalidScope(db, runId, plan) {
|
|
|
1939
1873
|
after ?? null
|
|
1940
1874
|
);
|
|
1941
1875
|
db.insert(maintenanceCleanupLog).values({
|
|
1942
|
-
id:
|
|
1876
|
+
id: randomUUID2(),
|
|
1943
1877
|
run_id: runId,
|
|
1944
1878
|
action: "reject_invalid_scope",
|
|
1945
1879
|
memory_id: plan.memory_id,
|
|
@@ -1998,7 +1932,7 @@ function applyRejectGenericScannedTooling(db, runId, plan) {
|
|
|
1998
1932
|
after ?? null
|
|
1999
1933
|
);
|
|
2000
1934
|
db.insert(maintenanceCleanupLog).values({
|
|
2001
|
-
id:
|
|
1935
|
+
id: randomUUID2(),
|
|
2002
1936
|
run_id: runId,
|
|
2003
1937
|
action: "reject_generic_scanned_tooling",
|
|
2004
1938
|
memory_id: plan.memory_id,
|
|
@@ -2020,11 +1954,13 @@ function planPromoteRepeats(db) {
|
|
|
2020
1954
|
text: memories.text,
|
|
2021
1955
|
repetition_count: memories.repetition_count,
|
|
2022
1956
|
source: memories.source,
|
|
2023
|
-
status: memories.status
|
|
1957
|
+
status: memories.status,
|
|
1958
|
+
scope: memories.scope
|
|
2024
1959
|
}).from(memories).where(and(eq(memories.status, "candidate"), eq(memories.source, "user_correction"))).all();
|
|
2025
1960
|
const out = [];
|
|
2026
1961
|
for (const row of rows) {
|
|
2027
1962
|
const text = row.text.trim();
|
|
1963
|
+
if (row.scope === "session") continue;
|
|
2028
1964
|
if (qualityReasons(text).length > 0) continue;
|
|
2029
1965
|
if (isDestructiveRisky(text)) continue;
|
|
2030
1966
|
if (row.repetition_count >= 2) {
|
|
@@ -2049,7 +1985,7 @@ function applyPromoteRepeat(db, runId, plan) {
|
|
|
2049
1985
|
after ?? null
|
|
2050
1986
|
);
|
|
2051
1987
|
db.insert(maintenanceCleanupLog).values({
|
|
2052
|
-
id:
|
|
1988
|
+
id: randomUUID2(),
|
|
2053
1989
|
run_id: runId,
|
|
2054
1990
|
action: "promote_repeat_correction",
|
|
2055
1991
|
memory_id: plan.memory_id,
|
|
@@ -2107,7 +2043,7 @@ function applySuppressCommand(db, runId, plan) {
|
|
|
2107
2043
|
after ?? null
|
|
2108
2044
|
);
|
|
2109
2045
|
db.insert(maintenanceCleanupLog).values({
|
|
2110
|
-
id:
|
|
2046
|
+
id: randomUUID2(),
|
|
2111
2047
|
run_id: runId,
|
|
2112
2048
|
action: "suppress_unproductive_command",
|
|
2113
2049
|
memory_id: plan.memory_id,
|
|
@@ -2202,7 +2138,7 @@ function applyGlobalizeCrossRepo(db, runId, plan) {
|
|
|
2202
2138
|
after ?? null
|
|
2203
2139
|
);
|
|
2204
2140
|
db.insert(maintenanceCleanupLog).values({
|
|
2205
|
-
id:
|
|
2141
|
+
id: randomUUID2(),
|
|
2206
2142
|
run_id: runId,
|
|
2207
2143
|
action: "globalize_cross_repo",
|
|
2208
2144
|
memory_id: winner.id,
|
|
@@ -2229,7 +2165,7 @@ function applyGlobalizeCrossRepo(db, runId, plan) {
|
|
|
2229
2165
|
afterLoser ?? null
|
|
2230
2166
|
);
|
|
2231
2167
|
db.insert(maintenanceCleanupLog).values({
|
|
2232
|
-
id:
|
|
2168
|
+
id: randomUUID2(),
|
|
2233
2169
|
run_id: runId,
|
|
2234
2170
|
action: "globalize_cross_repo",
|
|
2235
2171
|
memory_id: loserId,
|
|
@@ -2568,6 +2504,7 @@ var TRANSCRIPT_MARKERS = [
|
|
|
2568
2504
|
var DURABLE_DECISION_HINT = /\b(repo|repository|project|default|defaults|convention(?:al|s)?|configured|config|editorconfig|prettier|eslint|tsconfig|package\.json|ci|workflow|style|pattern|architecture|runtime|database|sqlite|pnpm|yarn|npm|uv|pytest|vitest)\b/i;
|
|
2569
2505
|
var TRANSCRIPT_LINE_RE = /^(?:[⏺⎿❯✻※]|(?:Bash|Edit|Write|Read|Grep|Glob|Task|TodoWrite)\(|\s*(?:│|├|┌|└|─)|\s*…|\s*={3,})/u;
|
|
2570
2506
|
function looksLikePastedTranscript(text) {
|
|
2507
|
+
if (looksLikePastedOperationalReport(text)) return true;
|
|
2571
2508
|
if (text.length < 1200) return false;
|
|
2572
2509
|
const markerCount = TRANSCRIPT_MARKERS.reduce(
|
|
2573
2510
|
(total, marker) => total + (text.includes(marker) ? 1 : 0),
|
|
@@ -2592,7 +2529,7 @@ function isDurableDecision(segment, first, second) {
|
|
|
2592
2529
|
async function processCorrection(db, text, ctx) {
|
|
2593
2530
|
text = redactSensitiveText(text);
|
|
2594
2531
|
if (isNonUserCaptureContext(text)) return { ids: [] };
|
|
2595
|
-
if (process.env.RECALL_LLM_CAPTURE_DISABLED !== "true" && hasAnyLlmProvider() && isPromptWorthLLM(text)) {
|
|
2532
|
+
if (process.env.RECALL_LLM_CAPTURE_DISABLED !== "true" && hasAnyLlmProvider() && (ctx.force_semantic_capture || isPromptWorthLLM(text))) {
|
|
2596
2533
|
const promptId = stablePromptId(ctx.sessionId, ctx.repo, text);
|
|
2597
2534
|
const taskId = enqueueExtractRulesFromPrompt(db, {
|
|
2598
2535
|
prompt_id: promptId,
|
|
@@ -2607,17 +2544,27 @@ async function processCorrection(db, text, ctx) {
|
|
|
2607
2544
|
wakeDispatcherBestEffort();
|
|
2608
2545
|
return { ids: [], pendingTaskId: taskId ?? `dedup:${promptId}` };
|
|
2609
2546
|
}
|
|
2610
|
-
const corrections = detectCorrections(text)
|
|
2547
|
+
const corrections = detectCorrections(text).filter(
|
|
2548
|
+
(correction) => correction.type === "review_pattern" || qualityReasons(correction.text).length === 0
|
|
2549
|
+
);
|
|
2550
|
+
if (corrections.length === 0 && ctx.force_semantic_capture) {
|
|
2551
|
+
corrections.push({
|
|
2552
|
+
type: "rule",
|
|
2553
|
+
text: ensureSentence(text),
|
|
2554
|
+
confidence: 0.35,
|
|
2555
|
+
original: text
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2611
2558
|
if (corrections.length === 0) return { ids: [] };
|
|
2612
2559
|
const profile = getRepoQualityProfile(db, ctx.repo);
|
|
2613
2560
|
const ids = [];
|
|
2614
2561
|
const captureContext = buildCaptureContext(ctx);
|
|
2562
|
+
let blockedByRejectedExemplar = 0;
|
|
2615
2563
|
for (const correction of corrections) {
|
|
2616
|
-
if (correction.
|
|
2617
|
-
|
|
2618
|
-
|
|
2564
|
+
if (await isSimilarToRejectedFragmentSemantic(db, correction.text)) {
|
|
2565
|
+
blockedByRejectedExemplar++;
|
|
2566
|
+
continue;
|
|
2619
2567
|
}
|
|
2620
|
-
if (await isSimilarToRejectedFragmentSemantic(db, correction.text)) continue;
|
|
2621
2568
|
const evidence = correction.type === "review_pattern" ? {
|
|
2622
2569
|
type: "review_feedback",
|
|
2623
2570
|
reported_by_user: true,
|
|
@@ -2673,6 +2620,7 @@ async function processCorrection(db, text, ctx) {
|
|
|
2673
2620
|
original_text: text
|
|
2674
2621
|
}
|
|
2675
2622
|
);
|
|
2623
|
+
if (inferredScope.scope === "session") continue;
|
|
2676
2624
|
const input = {
|
|
2677
2625
|
type: correction.type,
|
|
2678
2626
|
text: correction.text,
|
|
@@ -2688,7 +2636,6 @@ async function processCorrection(db, text, ctx) {
|
|
|
2688
2636
|
capture_context: captureContext
|
|
2689
2637
|
};
|
|
2690
2638
|
const id = createMemory(db, input);
|
|
2691
|
-
maybePromoteGroupCandidate(db, id);
|
|
2692
2639
|
enqueueVerifyCapture(db, {
|
|
2693
2640
|
id,
|
|
2694
2641
|
text: input.text,
|
|
@@ -2699,35 +2646,12 @@ async function processCorrection(db, text, ctx) {
|
|
|
2699
2646
|
});
|
|
2700
2647
|
ids.push(id);
|
|
2701
2648
|
}
|
|
2702
|
-
return { ids };
|
|
2649
|
+
return { ids, blockedByRejectedExemplar };
|
|
2703
2650
|
}
|
|
2704
2651
|
function stablePromptId(sessionId, repo, text) {
|
|
2705
2652
|
const hash = createHash("sha256").update(`${sessionId}${repo ?? ""}${normalizeDedupeText(text)}`).digest("hex").slice(0, 16);
|
|
2706
2653
|
return `prompt:${sessionId}:${hash}`;
|
|
2707
2654
|
}
|
|
2708
|
-
function maybePromoteGroupCandidate(db, candidateId) {
|
|
2709
|
-
const candidate = getMemory(db, candidateId);
|
|
2710
|
-
if (!candidate || candidate.status !== "candidate") return;
|
|
2711
|
-
if (isHighRiskRule(candidate.text)) return;
|
|
2712
|
-
const followedCount = queryMemories(db, {
|
|
2713
|
-
repo: candidate.repo ?? void 0,
|
|
2714
|
-
type: candidate.type,
|
|
2715
|
-
scope: candidate.scope
|
|
2716
|
-
}).filter((memory) => memory.id !== candidate.id).reduce((total, memory) => total + getMemoryFeedback(db, memory.id).filter((entry) => entry.outcome === "followed").length, 0);
|
|
2717
|
-
if (followedCount < 3) return;
|
|
2718
|
-
const before = candidate;
|
|
2719
|
-
promoteMemory(db, candidate.id, "repeat_correction");
|
|
2720
|
-
const after = getMemory(db, candidate.id);
|
|
2721
|
-
recordAuditWithSnapshot(
|
|
2722
|
-
db,
|
|
2723
|
-
candidate.id,
|
|
2724
|
-
"promoted",
|
|
2725
|
-
"system",
|
|
2726
|
-
`repetition:group_followed:${followedCount}`,
|
|
2727
|
-
before,
|
|
2728
|
-
after ?? null
|
|
2729
|
-
);
|
|
2730
|
-
}
|
|
2731
2655
|
function buildCaptureContext(ctx) {
|
|
2732
2656
|
const recentToolCalls = (ctx.recent_tool_calls ?? []).slice(-5).map((toolCall) => ({
|
|
2733
2657
|
name: toolCall.name,
|
|
@@ -2816,17 +2740,16 @@ function textSimilarity(a, b) {
|
|
|
2816
2740
|
}
|
|
2817
2741
|
var REJECTED_EXEMPLAR_THRESHOLD = 0.7;
|
|
2818
2742
|
var REJECTED_EXEMPLAR_SEMANTIC_THRESHOLD = 0.85;
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
return
|
|
2743
|
+
var HUMAN_REJECTION_ACTORS = ["mcp", "cli"];
|
|
2744
|
+
function isHumanRejection(db, memoryId) {
|
|
2745
|
+
const rows = db.select({ actor: auditTrail.actor }).from(auditTrail).where(and(eq(auditTrail.memory_id, memoryId), eq(auditTrail.action, "rejected"))).all();
|
|
2746
|
+
return rows.some((row) => HUMAN_REJECTION_ACTORS.includes(row.actor));
|
|
2823
2747
|
}
|
|
2824
|
-
var MACHINE_REJECTION_ACTORS = ["auto-pruner", "cleanup_script", "maintenance:cleanup"];
|
|
2825
2748
|
function isSimilarToRejectedFragment(db, text, threshold = REJECTED_EXEMPLAR_THRESHOLD) {
|
|
2826
2749
|
const rejected = queryMemories(db, { status: "rejected" }).filter((m) => m.source === "user_correction" || m.source === "user_reported_review");
|
|
2827
2750
|
for (const exemplar of rejected) {
|
|
2828
2751
|
if (textSimilarity(text, exemplar.text) < threshold) continue;
|
|
2829
|
-
if (
|
|
2752
|
+
if (!isHumanRejection(db, exemplar.id)) continue;
|
|
2830
2753
|
return true;
|
|
2831
2754
|
}
|
|
2832
2755
|
return false;
|
|
@@ -2837,7 +2760,13 @@ async function isSimilarToRejectedFragmentSemantic(db, text, options = {}) {
|
|
|
2837
2760
|
if (isSimilarToRejectedFragment(db, text, lexicalT)) return true;
|
|
2838
2761
|
const config = loadEmbeddingConfigFromEnv();
|
|
2839
2762
|
if (!config) return false;
|
|
2840
|
-
const match = await findSimilarRejectedExemplar(
|
|
2763
|
+
const match = await findSimilarRejectedExemplar(
|
|
2764
|
+
db,
|
|
2765
|
+
text,
|
|
2766
|
+
config,
|
|
2767
|
+
semanticT,
|
|
2768
|
+
(id) => isHumanRejection(db, id)
|
|
2769
|
+
);
|
|
2841
2770
|
return match != null;
|
|
2842
2771
|
}
|
|
2843
2772
|
async function findDuplicateMemory(db, repo, type, text, threshold) {
|
|
@@ -3072,7 +3001,7 @@ function applySummarizeSession(db, task, result) {
|
|
|
3072
3001
|
const payload = task.payload;
|
|
3073
3002
|
const sessionId = payload.session_id;
|
|
3074
3003
|
if (!sessionId) throw new ApplyError("payload missing session_id", "invalid-state");
|
|
3075
|
-
const id =
|
|
3004
|
+
const id = randomUUID3();
|
|
3076
3005
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3077
3006
|
db.insert(historySnippets).values({
|
|
3078
3007
|
id,
|
|
@@ -3090,7 +3019,7 @@ function applySynthesizeRepo(db, task, result) {
|
|
|
3090
3019
|
const payload = task.payload;
|
|
3091
3020
|
const repo = payload.repo;
|
|
3092
3021
|
if (!repo) throw new ApplyError("payload missing repo", "invalid-state");
|
|
3093
|
-
const id =
|
|
3022
|
+
const id = randomUUID3();
|
|
3094
3023
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3095
3024
|
db.insert(historySnippets).values({
|
|
3096
3025
|
id,
|
|
@@ -3126,6 +3055,9 @@ function applyExtractRulesFromPrompt(db, task, result) {
|
|
|
3126
3055
|
const reinforcedIds = [];
|
|
3127
3056
|
const sessionId = payload.session_id ?? "unknown";
|
|
3128
3057
|
for (const rule of result.rules) {
|
|
3058
|
+
if (rule.scope === "session" || rule.durability === "ephemeral" || rule.durability === "ambiguous" || rule.durability !== "durable" && isEphemeralTaskConstraint(rule.text, payload.raw_prompt ?? "")) {
|
|
3059
|
+
continue;
|
|
3060
|
+
}
|
|
3129
3061
|
const evidence = {
|
|
3130
3062
|
type: "session_correction",
|
|
3131
3063
|
session: sessionId,
|
|
@@ -3321,7 +3253,7 @@ function hasActiveTaskForTarget(db, kind, target) {
|
|
|
3321
3253
|
}
|
|
3322
3254
|
function insertTaskIdempotent(db, input) {
|
|
3323
3255
|
if (hasActiveTaskForTarget(db, input.kind, input.target)) return null;
|
|
3324
|
-
const id =
|
|
3256
|
+
const id = randomUUID4();
|
|
3325
3257
|
db.insert(memoryMaintenanceTasks).values({
|
|
3326
3258
|
id,
|
|
3327
3259
|
kind: input.kind,
|
|
@@ -3821,6 +3753,10 @@ var ExtractedRule = z.object({
|
|
|
3821
3753
|
scope: MemoryScope,
|
|
3822
3754
|
path_scope: z.string().max(512).nullable().optional(),
|
|
3823
3755
|
confidence: z.number().min(0).max(1),
|
|
3756
|
+
// Optional for compatibility with already-queued tasks and older model
|
|
3757
|
+
// responses. New extraction prompts require this semantic judgment.
|
|
3758
|
+
durability: z.enum(["durable", "ephemeral", "ambiguous"]).optional(),
|
|
3759
|
+
durability_evidence: z.string().max(500).nullable().optional(),
|
|
3824
3760
|
is_destructive_risky: z.boolean().optional(),
|
|
3825
3761
|
rationale: z.string().max(500).nullable().optional()
|
|
3826
3762
|
});
|
|
@@ -4009,12 +3945,6 @@ export {
|
|
|
4009
3945
|
formatHealthReport,
|
|
4010
3946
|
getRepoQualityProfile,
|
|
4011
3947
|
seedScannedConfidence,
|
|
4012
|
-
recordAudit,
|
|
4013
|
-
recordAuditWithSnapshot,
|
|
4014
|
-
getAuditTrail,
|
|
4015
|
-
getRecentAudit,
|
|
4016
|
-
rollbackMemory,
|
|
4017
|
-
formatAuditTrail,
|
|
4018
3948
|
DEFAULT_LEASE_SECONDS2 as DEFAULT_LEASE_SECONDS,
|
|
4019
3949
|
DEFAULT_PRIORITIES,
|
|
4020
3950
|
DEFAULT_ENQUEUE_CONFIG,
|
|
@@ -4079,4 +4009,4 @@ export {
|
|
|
4079
4009
|
processCorrection,
|
|
4080
4010
|
processReviewFeedback
|
|
4081
4011
|
};
|
|
4082
|
-
//# sourceMappingURL=chunk-
|
|
4012
|
+
//# sourceMappingURL=chunk-TA4WSV6A.js.map
|