@edihasaj/recall 2.0.7 → 2.0.9
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 +11 -0
- package/dist/{chunk-2WBJWKIK.js → chunk-27L3NQUO.js} +20 -6
- package/dist/chunk-27L3NQUO.js.map +1 -0
- package/dist/{chunk-MZTZKBRL.js → chunk-BTHB6Q43.js} +2 -2
- package/dist/{chunk-BJZCBMU4.js → chunk-D6COH25L.js} +22 -16
- package/dist/chunk-D6COH25L.js.map +1 -0
- package/dist/{chunk-VH3FI2X3.js → chunk-DH6RDBAI.js} +843 -144
- package/dist/chunk-DH6RDBAI.js.map +1 -0
- package/dist/{chunk-EDUIDJWZ.js → chunk-IKD5BHN6.js} +2 -2
- package/dist/{chunk-EDUIDJWZ.js.map → chunk-IKD5BHN6.js.map} +1 -1
- package/dist/{chunk-DQMKYMUS.js → chunk-J3QU7QT3.js} +435 -89
- package/dist/chunk-J3QU7QT3.js.map +1 -0
- package/dist/{chunk-63H4ENYA.js → chunk-J4EGDZIT.js} +351 -139
- package/dist/chunk-J4EGDZIT.js.map +1 -0
- package/dist/{chunk-AVUTQWZE.js → chunk-K3Z6YUKH.js} +5 -5
- package/dist/{chunk-V3MYT3AT.js → chunk-KHE2ME44.js} +3 -3
- package/dist/{chunk-YDVBXHX2.js → chunk-N23KB2S7.js} +5 -5
- package/dist/{chunk-QPOOF2GK.js → chunk-NENWBA4Q.js} +3 -3
- package/dist/{chunk-M5MPUMCJ.js → chunk-RELMDL4Y.js} +3 -3
- package/dist/{chunk-S46JVROA.js → chunk-ROFI66JK.js} +2 -2
- package/dist/{chunk-W75S5CK3.js → chunk-SJ23JYZJ.js} +2 -2
- package/dist/{chunk-BTD3BYVV.js → chunk-T3DS4QYF.js} +2 -2
- package/dist/{chunk-MQPMF5F3.js → chunk-TEDEFEXJ.js} +7 -7
- package/dist/{chunk-EX5UTOIU.js → chunk-UJHXM7FK.js} +9 -9
- package/dist/{chunk-FOJHR4JJ.js → chunk-VBX7MM2C.js} +2 -2
- package/dist/{cleanup-EDWLCJPH.js → cleanup-FGPVQRYE.js} +11 -11
- package/dist/cli.js +839 -249
- package/dist/cli.js.map +1 -1
- package/dist/{codex-trust-H6KNABHV.js → codex-trust-CWD4SYOS.js} +4 -4
- package/dist/daemon.js +208 -48
- package/dist/daemon.js.map +1 -1
- package/dist/dispatcher-L77LKD7R.js +22 -0
- package/dist/{embeddings-W24SA6R3.js → embeddings-J24U3RAX.js} +5 -5
- package/dist/ingest-UU7VULPA.js +20 -0
- package/dist/{keychain-LVWMAS7D.js → keychain-23KFNHQ6.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-GMYJ5NGO.js → memory-value-MWWV4P4X.js} +11 -11
- package/dist/{provenance-KSBMVJO5.js → provenance-U2VAENS6.js} +9 -9
- package/dist/quality-PIYKKBIT.js +25 -0
- package/dist/retrieval-DDYCXIUG.js +15 -0
- package/dist/{store-QYLHMBPE.js → store-DL6YQ6C3.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-7P7XOGSC.js → tasks-3VQQG77M.js} +11 -11
- package/dist/{usage-KVVZQTZA.js → usage-UB4GLDGI.js} +4 -4
- package/dist/webui/assets/{GraphPage-DJhwG-72.js → GraphPage-BH_Mch3C.js} +2 -2
- package/dist/webui/assets/{GraphPage-DJhwG-72.js.map → GraphPage-BH_Mch3C.js.map} +1 -1
- package/dist/webui/assets/{index-Cpn2MjW0.js → index-CPFc-fiv.js} +25 -25
- package/dist/webui/assets/index-CPFc-fiv.js.map +1 -0
- package/dist/webui/index.html +1 -1
- package/package.json +2 -2
- package/dist/chunk-2WBJWKIK.js.map +0 -1
- package/dist/chunk-63H4ENYA.js.map +0 -1
- package/dist/chunk-BJZCBMU4.js.map +0 -1
- package/dist/chunk-DQMKYMUS.js.map +0 -1
- package/dist/chunk-VH3FI2X3.js.map +0 -1
- package/dist/dispatcher-W3PTGEKN.js +0 -22
- package/dist/ingest-FF67DX3F.js +0 -20
- package/dist/quality-6BN2ERKC.js +0 -25
- package/dist/retrieval-QLC3DNMW.js +0 -15
- package/dist/webui/assets/index-Cpn2MjW0.js.map +0 -1
- /package/dist/{chunk-MZTZKBRL.js.map → chunk-BTHB6Q43.js.map} +0 -0
- /package/dist/{chunk-AVUTQWZE.js.map → chunk-K3Z6YUKH.js.map} +0 -0
- /package/dist/{chunk-V3MYT3AT.js.map → chunk-KHE2ME44.js.map} +0 -0
- /package/dist/{chunk-YDVBXHX2.js.map → chunk-N23KB2S7.js.map} +0 -0
- /package/dist/{chunk-QPOOF2GK.js.map → chunk-NENWBA4Q.js.map} +0 -0
- /package/dist/{chunk-M5MPUMCJ.js.map → chunk-RELMDL4Y.js.map} +0 -0
- /package/dist/{chunk-S46JVROA.js.map → chunk-ROFI66JK.js.map} +0 -0
- /package/dist/{chunk-W75S5CK3.js.map → chunk-SJ23JYZJ.js.map} +0 -0
- /package/dist/{chunk-BTD3BYVV.js.map → chunk-T3DS4QYF.js.map} +0 -0
- /package/dist/{chunk-MQPMF5F3.js.map → chunk-TEDEFEXJ.js.map} +0 -0
- /package/dist/{chunk-EX5UTOIU.js.map → chunk-UJHXM7FK.js.map} +0 -0
- /package/dist/{chunk-FOJHR4JJ.js.map → chunk-VBX7MM2C.js.map} +0 -0
- /package/dist/{cleanup-EDWLCJPH.js.map → cleanup-FGPVQRYE.js.map} +0 -0
- /package/dist/{codex-trust-H6KNABHV.js.map → codex-trust-CWD4SYOS.js.map} +0 -0
- /package/dist/{dispatcher-W3PTGEKN.js.map → dispatcher-L77LKD7R.js.map} +0 -0
- /package/dist/{embeddings-W24SA6R3.js.map → embeddings-J24U3RAX.js.map} +0 -0
- /package/dist/{ingest-FF67DX3F.js.map → ingest-UU7VULPA.js.map} +0 -0
- /package/dist/{keychain-LVWMAS7D.js.map → keychain-23KFNHQ6.js.map} +0 -0
- /package/dist/{memory-value-GMYJ5NGO.js.map → memory-value-MWWV4P4X.js.map} +0 -0
- /package/dist/{provenance-KSBMVJO5.js.map → provenance-U2VAENS6.js.map} +0 -0
- /package/dist/{quality-6BN2ERKC.js.map → quality-PIYKKBIT.js.map} +0 -0
- /package/dist/{retrieval-QLC3DNMW.js.map → retrieval-DDYCXIUG.js.map} +0 -0
- /package/dist/{store-QYLHMBPE.js.map → store-DL6YQ6C3.js.map} +0 -0
- /package/dist/{tasks-7P7XOGSC.js.map → tasks-3VQQG77M.js.map} +0 -0
- /package/dist/{usage-KVVZQTZA.js.map → usage-UB4GLDGI.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
matchTokens,
|
|
3
3
|
textMatchScore
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-SJ23JYZJ.js";
|
|
5
5
|
import {
|
|
6
6
|
appendEvidence,
|
|
7
7
|
countDistinctCorrectionSessions,
|
|
@@ -23,13 +23,13 @@ import {
|
|
|
23
23
|
restoreAutoInject,
|
|
24
24
|
setMemoryNote,
|
|
25
25
|
updateMemoryCaptureContext
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-D6COH25L.js";
|
|
27
27
|
import {
|
|
28
28
|
desc
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-KHE2ME44.js";
|
|
30
30
|
import {
|
|
31
31
|
defineOwn
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-ROFI66JK.js";
|
|
33
33
|
import {
|
|
34
34
|
CONFIDENCE,
|
|
35
35
|
LlmCredentialError,
|
|
@@ -38,12 +38,13 @@ import {
|
|
|
38
38
|
findSemanticDuplicates,
|
|
39
39
|
findSimilarRejectedExemplar,
|
|
40
40
|
loadEmbeddingConfigFromEnv,
|
|
41
|
-
queueMemoryEmbeddingSync
|
|
42
|
-
|
|
41
|
+
queueMemoryEmbeddingSync,
|
|
42
|
+
rowToMemory
|
|
43
|
+
} from "./chunk-27L3NQUO.js";
|
|
43
44
|
import {
|
|
44
45
|
hasProviderConfigured,
|
|
45
46
|
init_keychain
|
|
46
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-VBX7MM2C.js";
|
|
47
48
|
import {
|
|
48
49
|
activityEvents,
|
|
49
50
|
and,
|
|
@@ -62,21 +63,22 @@ import {
|
|
|
62
63
|
memories,
|
|
63
64
|
memoryInjections,
|
|
64
65
|
memoryMaintenanceTasks,
|
|
66
|
+
memoryValueEvents,
|
|
65
67
|
or,
|
|
66
68
|
sql
|
|
67
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-T3DS4QYF.js";
|
|
68
70
|
import {
|
|
69
71
|
init_define_RECALL_BUILD_INFO
|
|
70
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-IKD5BHN6.js";
|
|
71
73
|
|
|
72
74
|
// src/maintenance/tasks.ts
|
|
73
75
|
init_define_RECALL_BUILD_INFO();
|
|
74
|
-
import { randomUUID as
|
|
76
|
+
import { randomUUID as randomUUID5 } from "crypto";
|
|
75
77
|
import { z } from "zod";
|
|
76
78
|
|
|
77
79
|
// src/maintenance/appliers.ts
|
|
78
80
|
init_define_RECALL_BUILD_INFO();
|
|
79
|
-
import { randomUUID as
|
|
81
|
+
import { randomUUID as randomUUID4 } from "crypto";
|
|
80
82
|
|
|
81
83
|
// src/contradictions/supersession.ts
|
|
82
84
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -401,6 +403,9 @@ function getRepoQualityProfile(db, repo) {
|
|
|
401
403
|
} else if (score > 0.8) {
|
|
402
404
|
compileConfidenceThreshold -= 0.03;
|
|
403
405
|
}
|
|
406
|
+
if (activeCount === 0) {
|
|
407
|
+
compileConfidenceThreshold = CONFIDENCE.ACTIVE_MIN;
|
|
408
|
+
}
|
|
404
409
|
let dedupSimilarityThreshold = stage === "cold" ? 0.85 : stage === "growing" ? 0.8 : 0.75;
|
|
405
410
|
if (score < 0.45) {
|
|
406
411
|
dedupSimilarityThreshold -= 0.05;
|
|
@@ -1135,7 +1140,7 @@ function inferFromGitOwnership(filePath, repoPath) {
|
|
|
1135
1140
|
|
|
1136
1141
|
// src/maintenance/cleanup.ts
|
|
1137
1142
|
init_define_RECALL_BUILD_INFO();
|
|
1138
|
-
import { randomUUID as
|
|
1143
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
1139
1144
|
|
|
1140
1145
|
// src/contradictions/detector.ts
|
|
1141
1146
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -1548,12 +1553,402 @@ function clamp3(n, min = 0, max = 1) {
|
|
|
1548
1553
|
return Math.max(min, Math.min(max, n));
|
|
1549
1554
|
}
|
|
1550
1555
|
|
|
1556
|
+
// src/maintenance/promote.ts
|
|
1557
|
+
init_define_RECALL_BUILD_INFO();
|
|
1558
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
1559
|
+
|
|
1560
|
+
// src/maintenance/promotion-score.ts
|
|
1561
|
+
init_define_RECALL_BUILD_INFO();
|
|
1562
|
+
var PROMOTION_SCORE_THRESHOLD = 8;
|
|
1563
|
+
var STALE_CANDIDATE_DAYS = 90;
|
|
1564
|
+
var PROMOTION_WEIGHTS = {
|
|
1565
|
+
/** Flat bonus once repetition_count >= 2 (two sessions produced the rule). */
|
|
1566
|
+
repetition: 8,
|
|
1567
|
+
followed: 2,
|
|
1568
|
+
followedCap: 8,
|
|
1569
|
+
used: 1,
|
|
1570
|
+
usedCap: 4,
|
|
1571
|
+
injectedSession: 1,
|
|
1572
|
+
injectedSessionCap: 4,
|
|
1573
|
+
injectedDay: 1,
|
|
1574
|
+
injectedDayCap: 3,
|
|
1575
|
+
positiveFeedback: 2,
|
|
1576
|
+
positiveFeedbackCap: 4,
|
|
1577
|
+
overridden: -2,
|
|
1578
|
+
contradicted: -4,
|
|
1579
|
+
activeContradiction: -6,
|
|
1580
|
+
staleCandidate: -3
|
|
1581
|
+
};
|
|
1582
|
+
function scorePromotionCandidate(e) {
|
|
1583
|
+
const W = PROMOTION_WEIGHTS;
|
|
1584
|
+
const explanation = [];
|
|
1585
|
+
let score = 0;
|
|
1586
|
+
const add = (label, points) => {
|
|
1587
|
+
if (points === 0) return;
|
|
1588
|
+
score += points;
|
|
1589
|
+
explanation.push(`${label}:${points > 0 ? "+" : ""}${points}`);
|
|
1590
|
+
};
|
|
1591
|
+
if (e.repetition_count >= 2) {
|
|
1592
|
+
if (e.source === "repo_scan" || e.source === "config_parse") {
|
|
1593
|
+
explanation.push("scan_repetition_unscored");
|
|
1594
|
+
} else {
|
|
1595
|
+
add(`repetition=${e.repetition_count}`, W.repetition);
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
if (e.followed > 0) add(`followed=${e.followed}`, Math.min(e.followed * W.followed, W.followedCap));
|
|
1599
|
+
if (e.used > 0) add(`used=${e.used}`, Math.min(e.used * W.used, W.usedCap));
|
|
1600
|
+
const followedInjectedSessions = Math.min(e.injected_sessions, e.followed);
|
|
1601
|
+
const followedInjectedDays = Math.min(e.injected_days, followedInjectedSessions);
|
|
1602
|
+
if (followedInjectedSessions > 0) {
|
|
1603
|
+
add(
|
|
1604
|
+
`injected_sessions=${e.injected_sessions}`,
|
|
1605
|
+
Math.min(followedInjectedSessions * W.injectedSession, W.injectedSessionCap)
|
|
1606
|
+
);
|
|
1607
|
+
}
|
|
1608
|
+
if (followedInjectedDays > 0) {
|
|
1609
|
+
add(`injected_days=${e.injected_days}`, Math.min(followedInjectedDays * W.injectedDay, W.injectedDayCap));
|
|
1610
|
+
}
|
|
1611
|
+
if (e.positive_feedback > 0) {
|
|
1612
|
+
add(
|
|
1613
|
+
`positive_feedback=${e.positive_feedback}`,
|
|
1614
|
+
Math.min(e.positive_feedback * W.positiveFeedback, W.positiveFeedbackCap)
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
if (e.overridden > 0) add(`overridden=${e.overridden}`, e.overridden * W.overridden);
|
|
1618
|
+
if (e.contradicted > 0) add(`contradicted=${e.contradicted}`, e.contradicted * W.contradicted);
|
|
1619
|
+
if (e.active_contradiction_ids.length > 0) {
|
|
1620
|
+
add(`active_contradictions=${e.active_contradiction_ids.length}`, W.activeContradiction);
|
|
1621
|
+
}
|
|
1622
|
+
if (e.stale) add(`stale_candidate=${e.age_days}d`, W.staleCandidate);
|
|
1623
|
+
if (e.negative_feedback > 0) explanation.push(`negative_feedback=${e.negative_feedback}`);
|
|
1624
|
+
if (e.ignored > 0) explanation.push(`ignored=${e.ignored}`);
|
|
1625
|
+
if (e.implicit_positive > 0 || e.implicit_negative > 0) {
|
|
1626
|
+
explanation.push(`implicit=+${e.implicit_positive}/-${e.implicit_negative}(unscored)`);
|
|
1627
|
+
}
|
|
1628
|
+
const guardReasons = suppressionGuardReasons(e.guards);
|
|
1629
|
+
let decision;
|
|
1630
|
+
if (guardReasons.length > 0) {
|
|
1631
|
+
decision = "suppressed";
|
|
1632
|
+
for (const reason of guardReasons) explanation.push(`suppressed_due_to_${reason}`);
|
|
1633
|
+
} else if (e.negative_feedback > e.positive_feedback) {
|
|
1634
|
+
decision = "suppressed";
|
|
1635
|
+
explanation.push("suppressed_due_to_negative_feedback");
|
|
1636
|
+
} else if (e.active_contradiction_ids.length > 0) {
|
|
1637
|
+
decision = "suppressed";
|
|
1638
|
+
explanation.push("suppressed_due_to_contradiction");
|
|
1639
|
+
} else if (score >= PROMOTION_SCORE_THRESHOLD) {
|
|
1640
|
+
decision = "would_promote";
|
|
1641
|
+
explanation.push("meets_promotion_threshold");
|
|
1642
|
+
} else {
|
|
1643
|
+
decision = "needs_more_evidence";
|
|
1644
|
+
explanation.push("below_promotion_threshold");
|
|
1645
|
+
}
|
|
1646
|
+
return { score, decision, explanation };
|
|
1647
|
+
}
|
|
1648
|
+
function suppressionGuardReasons(g) {
|
|
1649
|
+
const reasons = [];
|
|
1650
|
+
if (g.destructive_risky) reasons.push("destructive_risky");
|
|
1651
|
+
if (g.trigger_template) reasons.push("trigger_template");
|
|
1652
|
+
if (g.non_user_capture) reasons.push("non_user_capture");
|
|
1653
|
+
if (g.non_durable_provenance) reasons.push("non_durable_provenance");
|
|
1654
|
+
if (g.session_scope) reasons.push("session_scope");
|
|
1655
|
+
if (g.fragment_reasons.length > 0) reasons.push(`fragment:${g.fragment_reasons.join("+")}`);
|
|
1656
|
+
return reasons;
|
|
1657
|
+
}
|
|
1658
|
+
var CHUNK = 400;
|
|
1659
|
+
var IMPLICIT_POSITIVE = /* @__PURE__ */ new Set(["test_pass", "file_unchanged", "task_accepted"]);
|
|
1660
|
+
var IMPLICIT_NEGATIVE = /* @__PURE__ */ new Set(["test_fail", "file_rewritten", "task_rejected"]);
|
|
1661
|
+
function collectPromotionEvidenceBatch(db, items, opts = {}) {
|
|
1662
|
+
const now = opts.now ?? /* @__PURE__ */ new Date();
|
|
1663
|
+
const acc = /* @__PURE__ */ new Map();
|
|
1664
|
+
for (const item of items) acc.set(item.id, emptyAccumulator());
|
|
1665
|
+
const ids = [...acc.keys()];
|
|
1666
|
+
for (let i = 0; i < ids.length; i += CHUNK) {
|
|
1667
|
+
const chunk = ids.slice(i, i + CHUNK);
|
|
1668
|
+
const injections = db.select({
|
|
1669
|
+
memory_id: memoryInjections.memory_id,
|
|
1670
|
+
session_id: memoryInjections.session_id,
|
|
1671
|
+
injected_at: memoryInjections.injected_at,
|
|
1672
|
+
outcome: memoryInjections.outcome
|
|
1673
|
+
}).from(memoryInjections).where(inArray(memoryInjections.memory_id, chunk)).all();
|
|
1674
|
+
for (const row of injections) {
|
|
1675
|
+
const a = acc.get(row.memory_id);
|
|
1676
|
+
if (!a) continue;
|
|
1677
|
+
a.injectedSessions.add(row.session_id);
|
|
1678
|
+
a.injectedDaysBySession.set(row.session_id, row.injected_at.slice(0, 10));
|
|
1679
|
+
if (row.outcome) a.outcomes[row.outcome].add(row.session_id);
|
|
1680
|
+
}
|
|
1681
|
+
const feedback = db.select({
|
|
1682
|
+
memory_id: feedbackEvents.memory_id,
|
|
1683
|
+
session_id: feedbackEvents.session_id,
|
|
1684
|
+
injected: feedbackEvents.injected,
|
|
1685
|
+
outcome: feedbackEvents.outcome
|
|
1686
|
+
}).from(feedbackEvents).where(inArray(feedbackEvents.memory_id, chunk)).all();
|
|
1687
|
+
for (const row of feedback) {
|
|
1688
|
+
const a = acc.get(row.memory_id);
|
|
1689
|
+
if (!a) continue;
|
|
1690
|
+
if (row.injected) {
|
|
1691
|
+
a.outcomes[row.outcome].add(row.session_id);
|
|
1692
|
+
} else if (row.outcome === "followed") {
|
|
1693
|
+
a.positive.add(row.session_id);
|
|
1694
|
+
} else if (row.outcome === "overridden" || row.outcome === "contradicted") {
|
|
1695
|
+
a.negative.add(row.session_id);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
const used = db.select({
|
|
1699
|
+
memory_id: memoryValueEvents.memory_id,
|
|
1700
|
+
session_id: memoryValueEvents.session_id
|
|
1701
|
+
}).from(memoryValueEvents).where(and(
|
|
1702
|
+
inArray(memoryValueEvents.memory_id, chunk),
|
|
1703
|
+
eq(memoryValueEvents.event_type, "used")
|
|
1704
|
+
)).all();
|
|
1705
|
+
for (const row of used) {
|
|
1706
|
+
const a = row.memory_id ? acc.get(row.memory_id) : void 0;
|
|
1707
|
+
if (a) a.used.add(row.session_id);
|
|
1708
|
+
}
|
|
1709
|
+
const implicit = db.select({
|
|
1710
|
+
memory_id: implicitSignals.memory_id,
|
|
1711
|
+
signal_type: implicitSignals.signal_type
|
|
1712
|
+
}).from(implicitSignals).where(inArray(implicitSignals.memory_id, chunk)).all();
|
|
1713
|
+
for (const row of implicit) {
|
|
1714
|
+
const a = acc.get(row.memory_id);
|
|
1715
|
+
if (!a) continue;
|
|
1716
|
+
if (IMPLICIT_POSITIVE.has(row.signal_type)) a.implicitPositive += 1;
|
|
1717
|
+
else if (IMPLICIT_NEGATIVE.has(row.signal_type)) a.implicitNegative += 1;
|
|
1718
|
+
}
|
|
1719
|
+
const conflictRows = db.select({
|
|
1720
|
+
id: contradictions.id,
|
|
1721
|
+
a: contradictions.memory_a_id,
|
|
1722
|
+
b: contradictions.memory_b_id
|
|
1723
|
+
}).from(contradictions).where(and(
|
|
1724
|
+
eq(contradictions.resolved, false),
|
|
1725
|
+
or(inArray(contradictions.memory_a_id, chunk), inArray(contradictions.memory_b_id, chunk))
|
|
1726
|
+
)).all();
|
|
1727
|
+
for (const row of conflictRows) {
|
|
1728
|
+
acc.get(row.a)?.contradictions.set(row.id, row.b);
|
|
1729
|
+
acc.get(row.b)?.contradictions.set(row.id, row.a);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
const liveOthers = liveMemoryIds(db, [...acc.values()].flatMap((a) => [...a.contradictions.values()]));
|
|
1733
|
+
const out = /* @__PURE__ */ new Map();
|
|
1734
|
+
for (const item of items) {
|
|
1735
|
+
const a = acc.get(item.id);
|
|
1736
|
+
if (!a) continue;
|
|
1737
|
+
const followedSessions = [...a.outcomes.followed].filter((session) => !a.outcomes.overridden.has(session) && !a.outcomes.contradicted.has(session));
|
|
1738
|
+
const followedInjectedSessions = followedSessions.filter((session) => a.injectedSessions.has(session));
|
|
1739
|
+
const followedInjectedDays = new Set(followedInjectedSessions.map((session) => a.injectedDaysBySession.get(session)).filter((day) => day !== void 0));
|
|
1740
|
+
const ageDays = ageInDays(item.created_at, now);
|
|
1741
|
+
out.set(item.id, {
|
|
1742
|
+
memory_id: item.id,
|
|
1743
|
+
source: item.source,
|
|
1744
|
+
repetition_count: item.repetition_count,
|
|
1745
|
+
injection_count: item.injection_count,
|
|
1746
|
+
followed: followedSessions.length,
|
|
1747
|
+
overridden: a.outcomes.overridden.size,
|
|
1748
|
+
contradicted: a.outcomes.contradicted.size,
|
|
1749
|
+
ignored: a.outcomes.ignored.size,
|
|
1750
|
+
injected_sessions: followedInjectedSessions.length,
|
|
1751
|
+
injected_days: followedInjectedDays.size,
|
|
1752
|
+
used: a.used.size,
|
|
1753
|
+
positive_feedback: a.positive.size,
|
|
1754
|
+
negative_feedback: a.negative.size,
|
|
1755
|
+
implicit_positive: a.implicitPositive,
|
|
1756
|
+
implicit_negative: a.implicitNegative,
|
|
1757
|
+
active_contradiction_ids: [...a.contradictions.entries()].filter(([, other]) => liveOthers.has(other)).map(([id]) => id).sort(),
|
|
1758
|
+
age_days: ageDays,
|
|
1759
|
+
stale: ageDays > STALE_CANDIDATE_DAYS && item.injection_count === 0 && a.injectedSessions.size === 0,
|
|
1760
|
+
guards: guardsFor(item, opts.fragmentReasons)
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
return out;
|
|
1764
|
+
}
|
|
1765
|
+
function guardsFor(memory, fragmentReasons) {
|
|
1766
|
+
const text = memory.text.trim();
|
|
1767
|
+
return {
|
|
1768
|
+
destructive_risky: isDestructiveRisky(text),
|
|
1769
|
+
trigger_template: isTriggerTemplateRule(text),
|
|
1770
|
+
non_user_capture: hasNonUserEvidenceContext(memory),
|
|
1771
|
+
non_durable_provenance: hasNonDurableProvenance(memory),
|
|
1772
|
+
session_scope: memory.scope === "session",
|
|
1773
|
+
// Same rule as the repetition path: user_correction rows that the
|
|
1774
|
+
// fragment filter would reject must not promote first (no flip-flop).
|
|
1775
|
+
fragment_reasons: memory.source === "user_correction" && fragmentReasons ? fragmentReasons(text) : []
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
function hasNonUserEvidenceContext(memory) {
|
|
1779
|
+
if (!Array.isArray(memory.evidence)) return false;
|
|
1780
|
+
return memory.evidence.some((entry) => {
|
|
1781
|
+
if (!entry || typeof entry !== "object") return false;
|
|
1782
|
+
const context = entry.context;
|
|
1783
|
+
return typeof context === "string" && isNonUserCaptureContext(context);
|
|
1784
|
+
});
|
|
1785
|
+
}
|
|
1786
|
+
function liveMemoryIds(db, ids) {
|
|
1787
|
+
const unique = [...new Set(ids)];
|
|
1788
|
+
const live = /* @__PURE__ */ new Set();
|
|
1789
|
+
for (let i = 0; i < unique.length; i += CHUNK) {
|
|
1790
|
+
const rows = db.select({ id: memories.id }).from(memories).where(and(
|
|
1791
|
+
inArray(memories.id, unique.slice(i, i + CHUNK)),
|
|
1792
|
+
inArray(memories.status, ["active", "candidate"])
|
|
1793
|
+
)).all();
|
|
1794
|
+
for (const row of rows) live.add(row.id);
|
|
1795
|
+
}
|
|
1796
|
+
return live;
|
|
1797
|
+
}
|
|
1798
|
+
function emptyAccumulator() {
|
|
1799
|
+
return {
|
|
1800
|
+
outcomes: { followed: /* @__PURE__ */ new Set(), overridden: /* @__PURE__ */ new Set(), contradicted: /* @__PURE__ */ new Set(), ignored: /* @__PURE__ */ new Set() },
|
|
1801
|
+
injectedSessions: /* @__PURE__ */ new Set(),
|
|
1802
|
+
injectedDaysBySession: /* @__PURE__ */ new Map(),
|
|
1803
|
+
used: /* @__PURE__ */ new Set(),
|
|
1804
|
+
positive: /* @__PURE__ */ new Set(),
|
|
1805
|
+
negative: /* @__PURE__ */ new Set(),
|
|
1806
|
+
implicitPositive: 0,
|
|
1807
|
+
implicitNegative: 0,
|
|
1808
|
+
contradictions: /* @__PURE__ */ new Map()
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
function ageInDays(createdAt, now) {
|
|
1812
|
+
const created = Date.parse(createdAt);
|
|
1813
|
+
if (!Number.isFinite(created)) return 0;
|
|
1814
|
+
return Math.max(0, Math.floor((now.getTime() - created) / 864e5));
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
// src/maintenance/promote.ts
|
|
1818
|
+
var DEFAULT_ACTOR = "maintenance:cleanup";
|
|
1819
|
+
function planPromotions(db, opts) {
|
|
1820
|
+
const repetition = planRepetitionPromotions(db, opts.fragmentReasons);
|
|
1821
|
+
const repetitionIds = new Set(repetition.map((p) => p.memory_id));
|
|
1822
|
+
const evidence = evaluatePromotionCandidates(db, { ...opts, preAcceptedIds: repetitionIds }).filter((e) => e.decision === "would_promote" && !repetitionIds.has(e.memory_id)).map((e) => ({
|
|
1823
|
+
kind: "promote_repeat_correction",
|
|
1824
|
+
memory_id: e.memory_id,
|
|
1825
|
+
text: e.text,
|
|
1826
|
+
matched_pattern: "evidence_score",
|
|
1827
|
+
score: e.score,
|
|
1828
|
+
explanation: e.explanation
|
|
1829
|
+
}));
|
|
1830
|
+
return [...repetition, ...evidence];
|
|
1831
|
+
}
|
|
1832
|
+
function planRepetitionPromotions(db, fragmentReasons) {
|
|
1833
|
+
const rows = db.select({
|
|
1834
|
+
id: memories.id,
|
|
1835
|
+
text: memories.text,
|
|
1836
|
+
repetition_count: memories.repetition_count,
|
|
1837
|
+
scope: memories.scope
|
|
1838
|
+
}).from(memories).where(and(eq(memories.status, "candidate"), eq(memories.source, "user_correction"))).all();
|
|
1839
|
+
const out = [];
|
|
1840
|
+
for (const row of rows) {
|
|
1841
|
+
const text = row.text.trim();
|
|
1842
|
+
const memory = getMemory(db, row.id);
|
|
1843
|
+
if (!memory || hasNonDurableProvenance(memory)) continue;
|
|
1844
|
+
if (row.scope === "session") continue;
|
|
1845
|
+
if (fragmentReasons(text).length > 0) continue;
|
|
1846
|
+
if (isDestructiveRisky(text)) continue;
|
|
1847
|
+
if (row.repetition_count >= 2) {
|
|
1848
|
+
out.push({ kind: "promote_repeat_correction", memory_id: row.id, text, matched_pattern: "repetition" });
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
return out;
|
|
1852
|
+
}
|
|
1853
|
+
function evaluatePromotionCandidates(db, opts) {
|
|
1854
|
+
const items = db.select().from(memories).where(eq(memories.status, "candidate")).all().map(rowToMemory);
|
|
1855
|
+
const byId = new Map(items.map((m) => [m.id, m]));
|
|
1856
|
+
const evidence = collectPromotionEvidenceBatch(db, items, {
|
|
1857
|
+
now: opts.now,
|
|
1858
|
+
fragmentReasons: opts.fragmentReasons
|
|
1859
|
+
});
|
|
1860
|
+
const evaluations = [];
|
|
1861
|
+
for (const item of items) {
|
|
1862
|
+
const e = evidence.get(item.id);
|
|
1863
|
+
if (!e) continue;
|
|
1864
|
+
evaluations.push(toEvaluation(item, e));
|
|
1865
|
+
}
|
|
1866
|
+
applyLiveContradictionCheck(db, evaluations, byId, opts.preAcceptedIds ?? /* @__PURE__ */ new Set());
|
|
1867
|
+
return evaluations.sort((a, b) => b.score - a.score || a.memory_id.localeCompare(b.memory_id));
|
|
1868
|
+
}
|
|
1869
|
+
function toEvaluation(item, evidence) {
|
|
1870
|
+
const scored = scorePromotionCandidate(evidence);
|
|
1871
|
+
return {
|
|
1872
|
+
memory_id: item.id,
|
|
1873
|
+
text: item.text.trim(),
|
|
1874
|
+
source: item.source,
|
|
1875
|
+
evidence,
|
|
1876
|
+
score: scored.score,
|
|
1877
|
+
decision: scored.decision,
|
|
1878
|
+
explanation: scored.explanation
|
|
1879
|
+
};
|
|
1880
|
+
}
|
|
1881
|
+
function applyLiveContradictionCheck(db, evaluations, byId, preAcceptedIds) {
|
|
1882
|
+
const pending = evaluations.map((e, index) => ({ e, index })).filter(({ e }) => e.decision === "would_promote" && !preAcceptedIds.has(e.memory_id)).sort((x, y) => y.e.score - x.e.score || x.e.memory_id.localeCompare(y.e.memory_id));
|
|
1883
|
+
if (pending.length === 0) return;
|
|
1884
|
+
const accepted = db.select().from(memories).where(eq(memories.status, "active")).all().map(rowToMemory);
|
|
1885
|
+
for (const id of preAcceptedIds) {
|
|
1886
|
+
const m = byId.get(id);
|
|
1887
|
+
if (m) accepted.push(m);
|
|
1888
|
+
}
|
|
1889
|
+
for (const { e, index } of pending) {
|
|
1890
|
+
const candidate = byId.get(e.memory_id);
|
|
1891
|
+
if (!candidate) continue;
|
|
1892
|
+
const conflicts = accepted.filter((other) => other.id !== candidate.id && checkContradiction(candidate, other) != null).map((other) => `live:${other.id}`);
|
|
1893
|
+
if (conflicts.length === 0) {
|
|
1894
|
+
accepted.push(candidate);
|
|
1895
|
+
continue;
|
|
1896
|
+
}
|
|
1897
|
+
const evidence = {
|
|
1898
|
+
...e.evidence,
|
|
1899
|
+
active_contradiction_ids: [...e.evidence.active_contradiction_ids, ...conflicts]
|
|
1900
|
+
};
|
|
1901
|
+
evaluations[index] = toEvaluation(candidate, evidence);
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
function applyPromoteRepeat(db, runId, plan) {
|
|
1905
|
+
const before = getMemory(db, plan.memory_id);
|
|
1906
|
+
if (!before || before.status !== "candidate" || hasNonDurableProvenance(before)) return;
|
|
1907
|
+
if (plan.matched_pattern === "evidence_score" && isDestructiveRisky(before.text)) return;
|
|
1908
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1909
|
+
db.update(memories).set({ status: "active", confidence: Math.max(before.confidence, 0.7), updated_at: now, last_validated_at: now }).where(eq(memories.id, plan.memory_id)).run();
|
|
1910
|
+
const after = getMemory(db, plan.memory_id);
|
|
1911
|
+
recordAuditWithSnapshot(
|
|
1912
|
+
db,
|
|
1913
|
+
plan.memory_id,
|
|
1914
|
+
"promoted",
|
|
1915
|
+
DEFAULT_ACTOR,
|
|
1916
|
+
`cleanup_promote:${plan.matched_pattern}:run:${runId}`,
|
|
1917
|
+
before,
|
|
1918
|
+
after ?? null
|
|
1919
|
+
);
|
|
1920
|
+
const details = { matched_pattern: plan.matched_pattern };
|
|
1921
|
+
if (plan.score !== void 0) details.score = plan.score;
|
|
1922
|
+
if (plan.explanation) details.explanation = plan.explanation;
|
|
1923
|
+
db.insert(maintenanceCleanupLog).values({
|
|
1924
|
+
id: randomUUID2(),
|
|
1925
|
+
run_id: runId,
|
|
1926
|
+
action: "promote_repeat_correction",
|
|
1927
|
+
memory_id: plan.memory_id,
|
|
1928
|
+
related_memory_id: null,
|
|
1929
|
+
before_snapshot: before,
|
|
1930
|
+
after_snapshot: after,
|
|
1931
|
+
details,
|
|
1932
|
+
reverted: false,
|
|
1933
|
+
reverted_at: null,
|
|
1934
|
+
created_at: now
|
|
1935
|
+
}).run();
|
|
1936
|
+
}
|
|
1937
|
+
function formatPromoteLine(item) {
|
|
1938
|
+
let line = ` promote: ${item.memory_id.slice(0, 8)} via=${item.matched_pattern}`;
|
|
1939
|
+
if (item.score !== void 0) {
|
|
1940
|
+
line += ` score=${item.score}`;
|
|
1941
|
+
if (item.explanation && item.explanation.length > 0) line += ` [${item.explanation.join(", ")}]`;
|
|
1942
|
+
}
|
|
1943
|
+
return line;
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1551
1946
|
// src/maintenance/cleanup.ts
|
|
1552
1947
|
var SUPPRESS_INJECTION_FLOOR = 50;
|
|
1553
1948
|
var GLOBALIZE_REPO_FLOOR = 3;
|
|
1554
|
-
var
|
|
1949
|
+
var DEFAULT_ACTOR2 = "maintenance:cleanup";
|
|
1555
1950
|
function runDeterministicCleanup(db, opts = { dryRun: true }) {
|
|
1556
|
-
const runId =
|
|
1951
|
+
const runId = randomUUID3();
|
|
1557
1952
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1558
1953
|
const plan = [];
|
|
1559
1954
|
if (!opts.only || opts.only === "dedupe_exact_merge") {
|
|
@@ -1762,13 +2157,13 @@ function applyDedupeExact(db, runId, plan) {
|
|
|
1762
2157
|
db,
|
|
1763
2158
|
loser.id,
|
|
1764
2159
|
"rejected",
|
|
1765
|
-
|
|
2160
|
+
DEFAULT_ACTOR2,
|
|
1766
2161
|
`dedupe_exact:merged_into:${winner.id}:run:${runId}`,
|
|
1767
2162
|
loser,
|
|
1768
2163
|
after ?? null
|
|
1769
2164
|
);
|
|
1770
2165
|
db.insert(maintenanceCleanupLog).values({
|
|
1771
|
-
id:
|
|
2166
|
+
id: randomUUID3(),
|
|
1772
2167
|
run_id: runId,
|
|
1773
2168
|
action: "dedupe_exact_merge",
|
|
1774
2169
|
memory_id: loser.id,
|
|
@@ -1899,7 +2294,7 @@ function planRejectFragments(db) {
|
|
|
1899
2294
|
const out = [];
|
|
1900
2295
|
for (const row of rows) {
|
|
1901
2296
|
const reasons = qualityReasons(row.text);
|
|
1902
|
-
if (
|
|
2297
|
+
if (hasNonUserEvidenceContext2(row.evidence)) {
|
|
1903
2298
|
reasons.push("non_user_capture_context");
|
|
1904
2299
|
}
|
|
1905
2300
|
const actionableReasons = row.status === "active" ? reasons.filter((reason) => ACTIVE_FRAGMENT_REASONS.has(reason)) : reasons;
|
|
@@ -1914,7 +2309,7 @@ function planRejectFragments(db) {
|
|
|
1914
2309
|
}
|
|
1915
2310
|
return out;
|
|
1916
2311
|
}
|
|
1917
|
-
function
|
|
2312
|
+
function hasNonUserEvidenceContext2(value) {
|
|
1918
2313
|
if (!Array.isArray(value)) return false;
|
|
1919
2314
|
return value.some((item) => {
|
|
1920
2315
|
if (!item || typeof item !== "object" || Array.isArray(item)) return false;
|
|
@@ -1958,13 +2353,13 @@ function applyRejectFragment(db, runId, plan) {
|
|
|
1958
2353
|
db,
|
|
1959
2354
|
plan.memory_id,
|
|
1960
2355
|
"rejected",
|
|
1961
|
-
|
|
2356
|
+
DEFAULT_ACTOR2,
|
|
1962
2357
|
`cleanup_fragment:${plan.reasons.join(",")}:run:${runId}`,
|
|
1963
2358
|
before,
|
|
1964
2359
|
after ?? null
|
|
1965
2360
|
);
|
|
1966
2361
|
db.insert(maintenanceCleanupLog).values({
|
|
1967
|
-
id:
|
|
2362
|
+
id: randomUUID3(),
|
|
1968
2363
|
run_id: runId,
|
|
1969
2364
|
action: "reject_fragment_candidate",
|
|
1970
2365
|
memory_id: plan.memory_id,
|
|
@@ -2002,13 +2397,13 @@ function applyRejectTestFixtureRepo(db, runId, plan) {
|
|
|
2002
2397
|
db,
|
|
2003
2398
|
plan.memory_id,
|
|
2004
2399
|
"rejected",
|
|
2005
|
-
|
|
2400
|
+
DEFAULT_ACTOR2,
|
|
2006
2401
|
`cleanup_test_fixture_repo:${plan.repo}:run:${runId}`,
|
|
2007
2402
|
before,
|
|
2008
2403
|
after ?? null
|
|
2009
2404
|
);
|
|
2010
2405
|
db.insert(maintenanceCleanupLog).values({
|
|
2011
|
-
id:
|
|
2406
|
+
id: randomUUID3(),
|
|
2012
2407
|
run_id: runId,
|
|
2013
2408
|
action: "reject_test_fixture_repo",
|
|
2014
2409
|
memory_id: plan.memory_id,
|
|
@@ -2071,13 +2466,13 @@ function applyRejectInvalidScope(db, runId, plan) {
|
|
|
2071
2466
|
db,
|
|
2072
2467
|
plan.memory_id,
|
|
2073
2468
|
"rejected",
|
|
2074
|
-
|
|
2469
|
+
DEFAULT_ACTOR2,
|
|
2075
2470
|
`cleanup_invalid_scope:${plan.reasons.join(",")}:run:${runId}`,
|
|
2076
2471
|
before,
|
|
2077
2472
|
after ?? null
|
|
2078
2473
|
);
|
|
2079
2474
|
db.insert(maintenanceCleanupLog).values({
|
|
2080
|
-
id:
|
|
2475
|
+
id: randomUUID3(),
|
|
2081
2476
|
run_id: runId,
|
|
2082
2477
|
action: "reject_invalid_scope",
|
|
2083
2478
|
memory_id: plan.memory_id,
|
|
@@ -2130,13 +2525,13 @@ function applyRejectGenericScannedTooling(db, runId, plan) {
|
|
|
2130
2525
|
db,
|
|
2131
2526
|
plan.memory_id,
|
|
2132
2527
|
"rejected",
|
|
2133
|
-
|
|
2528
|
+
DEFAULT_ACTOR2,
|
|
2134
2529
|
`cleanup_generic_scanned_tooling:run:${runId}`,
|
|
2135
2530
|
before,
|
|
2136
2531
|
after ?? null
|
|
2137
2532
|
);
|
|
2138
2533
|
db.insert(maintenanceCleanupLog).values({
|
|
2139
|
-
id:
|
|
2534
|
+
id: randomUUID3(),
|
|
2140
2535
|
run_id: runId,
|
|
2141
2536
|
action: "reject_generic_scanned_tooling",
|
|
2142
2537
|
memory_id: plan.memory_id,
|
|
@@ -2152,57 +2547,8 @@ function applyRejectGenericScannedTooling(db, runId, plan) {
|
|
|
2152
2547
|
created_at: now
|
|
2153
2548
|
}).run();
|
|
2154
2549
|
}
|
|
2155
|
-
function planPromoteRepeats(db) {
|
|
2156
|
-
|
|
2157
|
-
id: memories.id,
|
|
2158
|
-
text: memories.text,
|
|
2159
|
-
repetition_count: memories.repetition_count,
|
|
2160
|
-
source: memories.source,
|
|
2161
|
-
status: memories.status,
|
|
2162
|
-
scope: memories.scope
|
|
2163
|
-
}).from(memories).where(and(eq(memories.status, "candidate"), eq(memories.source, "user_correction"))).all();
|
|
2164
|
-
const out = [];
|
|
2165
|
-
for (const row of rows) {
|
|
2166
|
-
const text = row.text.trim();
|
|
2167
|
-
const memory = getMemory(db, row.id);
|
|
2168
|
-
if (!memory || hasNonDurableProvenance(memory)) continue;
|
|
2169
|
-
if (row.scope === "session") continue;
|
|
2170
|
-
if (qualityReasons(text).length > 0) continue;
|
|
2171
|
-
if (isDestructiveRisky(text)) continue;
|
|
2172
|
-
if (row.repetition_count >= 2) {
|
|
2173
|
-
out.push({ kind: "promote_repeat_correction", memory_id: row.id, text, matched_pattern: "repetition" });
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
return out;
|
|
2177
|
-
}
|
|
2178
|
-
function applyPromoteRepeat(db, runId, plan) {
|
|
2179
|
-
const before = getMemory(db, plan.memory_id);
|
|
2180
|
-
if (!before || before.status !== "candidate" || hasNonDurableProvenance(before)) return;
|
|
2181
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2182
|
-
db.update(memories).set({ status: "active", confidence: Math.max(before.confidence, 0.7), updated_at: now, last_validated_at: now }).where(eq(memories.id, plan.memory_id)).run();
|
|
2183
|
-
const after = getMemory(db, plan.memory_id);
|
|
2184
|
-
recordAuditWithSnapshot(
|
|
2185
|
-
db,
|
|
2186
|
-
plan.memory_id,
|
|
2187
|
-
"promoted",
|
|
2188
|
-
DEFAULT_ACTOR,
|
|
2189
|
-
`cleanup_promote:${plan.matched_pattern}:run:${runId}`,
|
|
2190
|
-
before,
|
|
2191
|
-
after ?? null
|
|
2192
|
-
);
|
|
2193
|
-
db.insert(maintenanceCleanupLog).values({
|
|
2194
|
-
id: randomUUID2(),
|
|
2195
|
-
run_id: runId,
|
|
2196
|
-
action: "promote_repeat_correction",
|
|
2197
|
-
memory_id: plan.memory_id,
|
|
2198
|
-
related_memory_id: null,
|
|
2199
|
-
before_snapshot: before,
|
|
2200
|
-
after_snapshot: after,
|
|
2201
|
-
details: { matched_pattern: plan.matched_pattern },
|
|
2202
|
-
reverted: false,
|
|
2203
|
-
reverted_at: null,
|
|
2204
|
-
created_at: now
|
|
2205
|
-
}).run();
|
|
2550
|
+
function planPromoteRepeats(db, opts = {}) {
|
|
2551
|
+
return planPromotions(db, { fragmentReasons: qualityReasons, now: opts.now });
|
|
2206
2552
|
}
|
|
2207
2553
|
function planSuppressCommands(db) {
|
|
2208
2554
|
const candidates = db.select({
|
|
@@ -2243,13 +2589,13 @@ function applySuppressCommand(db, runId, plan) {
|
|
|
2243
2589
|
db,
|
|
2244
2590
|
plan.memory_id,
|
|
2245
2591
|
"demoted",
|
|
2246
|
-
|
|
2592
|
+
DEFAULT_ACTOR2,
|
|
2247
2593
|
`cleanup_suppress_command:inj=${plan.injection_count},followed=0:run:${runId}`,
|
|
2248
2594
|
before,
|
|
2249
2595
|
after ?? null
|
|
2250
2596
|
);
|
|
2251
2597
|
db.insert(maintenanceCleanupLog).values({
|
|
2252
|
-
id:
|
|
2598
|
+
id: randomUUID3(),
|
|
2253
2599
|
run_id: runId,
|
|
2254
2600
|
action: "suppress_unproductive_command",
|
|
2255
2601
|
memory_id: plan.memory_id,
|
|
@@ -2338,13 +2684,13 @@ function applyGlobalizeCrossRepo(db, runId, plan) {
|
|
|
2338
2684
|
db,
|
|
2339
2685
|
winner.id,
|
|
2340
2686
|
"edited",
|
|
2341
|
-
|
|
2687
|
+
DEFAULT_ACTOR2,
|
|
2342
2688
|
`cleanup_globalize:winner:run:${runId}`,
|
|
2343
2689
|
winner,
|
|
2344
2690
|
after ?? null
|
|
2345
2691
|
);
|
|
2346
2692
|
db.insert(maintenanceCleanupLog).values({
|
|
2347
|
-
id:
|
|
2693
|
+
id: randomUUID3(),
|
|
2348
2694
|
run_id: runId,
|
|
2349
2695
|
action: "globalize_cross_repo",
|
|
2350
2696
|
memory_id: winner.id,
|
|
@@ -2365,13 +2711,13 @@ function applyGlobalizeCrossRepo(db, runId, plan) {
|
|
|
2365
2711
|
db,
|
|
2366
2712
|
loserId,
|
|
2367
2713
|
"rejected",
|
|
2368
|
-
|
|
2714
|
+
DEFAULT_ACTOR2,
|
|
2369
2715
|
`cleanup_globalize:loser:winner=${winner.id}:run:${runId}`,
|
|
2370
2716
|
loser,
|
|
2371
2717
|
afterLoser ?? null
|
|
2372
2718
|
);
|
|
2373
2719
|
db.insert(maintenanceCleanupLog).values({
|
|
2374
|
-
id:
|
|
2720
|
+
id: randomUUID3(),
|
|
2375
2721
|
run_id: runId,
|
|
2376
2722
|
action: "globalize_cross_repo",
|
|
2377
2723
|
memory_id: loserId,
|
|
@@ -2431,7 +2777,7 @@ function revertCleanupRun(db, runId) {
|
|
|
2431
2777
|
db,
|
|
2432
2778
|
row.memory_id,
|
|
2433
2779
|
"rolled_back",
|
|
2434
|
-
|
|
2780
|
+
DEFAULT_ACTOR2,
|
|
2435
2781
|
`cleanup_revert:run:${runId}:log:${row.id}`,
|
|
2436
2782
|
current,
|
|
2437
2783
|
after ?? null
|
|
@@ -2491,7 +2837,7 @@ function formatCleanupReport(report) {
|
|
|
2491
2837
|
lines.push(` reject: ${item.memory_id.slice(0, 8)} reasons=${item.reasons.join(",")}`);
|
|
2492
2838
|
lines.push(` "${truncate(item.text, 80)}"`);
|
|
2493
2839
|
} else if (item.kind === "promote_repeat_correction") {
|
|
2494
|
-
lines.push(
|
|
2840
|
+
lines.push(formatPromoteLine(item));
|
|
2495
2841
|
lines.push(` "${truncate(item.text, 80)}"`);
|
|
2496
2842
|
} else if (item.kind === "suppress_unproductive_command") {
|
|
2497
2843
|
lines.push(` suppress: ${item.memory_id.slice(0, 8)} inj=${item.injection_count} followed=${item.followed_count}`);
|
|
@@ -3211,7 +3557,7 @@ function applySummarizeSession(db, task, result) {
|
|
|
3211
3557
|
const payload = task.payload;
|
|
3212
3558
|
const sessionId = payload.session_id;
|
|
3213
3559
|
if (!sessionId) throw new ApplyError("payload missing session_id", "invalid-state");
|
|
3214
|
-
const id =
|
|
3560
|
+
const id = randomUUID4();
|
|
3215
3561
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3216
3562
|
db.insert(historySnippets).values({
|
|
3217
3563
|
id,
|
|
@@ -3229,7 +3575,7 @@ function applySynthesizeRepo(db, task, result) {
|
|
|
3229
3575
|
const payload = task.payload;
|
|
3230
3576
|
const repo = payload.repo;
|
|
3231
3577
|
if (!repo) throw new ApplyError("payload missing repo", "invalid-state");
|
|
3232
|
-
const id =
|
|
3578
|
+
const id = randomUUID4();
|
|
3233
3579
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3234
3580
|
db.insert(historySnippets).values({
|
|
3235
3581
|
id,
|
|
@@ -3483,7 +3829,7 @@ function hasActiveTaskForTarget(db, kind, target) {
|
|
|
3483
3829
|
}
|
|
3484
3830
|
function insertTaskIdempotent(db, input) {
|
|
3485
3831
|
if (hasActiveTaskForTarget(db, input.kind, input.target)) return null;
|
|
3486
|
-
const id =
|
|
3832
|
+
const id = randomUUID5();
|
|
3487
3833
|
db.insert(memoryMaintenanceTasks).values({
|
|
3488
3834
|
id,
|
|
3489
3835
|
kind: input.kind,
|
|
@@ -4281,4 +4627,4 @@ export {
|
|
|
4281
4627
|
processCorrection,
|
|
4282
4628
|
processReviewFeedback
|
|
4283
4629
|
};
|
|
4284
|
-
//# sourceMappingURL=chunk-
|
|
4630
|
+
//# sourceMappingURL=chunk-J3QU7QT3.js.map
|