@remnic/core 10.0.8 → 10.0.10
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/access-admin-ops-surface.js +14 -14
- package/dist/access-authorization-probe.js +15 -15
- package/dist/access-boundary.js +14 -14
- package/dist/access-cli.js +52 -52
- package/dist/access-extraction-force-flush.js +14 -14
- package/dist/access-http-briefing.js +15 -15
- package/dist/access-http-query.js +16 -16
- package/dist/access-http.js +30 -30
- package/dist/access-identity-continuity-surface.js +14 -14
- package/dist/access-lcm-surface.js +14 -14
- package/dist/access-mcp.js +23 -23
- package/dist/access-namespace-preflight.js +14 -14
- package/dist/access-observe-write-surface.js +14 -14
- package/dist/access-operations-batch.js +15 -15
- package/dist/access-operations.js +22 -22
- package/dist/access-recall-concurrency.js +14 -14
- package/dist/access-recall-response.js +14 -14
- package/dist/access-recall-surface.js +14 -14
- package/dist/access-service.js +14 -14
- package/dist/access-surface-catalog.js +16 -16
- package/dist/active-recall.js +1 -1
- package/dist/briefing.js +2 -2
- package/dist/causal-consolidation.js +3 -3
- package/dist/{chunk-ZQYAE2C5.js → chunk-2U4BM3TW.js} +2 -2
- package/dist/{chunk-QFIPSKPC.js → chunk-3ZCRHW7U.js} +2 -2
- package/dist/{chunk-76KHEHT2.js → chunk-4N2MFNTG.js} +2 -2
- package/dist/{chunk-FBVLTTVV.js → chunk-4TP3MJ3D.js} +5 -5
- package/dist/{chunk-JSIQSZXI.js → chunk-56GJLXBA.js} +3 -3
- package/dist/{chunk-MVRIW6MI.js → chunk-6OAXWYE3.js} +2 -2
- package/dist/{chunk-KDYQYMJZ.js → chunk-7SUWY37K.js} +2 -2
- package/dist/{chunk-KRIEQCKE.js → chunk-A2L3P2IY.js} +2 -2
- package/dist/{chunk-AMFCRZYB.js → chunk-AV2OQF2O.js} +2 -2
- package/dist/{chunk-WJLGUY27.js → chunk-BD5QEP3T.js} +2 -1
- package/dist/{chunk-C3WJNRGR.js → chunk-BH44JOLA.js} +2 -2
- package/dist/{chunk-NYVKLB2I.js → chunk-BX4WDBTE.js} +11 -11
- package/dist/{chunk-V4WSQYO6.js → chunk-CAUNCRLQ.js} +21 -21
- package/dist/{chunk-RH6QEGCT.js → chunk-D5UPBXZM.js} +2 -2
- package/dist/{chunk-77HNHT6S.js → chunk-E57LYSHI.js} +114 -4
- package/dist/chunk-E57LYSHI.js.map +1 -0
- package/dist/{chunk-IOM5QSNR.js → chunk-EKKAHJ4B.js} +2 -2
- package/dist/{chunk-JK3DYMOC.js → chunk-GKOML66M.js} +2 -2
- package/dist/{chunk-QW7G7PWN.js → chunk-I2M4ZVDD.js} +2 -2
- package/dist/{chunk-JTUKDLAD.js → chunk-J6FFBORM.js} +2 -2
- package/dist/{chunk-MAJ2OKE4.js → chunk-J7MDPTX7.js} +6 -6
- package/dist/{chunk-5FNVK7MW.js → chunk-JVNEXW6X.js} +2 -2
- package/dist/{chunk-IJWEXCWF.js → chunk-JXWTPOMJ.js} +2 -2
- package/dist/{chunk-3R6SLDTH.js → chunk-KJOGIRMF.js} +2 -2
- package/dist/{chunk-GDI64ITR.js → chunk-KWVI52ER.js} +2 -2
- package/dist/{chunk-AV46CT77.js → chunk-KX36OCGK.js} +2 -2
- package/dist/{chunk-2K7D6EFT.js → chunk-L3G5CGL5.js} +674 -126
- package/dist/chunk-L3G5CGL5.js.map +1 -0
- package/dist/{chunk-CSUAHUOH.js → chunk-MK552I5J.js} +2 -2
- package/dist/{chunk-BPY4RRTF.js → chunk-MO25AN7J.js} +10 -10
- package/dist/{chunk-NAHUBSUF.js → chunk-N75Q5ZSP.js} +2 -2
- package/dist/{chunk-HZVYDWUP.js → chunk-NQMG2W5L.js} +2 -2
- package/dist/{chunk-L3Z4NXDO.js → chunk-O52WWLKU.js} +3 -3
- package/dist/{chunk-OC6JYPZX.js → chunk-O5MW6CQL.js} +2 -2
- package/dist/{chunk-6PHB45IU.js → chunk-O6YDGTH4.js} +2 -2
- package/dist/{chunk-E5274WUC.js → chunk-OAIWPB2I.js} +19 -2
- package/dist/chunk-OAIWPB2I.js.map +1 -0
- package/dist/{chunk-5NOPZYNI.js → chunk-OFDIGTC2.js} +7 -7
- package/dist/{chunk-5EOV7ANU.js → chunk-OGWEWJRH.js} +2 -2
- package/dist/{chunk-3ENX2RB4.js → chunk-OM3RWZQK.js} +2 -2
- package/dist/{chunk-GSAZBZMA.js → chunk-PDVWGGX4.js} +2 -2
- package/dist/{chunk-N44GZ73R.js → chunk-SOJ3IQD3.js} +3 -3
- package/dist/{chunk-4OKPH6FG.js → chunk-SQA2MM2F.js} +2 -2
- package/dist/{chunk-7O252IE6.js → chunk-SSAXGPXY.js} +2 -2
- package/dist/{chunk-R2AWYR4Q.js → chunk-SVDU4OHO.js} +2 -2
- package/dist/{chunk-WPFSZZ35.js → chunk-UOA2VQ7C.js} +2 -2
- package/dist/{chunk-S4GUMZRB.js → chunk-VA2HNBGQ.js} +17 -17
- package/dist/{chunk-YAF3NRNC.js → chunk-VBJD4RSJ.js} +2 -2
- package/dist/{chunk-A6G7K273.js → chunk-VDXTXVFZ.js} +3 -3
- package/dist/{chunk-5Q4NQNW7.js → chunk-VJGDQA3D.js} +2 -2
- package/dist/{chunk-QN77HA6P.js → chunk-WCTL3PVM.js} +2 -2
- package/dist/{chunk-NXLQQ6WI.js → chunk-WH4QXVKU.js} +2 -2
- package/dist/{chunk-3VTNNO2B.js → chunk-WXFKXCOQ.js} +3 -3
- package/dist/{chunk-K3DZ3G5I.js → chunk-XQIHFXYP.js} +2 -2
- package/dist/{chunk-VSHRMIJH.js → chunk-YYNHJF3N.js} +2 -2
- package/dist/cli.js +40 -40
- package/dist/coding/export-okf-codegraph.js +1 -1
- package/dist/compounding/engine.d.ts +1 -5
- package/dist/compounding/engine.d.ts.map +1 -1
- package/dist/compounding/engine.js +5 -3
- package/dist/compounding/iso-week.d.ts +18 -0
- package/dist/compounding/iso-week.d.ts.map +1 -0
- package/dist/compounding/weekly-evidence.d.ts +123 -0
- package/dist/compounding/weekly-evidence.d.ts.map +1 -0
- package/dist/config.js +1 -1
- package/dist/connectors/codex-materialize-runner.js +2 -2
- package/dist/connectors/index.js +2 -2
- package/dist/convergence-refresh.js +4 -4
- package/dist/corpus-watermark.js +4 -4
- package/dist/entity-retrieval.js +2 -2
- package/dist/external-wiki-access.js +15 -15
- package/dist/extraction.js +2 -2
- package/dist/harmonic-retrieval.js +2 -2
- package/dist/index.js +52 -52
- package/dist/location/index.js +4 -4
- package/dist/maintenance/memory-governance.js +2 -2
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +2 -2
- package/dist/maintenance/rebuild-memory-projection-runner.js +4 -4
- package/dist/maintenance/rebuild-memory-projection.js +3 -3
- package/dist/memory-browse-operations.js +15 -15
- package/dist/memory-browse.js +2 -2
- package/dist/namespaces/migrate.js +3 -3
- package/dist/namespaces/storage.js +2 -2
- package/dist/operator-doctor-corpus.js +5 -5
- package/dist/operator-toolkit.js +10 -10
- package/dist/orchestration/generic-recall-paths.d.ts.map +1 -1
- package/dist/orchestration/maintenance.js +11 -11
- package/dist/orchestrator.js +52 -52
- package/dist/recall-navigation-operations.js +15 -15
- package/dist/recall-navigation.js +14 -14
- package/dist/recall-state-view-admission.js +2 -2
- package/dist/recall-why-service.js +2 -2
- package/dist/resume-bundles.js +1 -1
- package/dist/semantic-consolidation.js +3 -3
- package/dist/semantic-rule-promotion.js +2 -2
- package/dist/semantic-rule-verifier.js +2 -2
- package/dist/shared-context/manager.d.ts +18 -0
- package/dist/shared-context/manager.d.ts.map +1 -1
- package/dist/shared-context/manager.js +7 -1
- package/dist/source-agent-qualifier.js +2 -2
- package/dist/standup/build.js +2 -2
- package/dist/storage.js +1 -1
- package/dist/support-passport/index.js +17 -17
- package/dist/transfer/export-okf.js +2 -2
- package/dist/verified-recall.js +2 -2
- package/dist/who-knows-cli.js +3 -3
- package/dist/who-knows.js +2 -2
- package/package.json +2 -2
- package/src/compounding/engine.ts +135 -130
- package/src/compounding/iso-week.ts +60 -0
- package/src/compounding/weekly-evidence.ts +698 -0
- package/src/orchestration/generic-recall-paths.ts +27 -1
- package/src/shared-context/manager.ts +132 -3
- package/dist/chunk-2K7D6EFT.js.map +0 -1
- package/dist/chunk-77HNHT6S.js.map +0 -1
- package/dist/chunk-E5274WUC.js.map +0 -1
- /package/dist/{chunk-ZQYAE2C5.js.map → chunk-2U4BM3TW.js.map} +0 -0
- /package/dist/{chunk-QFIPSKPC.js.map → chunk-3ZCRHW7U.js.map} +0 -0
- /package/dist/{chunk-76KHEHT2.js.map → chunk-4N2MFNTG.js.map} +0 -0
- /package/dist/{chunk-FBVLTTVV.js.map → chunk-4TP3MJ3D.js.map} +0 -0
- /package/dist/{chunk-JSIQSZXI.js.map → chunk-56GJLXBA.js.map} +0 -0
- /package/dist/{chunk-MVRIW6MI.js.map → chunk-6OAXWYE3.js.map} +0 -0
- /package/dist/{chunk-KDYQYMJZ.js.map → chunk-7SUWY37K.js.map} +0 -0
- /package/dist/{chunk-KRIEQCKE.js.map → chunk-A2L3P2IY.js.map} +0 -0
- /package/dist/{chunk-AMFCRZYB.js.map → chunk-AV2OQF2O.js.map} +0 -0
- /package/dist/{chunk-WJLGUY27.js.map → chunk-BD5QEP3T.js.map} +0 -0
- /package/dist/{chunk-C3WJNRGR.js.map → chunk-BH44JOLA.js.map} +0 -0
- /package/dist/{chunk-NYVKLB2I.js.map → chunk-BX4WDBTE.js.map} +0 -0
- /package/dist/{chunk-V4WSQYO6.js.map → chunk-CAUNCRLQ.js.map} +0 -0
- /package/dist/{chunk-RH6QEGCT.js.map → chunk-D5UPBXZM.js.map} +0 -0
- /package/dist/{chunk-IOM5QSNR.js.map → chunk-EKKAHJ4B.js.map} +0 -0
- /package/dist/{chunk-JK3DYMOC.js.map → chunk-GKOML66M.js.map} +0 -0
- /package/dist/{chunk-QW7G7PWN.js.map → chunk-I2M4ZVDD.js.map} +0 -0
- /package/dist/{chunk-JTUKDLAD.js.map → chunk-J6FFBORM.js.map} +0 -0
- /package/dist/{chunk-MAJ2OKE4.js.map → chunk-J7MDPTX7.js.map} +0 -0
- /package/dist/{chunk-5FNVK7MW.js.map → chunk-JVNEXW6X.js.map} +0 -0
- /package/dist/{chunk-IJWEXCWF.js.map → chunk-JXWTPOMJ.js.map} +0 -0
- /package/dist/{chunk-3R6SLDTH.js.map → chunk-KJOGIRMF.js.map} +0 -0
- /package/dist/{chunk-GDI64ITR.js.map → chunk-KWVI52ER.js.map} +0 -0
- /package/dist/{chunk-AV46CT77.js.map → chunk-KX36OCGK.js.map} +0 -0
- /package/dist/{chunk-CSUAHUOH.js.map → chunk-MK552I5J.js.map} +0 -0
- /package/dist/{chunk-BPY4RRTF.js.map → chunk-MO25AN7J.js.map} +0 -0
- /package/dist/{chunk-NAHUBSUF.js.map → chunk-N75Q5ZSP.js.map} +0 -0
- /package/dist/{chunk-HZVYDWUP.js.map → chunk-NQMG2W5L.js.map} +0 -0
- /package/dist/{chunk-L3Z4NXDO.js.map → chunk-O52WWLKU.js.map} +0 -0
- /package/dist/{chunk-OC6JYPZX.js.map → chunk-O5MW6CQL.js.map} +0 -0
- /package/dist/{chunk-6PHB45IU.js.map → chunk-O6YDGTH4.js.map} +0 -0
- /package/dist/{chunk-5NOPZYNI.js.map → chunk-OFDIGTC2.js.map} +0 -0
- /package/dist/{chunk-5EOV7ANU.js.map → chunk-OGWEWJRH.js.map} +0 -0
- /package/dist/{chunk-3ENX2RB4.js.map → chunk-OM3RWZQK.js.map} +0 -0
- /package/dist/{chunk-GSAZBZMA.js.map → chunk-PDVWGGX4.js.map} +0 -0
- /package/dist/{chunk-N44GZ73R.js.map → chunk-SOJ3IQD3.js.map} +0 -0
- /package/dist/{chunk-4OKPH6FG.js.map → chunk-SQA2MM2F.js.map} +0 -0
- /package/dist/{chunk-7O252IE6.js.map → chunk-SSAXGPXY.js.map} +0 -0
- /package/dist/{chunk-R2AWYR4Q.js.map → chunk-SVDU4OHO.js.map} +0 -0
- /package/dist/{chunk-WPFSZZ35.js.map → chunk-UOA2VQ7C.js.map} +0 -0
- /package/dist/{chunk-S4GUMZRB.js.map → chunk-VA2HNBGQ.js.map} +0 -0
- /package/dist/{chunk-YAF3NRNC.js.map → chunk-VBJD4RSJ.js.map} +0 -0
- /package/dist/{chunk-A6G7K273.js.map → chunk-VDXTXVFZ.js.map} +0 -0
- /package/dist/{chunk-5Q4NQNW7.js.map → chunk-VJGDQA3D.js.map} +0 -0
- /package/dist/{chunk-QN77HA6P.js.map → chunk-WCTL3PVM.js.map} +0 -0
- /package/dist/{chunk-NXLQQ6WI.js.map → chunk-WH4QXVKU.js.map} +0 -0
- /package/dist/{chunk-3VTNNO2B.js.map → chunk-WXFKXCOQ.js.map} +0 -0
- /package/dist/{chunk-K3DZ3G5I.js.map → chunk-XQIHFXYP.js.map} +0 -0
- /package/dist/{chunk-VSHRMIJH.js.map → chunk-YYNHJF3N.js.map} +0 -0
|
@@ -1,32 +1,560 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SharedFeedbackEntrySchema,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
migrateLegacyFeedbackInbox,
|
|
4
|
+
resolveFeedbackInboxPath
|
|
5
|
+
} from "./chunk-E57LYSHI.js";
|
|
5
6
|
import {
|
|
6
7
|
composeSalvagedEnvelope
|
|
7
8
|
} from "./chunk-ZSJGYC3C.js";
|
|
8
9
|
import {
|
|
9
|
-
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
resolveDefaultNamespaceRoot
|
|
11
|
+
} from "./chunk-D5UPBXZM.js";
|
|
12
|
+
import {
|
|
13
|
+
StorageManager,
|
|
14
|
+
readRawMemoryDocument
|
|
15
|
+
} from "./chunk-BD5QEP3T.js";
|
|
11
16
|
import {
|
|
12
17
|
parseContinuityImprovementLoops
|
|
13
18
|
} from "./chunk-LDXUBPMO.js";
|
|
19
|
+
import {
|
|
20
|
+
getKey,
|
|
21
|
+
secureStoreDir
|
|
22
|
+
} from "./chunk-BJMBJZ2Y.js";
|
|
23
|
+
import {
|
|
24
|
+
readMaybeEncryptedLines
|
|
25
|
+
} from "./chunk-FQD2KPQH.js";
|
|
26
|
+
import {
|
|
27
|
+
assertPathInsideRoot
|
|
28
|
+
} from "./chunk-C7HJ3NEI.js";
|
|
14
29
|
import {
|
|
15
30
|
sanitizeMemoryContent
|
|
16
31
|
} from "./chunk-5GKPFL3S.js";
|
|
32
|
+
import {
|
|
33
|
+
isSafeRouteNamespace
|
|
34
|
+
} from "./chunk-PCXDUHQH.js";
|
|
35
|
+
import {
|
|
36
|
+
namespaceIdentityFromToken
|
|
37
|
+
} from "./chunk-VUFL7X3H.js";
|
|
17
38
|
import {
|
|
18
39
|
resolveConsolidationCapabilities,
|
|
19
40
|
resolveConversationContextCapabilities,
|
|
20
41
|
resolveQmdCapabilities
|
|
21
42
|
} from "./chunk-2EMROIXS.js";
|
|
43
|
+
import {
|
|
44
|
+
readMaybeEncryptedFile
|
|
45
|
+
} from "./chunk-MAAL6OZV.js";
|
|
46
|
+
import {
|
|
47
|
+
isErrnoCode
|
|
48
|
+
} from "./chunk-KNA3BXXL.js";
|
|
22
49
|
import {
|
|
23
50
|
log
|
|
24
51
|
} from "./chunk-3WCASNQZ.js";
|
|
25
52
|
|
|
26
53
|
// src/compounding/engine.ts
|
|
27
54
|
import { createHash } from "crypto";
|
|
28
|
-
import { mkdir, readFile, readdir, unlink, writeFile } from "fs/promises";
|
|
55
|
+
import { mkdir, readFile as readFile2, readdir as readdir2, unlink, writeFile } from "fs/promises";
|
|
56
|
+
import path2 from "path";
|
|
57
|
+
|
|
58
|
+
// src/compounding/iso-week.ts
|
|
59
|
+
var DAY_MS = 864e5;
|
|
60
|
+
var WEEK_MS = 7 * DAY_MS;
|
|
61
|
+
function isoWeekId(d) {
|
|
62
|
+
const dt = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
|
|
63
|
+
const day = dt.getUTCDay() || 7;
|
|
64
|
+
dt.setUTCDate(dt.getUTCDate() + 4 - day);
|
|
65
|
+
const yearStart = new Date(Date.UTC(dt.getUTCFullYear(), 0, 1));
|
|
66
|
+
const week = Math.ceil(((dt.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
|
|
67
|
+
const yyyy = dt.getUTCFullYear();
|
|
68
|
+
return `${yyyy}-W${String(week).padStart(2, "0")}`;
|
|
69
|
+
}
|
|
70
|
+
function isIsoWeekId(weekId) {
|
|
71
|
+
if (weekId.length !== 8 || weekId[4] !== "-" || weekId[5] !== "W") return false;
|
|
72
|
+
const year = weekId.slice(0, 4);
|
|
73
|
+
const week = weekId.slice(6);
|
|
74
|
+
for (let i = 0; i < year.length; i += 1) {
|
|
75
|
+
const code = year.charCodeAt(i);
|
|
76
|
+
if (code < 48 || code > 57) return false;
|
|
77
|
+
}
|
|
78
|
+
for (let i = 0; i < week.length; i += 1) {
|
|
79
|
+
const code = week.charCodeAt(i);
|
|
80
|
+
if (code < 48 || code > 57) return false;
|
|
81
|
+
}
|
|
82
|
+
const weekNum = Number(week);
|
|
83
|
+
return weekNum >= 1 && weekNum <= 53;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/compounding/weekly-evidence.ts
|
|
87
|
+
import { lstat, readFile, readdir, realpath } from "fs/promises";
|
|
29
88
|
import path from "path";
|
|
89
|
+
var DAY_MS2 = 864e5;
|
|
90
|
+
var WEEKLY_CORRECTION_READ_LIMIT = 500;
|
|
91
|
+
var WEEKLY_CORRECTION_SCAN_LIMIT = 2e3;
|
|
92
|
+
var CORRECTION_FILE_BYTE_LIMIT = 256 * 1024;
|
|
93
|
+
var CORRECTION_NOTE_LIMIT = 240;
|
|
94
|
+
function isoWeekStartMs(weekId) {
|
|
95
|
+
if (!isIsoWeekId(weekId)) return null;
|
|
96
|
+
const year = Number(weekId.slice(0, 4));
|
|
97
|
+
const week = Number(weekId.slice(6));
|
|
98
|
+
const jan4 = Date.UTC(year, 0, 4);
|
|
99
|
+
const jan4Day = new Date(jan4).getUTCDay() || 7;
|
|
100
|
+
const start = jan4 - (jan4Day - 1) * DAY_MS2 + (week - 1) * 7 * DAY_MS2;
|
|
101
|
+
if (isoWeekId(new Date(start)) !== weekId) return null;
|
|
102
|
+
return start;
|
|
103
|
+
}
|
|
104
|
+
async function readFeedbackEntriesForWeekFile(inboxPath, weekId) {
|
|
105
|
+
const out = [];
|
|
106
|
+
try {
|
|
107
|
+
const raw = await readFile(inboxPath, "utf-8");
|
|
108
|
+
const lines = raw.split("\n");
|
|
109
|
+
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
110
|
+
const line = lines[idx];
|
|
111
|
+
if (!line.trim()) continue;
|
|
112
|
+
try {
|
|
113
|
+
const obj = JSON.parse(line);
|
|
114
|
+
const parsed = SharedFeedbackEntrySchema.safeParse(obj);
|
|
115
|
+
if (!parsed.success) continue;
|
|
116
|
+
const d = new Date(parsed.data.date);
|
|
117
|
+
if (!Number.isFinite(d.getTime())) continue;
|
|
118
|
+
if (isoWeekId(d) !== weekId) continue;
|
|
119
|
+
const sourceLine = idx + 1;
|
|
120
|
+
out.push({
|
|
121
|
+
entry: parsed.data,
|
|
122
|
+
sourceLine,
|
|
123
|
+
sourcePath: inboxPath,
|
|
124
|
+
entryId: `${parsed.data.agent}-${parsed.data.date}-${sourceLine}`.replace(/[^a-zA-Z0-9._:-]/g, "_")
|
|
125
|
+
});
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
function buildActionFailurePatterns(events) {
|
|
134
|
+
const out = [];
|
|
135
|
+
for (const event of events) {
|
|
136
|
+
const failed = event.outcome === "failed" || event.outcome === "skipped";
|
|
137
|
+
if (!failed && event.policyDecision === null) continue;
|
|
138
|
+
const suffix = event.reason && event.reason.trim().length > 0 ? ` - ${event.reason.trim().slice(0, 140)}` : "";
|
|
139
|
+
out.push({
|
|
140
|
+
pattern: `memory-action/${event.namespace}: ${event.action} ${event.outcome}${event.policyDecision ? `/${event.policyDecision}` : ""}${suffix}`,
|
|
141
|
+
provenance: `${event.ledgerLabel}:*`
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
async function readWeeklyActionEvents(input) {
|
|
147
|
+
const seenActionIds = /* @__PURE__ */ new Set();
|
|
148
|
+
const out = [];
|
|
149
|
+
const rootRows = await input.storage.readMemoryActionEventRows(Number.MAX_SAFE_INTEGER);
|
|
150
|
+
for (const row of rootRows) {
|
|
151
|
+
pushActionEvent(out, seenActionIds, row.line, row.event, "default", "memory-actions.jsonl", input.weekId);
|
|
152
|
+
}
|
|
153
|
+
const rootReal = await realpath(input.memoryDir);
|
|
154
|
+
const namespaces = await listNamespaceStorageDirs(input.memoryDir, rootReal);
|
|
155
|
+
const key = getKey(secureStoreDir(input.memoryDir));
|
|
156
|
+
for (const ns of namespaces) {
|
|
157
|
+
const filePath = path.join(ns.root, "state", "memory-actions.jsonl");
|
|
158
|
+
const label = `namespaces/${ns.dirName}/state/memory-actions.jsonl`;
|
|
159
|
+
let entryStat;
|
|
160
|
+
try {
|
|
161
|
+
entryStat = await lstat(filePath);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
if (isErrnoCode(err, "ENOENT")) continue;
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
if (entryStat.isSymbolicLink() || !entryStat.isFile()) continue;
|
|
167
|
+
const fileReal = await realpath(filePath);
|
|
168
|
+
assertPathInsideRoot(rootReal, fileReal, filePath);
|
|
169
|
+
try {
|
|
170
|
+
let lineNumber = 0;
|
|
171
|
+
for await (const row of readMaybeEncryptedLines(
|
|
172
|
+
filePath,
|
|
173
|
+
() => readMaybeEncryptedFile(filePath, key, input.memoryDir)
|
|
174
|
+
)) {
|
|
175
|
+
lineNumber += 1;
|
|
176
|
+
const line = row.trim();
|
|
177
|
+
if (line.length === 0) continue;
|
|
178
|
+
const event = parseMemoryActionEventLine(line);
|
|
179
|
+
if (!event) continue;
|
|
180
|
+
pushActionEvent(out, seenActionIds, lineNumber, event, ns.namespace, label, input.weekId);
|
|
181
|
+
}
|
|
182
|
+
} catch (err) {
|
|
183
|
+
if (isErrnoCode(err, "ENOENT")) continue;
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
async function readWeeklyCorrections(input) {
|
|
190
|
+
const weekStartMs = isoWeekStartMs(input.weekId);
|
|
191
|
+
if (weekStartMs === null) return [];
|
|
192
|
+
const rootReal = await realpath(input.memoryDir);
|
|
193
|
+
const candidates = [];
|
|
194
|
+
await collectCorrectionCandidates(candidates, input.memoryDir, "default", input.weekId, weekStartMs, rootReal);
|
|
195
|
+
const namespaces = await listNamespaceStorageDirs(input.memoryDir, rootReal);
|
|
196
|
+
for (const ns of namespaces) {
|
|
197
|
+
await collectCorrectionCandidates(candidates, ns.root, ns.namespace, input.weekId, weekStartMs, rootReal);
|
|
198
|
+
}
|
|
199
|
+
candidates.sort((a, b) => b.sortMs - a.sortMs || a.filePath.localeCompare(b.filePath));
|
|
200
|
+
const ordered = preferVisibleCorrectionCandidates(
|
|
201
|
+
candidates,
|
|
202
|
+
input.memoryDir,
|
|
203
|
+
input.defaultNamespacePrefix ?? null
|
|
204
|
+
);
|
|
205
|
+
const out = [];
|
|
206
|
+
let scanned = 0;
|
|
207
|
+
for (const candidate of ordered) {
|
|
208
|
+
if (out.length >= WEEKLY_CORRECTION_READ_LIMIT || scanned >= WEEKLY_CORRECTION_SCAN_LIMIT) break;
|
|
209
|
+
scanned += 1;
|
|
210
|
+
const evidence = await readCorrectionCandidate(input.storage, input.memoryDir, input.weekId, candidate);
|
|
211
|
+
if (evidence) out.push(evidence);
|
|
212
|
+
}
|
|
213
|
+
if (scanned < candidates.length) {
|
|
214
|
+
log.warn(
|
|
215
|
+
`weekly synthesis kept ${out.length} accepted corrections after scanning ${scanned} of ${candidates.length} in-week candidates`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
function preferVisibleCorrectionCandidates(candidates, memoryDir, defaultNamespacePrefix) {
|
|
221
|
+
const visible = [];
|
|
222
|
+
const foreign = [];
|
|
223
|
+
for (const candidate of candidates) {
|
|
224
|
+
const relative = path.relative(memoryDir, candidate.filePath).split(path.sep).join("/");
|
|
225
|
+
if (provenanceVisibleInStoreRecall([relative], defaultNamespacePrefix)) visible.push(candidate);
|
|
226
|
+
else foreign.push(candidate);
|
|
227
|
+
}
|
|
228
|
+
return visible.concat(foreign);
|
|
229
|
+
}
|
|
230
|
+
function parseMemoryActionEventLine(line) {
|
|
231
|
+
let parsed;
|
|
232
|
+
try {
|
|
233
|
+
parsed = JSON.parse(line);
|
|
234
|
+
} catch {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
if (parsed.recordKind !== void 0) return null;
|
|
238
|
+
const outcome = parsed.outcome === "applied" || parsed.outcome === "skipped" || parsed.outcome === "failed" ? parsed.outcome : null;
|
|
239
|
+
const timestamp = parsed.timestamp;
|
|
240
|
+
const action = parsed.action;
|
|
241
|
+
if (typeof timestamp !== "string" || typeof action !== "string" || outcome === null) return null;
|
|
242
|
+
return { ...parsed, timestamp, action, outcome };
|
|
243
|
+
}
|
|
244
|
+
function pushActionEvent(out, seenActionIds, line, event, fallbackNamespace, ledgerLabel, weekId) {
|
|
245
|
+
const ts = new Date(event.timestamp);
|
|
246
|
+
if (!Number.isFinite(ts.getTime()) || isoWeekId(ts) !== weekId) return;
|
|
247
|
+
const actionId = typeof event.actionId === "string" && event.actionId.length > 0 ? event.actionId : null;
|
|
248
|
+
if (actionId) {
|
|
249
|
+
if (seenActionIds.has(actionId)) return;
|
|
250
|
+
seenActionIds.add(actionId);
|
|
251
|
+
}
|
|
252
|
+
out.push({
|
|
253
|
+
line,
|
|
254
|
+
action: event.action,
|
|
255
|
+
outcome: event.outcome,
|
|
256
|
+
policyDecision: event.policyDecision === "deny" || event.policyDecision === "defer" ? event.policyDecision : null,
|
|
257
|
+
namespace: typeof event.namespace === "string" && event.namespace.length > 0 ? event.namespace : fallbackNamespace,
|
|
258
|
+
reason: typeof event.reason === "string" ? event.reason : null,
|
|
259
|
+
ledgerLabel,
|
|
260
|
+
actionId
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async function listNamespaceStorageDirs(memoryDir, rootReal) {
|
|
264
|
+
const nsRoot = path.join(memoryDir, "namespaces");
|
|
265
|
+
let rootStat;
|
|
266
|
+
try {
|
|
267
|
+
rootStat = await lstat(nsRoot);
|
|
268
|
+
} catch (err) {
|
|
269
|
+
if (isErrnoCode(err, "ENOENT")) return [];
|
|
270
|
+
throw err;
|
|
271
|
+
}
|
|
272
|
+
if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) return [];
|
|
273
|
+
const nsReal = await realpath(nsRoot);
|
|
274
|
+
assertPathInsideRoot(rootReal, nsReal, nsRoot);
|
|
275
|
+
const names = await readdir(nsRoot);
|
|
276
|
+
const out = [];
|
|
277
|
+
for (const dirName of names) {
|
|
278
|
+
const namespace = namespaceFromDirName(dirName);
|
|
279
|
+
if (!namespace) continue;
|
|
280
|
+
const root = path.join(nsRoot, dirName);
|
|
281
|
+
let entryStat;
|
|
282
|
+
try {
|
|
283
|
+
entryStat = await lstat(root);
|
|
284
|
+
} catch (err) {
|
|
285
|
+
if (isErrnoCode(err, "ENOENT")) continue;
|
|
286
|
+
throw err;
|
|
287
|
+
}
|
|
288
|
+
if (entryStat.isSymbolicLink() || !entryStat.isDirectory()) continue;
|
|
289
|
+
const dirReal = await realpath(root);
|
|
290
|
+
assertPathInsideRoot(rootReal, dirReal, root);
|
|
291
|
+
out.push({ dirName, namespace, root });
|
|
292
|
+
}
|
|
293
|
+
out.sort((a, b) => a.dirName.localeCompare(b.dirName));
|
|
294
|
+
return out;
|
|
295
|
+
}
|
|
296
|
+
function namespaceFromDirName(dirName) {
|
|
297
|
+
if (dirName.length === 0 || dirName.includes("/") || dirName.includes("\\") || dirName.includes("..")) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
if (dirName.startsWith("ns-")) {
|
|
301
|
+
const decoded = namespaceIdentityFromToken(dirName);
|
|
302
|
+
if (decoded === null) return null;
|
|
303
|
+
if (decoded.length === 0) return "default";
|
|
304
|
+
return isSafeRouteNamespace(decoded) ? decoded : null;
|
|
305
|
+
}
|
|
306
|
+
return isSafeRouteNamespace(dirName) ? dirName : null;
|
|
307
|
+
}
|
|
308
|
+
async function collectCorrectionCandidates(candidates, storageRoot, namespace, weekId, weekStartMs, rootReal) {
|
|
309
|
+
await collectCorrectionDir(
|
|
310
|
+
candidates,
|
|
311
|
+
path.join(storageRoot, "corrections"),
|
|
312
|
+
namespace,
|
|
313
|
+
weekId,
|
|
314
|
+
weekStartMs,
|
|
315
|
+
rootReal
|
|
316
|
+
);
|
|
317
|
+
const factsDir = path.join(storageRoot, "facts");
|
|
318
|
+
const dayNames = await readContainedDirNames(factsDir, rootReal);
|
|
319
|
+
if (!dayNames) return;
|
|
320
|
+
for (const dayName of dayNames) {
|
|
321
|
+
if (!utcDayDirInWeek(dayName, weekId)) continue;
|
|
322
|
+
await collectCorrectionDir(candidates, path.join(factsDir, dayName), namespace, weekId, weekStartMs, rootReal);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async function collectCorrectionDir(candidates, dir, namespace, weekId, weekStartMs, rootReal) {
|
|
326
|
+
const names = await readContainedDirNames(dir, rootReal);
|
|
327
|
+
if (!names) return;
|
|
328
|
+
for (const name of names) {
|
|
329
|
+
if (!name.startsWith("correction-") || !name.endsWith(".md")) continue;
|
|
330
|
+
const filenameMs = correctionFilenameTimestampMs(name);
|
|
331
|
+
if (filenameMs !== null && isoWeekId(new Date(filenameMs)) !== weekId) continue;
|
|
332
|
+
const filePath = path.join(dir, name);
|
|
333
|
+
let entryStat;
|
|
334
|
+
try {
|
|
335
|
+
entryStat = await lstat(filePath);
|
|
336
|
+
} catch (err) {
|
|
337
|
+
if (isErrnoCode(err, "ENOENT")) continue;
|
|
338
|
+
throw err;
|
|
339
|
+
}
|
|
340
|
+
if (entryStat.isSymbolicLink() || !entryStat.isFile()) continue;
|
|
341
|
+
if (entryStat.size > CORRECTION_FILE_BYTE_LIMIT) continue;
|
|
342
|
+
const fileReal = await realpath(filePath);
|
|
343
|
+
assertPathInsideRoot(rootReal, fileReal, filePath);
|
|
344
|
+
if (filenameMs !== null) {
|
|
345
|
+
candidates.push({ filePath, sortMs: filenameMs, namespace });
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (entryStat.mtimeMs < weekStartMs) continue;
|
|
349
|
+
candidates.push({ filePath, sortMs: entryStat.mtimeMs, namespace });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
async function readContainedDirNames(dir, rootReal) {
|
|
353
|
+
let entryStat;
|
|
354
|
+
try {
|
|
355
|
+
entryStat = await lstat(dir);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
if (isErrnoCode(err, "ENOENT")) return null;
|
|
358
|
+
throw err;
|
|
359
|
+
}
|
|
360
|
+
if (entryStat.isSymbolicLink() || !entryStat.isDirectory()) return null;
|
|
361
|
+
const dirReal = await realpath(dir);
|
|
362
|
+
assertPathInsideRoot(rootReal, dirReal, dir);
|
|
363
|
+
return readdir(dir);
|
|
364
|
+
}
|
|
365
|
+
function utcDayDirInWeek(name, weekId) {
|
|
366
|
+
if (name.length !== 10 || name[4] !== "-" || name[7] !== "-") return false;
|
|
367
|
+
for (let i = 0; i < name.length; i += 1) {
|
|
368
|
+
if (i === 4 || i === 7) continue;
|
|
369
|
+
const code = name.charCodeAt(i);
|
|
370
|
+
if (code < 48 || code > 57) return false;
|
|
371
|
+
}
|
|
372
|
+
const year = Number(name.slice(0, 4));
|
|
373
|
+
const month = Number(name.slice(5, 7));
|
|
374
|
+
const day = Number(name.slice(8, 10));
|
|
375
|
+
if (month < 1 || month > 12 || day < 1 || day > 31) return false;
|
|
376
|
+
const stamp = new Date(Date.UTC(year, month - 1, day));
|
|
377
|
+
if (stamp.getUTCFullYear() !== year || stamp.getUTCMonth() !== month - 1 || stamp.getUTCDate() !== day) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
return isoWeekId(stamp) === weekId;
|
|
381
|
+
}
|
|
382
|
+
function correctionFilenameTimestampMs(fileName) {
|
|
383
|
+
const prefix = "correction-";
|
|
384
|
+
if (!fileName.startsWith(prefix) || !fileName.endsWith(".md")) return null;
|
|
385
|
+
const rest = fileName.slice(prefix.length, fileName.length - 3);
|
|
386
|
+
let i = 0;
|
|
387
|
+
while (i < rest.length) {
|
|
388
|
+
const code = rest.charCodeAt(i);
|
|
389
|
+
if (code < 48 || code > 57) break;
|
|
390
|
+
i += 1;
|
|
391
|
+
}
|
|
392
|
+
if (i < 10) return null;
|
|
393
|
+
if (i < rest.length && rest[i] !== "-") return null;
|
|
394
|
+
const ms = Number(rest.slice(0, i));
|
|
395
|
+
if (!Number.isSafeInteger(ms)) return null;
|
|
396
|
+
return ms;
|
|
397
|
+
}
|
|
398
|
+
async function readCorrectionCandidate(storage, memoryDir, weekId, candidate) {
|
|
399
|
+
const memory = await storage.readMemoryByPath(candidate.filePath);
|
|
400
|
+
if (!memory) return null;
|
|
401
|
+
const raw = readRawMemoryDocument(memory);
|
|
402
|
+
if (!raw) return null;
|
|
403
|
+
if (rawFrontmatterScalar(raw, "category") !== "correction") return null;
|
|
404
|
+
const status = rawFrontmatterScalar(raw, "status");
|
|
405
|
+
if (status && status !== "active") return null;
|
|
406
|
+
const created = rawFrontmatterScalar(raw, "created");
|
|
407
|
+
if (!created) return null;
|
|
408
|
+
const createdDate = new Date(created);
|
|
409
|
+
if (!Number.isFinite(createdDate.getTime()) || isoWeekId(createdDate) !== weekId) return null;
|
|
410
|
+
const note = collapseWhitespace(memory.content).slice(0, CORRECTION_NOTE_LIMIT);
|
|
411
|
+
if (note.length === 0) return null;
|
|
412
|
+
const rawSource = rawFrontmatterScalar(raw, "source");
|
|
413
|
+
const source = rawSource && rawSource !== "unknown" ? rawSource : null;
|
|
414
|
+
const entityRef = typeof memory.frontmatter.entityRef === "string" && memory.frontmatter.entityRef.length > 0 ? memory.frontmatter.entityRef : null;
|
|
415
|
+
const confidence = rawConfidence(raw);
|
|
416
|
+
const tags = Array.isArray(memory.frontmatter.tags) ? memory.frontmatter.tags.filter((tag) => typeof tag === "string" && tag.length > 0) : [];
|
|
417
|
+
const id = typeof memory.frontmatter.id === "string" && memory.frontmatter.id.length > 0 ? memory.frontmatter.id : path.basename(candidate.filePath, ".md");
|
|
418
|
+
return {
|
|
419
|
+
id,
|
|
420
|
+
namespace: candidate.namespace,
|
|
421
|
+
pattern: `correction: ${note}`,
|
|
422
|
+
note,
|
|
423
|
+
created,
|
|
424
|
+
source,
|
|
425
|
+
entityRef,
|
|
426
|
+
confidence,
|
|
427
|
+
tags,
|
|
428
|
+
provenance: path.relative(memoryDir, candidate.filePath).split(path.sep).join("/")
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
async function defaultNamespaceRecallPrefix(config) {
|
|
432
|
+
const root = await resolveDefaultNamespaceRoot(config);
|
|
433
|
+
const rel = path.relative(path.resolve(config.memoryDir), path.resolve(root));
|
|
434
|
+
if (rel === "" || rel === "." || rel.startsWith("..") || path.isAbsolute(rel)) return null;
|
|
435
|
+
const posix = rel.split(path.sep).join("/");
|
|
436
|
+
if (!posix.startsWith("namespaces/")) return null;
|
|
437
|
+
return `${posix}/`;
|
|
438
|
+
}
|
|
439
|
+
function visibleRubricEntries(entries, observationsFor, defaultNamespacePrefix) {
|
|
440
|
+
return entries.flatMap((entry) => {
|
|
441
|
+
const visible = observationsFor(entry).filter(
|
|
442
|
+
(item) => provenanceVisibleInStoreRecall(item.provenance, defaultNamespacePrefix)
|
|
443
|
+
);
|
|
444
|
+
if (visible.length === 0) return [];
|
|
445
|
+
return [{
|
|
446
|
+
...entry,
|
|
447
|
+
observations: visible.map((item) => item.note),
|
|
448
|
+
provenance: [...new Set(visible.flatMap((item) => item.provenance))],
|
|
449
|
+
observationEntries: visible
|
|
450
|
+
}];
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
function capWeeklyPatternDetails(details, categoryFor, defaultNamespacePrefix, limit = 500) {
|
|
454
|
+
const visibleActions = [];
|
|
455
|
+
const visibleOther = [];
|
|
456
|
+
const foreign = [];
|
|
457
|
+
for (const detail of details) {
|
|
458
|
+
if (!provenanceVisibleInStoreRecall(detail.provenance, defaultNamespacePrefix)) {
|
|
459
|
+
foreign.push(detail);
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
if (categoryFor(detail.pattern) === "action") visibleActions.push(detail);
|
|
463
|
+
else visibleOther.push(detail);
|
|
464
|
+
}
|
|
465
|
+
return [...visibleActions, ...visibleOther, ...foreign].slice(0, limit);
|
|
466
|
+
}
|
|
467
|
+
async function forgottenCorrectionPatterns(storage, memoryDir, registry, defaultNamespacePrefix) {
|
|
468
|
+
const out = /* @__PURE__ */ new Set();
|
|
469
|
+
for (const entry of registry) {
|
|
470
|
+
if (entry.category !== "correction" || entry.status !== "active") continue;
|
|
471
|
+
const visible = (entry.provenance ?? []).filter(
|
|
472
|
+
(item) => provenanceVisibleInStoreRecall([item], defaultNamespacePrefix)
|
|
473
|
+
);
|
|
474
|
+
if (visible.length === 0) continue;
|
|
475
|
+
let stillActive = false;
|
|
476
|
+
for (const rel of visible) {
|
|
477
|
+
if (rel.includes("..") || path.isAbsolute(rel)) {
|
|
478
|
+
stillActive = true;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
let memory;
|
|
482
|
+
try {
|
|
483
|
+
memory = await storage.readMemoryByPath(path.join(memoryDir, rel));
|
|
484
|
+
} catch {
|
|
485
|
+
stillActive = true;
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
if (!memory) {
|
|
489
|
+
const sourcePath = path.join(memoryDir, rel);
|
|
490
|
+
try {
|
|
491
|
+
await lstat(sourcePath);
|
|
492
|
+
stillActive = true;
|
|
493
|
+
break;
|
|
494
|
+
} catch (err) {
|
|
495
|
+
if (!isErrnoCode(err, "ENOENT")) {
|
|
496
|
+
stillActive = true;
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
const raw = readRawMemoryDocument(memory);
|
|
503
|
+
const status = raw ? rawFrontmatterScalar(raw, "status") : void 0;
|
|
504
|
+
if (!status || status === "active") {
|
|
505
|
+
stillActive = true;
|
|
506
|
+
break;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (!stillActive) out.add(entry.pattern);
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
function provenanceVisibleInStoreRecall(provenance, defaultNamespacePrefix = null) {
|
|
514
|
+
return provenance.length === 0 || provenance.some((item) => {
|
|
515
|
+
if (!item.startsWith("namespaces/")) return true;
|
|
516
|
+
return defaultNamespacePrefix !== null && item.startsWith(defaultNamespacePrefix);
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
function actionEventsVisibleInStore(events, defaultNamespacePrefix) {
|
|
520
|
+
return events.filter(
|
|
521
|
+
(event) => provenanceVisibleInStoreRecall([`${event.ledgerLabel}:L${event.line}`], defaultNamespacePrefix)
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
function collapseWhitespace(value) {
|
|
525
|
+
return value.replace(/\s+/g, " ").trim();
|
|
526
|
+
}
|
|
527
|
+
function rawConfidence(raw) {
|
|
528
|
+
const text = rawFrontmatterScalar(raw, "confidence");
|
|
529
|
+
if (!text) return null;
|
|
530
|
+
const value = Number(text);
|
|
531
|
+
if (!Number.isFinite(value)) return null;
|
|
532
|
+
return Math.max(0, Math.min(1, value));
|
|
533
|
+
}
|
|
534
|
+
function rawFrontmatterScalar(raw, key) {
|
|
535
|
+
const newline = raw.startsWith("---\r\n") ? 5 : raw.startsWith("---\n") ? 4 : -1;
|
|
536
|
+
if (newline < 0) return void 0;
|
|
537
|
+
const headerEnd = raw.indexOf("\n---", newline);
|
|
538
|
+
if (headerEnd < 0) return void 0;
|
|
539
|
+
const block = raw.slice(newline, headerEnd);
|
|
540
|
+
const prefix = `${key}:`;
|
|
541
|
+
for (const line of block.split("\n")) {
|
|
542
|
+
const normalized = line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
543
|
+
if (normalized.startsWith(" ") || normalized.startsWith(" ")) continue;
|
|
544
|
+
if (!normalized.startsWith(prefix)) continue;
|
|
545
|
+
let value = normalized.slice(prefix.length).trim();
|
|
546
|
+
if (value.length >= 2) {
|
|
547
|
+
const quote = value[0];
|
|
548
|
+
if ((quote === '"' || quote === "'") && value.endsWith(quote)) {
|
|
549
|
+
value = value.slice(1, -1);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return value.length > 0 ? value : void 0;
|
|
553
|
+
}
|
|
554
|
+
return void 0;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/compounding/engine.ts
|
|
30
558
|
var COMPOUNDING_VERSION = 2;
|
|
31
559
|
var RETIREMENT_WINDOW_WEEKS = 8;
|
|
32
560
|
function stableSlug(value) {
|
|
@@ -116,6 +644,13 @@ function inferLegacyMistakeMetadata(pattern) {
|
|
|
116
644
|
workflow: "memory-actions"
|
|
117
645
|
};
|
|
118
646
|
}
|
|
647
|
+
if (pattern.startsWith("correction:")) {
|
|
648
|
+
return {
|
|
649
|
+
category: "correction",
|
|
650
|
+
agent: null,
|
|
651
|
+
workflow: "corrections"
|
|
652
|
+
};
|
|
653
|
+
}
|
|
119
654
|
const scope = inferLegacyMistakeScope(pattern);
|
|
120
655
|
return {
|
|
121
656
|
category: "feedback",
|
|
@@ -184,15 +719,6 @@ function defaultTierMigrationCycleBudget(config, trigger) {
|
|
|
184
719
|
minIntervalMs: resolveQmdCapabilities(config).qmdTierAutoBackfill ? 12e4 : 3e5
|
|
185
720
|
};
|
|
186
721
|
}
|
|
187
|
-
function isoWeekId(d) {
|
|
188
|
-
const dt = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
|
|
189
|
-
const day = dt.getUTCDay() || 7;
|
|
190
|
-
dt.setUTCDate(dt.getUTCDate() + 4 - day);
|
|
191
|
-
const yearStart = new Date(Date.UTC(dt.getUTCFullYear(), 0, 1));
|
|
192
|
-
const week = Math.ceil(((dt.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
|
|
193
|
-
const yyyy = dt.getUTCFullYear();
|
|
194
|
-
return `${yyyy}-W${String(week).padStart(2, "0")}`;
|
|
195
|
-
}
|
|
196
722
|
function isoMonthId(d) {
|
|
197
723
|
return `${d.getUTCFullYear()}-${String(d.getUTCMonth() + 1).padStart(2, "0")}`;
|
|
198
724
|
}
|
|
@@ -227,17 +753,16 @@ var CompoundingEngine = class {
|
|
|
227
753
|
constructor(config, storage = new StorageManager(config.memoryDir)) {
|
|
228
754
|
this.config = config;
|
|
229
755
|
this.storage = storage;
|
|
230
|
-
this.weeklyDir =
|
|
231
|
-
this.rubricsDir =
|
|
232
|
-
this.rubricsIndexPath =
|
|
233
|
-
this.rubricsAgentsDir =
|
|
234
|
-
this.rubricsWorkflowsDir =
|
|
235
|
-
this.rubricsPath =
|
|
236
|
-
this.mistakesPath =
|
|
237
|
-
this.feedbackInboxPath =
|
|
238
|
-
this.identityAuditWeeklyDir =
|
|
239
|
-
this.identityAuditMonthlyDir =
|
|
240
|
-
this.memoryActionEventsPath = path.join(config.memoryDir, "state", "memory-actions.jsonl");
|
|
756
|
+
this.weeklyDir = path2.join(config.memoryDir, "compounding", "weekly");
|
|
757
|
+
this.rubricsDir = path2.join(config.memoryDir, "compounding", "rubrics");
|
|
758
|
+
this.rubricsIndexPath = path2.join(this.rubricsDir, "index.json");
|
|
759
|
+
this.rubricsAgentsDir = path2.join(this.rubricsDir, "agents");
|
|
760
|
+
this.rubricsWorkflowsDir = path2.join(this.rubricsDir, "workflows");
|
|
761
|
+
this.rubricsPath = path2.join(config.memoryDir, "compounding", "rubrics.md");
|
|
762
|
+
this.mistakesPath = path2.join(config.memoryDir, "compounding", "mistakes.json");
|
|
763
|
+
this.feedbackInboxPath = resolveFeedbackInboxPath(config);
|
|
764
|
+
this.identityAuditWeeklyDir = path2.join(config.memoryDir, "identity", "audits", "weekly");
|
|
765
|
+
this.identityAuditMonthlyDir = path2.join(config.memoryDir, "identity", "audits", "monthly");
|
|
241
766
|
}
|
|
242
767
|
config;
|
|
243
768
|
storage;
|
|
@@ -251,11 +776,10 @@ var CompoundingEngine = class {
|
|
|
251
776
|
feedbackInboxPath;
|
|
252
777
|
identityAuditWeeklyDir;
|
|
253
778
|
identityAuditMonthlyDir;
|
|
254
|
-
memoryActionEventsPath;
|
|
255
779
|
async ensureDirs() {
|
|
256
780
|
await mkdir(this.weeklyDir, { recursive: true });
|
|
257
|
-
await mkdir(
|
|
258
|
-
await mkdir(
|
|
781
|
+
await mkdir(path2.dirname(this.mistakesPath), { recursive: true });
|
|
782
|
+
await mkdir(path2.dirname(this.rubricsPath), { recursive: true });
|
|
259
783
|
await mkdir(this.rubricsDir, { recursive: true });
|
|
260
784
|
await mkdir(this.rubricsAgentsDir, { recursive: true });
|
|
261
785
|
await mkdir(this.rubricsWorkflowsDir, { recursive: true });
|
|
@@ -263,14 +787,33 @@ var CompoundingEngine = class {
|
|
|
263
787
|
async synthesizeWeekly(opts) {
|
|
264
788
|
await this.ensureDirs();
|
|
265
789
|
const weekId = opts?.weekId ?? isoWeekId(/* @__PURE__ */ new Date());
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
790
|
+
try {
|
|
791
|
+
await migrateLegacyFeedbackInbox(this.config);
|
|
792
|
+
} catch (error) {
|
|
793
|
+
log.warn(`[compounding] legacy feedback inbox migration failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`);
|
|
794
|
+
}
|
|
795
|
+
const entries = await readFeedbackEntriesForWeekFile(this.feedbackInboxPath, weekId);
|
|
796
|
+
const actionEvents = await readWeeklyActionEvents({
|
|
797
|
+
storage: this.storage,
|
|
798
|
+
memoryDir: this.config.memoryDir,
|
|
799
|
+
weekId
|
|
800
|
+
});
|
|
801
|
+
const defaultPrefix = await defaultNamespaceRecallPrefix(this.config);
|
|
802
|
+
const corrections = await readWeeklyCorrections({
|
|
803
|
+
storage: this.storage,
|
|
804
|
+
memoryDir: this.config.memoryDir,
|
|
805
|
+
weekId,
|
|
806
|
+
defaultNamespacePrefix: defaultPrefix
|
|
807
|
+
});
|
|
808
|
+
const actionPatterns = buildActionFailurePatterns(actionEvents);
|
|
269
809
|
const outcomeSummary = this.buildActionOutcomeSummary(actionEvents);
|
|
810
|
+
const storeOutcomeSummary = this.buildActionOutcomeSummary(actionEventsVisibleInStore(actionEvents, defaultPrefix));
|
|
270
811
|
const previousMistakes = await this.readMistakes();
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
|
|
812
|
+
const priorRegistry = previousMistakes?.registry ?? [];
|
|
813
|
+
const forgottenPatterns = await forgottenCorrectionPatterns(this.storage, this.config.memoryDir, priorRegistry, defaultPrefix);
|
|
814
|
+
const mistakes = this.buildMistakes(entries, actionPatterns, corrections, weekId, priorRegistry, defaultPrefix, forgottenPatterns);
|
|
815
|
+
const rubrics = this.buildRubricSnapshot(entries, storeOutcomeSummary, corrections);
|
|
816
|
+
let promotionCandidates = resolveConsolidationCapabilities(this.config).compoundingSemantic ? this.derivePromotionCandidates(storeOutcomeSummary, mistakes.registry, rubrics, defaultPrefix) : [];
|
|
274
817
|
if (resolveConversationContextCapabilities(this.config).cmcConsolidation) {
|
|
275
818
|
try {
|
|
276
819
|
const { deriveCausalPromotionCandidates, materializeAfterCausalConsolidation } = await import("./causal-consolidation.js");
|
|
@@ -315,10 +858,10 @@ var CompoundingEngine = class {
|
|
|
315
858
|
}
|
|
316
859
|
}
|
|
317
860
|
const continuity = resolveConsolidationCapabilities(this.config).continuityAudit ? await this.readContinuityAuditReferences(weekId) : { monthId: monthIdFromIsoWeek(weekId), weeklyPath: null, monthlyPath: null };
|
|
318
|
-
const reportPath =
|
|
861
|
+
const reportPath = path2.join(this.weeklyDir, `${weekId}.md`);
|
|
319
862
|
const md = this.formatWeeklyReport(weekId, entries, mistakes.patterns, mistakes.details, continuity, outcomeSummary, promotionCandidates);
|
|
320
863
|
await writeFile(reportPath, md, "utf-8");
|
|
321
|
-
const reportJsonPath =
|
|
864
|
+
const reportJsonPath = path2.join(this.weeklyDir, `${weekId}.json`);
|
|
322
865
|
const weeklyArtifact = {
|
|
323
866
|
version: COMPOUNDING_VERSION,
|
|
324
867
|
generatedAt: mistakes.updatedAt,
|
|
@@ -340,7 +883,7 @@ var CompoundingEngine = class {
|
|
|
340
883
|
severity: wrapped.entry.severity ?? null,
|
|
341
884
|
confidence: normalizeConfidence(wrapped.entry.confidence),
|
|
342
885
|
tags: normalizeTags(wrapped.entry.tags),
|
|
343
|
-
provenance: `${
|
|
886
|
+
provenance: `${path2.basename(wrapped.sourcePath)}:L${wrapped.sourceLine}#${wrapped.entryId}`,
|
|
344
887
|
evidenceWindow: normalizeEvidenceWindow(wrapped.entry.evidenceWindowStart, wrapped.entry.evidenceWindowEnd)
|
|
345
888
|
}))
|
|
346
889
|
},
|
|
@@ -355,7 +898,7 @@ var CompoundingEngine = class {
|
|
|
355
898
|
continuity
|
|
356
899
|
};
|
|
357
900
|
await writeFile(reportJsonPath, JSON.stringify(weeklyArtifact, null, 2) + "\n", "utf-8");
|
|
358
|
-
const rubricsMarkdown = this.formatRubrics(
|
|
901
|
+
const rubricsMarkdown = this.formatRubrics(storeOutcomeSummary, rubrics);
|
|
359
902
|
await writeFile(this.rubricsPath, rubricsMarkdown, "utf-8");
|
|
360
903
|
await writeFile(this.rubricsIndexPath, JSON.stringify(rubrics, null, 2) + "\n", "utf-8");
|
|
361
904
|
await this.syncRubricArtifacts(rubrics);
|
|
@@ -544,7 +1087,7 @@ var CompoundingEngine = class {
|
|
|
544
1087
|
}
|
|
545
1088
|
async readMistakes() {
|
|
546
1089
|
try {
|
|
547
|
-
const raw = await
|
|
1090
|
+
const raw = await readFile2(this.mistakesPath, "utf-8");
|
|
548
1091
|
const parsed = JSON.parse(raw);
|
|
549
1092
|
if (!parsed || !Array.isArray(parsed.patterns)) return null;
|
|
550
1093
|
if (!Array.isArray(parsed.registry)) {
|
|
@@ -578,7 +1121,7 @@ var CompoundingEngine = class {
|
|
|
578
1121
|
}
|
|
579
1122
|
async readRubrics() {
|
|
580
1123
|
try {
|
|
581
|
-
const raw = await
|
|
1124
|
+
const raw = await readFile2(this.rubricsIndexPath, "utf-8");
|
|
582
1125
|
const parsed = JSON.parse(raw);
|
|
583
1126
|
if (!parsed || !Array.isArray(parsed.agents) || !Array.isArray(parsed.workflows)) return null;
|
|
584
1127
|
parsed.agents = parsed.agents.map((entry) => this.normalizeRubricEntry(entry));
|
|
@@ -590,7 +1133,7 @@ var CompoundingEngine = class {
|
|
|
590
1133
|
}
|
|
591
1134
|
async readWeeklyArtifact(weekId) {
|
|
592
1135
|
try {
|
|
593
|
-
const raw = await
|
|
1136
|
+
const raw = await readFile2(path2.join(this.weeklyDir, `${weekId}.json`), "utf-8");
|
|
594
1137
|
const parsed = JSON.parse(raw);
|
|
595
1138
|
if (!parsed || parsed.weekId !== weekId || !Array.isArray(parsed.promotionCandidates)) {
|
|
596
1139
|
return null;
|
|
@@ -608,14 +1151,16 @@ var CompoundingEngine = class {
|
|
|
608
1151
|
const maxPatterns = Math.max(0, Math.floor(opts?.maxPatterns ?? 40));
|
|
609
1152
|
const maxRubrics = Math.max(0, Math.floor(opts?.maxRubrics ?? 4));
|
|
610
1153
|
const queryTokens = tokenizeRecallQuery(query);
|
|
611
|
-
const
|
|
1154
|
+
const defaultPrefix = await defaultNamespaceRecallPrefix(this.config);
|
|
1155
|
+
const activePatterns = (mistakes?.registry ?? []).filter((entry) => entry.status === "active" && provenanceVisibleInStoreRecall(entry.provenance, defaultPrefix)).sort(
|
|
612
1156
|
(a, b) => b.recurrenceCount - a.recurrenceCount || b.lastSeenAt.localeCompare(a.lastSeenAt) || a.pattern.localeCompare(b.pattern)
|
|
613
1157
|
);
|
|
614
1158
|
const topPatterns = activePatterns.slice(0, maxPatterns);
|
|
615
|
-
const allRubrics =
|
|
616
|
-
...rubrics?.workflows ?? [],
|
|
617
|
-
|
|
618
|
-
|
|
1159
|
+
const allRubrics = visibleRubricEntries(
|
|
1160
|
+
[...rubrics?.workflows ?? [], ...rubrics?.agents ?? []],
|
|
1161
|
+
(entry) => this.getRubricObservationEntries(entry),
|
|
1162
|
+
defaultPrefix
|
|
1163
|
+
);
|
|
619
1164
|
const scoredRubrics = allRubrics.map((entry) => ({
|
|
620
1165
|
entry,
|
|
621
1166
|
score: this.scoreRubricForQuery(entry, queryTokens)
|
|
@@ -650,65 +1195,6 @@ var CompoundingEngine = class {
|
|
|
650
1195
|
tierMigrationCycleBudget(trigger) {
|
|
651
1196
|
return defaultTierMigrationCycleBudget(this.config, trigger);
|
|
652
1197
|
}
|
|
653
|
-
async readFeedbackEntriesForWeek(weekId) {
|
|
654
|
-
const out = [];
|
|
655
|
-
try {
|
|
656
|
-
const raw = await readFile(this.feedbackInboxPath, "utf-8");
|
|
657
|
-
const lines = raw.split("\n");
|
|
658
|
-
for (let idx = 0; idx < lines.length; idx += 1) {
|
|
659
|
-
const line = lines[idx];
|
|
660
|
-
if (!line.trim()) continue;
|
|
661
|
-
try {
|
|
662
|
-
const obj = JSON.parse(line);
|
|
663
|
-
const parsed = SharedFeedbackEntrySchema.safeParse(obj);
|
|
664
|
-
if (!parsed.success) continue;
|
|
665
|
-
const d = new Date(parsed.data.date);
|
|
666
|
-
if (!Number.isFinite(d.getTime())) continue;
|
|
667
|
-
if (isoWeekId(d) !== weekId) continue;
|
|
668
|
-
const sourceLine = idx + 1;
|
|
669
|
-
out.push({
|
|
670
|
-
entry: parsed.data,
|
|
671
|
-
sourceLine,
|
|
672
|
-
sourcePath: this.feedbackInboxPath,
|
|
673
|
-
entryId: `${parsed.data.agent}-${parsed.data.date}-${sourceLine}`.replace(/[^a-zA-Z0-9._:-]/g, "_")
|
|
674
|
-
});
|
|
675
|
-
} catch {
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
} catch {
|
|
679
|
-
}
|
|
680
|
-
return out;
|
|
681
|
-
}
|
|
682
|
-
buildActionFailurePatterns(events) {
|
|
683
|
-
const out = [];
|
|
684
|
-
for (const event of events) {
|
|
685
|
-
const failed = event.outcome === "failed" || event.outcome === "skipped";
|
|
686
|
-
if (!failed && event.policyDecision === null) continue;
|
|
687
|
-
const suffix = event.reason && event.reason.trim().length > 0 ? ` - ${event.reason.trim().slice(0, 140)}` : "";
|
|
688
|
-
out.push(
|
|
689
|
-
`memory-action/${event.namespace}: ${event.action} ${event.outcome}${event.policyDecision ? `/${event.policyDecision}` : ""}${suffix}`
|
|
690
|
-
);
|
|
691
|
-
}
|
|
692
|
-
return out;
|
|
693
|
-
}
|
|
694
|
-
async readActionEventsForWeek(weekId) {
|
|
695
|
-
const out = [];
|
|
696
|
-
const rows = await this.storage.readMemoryActionEventRows(Number.MAX_SAFE_INTEGER);
|
|
697
|
-
for (const row of rows) {
|
|
698
|
-
const event = row.event;
|
|
699
|
-
const ts = new Date(event.timestamp);
|
|
700
|
-
if (!Number.isFinite(ts.getTime()) || isoWeekId(ts) !== weekId) continue;
|
|
701
|
-
out.push({
|
|
702
|
-
line: row.line,
|
|
703
|
-
action: event.action,
|
|
704
|
-
outcome: event.outcome,
|
|
705
|
-
policyDecision: event.policyDecision === "deny" || event.policyDecision === "defer" ? event.policyDecision : null,
|
|
706
|
-
namespace: typeof event.namespace === "string" && event.namespace.length > 0 ? event.namespace : "default",
|
|
707
|
-
reason: typeof event.reason === "string" ? event.reason : null
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
return out;
|
|
711
|
-
}
|
|
712
1198
|
buildActionOutcomeSummary(events) {
|
|
713
1199
|
const byAction = /* @__PURE__ */ new Map();
|
|
714
1200
|
for (const event of events) {
|
|
@@ -720,7 +1206,7 @@ var CompoundingEngine = class {
|
|
|
720
1206
|
if (event.outcome === "applied") acc.counts.applied += 1;
|
|
721
1207
|
else if (event.outcome === "skipped") acc.counts.skipped += 1;
|
|
722
1208
|
else acc.counts.failed += 1;
|
|
723
|
-
acc.provenance.add(`${
|
|
1209
|
+
acc.provenance.add(`${event.ledgerLabel}:L${event.line}`);
|
|
724
1210
|
byAction.set(key, acc);
|
|
725
1211
|
}
|
|
726
1212
|
const out = [];
|
|
@@ -739,7 +1225,7 @@ var CompoundingEngine = class {
|
|
|
739
1225
|
out.sort((a, b) => b.total - a.total || b.weightedScore - a.weightedScore || a.action.localeCompare(b.action));
|
|
740
1226
|
return out;
|
|
741
1227
|
}
|
|
742
|
-
derivePromotionCandidates(summary, mistakes, rubrics) {
|
|
1228
|
+
derivePromotionCandidates(summary, mistakes, rubrics, defaultNamespacePrefix = null) {
|
|
743
1229
|
const deduped = /* @__PURE__ */ new Map();
|
|
744
1230
|
const upsert = (candidate) => {
|
|
745
1231
|
const key = `${candidate.category}:${canonicalPromotionContentKey(candidate.content)}`;
|
|
@@ -780,6 +1266,7 @@ var CompoundingEngine = class {
|
|
|
780
1266
|
}
|
|
781
1267
|
for (const entry of mistakes) {
|
|
782
1268
|
if (entry.status !== "active") continue;
|
|
1269
|
+
if (!provenanceVisibleInStoreRecall(entry.provenance, defaultNamespacePrefix)) continue;
|
|
783
1270
|
if (entry.recurrenceCount < 2) continue;
|
|
784
1271
|
const content = normalizePromotedGuidanceContent(lessonContentFromPattern(entry.pattern, entry.agent));
|
|
785
1272
|
if (content.length === 0) continue;
|
|
@@ -802,6 +1289,7 @@ var CompoundingEngine = class {
|
|
|
802
1289
|
for (const rubric of [...rubrics.workflows, ...rubrics.agents]) {
|
|
803
1290
|
for (const observation of this.getRubricObservationEntries(rubric)) {
|
|
804
1291
|
if (this.isSyntheticOutcomeRubricObservation(observation.note)) continue;
|
|
1292
|
+
if (!provenanceVisibleInStoreRecall(observation.provenance, defaultNamespacePrefix)) continue;
|
|
805
1293
|
const evidenceCount = observation.provenance.length;
|
|
806
1294
|
if (evidenceCount < 2) continue;
|
|
807
1295
|
const content = normalizePromotedGuidanceContent(observation.note);
|
|
@@ -824,14 +1312,14 @@ var CompoundingEngine = class {
|
|
|
824
1312
|
}
|
|
825
1313
|
return [...deduped.values()].sort((a, b) => b.score - a.score || a.subject.localeCompare(b.subject)).slice(0, 10);
|
|
826
1314
|
}
|
|
827
|
-
buildMistakes(entries, actionPatterns = [],
|
|
1315
|
+
buildMistakes(entries, actionPatterns, corrections, weekId, previousRegistry = [], defaultNamespacePrefix = null, forgottenPatterns = /* @__PURE__ */ new Set()) {
|
|
828
1316
|
const patterns = [];
|
|
829
1317
|
const evidenceByPattern = /* @__PURE__ */ new Map();
|
|
830
1318
|
for (const wrapped of entries) {
|
|
831
1319
|
const e = wrapped.entry;
|
|
832
1320
|
const pattern = e.learning && e.learning.trim().length > 0 ? `${e.agent}: ${e.learning.trim()}` : e.decision === "rejected" ? `${e.agent}: ${e.reason.trim()}`.slice(0, 240) : null;
|
|
833
1321
|
if (!pattern) continue;
|
|
834
|
-
const provenance = [`${
|
|
1322
|
+
const provenance = [`${path2.basename(wrapped.sourcePath)}:L${wrapped.sourceLine}#${wrapped.entryId}`];
|
|
835
1323
|
patterns.push({ pattern, provenance });
|
|
836
1324
|
const previous = evidenceByPattern.get(pattern) ?? {
|
|
837
1325
|
category: "feedback",
|
|
@@ -854,9 +1342,34 @@ var CompoundingEngine = class {
|
|
|
854
1342
|
previous.evidenceWindow = mergeEvidenceWindows(previous.evidenceWindow, nextEvidenceWindow);
|
|
855
1343
|
evidenceByPattern.set(pattern, previous);
|
|
856
1344
|
}
|
|
857
|
-
for (const
|
|
858
|
-
patterns.push({ pattern, provenance: [
|
|
859
|
-
const
|
|
1345
|
+
for (const correction of corrections) {
|
|
1346
|
+
patterns.push({ pattern: correction.pattern, provenance: [correction.provenance] });
|
|
1347
|
+
const visible = provenanceVisibleInStoreRecall([correction.provenance], defaultNamespacePrefix);
|
|
1348
|
+
const prev = evidenceByPattern.get(correction.pattern) ?? {
|
|
1349
|
+
category: "correction",
|
|
1350
|
+
agent: visible ? correction.source : null,
|
|
1351
|
+
workflow: visible ? correction.entityRef ?? "corrections" : "corrections",
|
|
1352
|
+
tags: /* @__PURE__ */ new Set(),
|
|
1353
|
+
severity: null,
|
|
1354
|
+
confidence: visible ? correction.confidence : null,
|
|
1355
|
+
outcome: null,
|
|
1356
|
+
timestamps: [],
|
|
1357
|
+
evidenceWindow: { start: correction.created, end: correction.created }
|
|
1358
|
+
};
|
|
1359
|
+
if (visible) for (const tag of correction.tags) prev.tags.add(tag);
|
|
1360
|
+
prev.timestamps.push(correction.created);
|
|
1361
|
+
if (visible && prev.agent === null && correction.source) prev.agent = correction.source;
|
|
1362
|
+
if (visible && correction.entityRef && prev.workflow === "corrections") prev.workflow = correction.entityRef;
|
|
1363
|
+
if (visible && prev.confidence === null) prev.confidence = correction.confidence;
|
|
1364
|
+
prev.evidenceWindow = mergeEvidenceWindows(prev.evidenceWindow, {
|
|
1365
|
+
start: correction.created,
|
|
1366
|
+
end: correction.created
|
|
1367
|
+
});
|
|
1368
|
+
evidenceByPattern.set(correction.pattern, prev);
|
|
1369
|
+
}
|
|
1370
|
+
for (const item of actionPatterns) {
|
|
1371
|
+
patterns.push({ pattern: item.pattern, provenance: [item.provenance] });
|
|
1372
|
+
const previous = evidenceByPattern.get(item.pattern) ?? {
|
|
860
1373
|
category: "action",
|
|
861
1374
|
agent: null,
|
|
862
1375
|
workflow: "memory-actions",
|
|
@@ -867,7 +1380,7 @@ var CompoundingEngine = class {
|
|
|
867
1380
|
timestamps: [],
|
|
868
1381
|
evidenceWindow: { start: null, end: null }
|
|
869
1382
|
};
|
|
870
|
-
evidenceByPattern.set(pattern, previous);
|
|
1383
|
+
evidenceByPattern.set(item.pattern, previous);
|
|
871
1384
|
}
|
|
872
1385
|
const byPattern = /* @__PURE__ */ new Map();
|
|
873
1386
|
for (const item of patterns) {
|
|
@@ -875,7 +1388,11 @@ var CompoundingEngine = class {
|
|
|
875
1388
|
for (const provenance of item.provenance) existing.add(provenance);
|
|
876
1389
|
byPattern.set(item.pattern, existing);
|
|
877
1390
|
}
|
|
878
|
-
const details =
|
|
1391
|
+
const details = capWeeklyPatternDetails(
|
|
1392
|
+
[...byPattern.entries()].map(([pattern, provenance]) => ({ pattern, provenance: [...provenance].sort() })),
|
|
1393
|
+
(pattern) => evidenceByPattern.get(pattern)?.category,
|
|
1394
|
+
defaultNamespacePrefix
|
|
1395
|
+
);
|
|
879
1396
|
const previousById = new Map(previousRegistry.map((entry) => [entry.id, entry]));
|
|
880
1397
|
const previousByPattern = new Map(previousRegistry.map((entry) => [entry.pattern, entry]));
|
|
881
1398
|
const registry = details.map((detail) => {
|
|
@@ -917,8 +1434,8 @@ var CompoundingEngine = class {
|
|
|
917
1434
|
const staleWeeks = weekIdToIndex(weekId) - weekIdToIndex(previous.lastWeekId);
|
|
918
1435
|
registry.push({
|
|
919
1436
|
...previous,
|
|
920
|
-
status: staleWeeks >= RETIREMENT_WINDOW_WEEKS ? "retired" : previous.status,
|
|
921
|
-
retiredAt: staleWeeks >= RETIREMENT_WINDOW_WEEKS ? previous.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString() : previous.retiredAt ?? null
|
|
1437
|
+
status: forgottenPatterns.has(previous.pattern) || staleWeeks >= RETIREMENT_WINDOW_WEEKS ? "retired" : previous.status,
|
|
1438
|
+
retiredAt: forgottenPatterns.has(previous.pattern) || staleWeeks >= RETIREMENT_WINDOW_WEEKS ? previous.retiredAt ?? (/* @__PURE__ */ new Date()).toISOString() : previous.retiredAt ?? null
|
|
922
1439
|
});
|
|
923
1440
|
}
|
|
924
1441
|
registry.sort(
|
|
@@ -961,7 +1478,7 @@ var CompoundingEngine = class {
|
|
|
961
1478
|
lines.push(`- approved: ${approved}`);
|
|
962
1479
|
lines.push(`- approved_with_feedback: ${awf}`);
|
|
963
1480
|
lines.push(`- rejected: ${rejected}`);
|
|
964
|
-
const provenance = list.slice(0, 3).map((e) => `${
|
|
1481
|
+
const provenance = list.slice(0, 3).map((e) => `${path2.basename(e.sourcePath)}:L${e.sourceLine}#${e.entryId}`);
|
|
965
1482
|
if (provenance.length > 0) {
|
|
966
1483
|
lines.push(`- provenance: ${provenance.join(", ")}`);
|
|
967
1484
|
}
|
|
@@ -1026,14 +1543,14 @@ var CompoundingEngine = class {
|
|
|
1026
1543
|
}
|
|
1027
1544
|
return lines.join("\n");
|
|
1028
1545
|
}
|
|
1029
|
-
buildRubricSnapshot(entries, outcomeSummary) {
|
|
1546
|
+
buildRubricSnapshot(entries, outcomeSummary, corrections = []) {
|
|
1030
1547
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1031
1548
|
const byAgent = /* @__PURE__ */ new Map();
|
|
1032
1549
|
const byWorkflow = /* @__PURE__ */ new Map();
|
|
1033
1550
|
for (const wrapped of entries) {
|
|
1034
1551
|
const note = (wrapped.entry.learning && wrapped.entry.learning.trim().length > 0 ? wrapped.entry.learning : wrapped.entry.decision === "rejected" ? wrapped.entry.reason : "").trim();
|
|
1035
1552
|
if (!note) continue;
|
|
1036
|
-
const provenance = `${
|
|
1553
|
+
const provenance = `${path2.basename(wrapped.sourcePath)}:L${wrapped.sourceLine}#${wrapped.entryId}`;
|
|
1037
1554
|
const agentEntry = byAgent.get(wrapped.entry.agent) ?? {
|
|
1038
1555
|
id: stableRubricId("agent", wrapped.entry.agent),
|
|
1039
1556
|
kind: "agent",
|
|
@@ -1063,6 +1580,37 @@ var CompoundingEngine = class {
|
|
|
1063
1580
|
workflowEntry.tags = normalizeTags([...workflowEntry.tags, ...normalizeTags(wrapped.entry.tags)]);
|
|
1064
1581
|
byWorkflow.set(workflow, workflowEntry);
|
|
1065
1582
|
}
|
|
1583
|
+
for (const correction of corrections) {
|
|
1584
|
+
if (correction.source) {
|
|
1585
|
+
const agentEntry = byAgent.get(correction.source) ?? {
|
|
1586
|
+
id: stableRubricId("agent", correction.source),
|
|
1587
|
+
kind: "agent",
|
|
1588
|
+
subject: correction.source,
|
|
1589
|
+
observations: [],
|
|
1590
|
+
tags: [],
|
|
1591
|
+
provenance: [],
|
|
1592
|
+
observationEntries: [],
|
|
1593
|
+
updatedAt
|
|
1594
|
+
};
|
|
1595
|
+
this.addRubricObservation(agentEntry, correction.note, correction.provenance);
|
|
1596
|
+
agentEntry.tags = normalizeTags([...agentEntry.tags, ...correction.tags]);
|
|
1597
|
+
byAgent.set(correction.source, agentEntry);
|
|
1598
|
+
}
|
|
1599
|
+
const workflow = correction.entityRef ?? "corrections";
|
|
1600
|
+
const workflowEntry = byWorkflow.get(workflow) ?? {
|
|
1601
|
+
id: stableRubricId("workflow", workflow),
|
|
1602
|
+
kind: "workflow",
|
|
1603
|
+
subject: workflow,
|
|
1604
|
+
observations: [],
|
|
1605
|
+
tags: [],
|
|
1606
|
+
provenance: [],
|
|
1607
|
+
observationEntries: [],
|
|
1608
|
+
updatedAt
|
|
1609
|
+
};
|
|
1610
|
+
this.addRubricObservation(workflowEntry, correction.note, correction.provenance);
|
|
1611
|
+
workflowEntry.tags = normalizeTags([...workflowEntry.tags, ...correction.tags]);
|
|
1612
|
+
byWorkflow.set(workflow, workflowEntry);
|
|
1613
|
+
}
|
|
1066
1614
|
for (const item of outcomeSummary) {
|
|
1067
1615
|
const workflowEntry = byWorkflow.get(item.action) ?? {
|
|
1068
1616
|
id: stableRubricId("workflow", item.action),
|
|
@@ -1093,7 +1641,7 @@ var CompoundingEngine = class {
|
|
|
1093
1641
|
"",
|
|
1094
1642
|
`Generated: ${snapshot.updatedAt}`,
|
|
1095
1643
|
"",
|
|
1096
|
-
"Stable, deterministic rubric snapshot generated from weekly feedback
|
|
1644
|
+
"Stable, deterministic rubric snapshot generated from weekly feedback, correction memories, and action outcomes.",
|
|
1097
1645
|
""
|
|
1098
1646
|
];
|
|
1099
1647
|
lines.push("## Agent Rubrics");
|
|
@@ -1147,9 +1695,9 @@ var CompoundingEngine = class {
|
|
|
1147
1695
|
async replaceRubricDirectory(dir, entries) {
|
|
1148
1696
|
await mkdir(dir, { recursive: true });
|
|
1149
1697
|
try {
|
|
1150
|
-
const names = await
|
|
1698
|
+
const names = await readdir2(dir);
|
|
1151
1699
|
await Promise.all(
|
|
1152
|
-
names.filter((name) => name.endsWith(".md")).map((name) => unlink(
|
|
1700
|
+
names.filter((name) => name.endsWith(".md")).map((name) => unlink(path2.join(dir, name)).catch(() => void 0))
|
|
1153
1701
|
);
|
|
1154
1702
|
} catch {
|
|
1155
1703
|
}
|
|
@@ -1173,7 +1721,7 @@ var CompoundingEngine = class {
|
|
|
1173
1721
|
""
|
|
1174
1722
|
].join("\n");
|
|
1175
1723
|
const fileName = rubricArtifactFileName(entry, slugCollisions);
|
|
1176
|
-
await writeFile(
|
|
1724
|
+
await writeFile(path2.join(dir, fileName), body, "utf-8");
|
|
1177
1725
|
}));
|
|
1178
1726
|
}
|
|
1179
1727
|
scoreRubricForQuery(entry, queryTokens) {
|
|
@@ -1256,8 +1804,8 @@ var CompoundingEngine = class {
|
|
|
1256
1804
|
}
|
|
1257
1805
|
async readContinuityAuditReferences(weekId) {
|
|
1258
1806
|
const monthId = monthIdFromIsoWeek(weekId);
|
|
1259
|
-
const weeklyPath =
|
|
1260
|
-
const monthlyPath =
|
|
1807
|
+
const weeklyPath = path2.join(this.identityAuditWeeklyDir, `${weekId}.md`);
|
|
1808
|
+
const monthlyPath = path2.join(this.identityAuditMonthlyDir, `${monthId}.md`);
|
|
1261
1809
|
const [weeklyAudit, monthlyAudit] = await Promise.all([
|
|
1262
1810
|
this.readOptionalIdentityAuditForReference("weekly", weekId),
|
|
1263
1811
|
this.readOptionalIdentityAuditForReference("monthly", monthId)
|
|
@@ -1277,4 +1825,4 @@ export {
|
|
|
1277
1825
|
defaultTierMigrationCycleBudget,
|
|
1278
1826
|
CompoundingEngine
|
|
1279
1827
|
};
|
|
1280
|
-
//# sourceMappingURL=chunk-
|
|
1828
|
+
//# sourceMappingURL=chunk-L3G5CGL5.js.map
|