@remnic/core 9.3.756 → 9.3.758
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.d.ts +1 -1
- package/dist/access-admin-ops-surface.js +25 -25
- package/dist/access-boundary.d.ts +1 -1
- package/dist/access-boundary.js +26 -26
- package/dist/access-cli.js +86 -85
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +1 -1
- package/dist/access-http.js +31 -31
- package/dist/access-identity-continuity-surface.d.ts +166 -0
- package/dist/access-identity-continuity-surface.js +128 -0
- package/dist/access-lcm-surface.d.ts +1 -1
- package/dist/access-lcm-surface.js +25 -25
- package/dist/access-mcp.d.ts +1 -1
- package/dist/access-mcp.js +30 -30
- package/dist/access-observe-write-surface.d.ts +1 -1
- package/dist/access-observe-write-surface.js +25 -25
- package/dist/access-operations-batch.js +27 -27
- package/dist/access-operations.d.ts +1 -1
- package/dist/access-operations.js +29 -29
- package/dist/access-recall-surface.d.ts +1 -1
- package/dist/access-recall-surface.js +25 -25
- package/dist/access-schema.js +4 -4
- package/dist/{access-service-CJwcDoQp.d.ts → access-service-Z-8CnmrW.d.ts} +3 -2
- package/dist/access-service.d.ts +1 -1
- package/dist/access-service.js +25 -25
- package/dist/access-surface-catalog.d.ts +1 -1
- package/dist/{auto-sync-RZO5ZPHR.js → auto-sync-2SOUW4JW.js} +5 -5
- package/dist/briefing.js +9 -9
- package/dist/calibration.js +2 -2
- package/dist/{capsule-crypto-FFWJ4X4A.js → capsule-crypto-CZJSLEFG.js} +2 -2
- package/dist/capsule-crypto-CZJSLEFG.js.map +1 -0
- package/dist/causal-consolidation.js +13 -13
- package/dist/{chunk-WEPWY4HB.js → chunk-2BFLDH5F.js} +2 -2
- package/dist/{chunk-JTYM4HPA.js → chunk-2MR3MFQB.js} +2 -2
- package/dist/chunk-3I4FUAVJ.js +20 -0
- package/dist/chunk-3I4FUAVJ.js.map +1 -0
- package/dist/{chunk-TH7WMHVK.js → chunk-3NN73CM7.js} +2 -2
- package/dist/{chunk-A6XCHI53.js → chunk-3QLPBCFG.js} +8 -8
- package/dist/{chunk-EJJQDP3H.js → chunk-437S3G37.js} +1 -1
- package/dist/{chunk-DWDDQLSZ.js → chunk-6C6BBBCI.js} +276 -202
- package/dist/chunk-6C6BBBCI.js.map +1 -0
- package/dist/{chunk-7XH7VJN4.js → chunk-6T4LTI2F.js} +4 -4
- package/dist/{chunk-UNV6ZGTS.js → chunk-7I2QTC2K.js} +2 -2
- package/dist/{chunk-6DA5BBLS.js → chunk-7ME6VBF7.js} +107 -107
- package/dist/{chunk-AGNBY3VG.js → chunk-APJQ6UEA.js} +4 -4
- package/dist/{chunk-GG6G2RYR.js → chunk-CJDGB3EG.js} +2 -2
- package/dist/{chunk-PRX77NPC.js → chunk-CQCCVJZO.js} +2 -2
- package/dist/{chunk-ZUDM75KG.js → chunk-DCWIQFNA.js} +4 -4
- package/dist/{chunk-7APVFQ34.js → chunk-DUQHQ3TL.js} +294 -238
- package/dist/chunk-DUQHQ3TL.js.map +1 -0
- package/dist/{chunk-EF3VFQC4.js → chunk-EOTTKLPJ.js} +2 -2
- package/dist/{chunk-TCKP4EHY.js → chunk-FLVL4L3L.js} +2 -2
- package/dist/{chunk-NLXKSM46.js → chunk-HO3VUUGI.js} +2 -2
- package/dist/{chunk-4I45UZ4V.js → chunk-IBAU2RZN.js} +2 -2
- package/dist/{chunk-OLAVQS6S.js → chunk-ILB2MFTS.js} +2 -2
- package/dist/{chunk-4AC57RCM.js → chunk-IWI2ICTF.js} +4 -4
- package/dist/{chunk-5VWRYFQE.js → chunk-K2DJQOE3.js} +2 -2
- package/dist/{chunk-BTH6MQJT.js → chunk-LQDA67TT.js} +2 -2
- package/dist/{chunk-PBZQVVLG.js → chunk-LX4ZWRGD.js} +2 -2
- package/dist/{chunk-3I2IASNK.js → chunk-M5QKGHCR.js} +2 -2
- package/dist/{chunk-PPAEJXVF.js → chunk-NNL4LJAD.js} +2 -2
- package/dist/{chunk-TXV3I2O6.js → chunk-ODC4HOUZ.js} +2 -2
- package/dist/{chunk-7CFGXWYX.js → chunk-PJ5AG6D4.js} +2 -2
- package/dist/{chunk-EVVLGYHR.js → chunk-QEAOKI4U.js} +3 -3
- package/dist/{chunk-ZUHD6XZZ.js → chunk-QJUZAUAD.js} +32 -32
- package/dist/{chunk-REZ4TUD2.js → chunk-QKOTOUVR.js} +3 -3
- package/dist/{chunk-NG2NHB4C.js → chunk-QOGXUNWL.js} +2 -2
- package/dist/{chunk-YMGQXBPS.js → chunk-RF6BZHOD.js} +2 -2
- package/dist/{chunk-6DXXIXED.js → chunk-RQNV75HR.js} +2 -2
- package/dist/{chunk-GBXP62CL.js → chunk-TMXTQCJ7.js} +4 -4
- package/dist/{chunk-ZW5SZ3TH.js → chunk-TVWF3GNF.js} +8 -8
- package/dist/{chunk-5J4OL7TJ.js → chunk-VUA4S7P6.js} +4 -4
- package/dist/{chunk-PS572XYO.js → chunk-XQT5GSWU.js} +2 -2
- package/dist/{chunk-H2T4OJNI.js → chunk-YQYG24C6.js} +4 -4
- package/dist/{chunk-2OZ2JEUP.js → chunk-YTU7WKYN.js} +2 -2
- package/dist/{chunk-Y4TAFMUE.js → chunk-ZFYML7C3.js} +2 -2
- package/dist/{chunk-5ZKT7WTR.js → chunk-ZLOD23PD.js} +5 -5
- package/dist/{cli-cZyANcmY.d.ts → cli-C5pCwszN.d.ts} +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +52 -52
- package/dist/compounding/engine.js +9 -9
- package/dist/config-record.d.ts +11 -0
- package/dist/config-record.js +8 -0
- package/dist/config-record.js.map +1 -0
- package/dist/connectors/codex-materialize-runner.js +9 -9
- package/dist/connectors/index.js +9 -9
- package/dist/consolidation-provenance-check.js +2 -2
- package/dist/conversation-index/backend.js +2 -2
- package/dist/entity-retrieval.js +9 -9
- package/dist/extraction-faithfulness.js +3 -3
- package/dist/extraction-judge.js +3 -3
- package/dist/extraction.js +3 -3
- package/dist/fallback-llm.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +124 -120
- package/dist/lcm/index.js +3 -3
- package/dist/maintenance/memory-governance.js +9 -9
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +9 -9
- package/dist/maintenance/rebuild-memory-projection.js +10 -10
- package/dist/mcp-memory-inspector-app.d.ts +1 -1
- package/dist/namespaces/migrate.js +16 -16
- package/dist/namespaces/search.js +6 -6
- package/dist/namespaces/storage.js +9 -9
- package/dist/operator-toolkit.js +21 -21
- package/dist/orchestration/maintenance.js +11 -11
- package/dist/orchestrator.js +85 -84
- package/dist/recall-planner-llm.js +2 -2
- package/dist/search/factory.js +5 -5
- package/dist/search/index.js +9 -9
- package/dist/semantic-consolidation.js +10 -10
- package/dist/semantic-rule-promotion.js +9 -9
- package/dist/semantic-rule-verifier.js +9 -9
- package/dist/storage.d.ts +3 -4
- package/dist/storage.js +8 -8
- package/dist/summarizer.js +3 -3
- package/dist/transfer/backup.js +3 -3
- package/dist/transfer/capsule-export.js +3 -3
- package/dist/transfer/capsule-import.js +2 -2
- package/dist/transfer/import-sqlite.js +2 -2
- package/dist/verified-recall.js +9 -9
- package/package.json +2 -2
- package/src/access-identity-continuity-surface.test.ts +374 -0
- package/src/access-identity-continuity-surface.ts +322 -0
- package/src/access-service.ts +23 -171
- package/src/config-record.ts +25 -0
- package/src/index.ts +1 -0
- package/src/storage/identity-continuity-store.ts +223 -0
- package/src/storage.ts +25 -142
- package/dist/chunk-7APVFQ34.js.map +0 -1
- package/dist/chunk-DWDDQLSZ.js.map +0 -1
- /package/dist/{capsule-crypto-FFWJ4X4A.js.map → access-identity-continuity-surface.js.map} +0 -0
- /package/dist/{auto-sync-RZO5ZPHR.js.map → auto-sync-2SOUW4JW.js.map} +0 -0
- /package/dist/{chunk-WEPWY4HB.js.map → chunk-2BFLDH5F.js.map} +0 -0
- /package/dist/{chunk-JTYM4HPA.js.map → chunk-2MR3MFQB.js.map} +0 -0
- /package/dist/{chunk-TH7WMHVK.js.map → chunk-3NN73CM7.js.map} +0 -0
- /package/dist/{chunk-A6XCHI53.js.map → chunk-3QLPBCFG.js.map} +0 -0
- /package/dist/{chunk-EJJQDP3H.js.map → chunk-437S3G37.js.map} +0 -0
- /package/dist/{chunk-7XH7VJN4.js.map → chunk-6T4LTI2F.js.map} +0 -0
- /package/dist/{chunk-UNV6ZGTS.js.map → chunk-7I2QTC2K.js.map} +0 -0
- /package/dist/{chunk-6DA5BBLS.js.map → chunk-7ME6VBF7.js.map} +0 -0
- /package/dist/{chunk-AGNBY3VG.js.map → chunk-APJQ6UEA.js.map} +0 -0
- /package/dist/{chunk-GG6G2RYR.js.map → chunk-CJDGB3EG.js.map} +0 -0
- /package/dist/{chunk-PRX77NPC.js.map → chunk-CQCCVJZO.js.map} +0 -0
- /package/dist/{chunk-ZUDM75KG.js.map → chunk-DCWIQFNA.js.map} +0 -0
- /package/dist/{chunk-EF3VFQC4.js.map → chunk-EOTTKLPJ.js.map} +0 -0
- /package/dist/{chunk-TCKP4EHY.js.map → chunk-FLVL4L3L.js.map} +0 -0
- /package/dist/{chunk-NLXKSM46.js.map → chunk-HO3VUUGI.js.map} +0 -0
- /package/dist/{chunk-4I45UZ4V.js.map → chunk-IBAU2RZN.js.map} +0 -0
- /package/dist/{chunk-OLAVQS6S.js.map → chunk-ILB2MFTS.js.map} +0 -0
- /package/dist/{chunk-4AC57RCM.js.map → chunk-IWI2ICTF.js.map} +0 -0
- /package/dist/{chunk-5VWRYFQE.js.map → chunk-K2DJQOE3.js.map} +0 -0
- /package/dist/{chunk-BTH6MQJT.js.map → chunk-LQDA67TT.js.map} +0 -0
- /package/dist/{chunk-PBZQVVLG.js.map → chunk-LX4ZWRGD.js.map} +0 -0
- /package/dist/{chunk-3I2IASNK.js.map → chunk-M5QKGHCR.js.map} +0 -0
- /package/dist/{chunk-PPAEJXVF.js.map → chunk-NNL4LJAD.js.map} +0 -0
- /package/dist/{chunk-TXV3I2O6.js.map → chunk-ODC4HOUZ.js.map} +0 -0
- /package/dist/{chunk-7CFGXWYX.js.map → chunk-PJ5AG6D4.js.map} +0 -0
- /package/dist/{chunk-EVVLGYHR.js.map → chunk-QEAOKI4U.js.map} +0 -0
- /package/dist/{chunk-ZUHD6XZZ.js.map → chunk-QJUZAUAD.js.map} +0 -0
- /package/dist/{chunk-REZ4TUD2.js.map → chunk-QKOTOUVR.js.map} +0 -0
- /package/dist/{chunk-NG2NHB4C.js.map → chunk-QOGXUNWL.js.map} +0 -0
- /package/dist/{chunk-YMGQXBPS.js.map → chunk-RF6BZHOD.js.map} +0 -0
- /package/dist/{chunk-6DXXIXED.js.map → chunk-RQNV75HR.js.map} +0 -0
- /package/dist/{chunk-GBXP62CL.js.map → chunk-TMXTQCJ7.js.map} +0 -0
- /package/dist/{chunk-ZW5SZ3TH.js.map → chunk-TVWF3GNF.js.map} +0 -0
- /package/dist/{chunk-5J4OL7TJ.js.map → chunk-VUA4S7P6.js.map} +0 -0
- /package/dist/{chunk-PS572XYO.js.map → chunk-XQT5GSWU.js.map} +0 -0
- /package/dist/{chunk-H2T4OJNI.js.map → chunk-YQYG24C6.js.map} +0 -0
- /package/dist/{chunk-2OZ2JEUP.js.map → chunk-YTU7WKYN.js.map} +0 -0
- /package/dist/{chunk-Y4TAFMUE.js.map → chunk-ZFYML7C3.js.map} +0 -0
- /package/dist/{chunk-5ZKT7WTR.js.map → chunk-ZLOD23PD.js.map} +0 -0
|
@@ -28,6 +28,11 @@ import {
|
|
|
28
28
|
SPECULATIVE_TTL_DAYS,
|
|
29
29
|
confidenceTier
|
|
30
30
|
} from "./chunk-JS2HKKOK.js";
|
|
31
|
+
import {
|
|
32
|
+
getCachedEntities,
|
|
33
|
+
invalidateAllForDir,
|
|
34
|
+
setCachedEntities
|
|
35
|
+
} from "./chunk-AWJ2FHCF.js";
|
|
31
36
|
import {
|
|
32
37
|
inferMemoryStatus,
|
|
33
38
|
isArchivedMemoryPath,
|
|
@@ -45,10 +50,8 @@ import {
|
|
|
45
50
|
readProjectedMemoryTimeline
|
|
46
51
|
} from "./chunk-MB5RSUW6.js";
|
|
47
52
|
import {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
setCachedEntities
|
|
51
|
-
} from "./chunk-AWJ2FHCF.js";
|
|
53
|
+
rotateMarkdownFileToArchive
|
|
54
|
+
} from "./chunk-DM2T26WE.js";
|
|
52
55
|
import {
|
|
53
56
|
closeContinuityIncidentRecord,
|
|
54
57
|
createContinuityIncidentRecord,
|
|
@@ -58,13 +61,13 @@ import {
|
|
|
58
61
|
serializeContinuityIncident,
|
|
59
62
|
upsertContinuityLoopInMarkdown
|
|
60
63
|
} from "./chunk-LDXUBPMO.js";
|
|
61
|
-
import {
|
|
62
|
-
rotateMarkdownFileToArchive
|
|
63
|
-
} from "./chunk-DM2T26WE.js";
|
|
64
64
|
import {
|
|
65
65
|
parseFaithfulnessField,
|
|
66
66
|
serializeFaithfulnessFields
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-YTU7WKYN.js";
|
|
68
|
+
import {
|
|
69
|
+
createVersion
|
|
70
|
+
} from "./chunk-VF4XKTX3.js";
|
|
68
71
|
import {
|
|
69
72
|
computeContentHash,
|
|
70
73
|
normalizeContent
|
|
@@ -73,9 +76,6 @@ import {
|
|
|
73
76
|
isConsolidationOperator,
|
|
74
77
|
isValidDerivedFromEntry
|
|
75
78
|
} from "./chunk-G7D6GZ5J.js";
|
|
76
|
-
import {
|
|
77
|
-
createVersion
|
|
78
|
-
} from "./chunk-VF4XKTX3.js";
|
|
79
79
|
import {
|
|
80
80
|
parseProvenanceSources,
|
|
81
81
|
parseProvenanceTag,
|
|
@@ -112,10 +112,10 @@ import {
|
|
|
112
112
|
} from "./chunk-VS2IYZRU.js";
|
|
113
113
|
|
|
114
114
|
// src/storage.ts
|
|
115
|
-
import { access, readdir as
|
|
115
|
+
import { access, readdir as readdir4, readFile, stat as stat2, writeFile, mkdir, unlink as unlink2, appendFile, open } from "fs/promises";
|
|
116
116
|
import { appendFileSync, createReadStream, mkdirSync, readFileSync, statSync } from "fs";
|
|
117
117
|
import { createHash } from "crypto";
|
|
118
|
-
import
|
|
118
|
+
import path4 from "path";
|
|
119
119
|
|
|
120
120
|
// src/storage/memory-read-store.ts
|
|
121
121
|
import { lstat, readdir, realpath, stat } from "fs/promises";
|
|
@@ -1040,6 +1040,161 @@ ${rows.join("\n")}
|
|
|
1040
1040
|
}
|
|
1041
1041
|
};
|
|
1042
1042
|
|
|
1043
|
+
// src/storage/identity-continuity-store.ts
|
|
1044
|
+
import { readdir as readdir3 } from "fs/promises";
|
|
1045
|
+
import path3 from "path";
|
|
1046
|
+
var IdentityContinuityStore = class {
|
|
1047
|
+
constructor(deps) {
|
|
1048
|
+
this.deps = deps;
|
|
1049
|
+
}
|
|
1050
|
+
deps;
|
|
1051
|
+
async writeIdentityAnchor(content) {
|
|
1052
|
+
await this.deps.ensureDirectories();
|
|
1053
|
+
await this.deps.writeStorageSecureFile(this.deps.identityAnchorPath, content);
|
|
1054
|
+
}
|
|
1055
|
+
async readIdentityAnchor() {
|
|
1056
|
+
try {
|
|
1057
|
+
return await this.deps.readStorageSecureFile(this.deps.identityAnchorPath);
|
|
1058
|
+
} catch (err) {
|
|
1059
|
+
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
1060
|
+
return null;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
async appendContinuityIncident(input) {
|
|
1064
|
+
await this.deps.ensureDirectories();
|
|
1065
|
+
const now = /* @__PURE__ */ new Date();
|
|
1066
|
+
const nowIso = now.toISOString();
|
|
1067
|
+
const date = nowIso.slice(0, 10);
|
|
1068
|
+
const id = this.deps.generateId("incident");
|
|
1069
|
+
const incident = createContinuityIncidentRecord(id, input, nowIso);
|
|
1070
|
+
const filePath = path3.join(this.deps.identityIncidentsDir, `${date}-${id}.md`);
|
|
1071
|
+
await this.deps.writeStorageSecureFile(filePath, serializeContinuityIncident(incident));
|
|
1072
|
+
return { ...incident, filePath };
|
|
1073
|
+
}
|
|
1074
|
+
async readContinuityIncidents(limit = 200, state = "all") {
|
|
1075
|
+
const normalizedLimit = Number.isFinite(limit) ? Math.floor(limit) : 0;
|
|
1076
|
+
const cappedLimit = Math.max(0, normalizedLimit);
|
|
1077
|
+
if (cappedLimit === 0) return [];
|
|
1078
|
+
try {
|
|
1079
|
+
const candidates = await this.readContinuityIncidentFileNames();
|
|
1080
|
+
const incidents = [];
|
|
1081
|
+
for (const file of candidates) {
|
|
1082
|
+
if (incidents.length >= cappedLimit) break;
|
|
1083
|
+
const filePath = path3.join(this.deps.identityIncidentsDir, file);
|
|
1084
|
+
try {
|
|
1085
|
+
const raw = await this.deps.readStorageSecureFile(filePath);
|
|
1086
|
+
const parsed = parseContinuityIncident(raw);
|
|
1087
|
+
if (!parsed) continue;
|
|
1088
|
+
if (state !== "all" && parsed.state !== state) continue;
|
|
1089
|
+
incidents.push({ ...parsed, filePath });
|
|
1090
|
+
} catch (err) {
|
|
1091
|
+
if (err instanceof SecureStoreLockedError) throw err;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return incidents;
|
|
1095
|
+
} catch (err) {
|
|
1096
|
+
if (err instanceof SecureStoreLockedError) throw err;
|
|
1097
|
+
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
1098
|
+
return [];
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
async closeContinuityIncident(id, closure) {
|
|
1102
|
+
const directFilePath = await this.findContinuityIncidentFilePathById(id);
|
|
1103
|
+
const target = directFilePath ? await this.readContinuityIncidentFile(directFilePath) : null;
|
|
1104
|
+
if (!target || !directFilePath) return null;
|
|
1105
|
+
if (target.state === "closed") return target;
|
|
1106
|
+
const closed = closeContinuityIncidentRecord(target, closure, (/* @__PURE__ */ new Date()).toISOString());
|
|
1107
|
+
await this.deps.writeStorageSecureFile(directFilePath, serializeContinuityIncident(closed));
|
|
1108
|
+
return { ...closed, filePath: directFilePath };
|
|
1109
|
+
}
|
|
1110
|
+
async writeIdentityAudit(period, key, content) {
|
|
1111
|
+
await this.deps.ensureDirectories();
|
|
1112
|
+
const safeKey = this.sanitizeIdentityAuditKey(key);
|
|
1113
|
+
const dir = period === "weekly" ? this.deps.identityAuditsWeeklyDir : this.deps.identityAuditsMonthlyDir;
|
|
1114
|
+
const filePath = path3.join(dir, `${safeKey}.md`);
|
|
1115
|
+
await this.deps.writeStorageSecureFile(filePath, content);
|
|
1116
|
+
return filePath;
|
|
1117
|
+
}
|
|
1118
|
+
async readIdentityAudit(period, key) {
|
|
1119
|
+
try {
|
|
1120
|
+
const safeKey = this.sanitizeIdentityAuditKey(key);
|
|
1121
|
+
const dir = period === "weekly" ? this.deps.identityAuditsWeeklyDir : this.deps.identityAuditsMonthlyDir;
|
|
1122
|
+
return await this.deps.readStorageSecureFile(path3.join(dir, `${safeKey}.md`));
|
|
1123
|
+
} catch (err) {
|
|
1124
|
+
if (err instanceof Error && err.message === "Invalid identity audit key") return null;
|
|
1125
|
+
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
1126
|
+
return null;
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
async writeIdentityImprovementLoops(content) {
|
|
1130
|
+
await this.deps.ensureDirectories();
|
|
1131
|
+
await this.deps.writeStorageSecureFile(this.deps.identityImprovementLoopsPath, content);
|
|
1132
|
+
}
|
|
1133
|
+
async readIdentityImprovementLoops() {
|
|
1134
|
+
try {
|
|
1135
|
+
return await this.deps.readStorageSecureFile(this.deps.identityImprovementLoopsPath);
|
|
1136
|
+
} catch (err) {
|
|
1137
|
+
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
async readIdentityImprovementLoopRegister() {
|
|
1142
|
+
const raw = await this.readIdentityImprovementLoops();
|
|
1143
|
+
if (!raw) return [];
|
|
1144
|
+
return parseContinuityImprovementLoops(raw);
|
|
1145
|
+
}
|
|
1146
|
+
async upsertIdentityImprovementLoop(input) {
|
|
1147
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
1148
|
+
const raw = await this.readIdentityImprovementLoops();
|
|
1149
|
+
const { markdown, loop } = upsertContinuityLoopInMarkdown(raw, input, nowIso);
|
|
1150
|
+
await this.writeIdentityImprovementLoops(markdown);
|
|
1151
|
+
return loop;
|
|
1152
|
+
}
|
|
1153
|
+
async reviewIdentityImprovementLoop(id, input) {
|
|
1154
|
+
const raw = await this.readIdentityImprovementLoops();
|
|
1155
|
+
const { markdown, loop } = reviewContinuityLoopInMarkdown(raw, id, input, (/* @__PURE__ */ new Date()).toISOString());
|
|
1156
|
+
if (!loop) return null;
|
|
1157
|
+
await this.writeIdentityImprovementLoops(markdown);
|
|
1158
|
+
return loop;
|
|
1159
|
+
}
|
|
1160
|
+
async readContinuityIncidentFileNames() {
|
|
1161
|
+
const files = await readdir3(this.deps.identityIncidentsDir);
|
|
1162
|
+
return files.filter((file) => file.endsWith(".md")).sort().reverse();
|
|
1163
|
+
}
|
|
1164
|
+
async readContinuityIncidentFile(filePath) {
|
|
1165
|
+
try {
|
|
1166
|
+
const raw = await this.deps.readStorageSecureFile(filePath);
|
|
1167
|
+
const parsed = parseContinuityIncident(raw);
|
|
1168
|
+
return parsed ? { ...parsed, filePath } : null;
|
|
1169
|
+
} catch (err) {
|
|
1170
|
+
if (err instanceof SecureStoreLockedError) throw err;
|
|
1171
|
+
return null;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
async findContinuityIncidentFilePathById(id) {
|
|
1175
|
+
const fileNames = await this.readContinuityIncidentFileNames();
|
|
1176
|
+
const directMatch = fileNames.find((name) => name.endsWith(`-${id}.md`));
|
|
1177
|
+
if (directMatch) {
|
|
1178
|
+
const directPath = path3.join(this.deps.identityIncidentsDir, directMatch);
|
|
1179
|
+
const parsed = await this.readContinuityIncidentFile(directPath);
|
|
1180
|
+
if (parsed?.id === id) return directPath;
|
|
1181
|
+
}
|
|
1182
|
+
for (const fileName of fileNames) {
|
|
1183
|
+
const filePath = path3.join(this.deps.identityIncidentsDir, fileName);
|
|
1184
|
+
const parsed = await this.readContinuityIncidentFile(filePath);
|
|
1185
|
+
if (parsed?.id === id) return filePath;
|
|
1186
|
+
}
|
|
1187
|
+
return null;
|
|
1188
|
+
}
|
|
1189
|
+
sanitizeIdentityAuditKey(key) {
|
|
1190
|
+
const trimmed = key.trim();
|
|
1191
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(trimmed) || trimmed.includes("..")) {
|
|
1192
|
+
throw new Error("Invalid identity audit key");
|
|
1193
|
+
}
|
|
1194
|
+
return trimmed;
|
|
1195
|
+
}
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1043
1198
|
// src/storage.ts
|
|
1044
1199
|
var ARTIFACT_SEARCH_STOPWORDS = /* @__PURE__ */ new Set([
|
|
1045
1200
|
"a",
|
|
@@ -1645,17 +1800,17 @@ var KNOWN_ENTITY_FILENAME_PREFIXES = /* @__PURE__ */ new Set([
|
|
|
1645
1800
|
"topic"
|
|
1646
1801
|
]);
|
|
1647
1802
|
function inferEntityTypeFromFilename(pathRel) {
|
|
1648
|
-
const basename =
|
|
1803
|
+
const basename = path4.basename(pathRel, ".md").toLowerCase();
|
|
1649
1804
|
const separator = basename.indexOf("-");
|
|
1650
1805
|
if (separator <= 0) return void 0;
|
|
1651
1806
|
const candidate = basename.slice(0, separator);
|
|
1652
1807
|
return KNOWN_ENTITY_FILENAME_PREFIXES.has(candidate) ? candidate : void 0;
|
|
1653
1808
|
}
|
|
1654
1809
|
function normalizeFrontmatterForPath(frontmatter, pathRel, content = "") {
|
|
1655
|
-
const normalizedPath = pathRel.split(
|
|
1810
|
+
const normalizedPath = pathRel.split(path4.sep).join("/");
|
|
1656
1811
|
let normalizedFrontmatter = frontmatter;
|
|
1657
1812
|
if (normalizedPath === "entities" || normalizedPath.startsWith("entities/") || normalizedPath.includes("/entities/")) {
|
|
1658
|
-
const basename =
|
|
1813
|
+
const basename = path4.basename(pathRel, ".md");
|
|
1659
1814
|
const inferredType = inferEntityTypeFromContent(content) || inferEntityTypeFromFilename(pathRel) || "entity";
|
|
1660
1815
|
const existingTags = Array.isArray(frontmatter.tags) ? frontmatter.tags : [];
|
|
1661
1816
|
normalizedFrontmatter = {
|
|
@@ -1722,8 +1877,8 @@ var ContentHashIndex = class _ContentHashIndex {
|
|
|
1722
1877
|
secureStoreKeyProvider;
|
|
1723
1878
|
secureStoreWriteKeyProvider;
|
|
1724
1879
|
memoryDir;
|
|
1725
|
-
constructor(stateDir, secureStoreKeyProvider = () => null, secureStoreWriteKeyProvider = secureStoreKeyProvider, memoryDir =
|
|
1726
|
-
this.filePath =
|
|
1880
|
+
constructor(stateDir, secureStoreKeyProvider = () => null, secureStoreWriteKeyProvider = secureStoreKeyProvider, memoryDir = path4.dirname(stateDir)) {
|
|
1881
|
+
this.filePath = path4.join(stateDir, "fact-hashes.txt");
|
|
1727
1882
|
this.secureStoreKeyProvider = secureStoreKeyProvider;
|
|
1728
1883
|
this.secureStoreWriteKeyProvider = secureStoreWriteKeyProvider;
|
|
1729
1884
|
this.memoryDir = memoryDir;
|
|
@@ -1770,7 +1925,7 @@ var ContentHashIndex = class _ContentHashIndex {
|
|
|
1770
1925
|
/** Persist index to disk if changed. */
|
|
1771
1926
|
async save() {
|
|
1772
1927
|
if (!this.dirty) return;
|
|
1773
|
-
await mkdir(
|
|
1928
|
+
await mkdir(path4.dirname(this.filePath), { recursive: true });
|
|
1774
1929
|
await writeMaybeEncryptedFile(
|
|
1775
1930
|
this.filePath,
|
|
1776
1931
|
[...this.hashes].join("\n") + "\n",
|
|
@@ -2836,7 +2991,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
2836
2991
|
void 0,
|
|
2837
2992
|
this.baseDir
|
|
2838
2993
|
);
|
|
2839
|
-
const rel =
|
|
2994
|
+
const rel = path4.relative(this.baseDir, filePath).split(path4.sep).join("/");
|
|
2840
2995
|
return `${rel}:${version.versionId}`;
|
|
2841
2996
|
} catch (err) {
|
|
2842
2997
|
log.warn(
|
|
@@ -2878,18 +3033,28 @@ var StorageManager3 = class _StorageManager {
|
|
|
2878
3033
|
}
|
|
2879
3034
|
return this._entityStore;
|
|
2880
3035
|
}
|
|
3036
|
+
/** IdentityContinuityStore (storage.ts decomposition). Lazy; selfDeps live wiring. */
|
|
3037
|
+
_identityContinuityStore;
|
|
3038
|
+
get identityContinuityStore() {
|
|
3039
|
+
if (!this._identityContinuityStore) {
|
|
3040
|
+
this._identityContinuityStore = new IdentityContinuityStore(
|
|
3041
|
+
selfDeps(this)
|
|
3042
|
+
);
|
|
3043
|
+
}
|
|
3044
|
+
return this._identityContinuityStore;
|
|
3045
|
+
}
|
|
2881
3046
|
get dir() {
|
|
2882
3047
|
return this.baseDir;
|
|
2883
3048
|
}
|
|
2884
3049
|
identityFilePath(workspaceDir, namespace) {
|
|
2885
3050
|
const rawNamespace = typeof namespace === "string" ? namespace.trim() : "";
|
|
2886
|
-
if (!rawNamespace) return
|
|
3051
|
+
if (!rawNamespace) return path4.join(workspaceDir, "IDENTITY.md");
|
|
2887
3052
|
const safeNamespace = rawNamespace.replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
2888
|
-
return
|
|
3053
|
+
return path4.join(workspaceDir, `IDENTITY.${safeNamespace}.md`);
|
|
2889
3054
|
}
|
|
2890
3055
|
versionFilePath(kind) {
|
|
2891
3056
|
const fileName = kind === "memory-status" ? ".memory-status-version.log" : kind === "artifact-write" ? ".artifact-write-version.log" : ".cold-write-version.log";
|
|
2892
|
-
return
|
|
3057
|
+
return path4.join(this.stateDir, fileName);
|
|
2893
3058
|
}
|
|
2894
3059
|
bumpSharedVersion(kind, fallbackMap) {
|
|
2895
3060
|
const filePath = this.versionFilePath(kind);
|
|
@@ -2936,7 +3101,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
2936
3101
|
// memories.
|
|
2937
3102
|
// -------------------------------------------------------------------------
|
|
2938
3103
|
get wearablesDir() {
|
|
2939
|
-
return
|
|
3104
|
+
return path4.join(this.baseDir, WEARABLES_DIR_NAME);
|
|
2940
3105
|
}
|
|
2941
3106
|
/**
|
|
2942
3107
|
* Resolve the on-disk path for a source/day transcript. Throws on
|
|
@@ -2954,7 +3119,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
2954
3119
|
`invalid wearable transcript date '${String(date)}' \u2014 expected YYYY-MM-DD`
|
|
2955
3120
|
);
|
|
2956
3121
|
}
|
|
2957
|
-
return
|
|
3122
|
+
return path4.join(this.wearablesDir, sourceId, `${date}.md`);
|
|
2958
3123
|
}
|
|
2959
3124
|
async writeWearableDayTranscript(sourceId, date, serialized) {
|
|
2960
3125
|
const targetPath = this.wearableTranscriptPath(sourceId, date);
|
|
@@ -3041,25 +3206,25 @@ var StorageManager3 = class _StorageManager {
|
|
|
3041
3206
|
});
|
|
3042
3207
|
}
|
|
3043
3208
|
get factsDir() {
|
|
3044
|
-
return
|
|
3209
|
+
return path4.join(this.baseDir, "facts");
|
|
3045
3210
|
}
|
|
3046
3211
|
get correctionsDir() {
|
|
3047
|
-
return
|
|
3212
|
+
return path4.join(this.baseDir, "corrections");
|
|
3048
3213
|
}
|
|
3049
3214
|
get proceduresDir() {
|
|
3050
|
-
return
|
|
3215
|
+
return path4.join(this.baseDir, "procedures");
|
|
3051
3216
|
}
|
|
3052
3217
|
get reasoningTracesDir() {
|
|
3053
|
-
return
|
|
3218
|
+
return path4.join(this.baseDir, "reasoning-traces");
|
|
3054
3219
|
}
|
|
3055
3220
|
get entitiesDir() {
|
|
3056
|
-
return
|
|
3221
|
+
return path4.join(this.baseDir, "entities");
|
|
3057
3222
|
}
|
|
3058
3223
|
resolveEntityFilePath(name) {
|
|
3059
3224
|
if (typeof name !== "string") return null;
|
|
3060
|
-
const filePath =
|
|
3061
|
-
const relative =
|
|
3062
|
-
if (relative === "" || relative.startsWith("..") ||
|
|
3225
|
+
const filePath = path4.resolve(this.entitiesDir, `${name}.md`);
|
|
3226
|
+
const relative = path4.relative(this.entitiesDir, filePath);
|
|
3227
|
+
if (relative === "" || relative.startsWith("..") || path4.isAbsolute(relative)) {
|
|
3063
3228
|
return null;
|
|
3064
3229
|
}
|
|
3065
3230
|
return filePath;
|
|
@@ -3074,10 +3239,10 @@ var StorageManager3 = class _StorageManager {
|
|
|
3074
3239
|
return writeMaybeEncryptedFileFromChunks(filePath, chunks, this.resolveWriteKey(), {}, this.baseDir).then(() => this.notifyCatalogWrite());
|
|
3075
3240
|
}
|
|
3076
3241
|
assertManagedStoragePath(filePath, method) {
|
|
3077
|
-
const resolved =
|
|
3078
|
-
const base =
|
|
3079
|
-
const rel =
|
|
3080
|
-
if (rel === "" || rel === ".." || rel.startsWith(`..${
|
|
3242
|
+
const resolved = path4.resolve(filePath);
|
|
3243
|
+
const base = path4.resolve(this.baseDir);
|
|
3244
|
+
const rel = path4.relative(base, resolved);
|
|
3245
|
+
if (rel === "" || rel === ".." || rel.startsWith(`..${path4.sep}`) || path4.isAbsolute(rel)) {
|
|
3081
3246
|
throw new Error(`${method}: file path escapes memory dir`);
|
|
3082
3247
|
}
|
|
3083
3248
|
return resolved;
|
|
@@ -3089,7 +3254,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3089
3254
|
async digestOfflineSyncFile(filePath) {
|
|
3090
3255
|
const target = this.assertManagedStoragePath(filePath, "storage.digestOfflineSyncFile");
|
|
3091
3256
|
const st = await stat2(target);
|
|
3092
|
-
const relPath =
|
|
3257
|
+
const relPath = path4.relative(this.baseDir, target).split(path4.sep).join("/");
|
|
3093
3258
|
const cache = await this.loadOfflineSyncDigestCache();
|
|
3094
3259
|
const cached = cache.get(relPath);
|
|
3095
3260
|
if (cached && cached.statBytes === st.size && cached.mtimeMs === st.mtimeMs && cached.ctimeMs === st.ctimeMs && !cached.encrypted) {
|
|
@@ -3150,7 +3315,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3150
3315
|
const bytes = typeof record.bytes === "number" ? record.bytes : NaN;
|
|
3151
3316
|
const sha256 = typeof record.sha256 === "string" ? record.sha256 : "";
|
|
3152
3317
|
const encrypted = record.encrypted === true;
|
|
3153
|
-
if (cachePath.length === 0 || cachePath === ".." || cachePath.startsWith("../") ||
|
|
3318
|
+
if (cachePath.length === 0 || cachePath === ".." || cachePath.startsWith("../") || path4.isAbsolute(cachePath) || !Number.isFinite(statBytes) || !Number.isFinite(mtimeMs) || !Number.isFinite(ctimeMs) || !Number.isFinite(bytes) || !/^[a-f0-9]{64}$/i.test(sha256)) {
|
|
3154
3319
|
continue;
|
|
3155
3320
|
}
|
|
3156
3321
|
cache.set(cachePath, { statBytes, mtimeMs, ctimeMs, encrypted, sha256, bytes });
|
|
@@ -3192,7 +3357,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3192
3357
|
const cache = this.offlineSyncDigestCache;
|
|
3193
3358
|
if (!cache) return;
|
|
3194
3359
|
const entries = [...cache.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([entryPath, entry]) => ({ path: entryPath, ...entry }));
|
|
3195
|
-
await mkdir(
|
|
3360
|
+
await mkdir(path4.dirname(this.offlineSyncDigestCachePath), { recursive: true });
|
|
3196
3361
|
await writeFile(
|
|
3197
3362
|
this.offlineSyncDigestCachePath,
|
|
3198
3363
|
`${JSON.stringify({ version: 1, entries })}
|
|
@@ -3245,10 +3410,10 @@ var StorageManager3 = class _StorageManager {
|
|
|
3245
3410
|
if (isErrnoCode(error, "ENOENT")) return;
|
|
3246
3411
|
throw error;
|
|
3247
3412
|
});
|
|
3248
|
-
if (filePath.includes(`${
|
|
3413
|
+
if (filePath.includes(`${path4.sep}cold${path4.sep}`)) {
|
|
3249
3414
|
this.invalidateColdMemoriesCache();
|
|
3250
3415
|
}
|
|
3251
|
-
if (filePath.includes(`${
|
|
3416
|
+
if (filePath.includes(`${path4.sep}artifacts${path4.sep}`)) {
|
|
3252
3417
|
this.bumpArtifactWriteVersion();
|
|
3253
3418
|
}
|
|
3254
3419
|
this.bumpMemoryStatusVersion();
|
|
@@ -3276,7 +3441,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3276
3441
|
}
|
|
3277
3442
|
async appendStorageSecureFileUnlocked(filePath, content) {
|
|
3278
3443
|
const writeKey = this.resolveWriteKey();
|
|
3279
|
-
await mkdir(
|
|
3444
|
+
await mkdir(path4.dirname(filePath), { recursive: true });
|
|
3280
3445
|
if (writeKey === null) {
|
|
3281
3446
|
try {
|
|
3282
3447
|
if (isEncryptedFile(await readFile(filePath))) {
|
|
@@ -3302,16 +3467,16 @@ var StorageManager3 = class _StorageManager {
|
|
|
3302
3467
|
this.notifyCatalogWrite();
|
|
3303
3468
|
}
|
|
3304
3469
|
get stateDir() {
|
|
3305
|
-
return
|
|
3470
|
+
return path4.join(this.baseDir, "state");
|
|
3306
3471
|
}
|
|
3307
3472
|
get offlineSyncDigestCachePath() {
|
|
3308
|
-
return
|
|
3473
|
+
return path4.join(this.baseDir, ".offline-sync", "digest-cache.v1.json");
|
|
3309
3474
|
}
|
|
3310
3475
|
get entitySynthesisQueuePath() {
|
|
3311
|
-
return
|
|
3476
|
+
return path4.join(this.stateDir, "entity-synthesis-queue.json");
|
|
3312
3477
|
}
|
|
3313
3478
|
get factHashIndexReadyPath() {
|
|
3314
|
-
return
|
|
3479
|
+
return path4.join(this.stateDir, "fact-hashes.ready");
|
|
3315
3480
|
}
|
|
3316
3481
|
// ── Tombstone store access (issue #1579) ─────────────────────────────────
|
|
3317
3482
|
/**
|
|
@@ -3321,7 +3486,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3321
3486
|
* helpers are injected into the store).
|
|
3322
3487
|
*/
|
|
3323
3488
|
get tombstonesPath() {
|
|
3324
|
-
return
|
|
3489
|
+
return path4.join(this.stateDir, "tombstones.jsonl");
|
|
3325
3490
|
}
|
|
3326
3491
|
/**
|
|
3327
3492
|
* Configure the tombstone invariant for this storage instance. Installed
|
|
@@ -3520,7 +3685,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3520
3685
|
);
|
|
3521
3686
|
}
|
|
3522
3687
|
await factHashIndex.save();
|
|
3523
|
-
await mkdir(
|
|
3688
|
+
await mkdir(path4.dirname(this.factHashIndexReadyPath), { recursive: true });
|
|
3524
3689
|
await writeFile(this.factHashIndexReadyPath, "v1\n", "utf-8");
|
|
3525
3690
|
this.factHashIndexAuthoritative = true;
|
|
3526
3691
|
})().finally(() => {
|
|
@@ -3529,55 +3694,55 @@ var StorageManager3 = class _StorageManager {
|
|
|
3529
3694
|
await this.factHashIndexAuthoritativePromise;
|
|
3530
3695
|
}
|
|
3531
3696
|
get questionsDir() {
|
|
3532
|
-
return
|
|
3697
|
+
return path4.join(this.baseDir, "questions");
|
|
3533
3698
|
}
|
|
3534
3699
|
get artifactsDir() {
|
|
3535
|
-
return
|
|
3700
|
+
return path4.join(this.baseDir, "artifacts");
|
|
3536
3701
|
}
|
|
3537
3702
|
get identityDir() {
|
|
3538
|
-
return
|
|
3703
|
+
return path4.join(this.baseDir, "identity");
|
|
3539
3704
|
}
|
|
3540
3705
|
get identityAnchorPath() {
|
|
3541
|
-
return
|
|
3706
|
+
return path4.join(this.identityDir, "identity-anchor.md");
|
|
3542
3707
|
}
|
|
3543
3708
|
get identityIncidentsDir() {
|
|
3544
|
-
return
|
|
3709
|
+
return path4.join(this.identityDir, "incidents");
|
|
3545
3710
|
}
|
|
3546
3711
|
get identityAuditsWeeklyDir() {
|
|
3547
|
-
return
|
|
3712
|
+
return path4.join(this.identityDir, "audits", "weekly");
|
|
3548
3713
|
}
|
|
3549
3714
|
get identityAuditsMonthlyDir() {
|
|
3550
|
-
return
|
|
3715
|
+
return path4.join(this.identityDir, "audits", "monthly");
|
|
3551
3716
|
}
|
|
3552
3717
|
get identityImprovementLoopsPath() {
|
|
3553
|
-
return
|
|
3718
|
+
return path4.join(this.identityDir, "improvement-loops.md");
|
|
3554
3719
|
}
|
|
3555
3720
|
get identityReflectionsPath() {
|
|
3556
|
-
return
|
|
3721
|
+
return path4.join(this.identityDir, "reflections.md");
|
|
3557
3722
|
}
|
|
3558
3723
|
get profilePath() {
|
|
3559
|
-
return
|
|
3724
|
+
return path4.join(this.baseDir, "profile.md");
|
|
3560
3725
|
}
|
|
3561
3726
|
get memoryActionsPath() {
|
|
3562
|
-
return
|
|
3727
|
+
return path4.join(this.stateDir, "memory-actions.jsonl");
|
|
3563
3728
|
}
|
|
3564
3729
|
get memoryLifecycleLedgerPath() {
|
|
3565
|
-
return
|
|
3730
|
+
return path4.join(this.stateDir, "memory-lifecycle-ledger.jsonl");
|
|
3566
3731
|
}
|
|
3567
3732
|
get compressionGuidelinesPath() {
|
|
3568
|
-
return
|
|
3733
|
+
return path4.join(this.stateDir, "compression-guidelines.md");
|
|
3569
3734
|
}
|
|
3570
3735
|
get compressionGuidelineDraftPath() {
|
|
3571
|
-
return
|
|
3736
|
+
return path4.join(this.stateDir, "compression-guidelines.draft.md");
|
|
3572
3737
|
}
|
|
3573
3738
|
get compressionGuidelineStatePath() {
|
|
3574
|
-
return
|
|
3739
|
+
return path4.join(this.stateDir, "compression-guideline-state.json");
|
|
3575
3740
|
}
|
|
3576
3741
|
get compressionGuidelineDraftStatePath() {
|
|
3577
|
-
return
|
|
3742
|
+
return path4.join(this.stateDir, "compression-guideline-draft-state.json");
|
|
3578
3743
|
}
|
|
3579
3744
|
get behaviorSignalsPath() {
|
|
3580
|
-
return
|
|
3745
|
+
return path4.join(this.stateDir, "behavior-signals.jsonl");
|
|
3581
3746
|
}
|
|
3582
3747
|
/**
|
|
3583
3748
|
* Buffer surprise telemetry ledger (issue #563 PR 3).
|
|
@@ -3590,7 +3755,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3590
3755
|
* governance sweeps can treat it uniformly.
|
|
3591
3756
|
*/
|
|
3592
3757
|
get bufferSurpriseLedgerPath() {
|
|
3593
|
-
return
|
|
3758
|
+
return path4.join(this.stateDir, "buffer-surprise-ledger.jsonl");
|
|
3594
3759
|
}
|
|
3595
3760
|
/**
|
|
3596
3761
|
* Entity alias table loaded from THIS store's config/aliases.json.
|
|
@@ -3624,7 +3789,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3624
3789
|
this.loadAliasesSync();
|
|
3625
3790
|
}
|
|
3626
3791
|
loadAliasesSync() {
|
|
3627
|
-
const aliasPath =
|
|
3792
|
+
const aliasPath = path4.join(this.baseDir, "config", "aliases.json");
|
|
3628
3793
|
this.userAliases = {};
|
|
3629
3794
|
try {
|
|
3630
3795
|
const raw = readFileSync(aliasPath, "utf-8");
|
|
@@ -3649,9 +3814,9 @@ var StorageManager3 = class _StorageManager {
|
|
|
3649
3814
|
}
|
|
3650
3815
|
async ensureDirectories() {
|
|
3651
3816
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
3652
|
-
await mkdir(
|
|
3653
|
-
await mkdir(
|
|
3654
|
-
await mkdir(
|
|
3817
|
+
await mkdir(path4.join(this.factsDir, today), { recursive: true });
|
|
3818
|
+
await mkdir(path4.join(this.proceduresDir, today), { recursive: true });
|
|
3819
|
+
await mkdir(path4.join(this.reasoningTracesDir, today), { recursive: true });
|
|
3655
3820
|
await mkdir(this.correctionsDir, { recursive: true });
|
|
3656
3821
|
await mkdir(this.entitiesDir, { recursive: true });
|
|
3657
3822
|
await mkdir(this.stateDir, { recursive: true });
|
|
@@ -3661,7 +3826,7 @@ var StorageManager3 = class _StorageManager {
|
|
|
3661
3826
|
await mkdir(this.identityIncidentsDir, { recursive: true });
|
|
3662
3827
|
await mkdir(this.identityAuditsWeeklyDir, { recursive: true });
|
|
3663
3828
|
await mkdir(this.identityAuditsMonthlyDir, { recursive: true });
|
|
3664
|
-
await mkdir(
|
|
3829
|
+
await mkdir(path4.join(this.baseDir, "config"), { recursive: true });
|
|
3665
3830
|
}
|
|
3666
3831
|
/**
|
|
3667
3832
|
* Resolve the on-disk write path for a memory of the given category, creating
|
|
@@ -3678,11 +3843,11 @@ var StorageManager3 = class _StorageManager {
|
|
|
3678
3843
|
async resolveCategoryWritePath(category, id, today) {
|
|
3679
3844
|
if (category === "correction") {
|
|
3680
3845
|
await mkdir(this.correctionsDir, { recursive: true });
|
|
3681
|
-
return
|
|
3846
|
+
return path4.join(this.correctionsDir, `${id}.md`);
|
|
3682
3847
|
}
|
|
3683
|
-
const datedDir =
|
|
3848
|
+
const datedDir = path4.join(getCategoryDir(this.baseDir, category), today);
|
|
3684
3849
|
await mkdir(datedDir, { recursive: true });
|
|
3685
|
-
return
|
|
3850
|
+
return path4.join(datedDir, `${id}.md`);
|
|
3686
3851
|
}
|
|
3687
3852
|
async writeMemory(category, content, options = {}) {
|
|
3688
3853
|
await this.ensureDirectories();
|
|
@@ -3932,7 +4097,7 @@ ${sanitized.text}
|
|
|
3932
4097
|
await this.ensureDirectories();
|
|
3933
4098
|
const now = /* @__PURE__ */ new Date();
|
|
3934
4099
|
const day = now.toISOString().slice(0, 10);
|
|
3935
|
-
const dir =
|
|
4100
|
+
const dir = path4.join(this.artifactsDir, day);
|
|
3936
4101
|
await mkdir(dir, { recursive: true });
|
|
3937
4102
|
const id = `artifact-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
|
|
3938
4103
|
const fm = {
|
|
@@ -3956,7 +4121,7 @@ ${sanitized.text}
|
|
|
3956
4121
|
log.warn(`artifact content rejected for ${id}; violations=${sanitized.violations.join(", ")}`);
|
|
3957
4122
|
return "";
|
|
3958
4123
|
}
|
|
3959
|
-
const filePath =
|
|
4124
|
+
const filePath = path4.join(dir, `${id}.md`);
|
|
3960
4125
|
await this.writeStorageSecureFile(filePath, `${serializeFrontmatter(fm)}
|
|
3961
4126
|
|
|
3962
4127
|
${sanitized.text}
|
|
@@ -4158,7 +4323,7 @@ ${sanitized.text}
|
|
|
4158
4323
|
* per-process in-memory cache safe across process boundaries.
|
|
4159
4324
|
*/
|
|
4160
4325
|
invalidateColdMemoriesCache() {
|
|
4161
|
-
const coldRoot =
|
|
4326
|
+
const coldRoot = path4.join(this.baseDir, "cold");
|
|
4162
4327
|
_StorageManager.coldMemoriesCache.delete(coldRoot);
|
|
4163
4328
|
this.bumpColdWriteVersion();
|
|
4164
4329
|
invalidateAllForDir(this.baseDir);
|
|
@@ -4248,7 +4413,7 @@ ${sanitized.text}
|
|
|
4248
4413
|
const correctionPaths = [];
|
|
4249
4414
|
const factPaths = [];
|
|
4250
4415
|
for (const filePath of filePaths) {
|
|
4251
|
-
if (filePath === this.correctionsDir || filePath.startsWith(`${this.correctionsDir}${
|
|
4416
|
+
if (filePath === this.correctionsDir || filePath.startsWith(`${this.correctionsDir}${path4.sep}`)) {
|
|
4252
4417
|
correctionPaths.push(filePath);
|
|
4253
4418
|
} else {
|
|
4254
4419
|
factPaths.push(filePath);
|
|
@@ -4311,9 +4476,9 @@ ${sanitized.text}
|
|
|
4311
4476
|
const root = this.archiveDir;
|
|
4312
4477
|
const readDir = async (dir) => {
|
|
4313
4478
|
try {
|
|
4314
|
-
const entries = await
|
|
4479
|
+
const entries = await readdir4(dir, { withFileTypes: true });
|
|
4315
4480
|
for (const entry of entries) {
|
|
4316
|
-
const fullPath =
|
|
4481
|
+
const fullPath = path4.join(dir, entry.name);
|
|
4317
4482
|
if (entry.isDirectory()) {
|
|
4318
4483
|
await readDir(fullPath);
|
|
4319
4484
|
} else if (entry.name.endsWith(".md")) {
|
|
@@ -4348,7 +4513,7 @@ ${sanitized.text}
|
|
|
4348
4513
|
);
|
|
4349
4514
|
}
|
|
4350
4515
|
resolveTierRootDir(tier) {
|
|
4351
|
-
return tier === "cold" ?
|
|
4516
|
+
return tier === "cold" ? path4.join(this.baseDir, "cold") : this.baseDir;
|
|
4352
4517
|
}
|
|
4353
4518
|
resolveMemoryDateDir(memory) {
|
|
4354
4519
|
const preferred = memory.frontmatter.created || memory.frontmatter.updated;
|
|
@@ -4363,13 +4528,13 @@ ${sanitized.text}
|
|
|
4363
4528
|
buildTierMemoryPath(memory, tier) {
|
|
4364
4529
|
const root = this.resolveTierRootDir(tier);
|
|
4365
4530
|
if (this.isArtifactMemory(memory)) {
|
|
4366
|
-
return
|
|
4531
|
+
return path4.join(root, "artifacts", this.resolveMemoryDateDir(memory), `${memory.frontmatter.id}.md`);
|
|
4367
4532
|
}
|
|
4368
4533
|
if (memory.frontmatter.category === "correction") {
|
|
4369
|
-
return
|
|
4534
|
+
return path4.join(root, "corrections", `${memory.frontmatter.id}.md`);
|
|
4370
4535
|
}
|
|
4371
4536
|
const dir = categoryDirName(memory.frontmatter.category);
|
|
4372
|
-
return
|
|
4537
|
+
return path4.join(root, dir, this.resolveMemoryDateDir(memory), `${memory.frontmatter.id}.md`);
|
|
4373
4538
|
}
|
|
4374
4539
|
async writeMemoryFileAtomic(targetPath, memory) {
|
|
4375
4540
|
const fileContent = `${serializeFrontmatter(memory.frontmatter)}
|
|
@@ -4382,8 +4547,8 @@ ${memory.content}
|
|
|
4382
4547
|
}
|
|
4383
4548
|
async moveMemoryToPath(memory, targetPath) {
|
|
4384
4549
|
await this.writeMemoryFileAtomic(targetPath, memory);
|
|
4385
|
-
const sourcePath =
|
|
4386
|
-
const destPath =
|
|
4550
|
+
const sourcePath = path4.resolve(memory.path);
|
|
4551
|
+
const destPath = path4.resolve(targetPath);
|
|
4387
4552
|
if (sourcePath !== destPath) {
|
|
4388
4553
|
try {
|
|
4389
4554
|
await unlink2(memory.path);
|
|
@@ -4398,8 +4563,8 @@ ${memory.content}
|
|
|
4398
4563
|
}
|
|
4399
4564
|
async migrateMemoryToTier(memory, targetTier) {
|
|
4400
4565
|
const targetPath = this.buildTierMemoryPath(memory, targetTier);
|
|
4401
|
-
const sourcePath =
|
|
4402
|
-
const destPath =
|
|
4566
|
+
const sourcePath = path4.resolve(memory.path);
|
|
4567
|
+
const destPath = path4.resolve(targetPath);
|
|
4403
4568
|
if (sourcePath === destPath) {
|
|
4404
4569
|
return { changed: false, targetPath };
|
|
4405
4570
|
}
|
|
@@ -4425,7 +4590,7 @@ ${memory.content}
|
|
|
4425
4590
|
return { changed: true, targetPath };
|
|
4426
4591
|
}
|
|
4427
4592
|
get archiveDir() {
|
|
4428
|
-
return
|
|
4593
|
+
return path4.join(this.baseDir, "archive");
|
|
4429
4594
|
}
|
|
4430
4595
|
/**
|
|
4431
4596
|
* Archive a memory by moving it from facts/ to archive/YYYY-MM-DD/.
|
|
@@ -4436,7 +4601,7 @@ ${memory.content}
|
|
|
4436
4601
|
try {
|
|
4437
4602
|
const now = lifecycle?.at ?? /* @__PURE__ */ new Date();
|
|
4438
4603
|
const today = now.toISOString().slice(0, 10);
|
|
4439
|
-
const destDir =
|
|
4604
|
+
const destDir = path4.join(this.archiveDir, today);
|
|
4440
4605
|
await mkdir(destDir, { recursive: true });
|
|
4441
4606
|
const updatedFm = {
|
|
4442
4607
|
...memory.frontmatter,
|
|
@@ -4448,7 +4613,7 @@ ${memory.content}
|
|
|
4448
4613
|
|
|
4449
4614
|
${memory.content}
|
|
4450
4615
|
`;
|
|
4451
|
-
const destPath =
|
|
4616
|
+
const destPath = path4.join(destDir, path4.basename(memory.path));
|
|
4452
4617
|
await this.writeStorageSecureFile(destPath, fileContent);
|
|
4453
4618
|
await unlink2(memory.path);
|
|
4454
4619
|
this.invalidateAllMemoriesCache();
|
|
@@ -4477,7 +4642,7 @@ ${memory.content}
|
|
|
4477
4642
|
}
|
|
4478
4643
|
async readEntities() {
|
|
4479
4644
|
try {
|
|
4480
|
-
const entries = await
|
|
4645
|
+
const entries = await readdir4(this.entitiesDir);
|
|
4481
4646
|
return entries.filter((e) => e.endsWith(".md")).map((e) => e.replace(".md", ""));
|
|
4482
4647
|
} catch {
|
|
4483
4648
|
return [];
|
|
@@ -4596,7 +4761,7 @@ ${memory.content}
|
|
|
4596
4761
|
`;
|
|
4597
4762
|
await this.writeStorageSecureFile(memory.path, fileContent);
|
|
4598
4763
|
this.invalidateAllMemoriesCache();
|
|
4599
|
-
if (memory.path.includes(`${
|
|
4764
|
+
if (memory.path.includes(`${path4.sep}cold${path4.sep}`)) {
|
|
4600
4765
|
this.invalidateColdMemoriesCache();
|
|
4601
4766
|
}
|
|
4602
4767
|
try {
|
|
@@ -4668,7 +4833,7 @@ ${memory.content}
|
|
|
4668
4833
|
return deleted;
|
|
4669
4834
|
}
|
|
4670
4835
|
async loadBuffer() {
|
|
4671
|
-
const bufferPath =
|
|
4836
|
+
const bufferPath = path4.join(this.stateDir, "buffer.json");
|
|
4672
4837
|
try {
|
|
4673
4838
|
const raw = await this.readStorageSecureFile(bufferPath);
|
|
4674
4839
|
return JSON.parse(raw);
|
|
@@ -4680,11 +4845,11 @@ ${memory.content}
|
|
|
4680
4845
|
}
|
|
4681
4846
|
async saveBuffer(state) {
|
|
4682
4847
|
await this.ensureDirectories();
|
|
4683
|
-
const bufferPath =
|
|
4848
|
+
const bufferPath = path4.join(this.stateDir, "buffer.json");
|
|
4684
4849
|
await this.writeStorageSecureFile(bufferPath, JSON.stringify(state, null, 2));
|
|
4685
4850
|
}
|
|
4686
4851
|
async loadMeta() {
|
|
4687
|
-
const metaPath =
|
|
4852
|
+
const metaPath = path4.join(this.stateDir, "meta.json");
|
|
4688
4853
|
try {
|
|
4689
4854
|
const raw = await this.readStorageSecureFile(metaPath);
|
|
4690
4855
|
const parsed = JSON.parse(raw);
|
|
@@ -4718,7 +4883,7 @@ ${memory.content}
|
|
|
4718
4883
|
}
|
|
4719
4884
|
async saveMeta(state) {
|
|
4720
4885
|
await this.ensureDirectories();
|
|
4721
|
-
const metaPath =
|
|
4886
|
+
const metaPath = path4.join(this.stateDir, "meta.json");
|
|
4722
4887
|
await this.writeStorageSecureFile(metaPath, JSON.stringify(state, null, 2));
|
|
4723
4888
|
}
|
|
4724
4889
|
async appendMemoryActionEvents(events) {
|
|
@@ -4804,7 +4969,7 @@ ${memory.content}
|
|
|
4804
4969
|
async appendReextractJobs(events) {
|
|
4805
4970
|
if (events.length === 0) return 0;
|
|
4806
4971
|
await this.ensureDirectories();
|
|
4807
|
-
const filePath =
|
|
4972
|
+
const filePath = path4.join(this.stateDir, "reextract-jobs.jsonl");
|
|
4808
4973
|
const lines = events.map((event) => JSON.stringify(event)).join("\n") + "\n";
|
|
4809
4974
|
try {
|
|
4810
4975
|
await this.appendStorageSecureFile(filePath, lines);
|
|
@@ -4817,7 +4982,7 @@ ${memory.content}
|
|
|
4817
4982
|
}
|
|
4818
4983
|
async readReextractJobs(limit = 200) {
|
|
4819
4984
|
const safeLimit = Number.isFinite(limit) ? Math.max(1, Math.min(1e3, Math.floor(limit))) : 200;
|
|
4820
|
-
const filePath =
|
|
4985
|
+
const filePath = path4.join(this.stateDir, "reextract-jobs.jsonl");
|
|
4821
4986
|
try {
|
|
4822
4987
|
const raw = await this.readStorageSecureFile(filePath);
|
|
4823
4988
|
const lines = raw.split("\n").filter((line) => line.trim().length > 0);
|
|
@@ -5009,113 +5174,40 @@ ${memory.content}
|
|
|
5009
5174
|
);
|
|
5010
5175
|
}
|
|
5011
5176
|
async writeIdentityAnchor(content) {
|
|
5012
|
-
|
|
5013
|
-
await this.writeStorageSecureFile(this.identityAnchorPath, content);
|
|
5177
|
+
return this.identityContinuityStore.writeIdentityAnchor(content);
|
|
5014
5178
|
}
|
|
5015
5179
|
async readIdentityAnchor() {
|
|
5016
|
-
|
|
5017
|
-
return await this.readStorageSecureFile(this.identityAnchorPath);
|
|
5018
|
-
} catch (err) {
|
|
5019
|
-
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
5020
|
-
return null;
|
|
5021
|
-
}
|
|
5180
|
+
return this.identityContinuityStore.readIdentityAnchor();
|
|
5022
5181
|
}
|
|
5023
5182
|
async appendContinuityIncident(input) {
|
|
5024
|
-
|
|
5025
|
-
const now = /* @__PURE__ */ new Date();
|
|
5026
|
-
const nowIso = now.toISOString();
|
|
5027
|
-
const date = nowIso.slice(0, 10);
|
|
5028
|
-
const id = this.generateId("incident");
|
|
5029
|
-
const incident = createContinuityIncidentRecord(id, input, nowIso);
|
|
5030
|
-
const filePath = path3.join(this.identityIncidentsDir, `${date}-${id}.md`);
|
|
5031
|
-
await this.writeStorageSecureFile(filePath, serializeContinuityIncident(incident));
|
|
5032
|
-
return { ...incident, filePath };
|
|
5183
|
+
return this.identityContinuityStore.appendContinuityIncident(input);
|
|
5033
5184
|
}
|
|
5034
5185
|
async readContinuityIncidents(limit = 200, state = "all") {
|
|
5035
|
-
|
|
5036
|
-
const cappedLimit = Math.max(0, normalizedLimit);
|
|
5037
|
-
if (cappedLimit === 0) return [];
|
|
5038
|
-
try {
|
|
5039
|
-
const candidates = await this.readContinuityIncidentFileNames();
|
|
5040
|
-
const incidents = [];
|
|
5041
|
-
for (const file of candidates) {
|
|
5042
|
-
if (incidents.length >= cappedLimit) break;
|
|
5043
|
-
const filePath = path3.join(this.identityIncidentsDir, file);
|
|
5044
|
-
try {
|
|
5045
|
-
const raw = await this.readStorageSecureFile(filePath);
|
|
5046
|
-
const parsed = parseContinuityIncident(raw);
|
|
5047
|
-
if (!parsed) continue;
|
|
5048
|
-
if (state !== "all" && parsed.state !== state) continue;
|
|
5049
|
-
incidents.push({ ...parsed, filePath });
|
|
5050
|
-
} catch (err) {
|
|
5051
|
-
if (err instanceof SecureStoreLockedError) throw err;
|
|
5052
|
-
}
|
|
5053
|
-
}
|
|
5054
|
-
return incidents;
|
|
5055
|
-
} catch (err) {
|
|
5056
|
-
if (err instanceof SecureStoreLockedError) throw err;
|
|
5057
|
-
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
5058
|
-
return [];
|
|
5059
|
-
}
|
|
5186
|
+
return this.identityContinuityStore.readContinuityIncidents(limit, state);
|
|
5060
5187
|
}
|
|
5061
5188
|
async closeContinuityIncident(id, closure) {
|
|
5062
|
-
|
|
5063
|
-
const target = directFilePath ? await this.readContinuityIncidentFile(directFilePath) : null;
|
|
5064
|
-
if (!target || !directFilePath) return null;
|
|
5065
|
-
if (target.state === "closed") return target;
|
|
5066
|
-
const closed = closeContinuityIncidentRecord(target, closure, (/* @__PURE__ */ new Date()).toISOString());
|
|
5067
|
-
await this.writeStorageSecureFile(directFilePath, serializeContinuityIncident(closed));
|
|
5068
|
-
return { ...closed, filePath: directFilePath };
|
|
5189
|
+
return this.identityContinuityStore.closeContinuityIncident(id, closure);
|
|
5069
5190
|
}
|
|
5070
5191
|
async writeIdentityAudit(period, key, content) {
|
|
5071
|
-
|
|
5072
|
-
const safeKey = this.sanitizeIdentityAuditKey(key);
|
|
5073
|
-
const dir = period === "weekly" ? this.identityAuditsWeeklyDir : this.identityAuditsMonthlyDir;
|
|
5074
|
-
const filePath = path3.join(dir, `${safeKey}.md`);
|
|
5075
|
-
await this.writeStorageSecureFile(filePath, content);
|
|
5076
|
-
return filePath;
|
|
5192
|
+
return this.identityContinuityStore.writeIdentityAudit(period, key, content);
|
|
5077
5193
|
}
|
|
5078
5194
|
async readIdentityAudit(period, key) {
|
|
5079
|
-
|
|
5080
|
-
const safeKey = this.sanitizeIdentityAuditKey(key);
|
|
5081
|
-
const dir = period === "weekly" ? this.identityAuditsWeeklyDir : this.identityAuditsMonthlyDir;
|
|
5082
|
-
return await this.readStorageSecureFile(path3.join(dir, `${safeKey}.md`));
|
|
5083
|
-
} catch (err) {
|
|
5084
|
-
if (err instanceof Error && err.message === "Invalid identity audit key") return null;
|
|
5085
|
-
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
5086
|
-
return null;
|
|
5087
|
-
}
|
|
5195
|
+
return this.identityContinuityStore.readIdentityAudit(period, key);
|
|
5088
5196
|
}
|
|
5089
5197
|
async writeIdentityImprovementLoops(content) {
|
|
5090
|
-
|
|
5091
|
-
await this.writeStorageSecureFile(this.identityImprovementLoopsPath, content);
|
|
5198
|
+
return this.identityContinuityStore.writeIdentityImprovementLoops(content);
|
|
5092
5199
|
}
|
|
5093
5200
|
async readIdentityImprovementLoops() {
|
|
5094
|
-
|
|
5095
|
-
return await this.readStorageSecureFile(this.identityImprovementLoopsPath);
|
|
5096
|
-
} catch (err) {
|
|
5097
|
-
if (!isErrnoCode(err, "ENOENT")) throw err;
|
|
5098
|
-
return null;
|
|
5099
|
-
}
|
|
5201
|
+
return this.identityContinuityStore.readIdentityImprovementLoops();
|
|
5100
5202
|
}
|
|
5101
5203
|
async readIdentityImprovementLoopRegister() {
|
|
5102
|
-
|
|
5103
|
-
if (!raw) return [];
|
|
5104
|
-
return parseContinuityImprovementLoops(raw);
|
|
5204
|
+
return this.identityContinuityStore.readIdentityImprovementLoopRegister();
|
|
5105
5205
|
}
|
|
5106
5206
|
async upsertIdentityImprovementLoop(input) {
|
|
5107
|
-
|
|
5108
|
-
const raw = await this.readIdentityImprovementLoops();
|
|
5109
|
-
const { markdown, loop } = upsertContinuityLoopInMarkdown(raw, input, nowIso);
|
|
5110
|
-
await this.writeIdentityImprovementLoops(markdown);
|
|
5111
|
-
return loop;
|
|
5207
|
+
return this.identityContinuityStore.upsertIdentityImprovementLoop(input);
|
|
5112
5208
|
}
|
|
5113
5209
|
async reviewIdentityImprovementLoop(id, input) {
|
|
5114
|
-
|
|
5115
|
-
const { markdown, loop } = reviewContinuityLoopInMarkdown(raw, id, input, (/* @__PURE__ */ new Date()).toISOString());
|
|
5116
|
-
if (!loop) return null;
|
|
5117
|
-
await this.writeIdentityImprovementLoops(markdown);
|
|
5118
|
-
return loop;
|
|
5210
|
+
return this.identityContinuityStore.reviewIdentityImprovementLoop(id, input);
|
|
5119
5211
|
}
|
|
5120
5212
|
// ---------------------------------------------------------------------------
|
|
5121
5213
|
// Question storage
|
|
@@ -5125,42 +5217,6 @@ ${memory.content}
|
|
|
5125
5217
|
const rand = Math.random().toString(36).slice(2, 4);
|
|
5126
5218
|
return `${prefix}-${ts}-${rand}`;
|
|
5127
5219
|
}
|
|
5128
|
-
async readContinuityIncidentFileNames() {
|
|
5129
|
-
const files = await readdir3(this.identityIncidentsDir);
|
|
5130
|
-
return files.filter((file) => file.endsWith(".md")).sort().reverse();
|
|
5131
|
-
}
|
|
5132
|
-
async readContinuityIncidentFile(filePath) {
|
|
5133
|
-
try {
|
|
5134
|
-
const raw = await this.readStorageSecureFile(filePath);
|
|
5135
|
-
const parsed = parseContinuityIncident(raw);
|
|
5136
|
-
return parsed ? { ...parsed, filePath } : null;
|
|
5137
|
-
} catch (err) {
|
|
5138
|
-
if (err instanceof SecureStoreLockedError) throw err;
|
|
5139
|
-
return null;
|
|
5140
|
-
}
|
|
5141
|
-
}
|
|
5142
|
-
async findContinuityIncidentFilePathById(id) {
|
|
5143
|
-
const fileNames = await this.readContinuityIncidentFileNames();
|
|
5144
|
-
const directMatch = fileNames.find((name) => name.endsWith(`-${id}.md`));
|
|
5145
|
-
if (directMatch) {
|
|
5146
|
-
const directPath = path3.join(this.identityIncidentsDir, directMatch);
|
|
5147
|
-
const parsed = await this.readContinuityIncidentFile(directPath);
|
|
5148
|
-
if (parsed?.id === id) return directPath;
|
|
5149
|
-
}
|
|
5150
|
-
for (const fileName of fileNames) {
|
|
5151
|
-
const filePath = path3.join(this.identityIncidentsDir, fileName);
|
|
5152
|
-
const parsed = await this.readContinuityIncidentFile(filePath);
|
|
5153
|
-
if (parsed?.id === id) return filePath;
|
|
5154
|
-
}
|
|
5155
|
-
return null;
|
|
5156
|
-
}
|
|
5157
|
-
sanitizeIdentityAuditKey(key) {
|
|
5158
|
-
const trimmed = key.trim();
|
|
5159
|
-
if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(trimmed) || trimmed.includes("..")) {
|
|
5160
|
-
throw new Error("Invalid identity audit key");
|
|
5161
|
-
}
|
|
5162
|
-
return trimmed;
|
|
5163
|
-
}
|
|
5164
5220
|
async writeQuestion(question, context, priority) {
|
|
5165
5221
|
await mkdir(this.questionsDir, { recursive: true });
|
|
5166
5222
|
const id = this.generateId("q");
|
|
@@ -5178,7 +5234,7 @@ ${question}
|
|
|
5178
5234
|
|
|
5179
5235
|
**Context:** ${context}
|
|
5180
5236
|
`;
|
|
5181
|
-
const filePath =
|
|
5237
|
+
const filePath = path4.join(this.questionsDir, `${id}.md`);
|
|
5182
5238
|
await this.writeStorageSecureFile(filePath, content);
|
|
5183
5239
|
log.debug(`wrote question ${id} to ${filePath}`);
|
|
5184
5240
|
this.invalidateQuestionsCache();
|
|
@@ -5198,7 +5254,7 @@ ${question}
|
|
|
5198
5254
|
if (!match) return null;
|
|
5199
5255
|
const frontmatterStr = match[1];
|
|
5200
5256
|
const body = match[2].trim();
|
|
5201
|
-
const id = this.extractFrontmatterValue(frontmatterStr, "id") ??
|
|
5257
|
+
const id = this.extractFrontmatterValue(frontmatterStr, "id") ?? path4.basename(filePath, ".md");
|
|
5202
5258
|
const created = this.extractFrontmatterValue(frontmatterStr, "created") ?? "";
|
|
5203
5259
|
const priority = parseFloat(
|
|
5204
5260
|
this.extractFrontmatterValue(frontmatterStr, "priority") ?? "0.5"
|
|
@@ -5260,11 +5316,11 @@ ${question}
|
|
|
5260
5316
|
} catch {
|
|
5261
5317
|
}
|
|
5262
5318
|
const hygiene = opts?.hygiene;
|
|
5263
|
-
const rotateEnabled = hygiene?.enabled === true && hygiene.rotateEnabled === true && Array.isArray(hygiene.rotatePaths) && hygiene.rotatePaths.includes(
|
|
5319
|
+
const rotateEnabled = hygiene?.enabled === true && hygiene.rotateEnabled === true && Array.isArray(hygiene.rotatePaths) && hygiene.rotatePaths.includes(path4.basename(identityPath));
|
|
5264
5320
|
if (rotateEnabled) {
|
|
5265
5321
|
const maxBytes = hygiene.rotateMaxBytes;
|
|
5266
5322
|
if (existing.length > maxBytes) {
|
|
5267
|
-
const archiveDir =
|
|
5323
|
+
const archiveDir = path4.join(workspaceDir, hygiene.archiveDir);
|
|
5268
5324
|
const { newContent } = await rotateMarkdownFileToArchive({
|
|
5269
5325
|
filePath: identityPath,
|
|
5270
5326
|
archiveDir,
|
|
@@ -5358,7 +5414,7 @@ ${reflection}
|
|
|
5358
5414
|
* Deduplicates by target+label.
|
|
5359
5415
|
*/
|
|
5360
5416
|
async addEntityRelationship(name, rel) {
|
|
5361
|
-
const filePath =
|
|
5417
|
+
const filePath = path4.join(this.entitiesDir, `${name}.md`);
|
|
5362
5418
|
let entity;
|
|
5363
5419
|
try {
|
|
5364
5420
|
const content = await this.readStorageSecureFile(filePath);
|
|
@@ -5383,7 +5439,7 @@ ${reflection}
|
|
|
5383
5439
|
* Prepends to the beginning, prunes oldest entries beyond maxEntries.
|
|
5384
5440
|
*/
|
|
5385
5441
|
async addEntityActivity(name, entry, maxEntries) {
|
|
5386
|
-
const filePath =
|
|
5442
|
+
const filePath = path4.join(this.entitiesDir, `${name}.md`);
|
|
5387
5443
|
let entity;
|
|
5388
5444
|
try {
|
|
5389
5445
|
const content = await this.readStorageSecureFile(filePath);
|
|
@@ -5406,7 +5462,7 @@ ${reflection}
|
|
|
5406
5462
|
* Add an alias to an entity file. Deduplicates.
|
|
5407
5463
|
*/
|
|
5408
5464
|
async addEntityAlias(name, alias) {
|
|
5409
|
-
const filePath =
|
|
5465
|
+
const filePath = path4.join(this.entitiesDir, `${name}.md`);
|
|
5410
5466
|
let entity;
|
|
5411
5467
|
try {
|
|
5412
5468
|
const content = await this.readStorageSecureFile(filePath);
|
|
@@ -5437,7 +5493,7 @@ ${reflection}
|
|
|
5437
5493
|
const updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
5438
5494
|
let synthesisTimelineCount;
|
|
5439
5495
|
try {
|
|
5440
|
-
const filePath =
|
|
5496
|
+
const filePath = path4.join(this.entitiesDir, `${name}.md`);
|
|
5441
5497
|
const content = await this.readStorageSecureFile(filePath);
|
|
5442
5498
|
synthesisTimelineCount = parseEntityFile(content, this.entitySchemas).timeline.length;
|
|
5443
5499
|
} catch (err) {
|
|
@@ -5520,7 +5576,7 @@ ${reflection}
|
|
|
5520
5576
|
if (!raw) continue;
|
|
5521
5577
|
const serialized = serializeEntityFile(parseEntityFile(raw, this.entitySchemas), this.entitySchemas);
|
|
5522
5578
|
if (raw.trimEnd() === serialized.trimEnd()) continue;
|
|
5523
|
-
await this.writeStorageSecureFile(
|
|
5579
|
+
await this.writeStorageSecureFile(path4.join(this.entitiesDir, `${entityName}.md`), serialized);
|
|
5524
5580
|
migrated += 1;
|
|
5525
5581
|
}
|
|
5526
5582
|
if (migrated > 0) {
|
|
@@ -5663,7 +5719,7 @@ ${memory.content}
|
|
|
5663
5719
|
const filePaths = await this.collectActiveMemoryPaths();
|
|
5664
5720
|
const foundIds = /* @__PURE__ */ new Set();
|
|
5665
5721
|
for (const filePath of filePaths) {
|
|
5666
|
-
const basename =
|
|
5722
|
+
const basename = path4.basename(filePath, ".md");
|
|
5667
5723
|
if (wantedIds.has(basename)) {
|
|
5668
5724
|
foundIds.add(basename);
|
|
5669
5725
|
if (foundIds.size === wantedIds.size) break;
|
|
@@ -5853,14 +5909,14 @@ Reason: ${reason}`, {
|
|
|
5853
5909
|
// Memory Summarization (Phase 4A)
|
|
5854
5910
|
// ---------------------------------------------------------------------------
|
|
5855
5911
|
get summariesDir() {
|
|
5856
|
-
return
|
|
5912
|
+
return path4.join(this.baseDir, "summaries");
|
|
5857
5913
|
}
|
|
5858
5914
|
/**
|
|
5859
5915
|
* Write a memory summary.
|
|
5860
5916
|
*/
|
|
5861
5917
|
async writeSummary(summary) {
|
|
5862
5918
|
await mkdir(this.summariesDir, { recursive: true });
|
|
5863
|
-
const filePath =
|
|
5919
|
+
const filePath = path4.join(this.summariesDir, `${summary.id}.json`);
|
|
5864
5920
|
await this.writeStorageSecureFile(filePath, JSON.stringify(summary, null, 2));
|
|
5865
5921
|
log.debug(`wrote summary ${summary.id}`);
|
|
5866
5922
|
}
|
|
@@ -5869,11 +5925,11 @@ Reason: ${reason}`, {
|
|
|
5869
5925
|
*/
|
|
5870
5926
|
async readSummaries() {
|
|
5871
5927
|
try {
|
|
5872
|
-
const files = await
|
|
5928
|
+
const files = await readdir4(this.summariesDir);
|
|
5873
5929
|
const summaries = [];
|
|
5874
5930
|
for (const file of files) {
|
|
5875
5931
|
if (!file.endsWith(".json")) continue;
|
|
5876
|
-
const filePath =
|
|
5932
|
+
const filePath = path4.join(this.summariesDir, file);
|
|
5877
5933
|
const raw = await this.readStorageSecureFile(filePath);
|
|
5878
5934
|
summaries.push(JSON.parse(raw));
|
|
5879
5935
|
}
|
|
@@ -5934,7 +5990,7 @@ ${memory.content}
|
|
|
5934
5990
|
* Save topic scores to meta.json.
|
|
5935
5991
|
*/
|
|
5936
5992
|
async saveTopics(topics) {
|
|
5937
|
-
const metaPath =
|
|
5993
|
+
const metaPath = path4.join(this.stateDir, "topics.json");
|
|
5938
5994
|
await mkdir(this.stateDir, { recursive: true });
|
|
5939
5995
|
await this.writeStorageSecureFile(metaPath, JSON.stringify({ topics, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, null, 2));
|
|
5940
5996
|
log.debug(`saved ${topics.length} topic scores`);
|
|
@@ -5943,7 +5999,7 @@ ${memory.content}
|
|
|
5943
5999
|
* Load topic scores from meta.json.
|
|
5944
6000
|
*/
|
|
5945
6001
|
async loadTopics() {
|
|
5946
|
-
const metaPath =
|
|
6002
|
+
const metaPath = path4.join(this.stateDir, "topics.json");
|
|
5947
6003
|
try {
|
|
5948
6004
|
const raw = await this.readStorageSecureFile(metaPath);
|
|
5949
6005
|
return JSON.parse(raw);
|
|
@@ -6040,4 +6096,4 @@ export {
|
|
|
6040
6096
|
isValidBufferSurpriseEvent,
|
|
6041
6097
|
StorageManager3 as StorageManager
|
|
6042
6098
|
};
|
|
6043
|
-
//# sourceMappingURL=chunk-
|
|
6099
|
+
//# sourceMappingURL=chunk-DUQHQ3TL.js.map
|