@remnic/core 9.3.594 → 9.3.596
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-cli.js +14 -14
- package/dist/access-http.js +6 -6
- package/dist/access-mcp.js +5 -5
- package/dist/access-schema.d.ts +7 -7
- package/dist/access-service.js +4 -4
- package/dist/briefing.js +2 -2
- package/dist/causal-consolidation.js +3 -3
- package/dist/{chunk-ARY5OOLG.js → chunk-557IAFPD.js} +2 -2
- package/dist/{chunk-VFB2G5YL.js → chunk-5BUGGPBR.js} +4 -4
- package/dist/{chunk-USYGGIJZ.js → chunk-D2MMMTDV.js} +2 -2
- package/dist/{chunk-XM7BYXT7.js → chunk-D65TSG24.js} +2 -2
- package/dist/{chunk-FHBEL473.js → chunk-DOX2CG6Y.js} +54 -5
- package/dist/chunk-DOX2CG6Y.js.map +1 -0
- package/dist/{chunk-DARLGSFX.js → chunk-ELKI4BB6.js} +4 -4
- package/dist/{chunk-QRWZOCJN.js → chunk-F4LM4ULA.js} +12 -12
- package/dist/{chunk-7WU3FML2.js → chunk-IEFHBIU2.js} +11 -11
- package/dist/{chunk-7WU3FML2.js.map → chunk-IEFHBIU2.js.map} +1 -1
- package/dist/{chunk-KDUFBSBF.js → chunk-IK34DVAC.js} +2 -2
- package/dist/{chunk-OPYFD6PD.js → chunk-IK7DCC5H.js} +2 -2
- package/dist/{chunk-574MU2Y3.js → chunk-JTDRJQ3K.js} +2 -2
- package/dist/{chunk-LAL7WBLY.js → chunk-LYPDMKUT.js} +3 -3
- package/dist/{chunk-GBXGCFRH.js → chunk-MA5MWGKP.js} +2 -2
- package/dist/{chunk-HQO5EBUC.js → chunk-MLT75J5S.js} +3 -3
- package/dist/{chunk-7X7TBJRX.js → chunk-NOMEVTUD.js} +2 -2
- package/dist/{chunk-SUTSSOYU.js → chunk-OD5LFAPZ.js} +2 -2
- package/dist/{chunk-XT7XVA53.js → chunk-OI27U2HT.js} +2 -2
- package/dist/{chunk-MQEIWDYW.js → chunk-QDDHYAKV.js} +2 -2
- package/dist/{chunk-ZY6UPHNY.js → chunk-TYICDVQW.js} +3 -3
- package/dist/{chunk-XRWTAEZM.js → chunk-W5O2FQTZ.js} +2 -2
- package/dist/{chunk-V3RXWQIE.js → chunk-WXACKLKP.js} +209 -59
- package/dist/chunk-WXACKLKP.js.map +1 -0
- package/dist/{chunk-IRFF6LSF.js → chunk-YFS5OEKO.js} +36 -1
- package/dist/chunk-YFS5OEKO.js.map +1 -0
- package/dist/cli.js +15 -15
- package/dist/compounding/engine.js +2 -2
- package/dist/connectors/codex-materialize-runner.js +2 -2
- package/dist/connectors/index.js +2 -2
- package/dist/entity-retrieval.js +2 -2
- package/dist/index.js +22 -22
- package/dist/maintenance/memory-governance.js +2 -2
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +2 -2
- package/dist/maintenance/rebuild-memory-projection.js +3 -3
- package/dist/namespaces/migrate.js +3 -3
- package/dist/namespaces/storage.js +2 -2
- package/dist/operator-toolkit.js +5 -5
- package/dist/orchestrator.js +11 -11
- package/dist/retrieval-agents.js +2 -2
- 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/storage.d.ts +2 -0
- package/dist/storage.js +1 -1
- package/dist/temporal-index.js +1 -1
- package/dist/verified-recall.js +2 -2
- package/package.json +1 -1
- package/src/dedup/semantic.test.ts +33 -0
- package/src/dedup/semantic.ts +7 -1
- package/src/entity-retrieval.ts +64 -3
- package/src/storage.ts +40 -0
- package/src/temporal-index.test.ts +191 -0
- package/src/temporal-index.ts +291 -100
- package/dist/chunk-FHBEL473.js.map +0 -1
- package/dist/chunk-IRFF6LSF.js.map +0 -1
- package/dist/chunk-V3RXWQIE.js.map +0 -1
- /package/dist/{chunk-ARY5OOLG.js.map → chunk-557IAFPD.js.map} +0 -0
- /package/dist/{chunk-VFB2G5YL.js.map → chunk-5BUGGPBR.js.map} +0 -0
- /package/dist/{chunk-USYGGIJZ.js.map → chunk-D2MMMTDV.js.map} +0 -0
- /package/dist/{chunk-XM7BYXT7.js.map → chunk-D65TSG24.js.map} +0 -0
- /package/dist/{chunk-DARLGSFX.js.map → chunk-ELKI4BB6.js.map} +0 -0
- /package/dist/{chunk-QRWZOCJN.js.map → chunk-F4LM4ULA.js.map} +0 -0
- /package/dist/{chunk-KDUFBSBF.js.map → chunk-IK34DVAC.js.map} +0 -0
- /package/dist/{chunk-OPYFD6PD.js.map → chunk-IK7DCC5H.js.map} +0 -0
- /package/dist/{chunk-574MU2Y3.js.map → chunk-JTDRJQ3K.js.map} +0 -0
- /package/dist/{chunk-LAL7WBLY.js.map → chunk-LYPDMKUT.js.map} +0 -0
- /package/dist/{chunk-GBXGCFRH.js.map → chunk-MA5MWGKP.js.map} +0 -0
- /package/dist/{chunk-HQO5EBUC.js.map → chunk-MLT75J5S.js.map} +0 -0
- /package/dist/{chunk-7X7TBJRX.js.map → chunk-NOMEVTUD.js.map} +0 -0
- /package/dist/{chunk-SUTSSOYU.js.map → chunk-OD5LFAPZ.js.map} +0 -0
- /package/dist/{chunk-XT7XVA53.js.map → chunk-OI27U2HT.js.map} +0 -0
- /package/dist/{chunk-MQEIWDYW.js.map → chunk-QDDHYAKV.js.map} +0 -0
- /package/dist/{chunk-ZY6UPHNY.js.map → chunk-TYICDVQW.js.map} +0 -0
- /package/dist/{chunk-XRWTAEZM.js.map → chunk-W5O2FQTZ.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YFS5OEKO.js";
|
|
4
4
|
|
|
5
5
|
// src/semantic-rule-promotion.ts
|
|
6
6
|
import { createHash, randomUUID } from "crypto";
|
|
@@ -529,4 +529,4 @@ export {
|
|
|
529
529
|
setSemanticRulePromotionTestHooks,
|
|
530
530
|
promoteSemanticRuleFromMemory
|
|
531
531
|
};
|
|
532
|
-
//# sourceMappingURL=chunk-
|
|
532
|
+
//# sourceMappingURL=chunk-IK34DVAC.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-ZFXCQPNO.js";
|
|
5
5
|
import {
|
|
6
6
|
StorageManager
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YFS5OEKO.js";
|
|
8
8
|
import {
|
|
9
9
|
isSafeRouteNamespace
|
|
10
10
|
} from "./chunk-U3PN77QT.js";
|
|
@@ -156,4 +156,4 @@ export {
|
|
|
156
156
|
getCategoryDir,
|
|
157
157
|
NamespaceStorageRouter
|
|
158
158
|
};
|
|
159
|
-
//# sourceMappingURL=chunk-
|
|
159
|
+
//# sourceMappingURL=chunk-IK7DCC5H.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
ALL_CATEGORY_DIRS,
|
|
6
6
|
NamespaceStorageRouter
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-IK7DCC5H.js";
|
|
8
8
|
import {
|
|
9
9
|
namespaceIdentityFromToken,
|
|
10
10
|
namespaceIdentityToken
|
|
@@ -202,4 +202,4 @@ export {
|
|
|
202
202
|
verifyNamespaces,
|
|
203
203
|
runNamespaceMigration
|
|
204
204
|
};
|
|
205
|
-
//# sourceMappingURL=chunk-
|
|
205
|
+
//# sourceMappingURL=chunk-JTDRJQ3K.js.map
|
|
@@ -11,13 +11,13 @@ import {
|
|
|
11
11
|
} from "./chunk-D24OXEPB.js";
|
|
12
12
|
import {
|
|
13
13
|
EngramAccessInputError
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5BUGGPBR.js";
|
|
15
15
|
import {
|
|
16
16
|
projectTagProjectId
|
|
17
17
|
} from "./chunk-EDQVAMQI.js";
|
|
18
18
|
import {
|
|
19
19
|
validateBriefingFormat
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-QDDHYAKV.js";
|
|
21
21
|
import {
|
|
22
22
|
expandTildePath
|
|
23
23
|
} from "./chunk-EYIEWJNI.js";
|
|
@@ -2860,4 +2860,4 @@ ${body}`;
|
|
|
2860
2860
|
export {
|
|
2861
2861
|
EngramMcpServer
|
|
2862
2862
|
};
|
|
2863
|
-
//# sourceMappingURL=chunk-
|
|
2863
|
+
//# sourceMappingURL=chunk-LYPDMKUT.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-HQ6NIBL6.js";
|
|
4
4
|
import {
|
|
5
5
|
StorageManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YFS5OEKO.js";
|
|
7
7
|
import {
|
|
8
8
|
getCachedEpisodeMap,
|
|
9
9
|
setCachedEpisodeMap
|
|
@@ -105,4 +105,4 @@ async function searchVerifiedEpisodes(options) {
|
|
|
105
105
|
export {
|
|
106
106
|
searchVerifiedEpisodes
|
|
107
107
|
};
|
|
108
|
-
//# sourceMappingURL=chunk-
|
|
108
|
+
//# sourceMappingURL=chunk-MA5MWGKP.js.map
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
import {
|
|
11
11
|
listMemoryGovernanceRuns,
|
|
12
12
|
readMemoryGovernanceRunArtifact
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-OI27U2HT.js";
|
|
14
14
|
import {
|
|
15
15
|
StorageManager
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-YFS5OEKO.js";
|
|
17
17
|
import {
|
|
18
18
|
MEMORY_LIFECYCLE_EVENT_SORT_ORDER,
|
|
19
19
|
buildLifecycleEventsForMemory,
|
|
@@ -929,4 +929,4 @@ export {
|
|
|
929
929
|
verifyMemoryProjection,
|
|
930
930
|
repairMemoryProjection
|
|
931
931
|
};
|
|
932
|
-
//# sourceMappingURL=chunk-
|
|
932
|
+
//# sourceMappingURL=chunk-MLT75J5S.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "./chunk-3UXOZBHV.js";
|
|
8
8
|
import {
|
|
9
9
|
StorageManager
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-YFS5OEKO.js";
|
|
11
11
|
import {
|
|
12
12
|
isSafeRouteNamespace
|
|
13
13
|
} from "./chunk-U3PN77QT.js";
|
|
@@ -117,4 +117,4 @@ export {
|
|
|
117
117
|
runCodexMaterialize,
|
|
118
118
|
runPostConsolidationMaterialize
|
|
119
119
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
120
|
+
//# sourceMappingURL=chunk-NOMEVTUD.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-DRD2Q7HQ.js";
|
|
5
5
|
import {
|
|
6
6
|
StorageManager
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YFS5OEKO.js";
|
|
8
8
|
import {
|
|
9
9
|
parseContinuityImprovementLoops
|
|
10
10
|
} from "./chunk-QSVPYQPG.js";
|
|
@@ -1259,4 +1259,4 @@ export {
|
|
|
1259
1259
|
defaultTierMigrationCycleBudget,
|
|
1260
1260
|
CompoundingEngine
|
|
1261
1261
|
};
|
|
1262
|
-
//# sourceMappingURL=chunk-
|
|
1262
|
+
//# sourceMappingURL=chunk-OD5LFAPZ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YFS5OEKO.js";
|
|
4
4
|
import {
|
|
5
5
|
decideLifecycleTransition
|
|
6
6
|
} from "./chunk-TBBDFYXW.js";
|
|
@@ -729,4 +729,4 @@ export {
|
|
|
729
729
|
listMemoryGovernanceRuns,
|
|
730
730
|
readMemoryGovernanceRunArtifact
|
|
731
731
|
};
|
|
732
|
-
//# sourceMappingURL=chunk-
|
|
732
|
+
//# sourceMappingURL=chunk-OI27U2HT.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager,
|
|
3
3
|
normalizeEntityName
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YFS5OEKO.js";
|
|
5
5
|
import {
|
|
6
6
|
readEnvVar,
|
|
7
7
|
resolveHomeDir
|
|
@@ -824,4 +824,4 @@ export {
|
|
|
824
824
|
resolveBriefingSaveDir,
|
|
825
825
|
briefingFilename
|
|
826
826
|
};
|
|
827
|
-
//# sourceMappingURL=chunk-
|
|
827
|
+
//# sourceMappingURL=chunk-QDDHYAKV.js.map
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-AU7Q3LSC.js";
|
|
4
4
|
import {
|
|
5
5
|
EngramMcpServer
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LYPDMKUT.js";
|
|
7
7
|
import {
|
|
8
8
|
EngramAccessInputError
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-5BUGGPBR.js";
|
|
10
10
|
import {
|
|
11
11
|
projectTagProjectId
|
|
12
12
|
} from "./chunk-EDQVAMQI.js";
|
|
@@ -1846,4 +1846,4 @@ var EngramAccessHttpServer = class {
|
|
|
1846
1846
|
export {
|
|
1847
1847
|
EngramAccessHttpServer
|
|
1848
1848
|
};
|
|
1849
|
-
//# sourceMappingURL=chunk-
|
|
1849
|
+
//# sourceMappingURL=chunk-TYICDVQW.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YFS5OEKO.js";
|
|
4
4
|
import {
|
|
5
5
|
getCachedRuleMemories,
|
|
6
6
|
setCachedRuleMemories
|
|
@@ -115,4 +115,4 @@ async function searchVerifiedSemanticRules(options) {
|
|
|
115
115
|
export {
|
|
116
116
|
searchVerifiedSemanticRules
|
|
117
117
|
};
|
|
118
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-W5O2FQTZ.js.map
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
// src/temporal-index.ts
|
|
2
|
+
import { execFileSync } from "child_process";
|
|
3
|
+
import * as crypto from "crypto";
|
|
2
4
|
import * as fs from "fs";
|
|
3
5
|
import * as path from "path";
|
|
4
6
|
var INDEX_VERSION = 1;
|
|
5
7
|
var TEMPORAL_INDEX_FILE = "index_time.json";
|
|
6
8
|
var TAG_INDEX_FILE = "index_tags.json";
|
|
7
9
|
var TAG_INDEX_VERSION = 2;
|
|
10
|
+
var INDEX_LOCK_STALE_MS = 6e4;
|
|
11
|
+
var INDEX_LOCK_POLL_MS = 10;
|
|
12
|
+
var INDEX_PROCESS_START_TOLERANCE_MS = 2e3;
|
|
13
|
+
var INDEX_LOCK_SLEEP = new Int32Array(new SharedArrayBuffer(4));
|
|
14
|
+
var INDEX_PROCESS_STARTED_AT_MS = Date.now() - process.uptime() * 1e3;
|
|
8
15
|
function stateDir(memoryDir) {
|
|
9
16
|
return path.join(memoryDir, "state");
|
|
10
17
|
}
|
|
@@ -28,25 +35,159 @@ function readJsonSafe(filePath, fallback) {
|
|
|
28
35
|
return fallback;
|
|
29
36
|
}
|
|
30
37
|
}
|
|
31
|
-
function
|
|
38
|
+
function sleepSync(ms) {
|
|
39
|
+
Atomics.wait(INDEX_LOCK_SLEEP, 0, 0, ms);
|
|
40
|
+
}
|
|
41
|
+
function uniqueTempPath(filePath) {
|
|
42
|
+
const dir = path.dirname(filePath);
|
|
43
|
+
const base = path.basename(filePath);
|
|
44
|
+
const nonce = crypto.randomBytes(6).toString("hex");
|
|
45
|
+
return path.join(dir, `.${base}.${process.pid}.${Date.now()}.${nonce}.tmp`);
|
|
46
|
+
}
|
|
47
|
+
function lockOwnerPath(lockDir) {
|
|
48
|
+
return path.join(lockDir, "owner.json");
|
|
49
|
+
}
|
|
50
|
+
function writeIndexLockOwner(lockDir) {
|
|
32
51
|
try {
|
|
33
|
-
fs.writeFileSync(
|
|
52
|
+
fs.writeFileSync(
|
|
53
|
+
lockOwnerPath(lockDir),
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
pid: process.pid,
|
|
56
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
57
|
+
processStartedAtMs: INDEX_PROCESS_STARTED_AT_MS
|
|
58
|
+
}),
|
|
59
|
+
{
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
flag: "wx"
|
|
62
|
+
}
|
|
63
|
+
);
|
|
34
64
|
} catch {
|
|
35
65
|
}
|
|
36
66
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
67
|
+
function readIndexLockOwner(lockDir) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(fs.readFileSync(lockOwnerPath(lockDir), "utf8"));
|
|
70
|
+
if (!(typeof parsed.pid === "number" && Number.isInteger(parsed.pid) && parsed.pid > 0)) return null;
|
|
71
|
+
const owner = { pid: parsed.pid };
|
|
72
|
+
if ("createdAt" in parsed && typeof parsed.createdAt === "string" && parsed.createdAt.length > 0) {
|
|
73
|
+
owner.createdAt = parsed.createdAt;
|
|
74
|
+
}
|
|
75
|
+
const processStartedAtMs = parsed.processStartedAtMs;
|
|
76
|
+
if (typeof processStartedAtMs === "number" && Number.isFinite(processStartedAtMs) && processStartedAtMs > 0) {
|
|
77
|
+
owner.processStartedAtMs = processStartedAtMs;
|
|
78
|
+
}
|
|
79
|
+
return owner;
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function processIsAlive(pid) {
|
|
85
|
+
try {
|
|
86
|
+
process.kill(pid, 0);
|
|
87
|
+
return true;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
const code = error?.code;
|
|
90
|
+
return code === "EPERM";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function readProcessStartedAtMs(pid) {
|
|
39
94
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
95
|
+
const output = execFileSync("ps", ["-p", String(pid), "-o", "lstart="], {
|
|
96
|
+
encoding: "utf8",
|
|
97
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
98
|
+
timeout: 1e3
|
|
99
|
+
}).trim();
|
|
100
|
+
if (!output) return null;
|
|
101
|
+
const startedAtMs = Date.parse(output);
|
|
102
|
+
return Number.isFinite(startedAtMs) ? startedAtMs : null;
|
|
42
103
|
} catch {
|
|
43
|
-
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function lockOwnerIsRunning(owner) {
|
|
108
|
+
if (!processIsAlive(owner.pid)) return false;
|
|
109
|
+
if (owner.processStartedAtMs === void 0) return true;
|
|
110
|
+
const runningStartedAtMs = readProcessStartedAtMs(owner.pid);
|
|
111
|
+
if (runningStartedAtMs === null) return true;
|
|
112
|
+
return runningStartedAtMs <= owner.processStartedAtMs + INDEX_PROCESS_START_TOLERANCE_MS;
|
|
113
|
+
}
|
|
114
|
+
function removeAbandonedIndexLock(lockDir) {
|
|
115
|
+
try {
|
|
116
|
+
const info = fs.lstatSync(lockDir);
|
|
117
|
+
if (info.isSymbolicLink()) return "blocked";
|
|
118
|
+
if (!info.isDirectory()) {
|
|
119
|
+
fs.rmSync(lockDir, { force: true });
|
|
120
|
+
return "removed";
|
|
121
|
+
}
|
|
122
|
+
const owner = readIndexLockOwner(lockDir);
|
|
123
|
+
if (owner !== null && lockOwnerIsRunning(owner)) return "wait";
|
|
124
|
+
if (owner === null && Date.now() - info.mtimeMs < INDEX_LOCK_STALE_MS) return "wait";
|
|
125
|
+
fs.rmSync(lockDir, { recursive: true, force: true });
|
|
126
|
+
return "removed";
|
|
127
|
+
} catch {
|
|
128
|
+
return "blocked";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function withIndexFileLock(filePath, update) {
|
|
132
|
+
const lockDir = `${filePath}.lock.d`;
|
|
133
|
+
let acquired = false;
|
|
134
|
+
while (!acquired) {
|
|
135
|
+
try {
|
|
136
|
+
fs.mkdirSync(lockDir);
|
|
137
|
+
writeIndexLockOwner(lockDir);
|
|
138
|
+
acquired = true;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
const code = error?.code;
|
|
141
|
+
if (code !== "EEXIST") return;
|
|
142
|
+
const cleanupResult = removeAbandonedIndexLock(lockDir);
|
|
143
|
+
if (cleanupResult === "blocked") return;
|
|
144
|
+
sleepSync(INDEX_LOCK_POLL_MS);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
update();
|
|
149
|
+
} finally {
|
|
44
150
|
try {
|
|
45
|
-
fs.
|
|
151
|
+
fs.rmSync(lockDir, { recursive: true, force: true });
|
|
46
152
|
} catch {
|
|
47
153
|
}
|
|
48
154
|
}
|
|
49
155
|
}
|
|
156
|
+
function writeJsonAtomic(filePath, data) {
|
|
157
|
+
const payload = JSON.stringify(data, null, 2);
|
|
158
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
159
|
+
const tmp = uniqueTempPath(filePath);
|
|
160
|
+
try {
|
|
161
|
+
fs.writeFileSync(tmp, payload, "utf8");
|
|
162
|
+
fs.renameSync(tmp, filePath);
|
|
163
|
+
return;
|
|
164
|
+
} catch {
|
|
165
|
+
try {
|
|
166
|
+
fs.unlinkSync(tmp);
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
169
|
+
sleepSync(INDEX_LOCK_POLL_MS);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function updateTemporalIndex(memoryDir, update) {
|
|
174
|
+
const indexPath = temporalIndexPath(memoryDir);
|
|
175
|
+
withIndexFileLock(indexPath, () => {
|
|
176
|
+
const index = readJsonSafe(indexPath, { version: INDEX_VERSION, dates: {} });
|
|
177
|
+
update(index);
|
|
178
|
+
writeJsonAtomic(indexPath, index);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function updateTagIndex(memoryDir, update) {
|
|
182
|
+
const indexPath = tagIndexPath(memoryDir);
|
|
183
|
+
withIndexFileLock(indexPath, () => {
|
|
184
|
+
const index = normalizeTagIndex(
|
|
185
|
+
readJsonSafe(indexPath, { version: TAG_INDEX_VERSION, tags: {}, aliases: {} })
|
|
186
|
+
);
|
|
187
|
+
update(index);
|
|
188
|
+
writeJsonAtomic(indexPath, index);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
50
191
|
function isoDateFromTimestamp(isoString) {
|
|
51
192
|
if (typeof isoString !== "string" || isoString.length < 10) {
|
|
52
193
|
console.warn(`[engram] temporal-index: malformed timestamp "${isoString}", falling back to today`);
|
|
@@ -245,46 +386,51 @@ function promptContainsAlias(prompt, alias) {
|
|
|
245
386
|
function indexMemory(memoryDir, memoryPath, createdAt, tags) {
|
|
246
387
|
try {
|
|
247
388
|
ensureStateDir(memoryDir);
|
|
248
|
-
const tPath = temporalIndexPath(memoryDir);
|
|
249
|
-
const tIndex = readJsonSafe(tPath, { version: INDEX_VERSION, dates: {} });
|
|
250
389
|
const dateKey = isoDateFromTimestamp(createdAt);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
390
|
+
updateTemporalIndex(memoryDir, (index) => {
|
|
391
|
+
addPathToSet(index.dates, dateKey, memoryPath);
|
|
392
|
+
});
|
|
393
|
+
updateTagIndex(memoryDir, (index) => {
|
|
394
|
+
for (const tag of tags) {
|
|
395
|
+
if (tag && typeof tag === "string") {
|
|
396
|
+
addTagGraphEntry(index, tag, memoryPath);
|
|
397
|
+
}
|
|
258
398
|
}
|
|
259
|
-
}
|
|
260
|
-
writeJsonAtomic(gPath, gIndex);
|
|
399
|
+
});
|
|
261
400
|
} catch {
|
|
262
401
|
}
|
|
263
402
|
}
|
|
264
403
|
function deindexMemory(memoryDir, memoryPath, createdAt, tags) {
|
|
265
404
|
try {
|
|
266
405
|
ensureStateDir(memoryDir);
|
|
267
|
-
const tPath = temporalIndexPath(memoryDir);
|
|
268
|
-
const tIndex = readJsonSafe(tPath, { version: INDEX_VERSION, dates: {} });
|
|
269
406
|
const dateKey = isoDateFromTimestamp(createdAt);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
407
|
+
updateTemporalIndex(memoryDir, (index) => {
|
|
408
|
+
removePathFromSet(index.dates, dateKey, memoryPath);
|
|
409
|
+
});
|
|
410
|
+
updateTagIndex(memoryDir, (index) => {
|
|
411
|
+
for (const tag of tags) {
|
|
412
|
+
if (tag && typeof tag === "string") {
|
|
413
|
+
removeTagGraphEntry(index, tag, memoryPath);
|
|
414
|
+
}
|
|
277
415
|
}
|
|
278
|
-
}
|
|
279
|
-
writeJsonAtomic(gPath, gIndex);
|
|
416
|
+
});
|
|
280
417
|
} catch {
|
|
281
418
|
}
|
|
282
419
|
}
|
|
283
420
|
function clearIndexes(memoryDir) {
|
|
284
421
|
try {
|
|
285
422
|
ensureStateDir(memoryDir);
|
|
286
|
-
|
|
287
|
-
|
|
423
|
+
updateTemporalIndex(memoryDir, (index) => {
|
|
424
|
+
index.version = INDEX_VERSION;
|
|
425
|
+
index.lastRebuildAt = void 0;
|
|
426
|
+
index.dates = {};
|
|
427
|
+
});
|
|
428
|
+
updateTagIndex(memoryDir, (index) => {
|
|
429
|
+
index.version = TAG_INDEX_VERSION;
|
|
430
|
+
index.lastRebuildAt = void 0;
|
|
431
|
+
index.tags = {};
|
|
432
|
+
index.aliases = {};
|
|
433
|
+
});
|
|
288
434
|
} catch {
|
|
289
435
|
}
|
|
290
436
|
}
|
|
@@ -299,21 +445,21 @@ function indexMemoriesBatch(memoryDir, entries) {
|
|
|
299
445
|
if (entries.length === 0) return;
|
|
300
446
|
try {
|
|
301
447
|
ensureStateDir(memoryDir);
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
for (const
|
|
310
|
-
|
|
311
|
-
|
|
448
|
+
updateTemporalIndex(memoryDir, (index) => {
|
|
449
|
+
for (const entry of entries) {
|
|
450
|
+
const dateKey = isoDateFromTimestamp(entry.createdAt);
|
|
451
|
+
addPathToSet(index.dates, dateKey, entry.path);
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
updateTagIndex(memoryDir, (index) => {
|
|
455
|
+
for (const entry of entries) {
|
|
456
|
+
for (const tag of entry.tags) {
|
|
457
|
+
if (tag && typeof tag === "string") {
|
|
458
|
+
addTagGraphEntry(index, tag, entry.path);
|
|
459
|
+
}
|
|
312
460
|
}
|
|
313
461
|
}
|
|
314
|
-
}
|
|
315
|
-
writeJsonAtomic(tPath, tIndex);
|
|
316
|
-
writeJsonAtomic(gPath, gIndex);
|
|
462
|
+
});
|
|
317
463
|
} catch {
|
|
318
464
|
}
|
|
319
465
|
}
|
|
@@ -458,10 +604,12 @@ function recencyWindowFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
458
604
|
"november",
|
|
459
605
|
"december"
|
|
460
606
|
];
|
|
461
|
-
const monthMatch = p.match(
|
|
607
|
+
const monthMatch = p.match(
|
|
608
|
+
/\b(january|february|march|april|may|june|july|august|september|october|november|december)(?:\s+(\d{4}))?\b/
|
|
609
|
+
);
|
|
462
610
|
if (monthMatch) {
|
|
463
611
|
const monthIdx = monthNames.indexOf(monthMatch[1]);
|
|
464
|
-
const year = monthMatch[2] ? parseInt(monthMatch[2], 10) : now.getFullYear();
|
|
612
|
+
const year = monthMatch[2] ? Number.parseInt(monthMatch[2], 10) : now.getFullYear();
|
|
465
613
|
if (/\bbefore\b/.test(p)) {
|
|
466
614
|
if (monthMatch[2]) {
|
|
467
615
|
const monthStart = new Date(year, monthIdx, 1);
|
|
@@ -475,19 +623,19 @@ function recencyWindowFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
475
623
|
}
|
|
476
624
|
const weekMatch = p.match(/(\d{1,5})\s*weeks?\s*ago/);
|
|
477
625
|
if (weekMatch) {
|
|
478
|
-
daysBack = Math.min(365, parseInt(weekMatch[1], 10) * 7);
|
|
626
|
+
daysBack = Math.min(365, Number.parseInt(weekMatch[1], 10) * 7);
|
|
479
627
|
} else {
|
|
480
628
|
const monthsAgoMatch = p.match(/(\d{1,5})\s*months?\s*ago/);
|
|
481
629
|
if (monthsAgoMatch) {
|
|
482
|
-
daysBack = Math.min(730, parseInt(monthsAgoMatch[1], 10) * 31);
|
|
630
|
+
daysBack = Math.min(730, Number.parseInt(monthsAgoMatch[1], 10) * 31);
|
|
483
631
|
} else {
|
|
484
632
|
const numMatch = p.match(/(\d{1,5})\s*days?\s*ago/);
|
|
485
633
|
if (numMatch) {
|
|
486
|
-
daysBack = Math.min(365, parseInt(numMatch[1], 10));
|
|
634
|
+
daysBack = Math.min(365, Number.parseInt(numMatch[1], 10));
|
|
487
635
|
} else {
|
|
488
636
|
const hrMatch = p.match(/(\d{1,5})\s*hours?\s*ago/);
|
|
489
637
|
if (hrMatch) {
|
|
490
|
-
daysBack = Math.max(1, Math.ceil(parseInt(hrMatch[1], 10) / 24));
|
|
638
|
+
daysBack = Math.max(1, Math.ceil(Number.parseInt(hrMatch[1], 10) / 24));
|
|
491
639
|
}
|
|
492
640
|
}
|
|
493
641
|
}
|
|
@@ -498,7 +646,7 @@ function recencyWindowFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
498
646
|
}
|
|
499
647
|
const usMatch = p.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/);
|
|
500
648
|
if (usMatch) {
|
|
501
|
-
const year = usMatch[3].length === 2 ? 2e3 + parseInt(usMatch[3], 10) : parseInt(usMatch[3], 10);
|
|
649
|
+
const year = usMatch[3].length === 2 ? 2e3 + Number.parseInt(usMatch[3], 10) : Number.parseInt(usMatch[3], 10);
|
|
502
650
|
return `${year}-${usMatch[1].padStart(2, "0")}-${usMatch[2].padStart(2, "0")}`;
|
|
503
651
|
}
|
|
504
652
|
const dayOfWeekMatch = p.match(/\blast\s+(monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/);
|
|
@@ -546,10 +694,12 @@ function recencyWindowBoundsFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
546
694
|
"november",
|
|
547
695
|
"december"
|
|
548
696
|
];
|
|
549
|
-
const monthMatch = p.match(
|
|
697
|
+
const monthMatch = p.match(
|
|
698
|
+
/\b(january|february|march|april|may|june|july|august|september|october|november|december)(?:\s+(\d{4}))?\b/
|
|
699
|
+
);
|
|
550
700
|
if (monthMatch) {
|
|
551
701
|
const monthIdx = monthNames.indexOf(monthMatch[1]);
|
|
552
|
-
const year = monthMatch[2] ? parseInt(monthMatch[2], 10) : now.getFullYear();
|
|
702
|
+
const year = monthMatch[2] ? Number.parseInt(monthMatch[2], 10) : now.getFullYear();
|
|
553
703
|
const isSinceOrAfter = /\b(since|after)\b/.test(p);
|
|
554
704
|
const isBefore = /\bbefore\b/.test(p);
|
|
555
705
|
if (isSinceOrAfter) {
|
|
@@ -563,15 +713,15 @@ function recencyWindowBoundsFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
563
713
|
let toDaysBack = -1;
|
|
564
714
|
const weekMatch = p.match(/(\d{1,5})\s*weeks?\s*ago/);
|
|
565
715
|
if (weekMatch) {
|
|
566
|
-
toDaysBack = Math.max(0, Math.min(52, parseInt(weekMatch[1], 10)) - 1) * 7;
|
|
716
|
+
toDaysBack = Math.max(0, Math.min(52, Number.parseInt(weekMatch[1], 10)) - 1) * 7;
|
|
567
717
|
} else {
|
|
568
718
|
const monthsAgoMatch = p.match(/(\d{1,5})\s*months?\s*ago/);
|
|
569
719
|
if (monthsAgoMatch) {
|
|
570
|
-
toDaysBack = Math.max(0, Math.min(24, parseInt(monthsAgoMatch[1], 10)) - 1) * 31;
|
|
720
|
+
toDaysBack = Math.max(0, Math.min(24, Number.parseInt(monthsAgoMatch[1], 10)) - 1) * 31;
|
|
571
721
|
} else {
|
|
572
722
|
const numMatch = p.match(/(\d{1,5})\s*days?\s*ago/);
|
|
573
723
|
if (numMatch) {
|
|
574
|
-
toDaysBack = Math.max(0, Math.min(365, parseInt(numMatch[1], 10)) - 1);
|
|
724
|
+
toDaysBack = Math.max(0, Math.min(365, Number.parseInt(numMatch[1], 10)) - 1);
|
|
575
725
|
} else {
|
|
576
726
|
const hrMatch = p.match(/(\d{1,5})\s*hours?\s*ago/);
|
|
577
727
|
if (hrMatch) {
|
|
@@ -587,7 +737,7 @@ function recencyWindowBoundsFromPrompt(prompt, nowMs = Date.now()) {
|
|
|
587
737
|
} else {
|
|
588
738
|
const usMatch = p.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/);
|
|
589
739
|
if (usMatch) {
|
|
590
|
-
const year = usMatch[3].length === 2 ? 2e3 + parseInt(usMatch[3], 10) : parseInt(usMatch[3], 10);
|
|
740
|
+
const year = usMatch[3].length === 2 ? 2e3 + Number.parseInt(usMatch[3], 10) : Number.parseInt(usMatch[3], 10);
|
|
591
741
|
const d = /* @__PURE__ */ new Date(`${year}-${usMatch[1].padStart(2, "0")}-${usMatch[2].padStart(2, "0")}T00:00:00Z`);
|
|
592
742
|
toDate = new Date(d.getTime() + 864e5).toISOString().slice(0, 10);
|
|
593
743
|
} else {
|
|
@@ -623,4 +773,4 @@ export {
|
|
|
623
773
|
recencyWindowFromPrompt,
|
|
624
774
|
recencyWindowBoundsFromPrompt
|
|
625
775
|
};
|
|
626
|
-
//# sourceMappingURL=chunk-
|
|
776
|
+
//# sourceMappingURL=chunk-WXACKLKP.js.map
|