@edihasaj/recall 0.8.3 → 0.8.5
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/README.md +10 -0
- package/dist/{chunk-3OYO5BW3.js → chunk-4VBHVY3D.js} +4 -4
- package/dist/chunk-4VBHVY3D.js.map +1 -0
- package/dist/{chunk-JRIM7VBY.js → chunk-A4ES3H4Y.js} +2 -2
- package/dist/{chunk-72USXFEP.js → chunk-BHTIIKRB.js} +4 -4
- package/dist/{chunk-37K4DPRI.js → chunk-BJTLWRZH.js} +2 -2
- package/dist/{chunk-DRHHOFBX.js → chunk-DYAQ4RKX.js} +263 -13
- package/dist/chunk-DYAQ4RKX.js.map +1 -0
- package/dist/{chunk-Z6RT5BUO.js → chunk-EYMC2PDI.js} +2 -2
- package/dist/{chunk-QDA5M3AJ.js → chunk-G5IAOZAL.js} +28 -2
- package/dist/chunk-G5IAOZAL.js.map +1 -0
- package/dist/{chunk-5E3KREDH.js → chunk-ITU4GQDL.js} +46 -10
- package/dist/chunk-ITU4GQDL.js.map +1 -0
- package/dist/{chunk-R3DJIEID.js → chunk-OR6VZZI6.js} +3 -3
- package/dist/chunk-PUMEMKGF.js +29 -0
- package/dist/chunk-PUMEMKGF.js.map +1 -0
- package/dist/{chunk-L2YIWNLN.js → chunk-Q6CNO5TF.js} +7 -7
- package/dist/{chunk-YL23MKB3.js → chunk-SAVLATC5.js} +24 -4
- package/dist/chunk-SAVLATC5.js.map +1 -0
- package/dist/{chunk-4LZMHQ6Y.js → chunk-VPZ4OZKK.js} +531 -597
- package/dist/chunk-VPZ4OZKK.js.map +1 -0
- package/dist/chunk-WC7S7BOP.js +328 -0
- package/dist/chunk-WC7S7BOP.js.map +1 -0
- package/dist/{cleanup-XOIYUPHS.js → cleanup-MPSAZNDH.js} +10 -6
- package/dist/cli.js +49 -31
- package/dist/cli.js.map +1 -1
- package/dist/daemon.js +31 -18
- package/dist/daemon.js.map +1 -1
- package/dist/{dispatcher-43DWN3ZP.js → dispatcher-RCCPGNDO.js} +6 -6
- package/dist/{embeddings-GKNH2E3N.js → embeddings-MNNECV6B.js} +3 -3
- package/dist/{ingest-QOZDSJOA.js → ingest-KVLFQ6J7.js} +6 -6
- package/dist/mcp.js +11 -9
- package/dist/mcp.js.map +1 -1
- package/dist/{quality-2JOLSIC3.js → quality-OXFQ7JXM.js} +8 -4
- package/dist/retrieval-27YV546Y.js +13 -0
- package/dist/{store-2BPQPOOZ.js → store-KU5H2RA2.js} +3 -3
- package/dist/sync-server.js +6 -0
- package/dist/sync-server.js.map +1 -1
- package/dist/{tasks-IFHV6EBT.js → tasks-SCYA2PJJ.js} +8 -6
- package/dist/{usage-YBS74UEU.js → usage-VVXTCJHT.js} +3 -3
- package/drizzle/0009_memory_value_events.sql +23 -0
- package/drizzle/meta/_journal.json +8 -1
- package/package.json +2 -1
- package/dist/chunk-3OYO5BW3.js.map +0 -1
- package/dist/chunk-4LZMHQ6Y.js.map +0 -1
- package/dist/chunk-5E3KREDH.js.map +0 -1
- package/dist/chunk-DRHHOFBX.js.map +0 -1
- package/dist/chunk-QDA5M3AJ.js.map +0 -1
- package/dist/chunk-YL23MKB3.js.map +0 -1
- package/dist/retrieval-PQE7OHHJ.js +0 -13
- /package/dist/{chunk-JRIM7VBY.js.map → chunk-A4ES3H4Y.js.map} +0 -0
- /package/dist/{chunk-72USXFEP.js.map → chunk-BHTIIKRB.js.map} +0 -0
- /package/dist/{chunk-37K4DPRI.js.map → chunk-BJTLWRZH.js.map} +0 -0
- /package/dist/{chunk-Z6RT5BUO.js.map → chunk-EYMC2PDI.js.map} +0 -0
- /package/dist/{chunk-R3DJIEID.js.map → chunk-OR6VZZI6.js.map} +0 -0
- /package/dist/{chunk-L2YIWNLN.js.map → chunk-Q6CNO5TF.js.map} +0 -0
- /package/dist/{cleanup-XOIYUPHS.js.map → cleanup-MPSAZNDH.js.map} +0 -0
- /package/dist/{dispatcher-43DWN3ZP.js.map → dispatcher-RCCPGNDO.js.map} +0 -0
- /package/dist/{embeddings-GKNH2E3N.js.map → embeddings-MNNECV6B.js.map} +0 -0
- /package/dist/{ingest-QOZDSJOA.js.map → ingest-KVLFQ6J7.js.map} +0 -0
- /package/dist/{quality-2JOLSIC3.js.map → quality-OXFQ7JXM.js.map} +0 -0
- /package/dist/{retrieval-PQE7OHHJ.js.map → retrieval-27YV546Y.js.map} +0 -0
- /package/dist/{store-2BPQPOOZ.js.map → store-KU5H2RA2.js.map} +0 -0
- /package/dist/{tasks-IFHV6EBT.js.map → tasks-SCYA2PJJ.js.map} +0 -0
- /package/dist/{usage-YBS74UEU.js.map → usage-VVXTCJHT.js.map} +0 -0
package/README.md
CHANGED
|
@@ -104,11 +104,17 @@ recall doctor
|
|
|
104
104
|
```bash
|
|
105
105
|
git clone https://github.com/edihasaj/recall.git
|
|
106
106
|
cd recall
|
|
107
|
+
nvm use
|
|
107
108
|
npm ci
|
|
108
109
|
npm run build
|
|
109
110
|
npm link
|
|
110
111
|
```
|
|
111
112
|
|
|
113
|
+
Source development expects Node 22, matching the bundled app runtime. If tests
|
|
114
|
+
fail with a `NODE_MODULE_VERSION` error from `better-sqlite3`, switch to Node
|
|
115
|
+
22 and reinstall dependencies so the native module ABI matches the test
|
|
116
|
+
runtime.
|
|
117
|
+
|
|
112
118
|
## Build macOS App From Source
|
|
113
119
|
|
|
114
120
|
Build the macOS app bundle:
|
|
@@ -117,6 +123,10 @@ Build the macOS app bundle:
|
|
|
117
123
|
npm run build:app
|
|
118
124
|
```
|
|
119
125
|
|
|
126
|
+
`scripts/build-app.sh` embeds Node 22. It prefers
|
|
127
|
+
`RECALL_NODE_PATH=/path/to/node` when set, otherwise the Node runtime from the
|
|
128
|
+
currently installed `/Applications/Recall.app`, then your shell `node`.
|
|
129
|
+
|
|
120
130
|
Install it into `/Applications`:
|
|
121
131
|
|
|
122
132
|
```bash
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CONFIDENCE,
|
|
3
3
|
PROMOTION,
|
|
4
4
|
queueMemoryEmbeddingSync
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-A4ES3H4Y.js";
|
|
6
6
|
import {
|
|
7
7
|
and,
|
|
8
8
|
eq,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
like,
|
|
13
13
|
memories,
|
|
14
14
|
sql
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-G5IAOZAL.js";
|
|
16
16
|
|
|
17
17
|
// src/models/dedupe.ts
|
|
18
18
|
function normalizeDedupeText(text) {
|
|
@@ -176,7 +176,7 @@ function listMemories(db, repo, options = {}) {
|
|
|
176
176
|
}
|
|
177
177
|
function listRepos(db) {
|
|
178
178
|
return [...new Set(
|
|
179
|
-
db.select({ repo: memories.repo }).from(memories).all().map((row) => row.repo).filter((repo) => Boolean(repo))
|
|
179
|
+
db.select({ repo: memories.repo }).from(memories).where(sql`${memories.status} != 'rejected'`).all().map((row) => row.repo).filter((repo) => Boolean(repo))
|
|
180
180
|
)].sort();
|
|
181
181
|
}
|
|
182
182
|
function promoteMemory(db, id, reason, evidence) {
|
|
@@ -463,4 +463,4 @@ export {
|
|
|
463
463
|
getMemoryFeedbackSummaries,
|
|
464
464
|
feedbackWeightedScore
|
|
465
465
|
};
|
|
466
|
-
//# sourceMappingURL=chunk-
|
|
466
|
+
//# sourceMappingURL=chunk-4VBHVY3D.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/models/dedupe.ts","../src/models/memory.ts"],"sourcesContent":["export function normalizeDedupeText(text: string): string {\n return text\n .toLowerCase()\n .replace(/\\s+/g, \" \")\n .replace(/[\\s.;:,!?`]+$/g, \"\")\n .trim();\n}\n\nexport function memoryDedupeKey(input: {\n type: string;\n scope: string;\n repo?: string | null;\n path_scope?: string | null;\n text: string;\n}): string {\n return [\n \"memory\",\n input.type,\n input.scope,\n input.repo ?? \"\",\n input.path_scope ?? \"\",\n normalizeDedupeText(input.text),\n ].join(\"\\u001f\");\n}\n\nexport function historySnippetDedupeKey(input: {\n repo?: string | null;\n session_id?: string | null;\n kind: string;\n text: string;\n}): string {\n return [\n \"history\",\n input.repo ?? \"\",\n input.session_id ?? \"\",\n input.kind,\n normalizeDedupeText(input.text),\n ].join(\"\\u001f\");\n}\n\nexport function activityEventDedupeKey(input: {\n session_id?: string | null;\n repo?: string | null;\n path?: string | null;\n source: string;\n event_type: string;\n request?: Record<string, unknown>;\n result?: Record<string, unknown>;\n}): string | null {\n if (!input.session_id) return null;\n return [\n \"activity\",\n input.session_id,\n input.repo ?? \"\",\n input.path ?? \"\",\n input.source,\n input.event_type,\n stableDedupeJson(stripVolatileFields(input.request ?? {})),\n stableDedupeJson(stripVolatileFields(input.result ?? {})),\n ].join(\"\\u001f\");\n}\n\nexport function hookCallDedupeKey(input: {\n session_id?: string | null;\n agent: string;\n event: string;\n ok: boolean;\n payload?: Record<string, unknown>;\n}): string | null {\n if (!input.session_id) return null;\n return [\n \"hook\",\n input.session_id,\n input.agent,\n input.event,\n input.ok ? \"ok\" : \"error\",\n stableDedupeJson(stripVolatileFields(input.payload ?? {})),\n ].join(\"\\u001f\");\n}\n\nexport function stripVolatileFields(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(stripVolatileFields);\n }\n if (!value || typeof value !== \"object\") {\n return value;\n }\n\n const out: Record<string, unknown> = {};\n for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {\n if (/_at$/u.test(key) || key === \"timestamp\") continue;\n if (entry === undefined) continue;\n out[key] = stripVolatileFields(entry);\n }\n return out;\n}\n\nexport function stableDedupeJson(value: unknown): string {\n if (Array.isArray(value)) {\n return `[${value.map(stableDedupeJson).join(\",\")}]`;\n }\n if (!value || typeof value !== \"object\") {\n return JSON.stringify(value);\n }\n\n const record = value as Record<string, unknown>;\n return `{${Object.keys(record).sort().map((key) => (\n `${JSON.stringify(key)}:${stableDedupeJson(record[key])}`\n )).join(\",\")}}`;\n}\n","import { eq, and, gte, inArray, like, sql } from \"drizzle-orm\";\nimport { randomUUID } from \"node:crypto\";\nimport type { RecallDb } from \"../db/client.js\";\nimport { memories, feedbackEvents } from \"../db/schema.js\";\nimport { memoryDedupeKey } from \"./dedupe.js\";\nimport { queueMemoryEmbeddingSync } from \"../embeddings/embeddings.js\";\nimport {\n CONFIDENCE,\n PROMOTION,\n type MemoryItem,\n type MemoryQuery,\n type MemoryStatus,\n type MemoryType,\n type MemoryScope,\n type MemorySource,\n type EvidenceEntry,\n type CaptureContext,\n type FeedbackOutcome,\n} from \"../types.js\";\n\ntype MemoryRow = typeof memories.$inferSelect;\n\n// --- Create ---\n\nexport interface CreateMemoryInput {\n type: MemoryType;\n text: string;\n scope: MemoryScope;\n path_scope?: string | null;\n repo?: string | null;\n source: MemorySource;\n confidence?: number;\n evidence?: EvidenceEntry[];\n capture_context?: CaptureContext | null;\n supersedes?: string | null;\n dedupe?: boolean;\n}\n\nexport function statusFromConfidence(confidence: number): MemoryStatus {\n if (confidence < CONFIDENCE.TRANSIENT_MAX) return \"transient\";\n if (confidence < CONFIDENCE.CANDIDATE_MAX) return \"candidate\";\n return \"active\";\n}\n\nexport function createMemory(db: RecallDb, input: CreateMemoryInput): string {\n const now = new Date().toISOString();\n const id = randomUUID();\n const confidence = input.confidence ?? 0.35; // default: low candidate\n const status = statusFromConfidence(confidence);\n const dedupeKey = input.dedupe === false\n ? null\n : memoryDedupeKey({\n type: input.type,\n scope: input.scope,\n repo: input.repo ?? null,\n path_scope: input.path_scope ?? null,\n text: input.text,\n });\n\n if (dedupeKey) {\n const existing = db.select().from(memories)\n .where(and(eq(memories.dedupe_key, dedupeKey), sql`${memories.status} != 'rejected'`))\n .get();\n if (existing) return existing.id;\n }\n\n // onConflictDoNothing closes the TOCTOU window between the pre-check SELECT\n // and this INSERT: when two writers race (e.g. concurrent Claude + Codex\n // session-start scans bootstrapping the same repo), both pass the SELECT\n // above, then one INSERT wins and the other previously threw\n // \"UNIQUE constraint failed: memories.dedupe_key\", crashing the whole hook.\n const result = db.insert(memories)\n .values({\n id,\n type: input.type,\n text: input.text,\n scope: input.scope,\n path_scope: input.path_scope ?? null,\n repo: input.repo ?? null,\n status,\n confidence,\n source: input.source,\n evidence: (input.evidence ?? []) as any,\n capture_context: input.capture_context ? input.capture_context as any : null,\n supersedes: input.supersedes ?? null,\n dedupe_key: dedupeKey,\n created_at: now,\n updated_at: now,\n last_validated_at: null,\n last_injected_at: null,\n injection_count: 0,\n override_count: 0,\n repetition_count: 0,\n })\n .onConflictDoNothing({ target: memories.dedupe_key })\n .run();\n\n if (dedupeKey && result.changes === 0) {\n // Lost the race (or a stale rejected row still holds the key): return the\n // existing memory's id rather than the uninserted one, and don't queue an\n // embedding for a row that was never written.\n const winner = db.select().from(memories)\n .where(eq(memories.dedupe_key, dedupeKey))\n .get();\n if (winner) return winner.id;\n }\n\n queueMemoryEmbeddingSync(db, id);\n return id;\n}\n\n// --- Read ---\n\nexport function getMemory(\n db: RecallDb,\n id: string,\n): MemoryItem | undefined {\n const row = db.select().from(memories).where(eq(memories.id, id)).get();\n if (!row) return undefined;\n return rowToMemory(row);\n}\n\nexport function queryMemories(\n db: RecallDb,\n query: MemoryQuery,\n): MemoryItem[] {\n const conditions = [];\n\n if (query.repo) conditions.push(eq(memories.repo, query.repo));\n if (query.status) conditions.push(eq(memories.status, query.status));\n if (query.type) conditions.push(eq(memories.type, query.type));\n if (query.scope) conditions.push(eq(memories.scope, query.scope));\n if (query.min_confidence != null)\n conditions.push(gte(memories.confidence, query.min_confidence));\n if (query.path) conditions.push(like(memories.path_scope, `%${query.path}%`));\n if (query.auto_inject != null) conditions.push(eq(memories.auto_inject, query.auto_inject));\n\n let statement = db.select().from(memories).$dynamic();\n if (conditions.length > 0) {\n statement = statement.where(and(...conditions));\n }\n if (query.offset != null) {\n statement = statement.offset(query.offset);\n }\n if (query.limit != null) {\n statement = statement.limit(query.limit);\n }\n\n const rows = statement.all();\n\n return rows.map(rowToMemory);\n}\n\nexport function listMemories(\n db: RecallDb,\n repo?: string,\n options: Pick<MemoryQuery, \"limit\" | \"offset\"> = {},\n): MemoryItem[] {\n return queryMemories(db, {\n repo,\n limit: options.limit,\n offset: options.offset,\n });\n}\n\nexport function listRepos(db: RecallDb): string[] {\n return [...new Set(\n db.select({ repo: memories.repo }).from(memories)\n .where(sql`${memories.status} != 'rejected'`)\n .all()\n .map((row) => row.repo)\n .filter((repo): repo is string => Boolean(repo)),\n )].sort();\n}\n\n// --- State transitions ---\n\nexport function promoteMemory(\n db: RecallDb,\n id: string,\n reason: \"explicit_confirm\" | \"repeat_correction\" | \"review_feedback\" | \"passive_gain\",\n evidence?: EvidenceEntry,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n if (mem.status === \"rejected\") return false; // must use reactivate\n\n let newConfidence: number;\n if (reason === \"explicit_confirm\") {\n newConfidence = Math.max(mem.confidence, PROMOTION.EXPLICIT_CONFIRM);\n } else if (reason === \"repeat_correction\") {\n newConfidence = Math.min(1, mem.confidence + PROMOTION.REPEAT_CORRECTION);\n } else if (reason === \"review_feedback\") {\n newConfidence = Math.min(1, mem.confidence + PROMOTION.REVIEW_FEEDBACK);\n } else {\n newConfidence = Math.min(1, mem.confidence + PROMOTION.PASSIVE_GAIN);\n }\n\n const newStatus = statusFromConfidence(newConfidence);\n const now = new Date().toISOString();\n\n const newEvidence = evidence\n ? [...mem.evidence, evidence]\n : mem.evidence;\n\n db.update(memories)\n .set({\n confidence: newConfidence,\n status: newStatus,\n evidence: newEvidence as any,\n updated_at: now,\n last_validated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n\n queueMemoryEmbeddingSync(db, id);\n return true;\n}\n\nexport function demoteMemory(\n db: RecallDb,\n id: string,\n reason: string,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n\n const newConfidence = Math.max(0, mem.confidence - 0.3);\n const newStatus = statusFromConfidence(newConfidence);\n const now = new Date().toISOString();\n\n db.update(memories)\n .set({\n confidence: newConfidence,\n status: newStatus === \"transient\" ? \"candidate\" : newStatus, // don't lose it completely\n updated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n\n queueMemoryEmbeddingSync(db, id);\n return true;\n}\n\nexport type DemoteGlobalResult =\n | { ok: true; outcome: \"rescoped\" | \"rejected\"; memory: MemoryItem }\n | { ok: false; reason: \"not_found\" | \"not_global\" };\n\nexport function demoteGlobalMemory(\n db: RecallDb,\n id: string,\n opts: { repo?: string | null } = {},\n): DemoteGlobalResult {\n const mem = getMemory(db, id);\n if (!mem) return { ok: false, reason: \"not_found\" };\n if (mem.scope !== \"global\") return { ok: false, reason: \"not_global\" };\n\n const targetRepo = opts.repo?.trim() || null;\n const now = new Date().toISOString();\n\n if (targetRepo) {\n const newDedupe = memoryDedupeKey({\n type: mem.type,\n scope: \"repo\",\n repo: targetRepo,\n path_scope: mem.path_scope,\n text: mem.text,\n });\n db.update(memories)\n .set({\n scope: \"repo\",\n repo: targetRepo,\n dedupe_key: newDedupe,\n updated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n } else {\n db.update(memories)\n .set({\n status: \"rejected\",\n confidence: 0,\n dedupe_key: null,\n updated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n }\n\n queueMemoryEmbeddingSync(db, id);\n const updated = getMemory(db, id)!;\n return { ok: true, outcome: targetRepo ? \"rescoped\" : \"rejected\", memory: updated };\n}\n\nexport function rejectMemory(db: RecallDb, id: string): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n\n db.update(memories)\n .set({\n status: \"rejected\",\n confidence: 0,\n dedupe_key: null,\n updated_at: new Date().toISOString(),\n })\n .where(eq(memories.id, id))\n .run();\n\n queueMemoryEmbeddingSync(db, id);\n return true;\n}\n\nexport function confirmMemory(db: RecallDb, id: string): boolean {\n return promoteMemory(db, id, \"explicit_confirm\", {\n type: \"session_correction\",\n session: \"cli\",\n timestamp: new Date().toISOString(),\n context: \"user explicitly confirmed\",\n });\n}\n\nexport function reactivateMemory(\n db: RecallDb,\n id: string,\n evidence: EvidenceEntry,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n if (mem.status !== \"rejected\") return false;\n\n const now = new Date().toISOString();\n const dedupeKey = memoryDedupeKey(mem);\n const existing = db.select().from(memories)\n .where(and(eq(memories.dedupe_key, dedupeKey), sql`${memories.status} != 'rejected'`))\n .get();\n if (existing && existing.id !== id) return false;\n\n db.update(memories)\n .set({\n status: \"candidate\",\n confidence: CONFIDENCE.TRANSIENT_MAX + 0.05,\n dedupe_key: dedupeKey,\n evidence: [...mem.evidence, evidence] as any,\n updated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n\n queueMemoryEmbeddingSync(db, id);\n return true;\n}\n\nexport function appendEvidence(\n db: RecallDb,\n id: string,\n evidence: EvidenceEntry,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n if (hasEquivalentEvidence(mem.evidence, evidence)) return true;\n\n const now = new Date().toISOString();\n db.update(memories)\n .set({\n evidence: [...mem.evidence, evidence] as any,\n updated_at: now,\n last_validated_at: now,\n })\n .where(eq(memories.id, id))\n .run();\n\n return true;\n}\n\nexport function updateMemoryCaptureContext(\n db: RecallDb,\n id: string,\n captureContext: CaptureContext,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n\n db.update(memories)\n .set({\n capture_context: captureContext as any,\n updated_at: new Date().toISOString(),\n })\n .where(eq(memories.id, id))\n .run();\n\n return true;\n}\n\nexport function incrementMemoryRepetition(\n db: RecallDb,\n id: string,\n): boolean {\n const mem = getMemory(db, id);\n if (!mem) return false;\n\n db.update(memories)\n .set({\n repetition_count: sql`repetition_count + 1`,\n updated_at: new Date().toISOString(),\n })\n .where(eq(memories.id, id))\n .run();\n\n return true;\n}\n\nexport function countDistinctCorrectionSessions(mem: MemoryItem): number {\n const sessions = new Set<string>();\n\n for (const entry of mem.evidence) {\n if (entry.type === \"session_correction\") {\n sessions.add(entry.session);\n } else if (entry.type === \"repeated_correction\") {\n for (const session of entry.sessions) {\n sessions.add(session);\n }\n }\n }\n\n return sessions.size;\n}\n\n// --- Feedback ---\n\nexport function recordFeedback(\n db: RecallDb,\n memoryId: string,\n sessionId: string,\n injected: boolean,\n outcome: FeedbackOutcome,\n): string {\n const id = randomUUID();\n const now = new Date().toISOString();\n\n db.insert(feedbackEvents)\n .values({\n id,\n memory_id: memoryId,\n session_id: sessionId,\n injected,\n outcome,\n timestamp: now,\n })\n .run();\n\n const mem = getMemory(db, memoryId);\n if (!mem) return id;\n\n const delta = outcome === \"followed\"\n ? 0.05\n : outcome === \"overridden\"\n ? -0.15\n : outcome === \"ignored\"\n ? -0.02\n : -0.25;\n const nextConfidence = Math.max(0, Math.min(1, mem.confidence + delta));\n const nextStatus = statusFromConfidence(nextConfidence);\n\n // Update injection tracking\n if (injected) {\n db.update(memories)\n .set({\n confidence: nextConfidence,\n status: nextStatus === \"transient\" ? \"candidate\" : nextStatus,\n updated_at: now,\n last_injected_at: now,\n injection_count: sql`injection_count + 1`,\n ...(outcome === \"overridden\" || outcome === \"contradicted\"\n ? { override_count: sql`override_count + 1` }\n : {}),\n })\n .where(eq(memories.id, memoryId))\n .run();\n } else {\n db.update(memories)\n .set({\n confidence: nextConfidence,\n status: nextStatus === \"transient\" ? \"candidate\" : nextStatus,\n updated_at: now,\n })\n .where(eq(memories.id, memoryId))\n .run();\n }\n\n return id;\n}\n\nexport function getMemoryFeedback(\n db: RecallDb,\n memoryId: string,\n) {\n return db\n .select()\n .from(feedbackEvents)\n .where(eq(feedbackEvents.memory_id, memoryId))\n .all();\n}\n\nexport interface FeedbackSummary {\n followed: number;\n overridden: number;\n contradicted: number;\n ignored: number;\n resolved: number;\n}\n\n/**\n * Aggregate feedback outcomes for a batch of memories in a single query.\n * `resolved` excludes `ignored` because the post-Phase-2.3 detector only\n * writes meaningful outcomes.\n */\nexport function getMemoryFeedbackSummaries(\n db: RecallDb,\n memoryIds: readonly string[],\n): Map<string, FeedbackSummary> {\n const empty = (): FeedbackSummary => ({\n followed: 0,\n overridden: 0,\n contradicted: 0,\n ignored: 0,\n resolved: 0,\n });\n const result = new Map<string, FeedbackSummary>();\n if (memoryIds.length === 0) return result;\n for (const id of memoryIds) result.set(id, empty());\n\n const rows = db.select({\n memory_id: feedbackEvents.memory_id,\n outcome: feedbackEvents.outcome,\n count: sql<number>`count(*)`.as(\"count\"),\n })\n .from(feedbackEvents)\n .where(inArray(feedbackEvents.memory_id, [...memoryIds]))\n .groupBy(feedbackEvents.memory_id, feedbackEvents.outcome)\n .all();\n\n for (const row of rows) {\n const entry = result.get(row.memory_id) ?? empty();\n if (row.outcome === \"followed\") entry.followed += row.count;\n else if (row.outcome === \"overridden\") entry.overridden += row.count;\n else if (row.outcome === \"contradicted\") entry.contradicted += row.count;\n else if (row.outcome === \"ignored\") entry.ignored += row.count;\n if (row.outcome !== \"ignored\") entry.resolved += row.count;\n result.set(row.memory_id, entry);\n }\n return result;\n}\n\n/**\n * Smoothed feedback-driven score in [0, 1]. Cold-start memories return their\n * confidence directly; as resolved samples accumulate, the score blends in\n * the empirical followed rate (Bayesian beta(1,1) prior, weight ramps to 1\n * at FEEDBACK_MATURITY resolved samples).\n */\nexport const FEEDBACK_MATURITY = 5;\nexport function feedbackWeightedScore(\n confidence: number,\n summary: FeedbackSummary,\n): number {\n const total = summary.resolved;\n const maturity = Math.min(total, FEEDBACK_MATURITY) / FEEDBACK_MATURITY;\n if (maturity === 0) return confidence;\n // Penalize contradictions harder than overrides.\n const positive = summary.followed;\n const negative = summary.overridden + 2 * summary.contradicted;\n const numerator = Math.max(0, positive - negative + 1);\n const denominator = Math.max(1, total + 2);\n const empirical = Math.min(1, numerator / denominator);\n return (1 - maturity) * confidence + maturity * empirical;\n}\n\n// --- Helpers ---\n\nfunction rowToMemory(row: MemoryRow): MemoryItem {\n const evidence =\n typeof row.evidence === \"string\"\n ? JSON.parse(row.evidence as string)\n : Array.isArray(row.evidence)\n ? row.evidence\n : [];\n const captureContext =\n typeof row.capture_context === \"string\"\n ? JSON.parse(row.capture_context as string)\n : row.capture_context ?? null;\n return {\n id: row.id,\n type: row.type,\n text: row.text,\n scope: row.scope,\n path_scope: row.path_scope,\n repo: row.repo,\n status: row.status,\n confidence: row.confidence,\n source: row.source,\n evidence: evidence as EvidenceEntry[],\n capture_context: captureContext as MemoryItem[\"capture_context\"],\n supersedes: row.supersedes,\n created_at: row.created_at,\n updated_at: row.updated_at,\n last_validated_at: row.last_validated_at,\n last_injected_at: row.last_injected_at,\n injection_count: row.injection_count,\n override_count: row.override_count,\n repetition_count: row.repetition_count,\n auto_inject: row.auto_inject,\n };\n}\n\nfunction hasEquivalentEvidence(\n existing: EvidenceEntry[],\n next: EvidenceEntry,\n): boolean {\n return existing.some((entry) => {\n if (entry.type !== next.type) return false;\n\n if (entry.type === \"session_correction\" && next.type === \"session_correction\") {\n return entry.session === next.session;\n }\n\n if (entry.type === \"review_feedback\" && next.type === \"review_feedback\") {\n return entry.reviewer === next.reviewer && entry.context === next.context;\n }\n\n if (entry.type === \"repo_scan\" && next.type === \"repo_scan\") {\n return entry.file === next.file;\n }\n\n if (entry.type === \"repeated_correction\" && next.type === \"repeated_correction\") {\n return entry.sessions.join(\"|\") === next.sessions.join(\"|\");\n }\n\n return false;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAO,SAAS,oBAAoB,MAAsB;AACxD,SAAO,KACJ,YAAY,EACZ,QAAQ,QAAQ,GAAG,EACnB,QAAQ,kBAAkB,EAAE,EAC5B,KAAK;AACV;AAEO,SAAS,gBAAgB,OAMrB;AACT,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,IACN,MAAM,QAAQ;AAAA,IACd,MAAM,cAAc;AAAA,IACpB,oBAAoB,MAAM,IAAI;AAAA,EAChC,EAAE,KAAK,GAAQ;AACjB;AAEO,SAAS,wBAAwB,OAK7B;AACT,SAAO;AAAA,IACL;AAAA,IACA,MAAM,QAAQ;AAAA,IACd,MAAM,cAAc;AAAA,IACpB,MAAM;AAAA,IACN,oBAAo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Y,MAAM,YAAY,KAAK;AAAA,IACpE;AAEA,QAAI,MAAM,SAAS,eAAe,KAAK,SAAS,aAAa;AAC3D,aAAO,MAAM,SAAS,KAAK;AAAA,IAC7B;AAEA,QAAI,MAAM,SAAS,yBAAyB,KAAK,SAAS,uBAAuB;AAC/E,aAAO,MAAM,SAAS,KAAK,GAAG,MAAM,KAAK,SAAS,KAAK,GAAG;AAAA,IAC5D;AAEA,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
llmUsage,
|
|
4
4
|
memories,
|
|
5
5
|
memoryEmbeddings
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-G5IAOZAL.js";
|
|
7
7
|
import {
|
|
8
8
|
getProviderConfig,
|
|
9
9
|
hasProviderConfigured,
|
|
@@ -2343,4 +2343,4 @@ export {
|
|
|
2343
2343
|
findSemanticDuplicates,
|
|
2344
2344
|
findSimilarRejectedExemplar
|
|
2345
2345
|
};
|
|
2346
|
-
//# sourceMappingURL=chunk-
|
|
2346
|
+
//# sourceMappingURL=chunk-A4ES3H4Y.js.map
|
|
@@ -2,14 +2,14 @@ import {
|
|
|
2
2
|
listEntitiesForMemory,
|
|
3
3
|
listMemoryIdsForEntity,
|
|
4
4
|
neighborsOf
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-EYMC2PDI.js";
|
|
6
6
|
import {
|
|
7
7
|
getMemory
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-4VBHVY3D.js";
|
|
9
9
|
import {
|
|
10
10
|
hybridSearch,
|
|
11
11
|
searchMemoryFtsIndex
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-A4ES3H4Y.js";
|
|
13
13
|
|
|
14
14
|
// src/graph/retrieval.ts
|
|
15
15
|
var SEED_WEIGHT = 1;
|
|
@@ -120,4 +120,4 @@ async function graphQuery(db, query, embeddingConfig, options = {}) {
|
|
|
120
120
|
export {
|
|
121
121
|
graphQuery
|
|
122
122
|
};
|
|
123
|
-
//# sourceMappingURL=chunk-
|
|
123
|
+
//# sourceMappingURL=chunk-BHTIIKRB.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sql
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-G5IAOZAL.js";
|
|
4
4
|
|
|
5
5
|
// node_modules/drizzle-orm/sql/expressions/select.js
|
|
6
6
|
function asc(column) {
|
|
@@ -14,4 +14,4 @@ export {
|
|
|
14
14
|
asc,
|
|
15
15
|
desc
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-BJTLWRZH.js.map
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
promoteMemory,
|
|
13
13
|
queryMemories,
|
|
14
14
|
updateMemoryCaptureContext
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4VBHVY3D.js";
|
|
16
16
|
import {
|
|
17
17
|
desc
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-BJTLWRZH.js";
|
|
19
19
|
import {
|
|
20
20
|
CONFIDENCE,
|
|
21
21
|
LlmCredentialError,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
findSimilarRejectedExemplar,
|
|
25
25
|
loadEmbeddingConfigFromEnv,
|
|
26
26
|
queueMemoryEmbeddingSync
|
|
27
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-A4ES3H4Y.js";
|
|
28
28
|
import {
|
|
29
29
|
activityEvents,
|
|
30
30
|
and,
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
memoryMaintenanceTasks,
|
|
46
46
|
or,
|
|
47
47
|
sql
|
|
48
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-G5IAOZAL.js";
|
|
49
49
|
import {
|
|
50
50
|
hasProviderConfigured,
|
|
51
51
|
init_keychain
|
|
@@ -1198,6 +1198,12 @@ function runDeterministicCleanup(db, opts = { dryRun: true }) {
|
|
|
1198
1198
|
if (!opts.only || opts.only === "globalize_cross_repo") {
|
|
1199
1199
|
plan.push(...planGlobalizeCrossRepo(db));
|
|
1200
1200
|
}
|
|
1201
|
+
if (!opts.only || opts.only === "reject_test_fixture_repo") {
|
|
1202
|
+
plan.push(...planRejectTestFixtureRepos(db));
|
|
1203
|
+
}
|
|
1204
|
+
if (!opts.only || opts.only === "reject_invalid_scope") {
|
|
1205
|
+
plan.push(...planRejectInvalidScopes(db));
|
|
1206
|
+
}
|
|
1201
1207
|
const counts = summarize(plan);
|
|
1202
1208
|
if (!opts.dryRun) {
|
|
1203
1209
|
for (const item of plan) {
|
|
@@ -1217,6 +1223,12 @@ function runDeterministicCleanup(db, opts = { dryRun: true }) {
|
|
|
1217
1223
|
case "globalize_cross_repo":
|
|
1218
1224
|
applyGlobalizeCrossRepo(db, runId, item);
|
|
1219
1225
|
break;
|
|
1226
|
+
case "reject_test_fixture_repo":
|
|
1227
|
+
applyRejectTestFixtureRepo(db, runId, item);
|
|
1228
|
+
break;
|
|
1229
|
+
case "reject_invalid_scope":
|
|
1230
|
+
applyRejectInvalidScope(db, runId, item);
|
|
1231
|
+
break;
|
|
1220
1232
|
}
|
|
1221
1233
|
}
|
|
1222
1234
|
}
|
|
@@ -1237,6 +1249,9 @@ function summarize(plan) {
|
|
|
1237
1249
|
let commandSuppressions = 0;
|
|
1238
1250
|
let globalizations = 0;
|
|
1239
1251
|
let globalizeLosers = 0;
|
|
1252
|
+
let testFixtureRejections = 0;
|
|
1253
|
+
let invalidScopeRejections = 0;
|
|
1254
|
+
let e2eArtifactRejections = 0;
|
|
1240
1255
|
for (const p of plan) {
|
|
1241
1256
|
if (p.kind === "dedupe_exact_merge") {
|
|
1242
1257
|
dedupeClusters += 1;
|
|
@@ -1247,9 +1262,16 @@ function summarize(plan) {
|
|
|
1247
1262
|
repeatPromotions += 1;
|
|
1248
1263
|
} else if (p.kind === "suppress_unproductive_command") {
|
|
1249
1264
|
commandSuppressions += 1;
|
|
1250
|
-
} else {
|
|
1265
|
+
} else if (p.kind === "globalize_cross_repo") {
|
|
1251
1266
|
globalizations += 1;
|
|
1252
1267
|
globalizeLosers += p.loser_ids.length;
|
|
1268
|
+
} else if (p.kind === "reject_test_fixture_repo") {
|
|
1269
|
+
testFixtureRejections += 1;
|
|
1270
|
+
} else {
|
|
1271
|
+
invalidScopeRejections += 1;
|
|
1272
|
+
}
|
|
1273
|
+
if (p.kind === "reject_fragment_candidate" && p.reasons.includes("e2e_verification_artifact")) {
|
|
1274
|
+
e2eArtifactRejections += 1;
|
|
1253
1275
|
}
|
|
1254
1276
|
}
|
|
1255
1277
|
return {
|
|
@@ -1259,7 +1281,10 @@ function summarize(plan) {
|
|
|
1259
1281
|
repeat_promotions: repeatPromotions,
|
|
1260
1282
|
command_suppressions: commandSuppressions,
|
|
1261
1283
|
globalizations,
|
|
1262
|
-
globalize_losers: globalizeLosers
|
|
1284
|
+
globalize_losers: globalizeLosers,
|
|
1285
|
+
test_fixture_rejections: testFixtureRejections,
|
|
1286
|
+
invalid_scope_rejections: invalidScopeRejections,
|
|
1287
|
+
e2e_artifact_rejections: e2eArtifactRejections
|
|
1263
1288
|
};
|
|
1264
1289
|
}
|
|
1265
1290
|
function normalizeText(text) {
|
|
@@ -1427,6 +1452,8 @@ var VERB_HINTS = [
|
|
|
1427
1452
|
"close",
|
|
1428
1453
|
"send",
|
|
1429
1454
|
"receive",
|
|
1455
|
+
"treat",
|
|
1456
|
+
"propose",
|
|
1430
1457
|
"configure",
|
|
1431
1458
|
"enable",
|
|
1432
1459
|
"disable"
|
|
@@ -1438,6 +1465,25 @@ var TRAILING_DOUBLE_DOT_RE = /\.{2,}\s*$/;
|
|
|
1438
1465
|
var TRAILING_DASH_RE = /[—–-]\s*$/;
|
|
1439
1466
|
var EMBEDDED_QUESTION_RE = /^\s*(?:always|never|must|don't|do not|required|prefer|should)\s+(?:can|could|would|will|do|does|did|is|are|was|were|have|has|should|may|might)\s+(?:you|we|i|they|it|he|she)\b/i;
|
|
1440
1467
|
var RULE_FILLER_PREFIX_RE = /^\s*(?:always|never|must|don't|do not|prefer|required)\s+(?:just|now|uh|um|so|like|maybe|kinda|sort\s+of)\b/i;
|
|
1468
|
+
var VAGUE_SPEECH_FRAGMENT_RE = /\b(?:or whatever|and stuff like that|stuff like that|something like that|things like that)\b/i;
|
|
1469
|
+
var WORKSPACE_ONLY_RULE_RE = /^\s*(?:always\s+)?keep\s+(?:all\s+)?(?:edits|work|changes)\s+inside\s+(?:(?:the\s+)?current\s+|(?:the\s+)?specified\s+|the\s+)?workspace(?:\s+at\s+\S+)?\.?\s*$/i;
|
|
1470
|
+
var BENCHMARK_ARTIFACT_RULE_RE = /\b(?:agent-scorecard|data\/agent-runs\.json|generated scorecard|benchmark tasks?|Oktapod and OpenClaw|OpenClaw and Oktapod|do not add Hermes)\b/i;
|
|
1471
|
+
var TOOL_EMBARGO_TASK_RULE_RE = /^\s*do\s+not\s+(?:open\s+browser,\s+screenshot,\s+or\s+devtools\s+tools|open\s+browser,\s+take\s+screenshots,\s+or\s+use\s+devtools\s+tools)(?:\s+(?:during|for)\s+(?:this\s+|the\s+)?(?:task|benchmark(?:\s+run)?))?\.?\s*$/i;
|
|
1472
|
+
var E2E_VERIFICATION_ARTIFACT_RE = /\b(?:recall\s+(?:e2e|end[- ]to[- ]end)\s+verification|(?:e2e|end[- ]to[- ]end)\s+verification\s+(?:smoke|fixture|artifact)|for\s+recall\s+(?:e2e|end[- ]to[- ]end)\s+verification)\b/i;
|
|
1473
|
+
var ACTIVE_FRAGMENT_REASONS = /* @__PURE__ */ new Set([
|
|
1474
|
+
"bare_modal",
|
|
1475
|
+
"trailing_question",
|
|
1476
|
+
"trailing_double_dot",
|
|
1477
|
+
"trailing_dash",
|
|
1478
|
+
"dangling_connector",
|
|
1479
|
+
"filler_prefix",
|
|
1480
|
+
"vague_speech_fragment",
|
|
1481
|
+
"workspace_only_runtime_rule",
|
|
1482
|
+
"benchmark_artifact_rule",
|
|
1483
|
+
"tool_embargo_task_rule",
|
|
1484
|
+
"e2e_verification_artifact",
|
|
1485
|
+
"embedded_question"
|
|
1486
|
+
]);
|
|
1441
1487
|
var MAX_RULE_LENGTH = 300;
|
|
1442
1488
|
var MIN_RULE_LENGTH = 20;
|
|
1443
1489
|
function planRejectFragments(db) {
|
|
@@ -1446,16 +1492,17 @@ function planRejectFragments(db) {
|
|
|
1446
1492
|
text: memories.text,
|
|
1447
1493
|
source: memories.source,
|
|
1448
1494
|
status: memories.status
|
|
1449
|
-
}).from(memories).where(and(
|
|
1495
|
+
}).from(memories).where(and(inArray(memories.status, ["active", "candidate"]), eq(memories.source, "user_correction"))).all();
|
|
1450
1496
|
const out = [];
|
|
1451
1497
|
for (const row of rows) {
|
|
1452
1498
|
const reasons = qualityReasons(row.text);
|
|
1453
|
-
|
|
1499
|
+
const actionableReasons = row.status === "active" ? reasons.filter((reason) => ACTIVE_FRAGMENT_REASONS.has(reason)) : reasons;
|
|
1500
|
+
if (actionableReasons.length > 0) {
|
|
1454
1501
|
out.push({
|
|
1455
1502
|
kind: "reject_fragment_candidate",
|
|
1456
1503
|
memory_id: row.id,
|
|
1457
1504
|
text: row.text,
|
|
1458
|
-
reasons
|
|
1505
|
+
reasons: actionableReasons
|
|
1459
1506
|
});
|
|
1460
1507
|
}
|
|
1461
1508
|
}
|
|
@@ -1472,6 +1519,11 @@ function qualityReasons(rawText) {
|
|
|
1472
1519
|
if (TRAILING_DASH_RE.test(text)) reasons.push("trailing_dash");
|
|
1473
1520
|
if (DANGLING_CONNECTOR_RE.test(text)) reasons.push("dangling_connector");
|
|
1474
1521
|
if (RULE_FILLER_PREFIX_RE.test(text)) reasons.push("filler_prefix");
|
|
1522
|
+
if (VAGUE_SPEECH_FRAGMENT_RE.test(text)) reasons.push("vague_speech_fragment");
|
|
1523
|
+
if (WORKSPACE_ONLY_RULE_RE.test(text)) reasons.push("workspace_only_runtime_rule");
|
|
1524
|
+
if (BENCHMARK_ARTIFACT_RULE_RE.test(text)) reasons.push("benchmark_artifact_rule");
|
|
1525
|
+
if (TOOL_EMBARGO_TASK_RULE_RE.test(text)) reasons.push("tool_embargo_task_rule");
|
|
1526
|
+
if (E2E_VERIFICATION_ARTIFACT_RE.test(text)) reasons.push("e2e_verification_artifact");
|
|
1475
1527
|
if (EMBEDDED_QUESTION_RE.test(text)) reasons.push("embedded_question");
|
|
1476
1528
|
const words = text.toLowerCase().replace(/[^\w' ]+/g, " ").split(/\s+/).filter(Boolean);
|
|
1477
1529
|
const hasVerb = words.some((w) => VERB_HINTS.includes(w));
|
|
@@ -1480,7 +1532,7 @@ function qualityReasons(rawText) {
|
|
|
1480
1532
|
}
|
|
1481
1533
|
function applyRejectFragment(db, runId, plan) {
|
|
1482
1534
|
const before = getMemory(db, plan.memory_id);
|
|
1483
|
-
if (!before ||
|
|
1535
|
+
if (!before || !["active", "candidate"].includes(before.status)) return;
|
|
1484
1536
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1485
1537
|
db.update(memories).set({ status: "rejected", dedupe_key: null, updated_at: now }).where(eq(memories.id, plan.memory_id)).run();
|
|
1486
1538
|
const after = getMemory(db, plan.memory_id);
|
|
@@ -1507,6 +1559,124 @@ function applyRejectFragment(db, runId, plan) {
|
|
|
1507
1559
|
created_at: now
|
|
1508
1560
|
}).run();
|
|
1509
1561
|
}
|
|
1562
|
+
var TEST_FIXTURE_REPO_RE = /^test\/recall-[a-z0-9-]+-repo-[a-z0-9]+$/i;
|
|
1563
|
+
function planRejectTestFixtureRepos(db) {
|
|
1564
|
+
const rows = db.select({
|
|
1565
|
+
id: memories.id,
|
|
1566
|
+
repo: memories.repo,
|
|
1567
|
+
text: memories.text,
|
|
1568
|
+
status: memories.status
|
|
1569
|
+
}).from(memories).where(inArray(memories.status, ["active", "candidate"])).all();
|
|
1570
|
+
return rows.filter((row) => row.repo != null && TEST_FIXTURE_REPO_RE.test(row.repo)).map((row) => ({
|
|
1571
|
+
kind: "reject_test_fixture_repo",
|
|
1572
|
+
memory_id: row.id,
|
|
1573
|
+
repo: row.repo,
|
|
1574
|
+
text: row.text
|
|
1575
|
+
}));
|
|
1576
|
+
}
|
|
1577
|
+
function applyRejectTestFixtureRepo(db, runId, plan) {
|
|
1578
|
+
const before = getMemory(db, plan.memory_id);
|
|
1579
|
+
if (!before || !["active", "candidate"].includes(before.status)) return;
|
|
1580
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1581
|
+
db.update(memories).set({ status: "rejected", dedupe_key: null, updated_at: now }).where(eq(memories.id, plan.memory_id)).run();
|
|
1582
|
+
const after = getMemory(db, plan.memory_id);
|
|
1583
|
+
recordAuditWithSnapshot(
|
|
1584
|
+
db,
|
|
1585
|
+
plan.memory_id,
|
|
1586
|
+
"rejected",
|
|
1587
|
+
DEFAULT_ACTOR,
|
|
1588
|
+
`cleanup_test_fixture_repo:${plan.repo}:run:${runId}`,
|
|
1589
|
+
before,
|
|
1590
|
+
after ?? null
|
|
1591
|
+
);
|
|
1592
|
+
db.insert(maintenanceCleanupLog).values({
|
|
1593
|
+
id: randomUUID3(),
|
|
1594
|
+
run_id: runId,
|
|
1595
|
+
action: "reject_test_fixture_repo",
|
|
1596
|
+
memory_id: plan.memory_id,
|
|
1597
|
+
related_memory_id: null,
|
|
1598
|
+
before_snapshot: before,
|
|
1599
|
+
after_snapshot: after,
|
|
1600
|
+
details: { repo: plan.repo },
|
|
1601
|
+
reverted: false,
|
|
1602
|
+
reverted_at: null,
|
|
1603
|
+
created_at: now
|
|
1604
|
+
}).run();
|
|
1605
|
+
}
|
|
1606
|
+
function isTempPath(path) {
|
|
1607
|
+
if (!path) return false;
|
|
1608
|
+
return path.startsWith("/tmp/") || path.startsWith("/private/tmp/") || path.includes("/tmp/");
|
|
1609
|
+
}
|
|
1610
|
+
function isWorkspaceRootAlias(repo) {
|
|
1611
|
+
return repo === "Projects";
|
|
1612
|
+
}
|
|
1613
|
+
function planRejectInvalidScopes(db) {
|
|
1614
|
+
const rows = db.select({
|
|
1615
|
+
id: memories.id,
|
|
1616
|
+
scope: memories.scope,
|
|
1617
|
+
repo: memories.repo,
|
|
1618
|
+
path_scope: memories.path_scope,
|
|
1619
|
+
text: memories.text,
|
|
1620
|
+
status: memories.status,
|
|
1621
|
+
source: memories.source
|
|
1622
|
+
}).from(memories).where(inArray(memories.status, ["active", "candidate"])).all();
|
|
1623
|
+
const out = [];
|
|
1624
|
+
for (const row of rows) {
|
|
1625
|
+
if (row.source !== "user_correction") continue;
|
|
1626
|
+
if (qualityReasons(row.text).length > 0) continue;
|
|
1627
|
+
const reasons = [];
|
|
1628
|
+
if (row.scope === "path" && !row.path_scope) reasons.push("path_scope_without_path");
|
|
1629
|
+
if (row.scope === "path" && isTempPath(row.path_scope)) reasons.push("temp_path_scope");
|
|
1630
|
+
if (row.scope === "repo" && isTempPath(row.path_scope)) reasons.push("temp_repo_path_scope");
|
|
1631
|
+
if (row.repo && isTempPath(row.repo)) reasons.push("repo_field_is_temp_path");
|
|
1632
|
+
if (isWorkspaceRootAlias(row.repo)) reasons.push("workspace_root_repo_alias");
|
|
1633
|
+
if (reasons.length === 0) continue;
|
|
1634
|
+
out.push({
|
|
1635
|
+
kind: "reject_invalid_scope",
|
|
1636
|
+
memory_id: row.id,
|
|
1637
|
+
scope: row.scope,
|
|
1638
|
+
repo: row.repo,
|
|
1639
|
+
path_scope: row.path_scope,
|
|
1640
|
+
text: row.text,
|
|
1641
|
+
reasons
|
|
1642
|
+
});
|
|
1643
|
+
}
|
|
1644
|
+
return out;
|
|
1645
|
+
}
|
|
1646
|
+
function applyRejectInvalidScope(db, runId, plan) {
|
|
1647
|
+
const before = getMemory(db, plan.memory_id);
|
|
1648
|
+
if (!before || !["active", "candidate"].includes(before.status)) return;
|
|
1649
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1650
|
+
db.update(memories).set({ status: "rejected", dedupe_key: null, updated_at: now }).where(eq(memories.id, plan.memory_id)).run();
|
|
1651
|
+
const after = getMemory(db, plan.memory_id);
|
|
1652
|
+
recordAuditWithSnapshot(
|
|
1653
|
+
db,
|
|
1654
|
+
plan.memory_id,
|
|
1655
|
+
"rejected",
|
|
1656
|
+
DEFAULT_ACTOR,
|
|
1657
|
+
`cleanup_invalid_scope:${plan.reasons.join(",")}:run:${runId}`,
|
|
1658
|
+
before,
|
|
1659
|
+
after ?? null
|
|
1660
|
+
);
|
|
1661
|
+
db.insert(maintenanceCleanupLog).values({
|
|
1662
|
+
id: randomUUID3(),
|
|
1663
|
+
run_id: runId,
|
|
1664
|
+
action: "reject_invalid_scope",
|
|
1665
|
+
memory_id: plan.memory_id,
|
|
1666
|
+
related_memory_id: null,
|
|
1667
|
+
before_snapshot: before,
|
|
1668
|
+
after_snapshot: after,
|
|
1669
|
+
details: {
|
|
1670
|
+
scope: plan.scope,
|
|
1671
|
+
repo: plan.repo,
|
|
1672
|
+
path_scope: plan.path_scope,
|
|
1673
|
+
reasons: plan.reasons
|
|
1674
|
+
},
|
|
1675
|
+
reverted: false,
|
|
1676
|
+
reverted_at: null,
|
|
1677
|
+
created_at: now
|
|
1678
|
+
}).run();
|
|
1679
|
+
}
|
|
1510
1680
|
function planPromoteRepeats(db) {
|
|
1511
1681
|
const rows = db.select({
|
|
1512
1682
|
id: memories.id,
|
|
@@ -1825,6 +1995,9 @@ function formatCleanupReport(report) {
|
|
|
1825
1995
|
lines.push(` repeat_promotions: ${report.counts.repeat_promotions}`);
|
|
1826
1996
|
lines.push(` command_suppressions: ${report.counts.command_suppressions}`);
|
|
1827
1997
|
lines.push(` globalizations: ${report.counts.globalizations} (losers=${report.counts.globalize_losers})`);
|
|
1998
|
+
lines.push(` test_fixture_rejects: ${report.counts.test_fixture_rejections}`);
|
|
1999
|
+
lines.push(` invalid_scope_rejects:${report.counts.invalid_scope_rejections}`);
|
|
2000
|
+
lines.push(` e2e_artifact_rejects: ${report.counts.e2e_artifact_rejections}`);
|
|
1828
2001
|
if (report.plan.length === 0) {
|
|
1829
2002
|
lines.push(" (no actions)");
|
|
1830
2003
|
return lines.join("\n");
|
|
@@ -1843,9 +2016,15 @@ function formatCleanupReport(report) {
|
|
|
1843
2016
|
} else if (item.kind === "suppress_unproductive_command") {
|
|
1844
2017
|
lines.push(` suppress: ${item.memory_id.slice(0, 8)} inj=${item.injection_count} followed=${item.followed_count}`);
|
|
1845
2018
|
lines.push(` "${truncate(item.text, 80)}"`);
|
|
1846
|
-
} else {
|
|
2019
|
+
} else if (item.kind === "globalize_cross_repo") {
|
|
1847
2020
|
lines.push(` globalize: keep ${item.winner_id.slice(0, 8)} drop ${item.loser_ids.length} repos=[${item.repos.join(",")}]`);
|
|
1848
2021
|
lines.push(` "${truncate(item.winner_text, 80)}"`);
|
|
2022
|
+
} else if (item.kind === "reject_test_fixture_repo") {
|
|
2023
|
+
lines.push(` reject-test-repo: ${item.memory_id.slice(0, 8)} repo=${item.repo}`);
|
|
2024
|
+
lines.push(` "${truncate(item.text, 80)}"`);
|
|
2025
|
+
} else {
|
|
2026
|
+
lines.push(` reject-invalid-scope: ${item.memory_id.slice(0, 8)} scope=${item.scope} repo=${item.repo ?? "-"} path=${item.path_scope ?? "-"} reasons=${item.reasons.join(",")}`);
|
|
2027
|
+
lines.push(` "${truncate(item.text, 80)}"`);
|
|
1849
2028
|
}
|
|
1850
2029
|
}
|
|
1851
2030
|
return lines.join("\n");
|
|
@@ -2888,6 +3067,72 @@ function abandonOverAttemptTasks(db) {
|
|
|
2888
3067
|
)).run();
|
|
2889
3068
|
return result.changes;
|
|
2890
3069
|
}
|
|
3070
|
+
var TEST_FIXTURE_REPO_RE2 = /^test\/recall-[a-z0-9-]+-repo-[a-z0-9]+$/i;
|
|
3071
|
+
function isTempPath2(value) {
|
|
3072
|
+
if (!value) return false;
|
|
3073
|
+
return value.startsWith("/tmp/") || value.startsWith("/private/tmp/") || value.includes("/tmp/");
|
|
3074
|
+
}
|
|
3075
|
+
function invalidTaskScopeReasons(repo) {
|
|
3076
|
+
const reasons = [];
|
|
3077
|
+
if (repo === "Projects") reasons.push("workspace_root_repo_alias");
|
|
3078
|
+
if (repo && TEST_FIXTURE_REPO_RE2.test(repo)) reasons.push("test_fixture_repo");
|
|
3079
|
+
if (isTempPath2(repo)) reasons.push("repo_field_is_temp_path");
|
|
3080
|
+
return reasons;
|
|
3081
|
+
}
|
|
3082
|
+
function payloadString(payload, key) {
|
|
3083
|
+
const value = payload[key];
|
|
3084
|
+
return typeof value === "string" && value.trim() ? value : null;
|
|
3085
|
+
}
|
|
3086
|
+
function taskTargetReasons(db, task) {
|
|
3087
|
+
const payload = task.payload ?? {};
|
|
3088
|
+
if (task.kind === "verify_capture" || task.kind === "refine_candidate") {
|
|
3089
|
+
const memoryId = payloadString(payload, "memory_id");
|
|
3090
|
+
if (!memoryId) return ["target_memory_id_missing"];
|
|
3091
|
+
const row = db.select({ status: memories.status }).from(memories).where(eq(memories.id, memoryId)).get();
|
|
3092
|
+
if (!row) return ["target_memory_missing"];
|
|
3093
|
+
if (row.status === "rejected") return ["target_memory_rejected"];
|
|
3094
|
+
}
|
|
3095
|
+
if (task.kind === "merge_duplicates") {
|
|
3096
|
+
const rawCandidates = Array.isArray(payload.candidates) ? payload.candidates : [];
|
|
3097
|
+
const ids = rawCandidates.map((candidate) => {
|
|
3098
|
+
if (!candidate || typeof candidate !== "object") return null;
|
|
3099
|
+
const id = candidate.id;
|
|
3100
|
+
return typeof id === "string" && id.trim() ? id : null;
|
|
3101
|
+
}).filter((id) => id != null);
|
|
3102
|
+
if (ids.length < 2) return ["merge_candidates_insufficient"];
|
|
3103
|
+
const live = db.select({ id: memories.id }).from(memories).where(and(
|
|
3104
|
+
inArray(memories.id, ids),
|
|
3105
|
+
inArray(memories.status, ["active", "candidate"])
|
|
3106
|
+
)).all();
|
|
3107
|
+
if (live.length < 2) return ["merge_candidates_not_live"];
|
|
3108
|
+
}
|
|
3109
|
+
return [];
|
|
3110
|
+
}
|
|
3111
|
+
function abandonInvalidOpenTasks(db, now = /* @__PURE__ */ new Date()) {
|
|
3112
|
+
const rows = db.select().from(memoryMaintenanceTasks).where(inArray(memoryMaintenanceTasks.status, OPEN_STATUSES)).all();
|
|
3113
|
+
let changed = 0;
|
|
3114
|
+
const nowIso = now.toISOString();
|
|
3115
|
+
for (const row of rows) {
|
|
3116
|
+
const reasons = [
|
|
3117
|
+
...invalidTaskScopeReasons(row.repo),
|
|
3118
|
+
...taskTargetReasons(db, row)
|
|
3119
|
+
];
|
|
3120
|
+
if (reasons.length === 0) continue;
|
|
3121
|
+
const result = db.update(memoryMaintenanceTasks).set({
|
|
3122
|
+
status: "abandoned",
|
|
3123
|
+
failure_reason: `invalid_task:${[...new Set(reasons)].join(",")}`.slice(0, 500),
|
|
3124
|
+
claimed_by: null,
|
|
3125
|
+
claimed_at: null,
|
|
3126
|
+
claim_expires_at: null,
|
|
3127
|
+
completed_at: nowIso
|
|
3128
|
+
}).where(and(
|
|
3129
|
+
eq(memoryMaintenanceTasks.id, row.id),
|
|
3130
|
+
inArray(memoryMaintenanceTasks.status, OPEN_STATUSES)
|
|
3131
|
+
)).run();
|
|
3132
|
+
changed += result.changes;
|
|
3133
|
+
}
|
|
3134
|
+
return changed;
|
|
3135
|
+
}
|
|
2891
3136
|
function applyBacklogCaps(db, config) {
|
|
2892
3137
|
let dropped = 0;
|
|
2893
3138
|
const overKindRows = db.select({
|
|
@@ -3127,6 +3372,7 @@ async function enqueueMaintenanceTasks(db, config = DEFAULT_ENQUEUE_CONFIG) {
|
|
|
3127
3372
|
const expired = sweepExpiredLeases(db);
|
|
3128
3373
|
abandonOverAttemptTasks(db);
|
|
3129
3374
|
const expiredPending = expireStalePendingTasks(db, config.summary_max_age_days * 2);
|
|
3375
|
+
const invalid = abandonInvalidOpenTasks(db);
|
|
3130
3376
|
const counts = {};
|
|
3131
3377
|
counts.refine_candidate = produceRefineCandidateTasks(db, config);
|
|
3132
3378
|
counts.summarize_history = produceSummarizeHistoryTasks(db, config);
|
|
@@ -3140,7 +3386,8 @@ async function enqueueMaintenanceTasks(db, config = DEFAULT_ENQUEUE_CONFIG) {
|
|
|
3140
3386
|
per_kind: counts,
|
|
3141
3387
|
expired_leases_swept: expired,
|
|
3142
3388
|
dropped_over_cap: dropped,
|
|
3143
|
-
expired_pending_tasks: expiredPending
|
|
3389
|
+
expired_pending_tasks: expiredPending,
|
|
3390
|
+
invalid_tasks_abandoned: invalid
|
|
3144
3391
|
};
|
|
3145
3392
|
}
|
|
3146
3393
|
var MemoryScope = z.enum(["session", "path", "repo", "team", "global"]);
|
|
@@ -3376,6 +3623,7 @@ export {
|
|
|
3376
3623
|
sweepExpiredLeases,
|
|
3377
3624
|
expireStalePendingTasks,
|
|
3378
3625
|
abandonOverAttemptTasks,
|
|
3626
|
+
abandonInvalidOpenTasks,
|
|
3379
3627
|
applyBacklogCaps,
|
|
3380
3628
|
enqueueExtractRulesFromPrompt,
|
|
3381
3629
|
enqueueVerifyCapture,
|
|
@@ -3404,6 +3652,8 @@ export {
|
|
|
3404
3652
|
planDedupeExact,
|
|
3405
3653
|
planRejectFragments,
|
|
3406
3654
|
qualityReasons,
|
|
3655
|
+
planRejectTestFixtureRepos,
|
|
3656
|
+
planRejectInvalidScopes,
|
|
3407
3657
|
planPromoteRepeats,
|
|
3408
3658
|
planSuppressCommands,
|
|
3409
3659
|
planGlobalizeCrossRepo,
|
|
@@ -3418,4 +3668,4 @@ export {
|
|
|
3418
3668
|
processCorrection,
|
|
3419
3669
|
processReviewFeedback
|
|
3420
3670
|
};
|
|
3421
|
-
//# sourceMappingURL=chunk-
|
|
3671
|
+
//# sourceMappingURL=chunk-DYAQ4RKX.js.map
|