nexus-agents 8.46.4 → 8.46.6
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/{ast-rule-runner-ODGZ3JZY.js → ast-rule-runner-ENNFRPS4.js} +3 -3
- package/dist/{child-mcp-config-L73W5MCX.js → child-mcp-config-Q3HTTXMZ.js} +2 -2
- package/dist/{chunk-ZII57VK4.js → chunk-2KEKNZOO.js} +2 -2
- package/dist/{chunk-A5MQ5FF4.js → chunk-2LO5BVCH.js} +7 -7
- package/dist/{chunk-H2BNQMYK.js → chunk-2QWHJXZ6.js} +2 -2
- package/dist/{chunk-P7BPGBJM.js → chunk-3IPZ5SPC.js} +5 -5
- package/dist/{chunk-JDSL3BGM.js → chunk-3WAYKX2L.js} +9 -9
- package/dist/{chunk-4H27PBKV.js → chunk-7RO52LJF.js} +2 -2
- package/dist/{chunk-FIG75K2B.js → chunk-7YM5D4F2.js} +3 -3
- package/dist/{chunk-X7ETIOZG.js → chunk-A7RVICRW.js} +2 -2
- package/dist/{chunk-FBBVRDK4.js → chunk-ATG4RSEH.js} +2 -2
- package/dist/{chunk-SBLNWD5V.js → chunk-AZSKRFB7.js} +4 -4
- package/dist/{chunk-3NAZYISV.js → chunk-DMFWCAXB.js} +2 -2
- package/dist/{chunk-HP4HIBBD.js → chunk-E5MTVRMV.js} +2 -2
- package/dist/{chunk-ALTDIXUX.js → chunk-EWEAJBFB.js} +2 -2
- package/dist/{chunk-23SIYJ56.js → chunk-HPG5SZOX.js} +4 -4
- package/dist/{chunk-W7AXQJNR.js → chunk-HPH77QTD.js} +2 -2
- package/dist/{chunk-II7NLF4Q.js → chunk-I2NOD7GW.js} +2 -2
- package/dist/{chunk-FK5THULN.js → chunk-IPMZAEPZ.js} +3 -3
- package/dist/{chunk-MSMKCCAD.js → chunk-JAUJ7PB4.js} +2 -2
- package/dist/{chunk-5H7SPGK7.js → chunk-KI4OIDBV.js} +4 -4
- package/dist/{chunk-732JANNS.js → chunk-KTLNUNDU.js} +2 -2
- package/dist/{chunk-VW3NK2DE.js → chunk-MIFCNJO6.js} +2 -2
- package/dist/{chunk-GPWTORER.js → chunk-NDH6MQMM.js} +6 -6
- package/dist/{chunk-WEXA77OT.js → chunk-NM3KSTH7.js} +2 -2
- package/dist/{chunk-HXQ3VKUO.js → chunk-NW4WPWZM.js} +8 -8
- package/dist/{chunk-YYJFZ7TO.js → chunk-PMOHJXRA.js} +260 -144
- package/dist/chunk-PMOHJXRA.js.map +1 -0
- package/dist/{chunk-YK4AB4OO.js → chunk-PRV5RSY5.js} +1107 -1075
- package/dist/chunk-PRV5RSY5.js.map +1 -0
- package/dist/{chunk-ZOU55MYG.js → chunk-QMZWUJ2I.js} +2 -2
- package/dist/{chunk-LFL2I5R7.js → chunk-RL3TZ4Y3.js} +6 -6
- package/dist/{chunk-FTLZG37P.js → chunk-RSLWBU7D.js} +2 -2
- package/dist/{chunk-V4RF47LZ.js → chunk-SEDQA6N5.js} +2 -2
- package/dist/{chunk-L6NP4YNS.js → chunk-SGIR6SBV.js} +2 -2
- package/dist/{chunk-INPRQQQK.js → chunk-SICXEQDA.js} +19 -6
- package/dist/{chunk-INPRQQQK.js.map → chunk-SICXEQDA.js.map} +1 -1
- package/dist/{chunk-DUF6QPTO.js → chunk-VP56PBMN.js} +3 -3
- package/dist/{chunk-Y633U7EJ.js → chunk-VY5V6GUW.js} +7 -7
- package/dist/{chunk-WTVA7SRV.js → chunk-YUMC7FOS.js} +5 -5
- package/dist/{chunk-M4Y2KBKB.js → chunk-ZUCCHUPM.js} +2 -2
- package/dist/{cli-circuit-breaker-BACT7C5F.js → cli-circuit-breaker-43R3IQPV.js} +3 -3
- package/dist/cli.js +45 -45
- package/dist/{composite-router-HYLUXT7U.js → composite-router-DT5FHIOJ.js} +2 -2
- package/dist/{consensus-vote-2YSLQTV2.js → consensus-vote-SPHM3DDZ.js} +19 -19
- package/dist/{context-retriever-UOSFEX4E.js → context-retriever-4VEN5UT3.js} +10 -10
- package/dist/{dist-TJCQ3JLP.js → dist-SAZAWYVP.js} +2 -2
- package/dist/{doctor-deep-SQQ4H2OV.js → doctor-deep-Z4MGK2BP.js} +3 -3
- package/dist/{doctor-live-DXYZSIPM.js → doctor-live-UGUWXT6Z.js} +9 -9
- package/dist/{expert-bridge-T2K3ZHIL.js → expert-bridge-C42WPTF6.js} +4 -4
- package/dist/{factory-I5BUOCTX.js → factory-NASBYAKW.js} +9 -9
- package/dist/{factory-MI6JZRQL.js → factory-UA5DZGHC.js} +5 -5
- package/dist/{improvement-review-3FTC27AP.js → improvement-review-2TLBC74T.js} +6 -6
- package/dist/index.d.ts +20 -1
- package/dist/index.js +33 -33
- package/dist/{init-opencode-VF4BC2HK.js → init-opencode-UTZY6BYY.js} +6 -6
- package/dist/issue-triage-PTD5H4PZ.js +17 -0
- package/dist/{pr-reviewer-helpers-IQIXZKXH.js → pr-reviewer-helpers-LQSGP46N.js} +4 -4
- package/dist/{registry-command-PLFFH6YS.js → registry-command-AWBOBXU2.js} +2 -2
- package/dist/{repo-security-plan-DZIBNTDL.js → repo-security-plan-TQVUCCQR.js} +3 -3
- package/dist/{research-helpers-synthesize-WWHRP2T3.js → research-helpers-synthesize-YABA2P4Q.js} +4 -4
- package/dist/{routing-memory-CCCVR5UQ.js → routing-memory-MWZHQWDB.js} +2 -2
- package/dist/{session-memory-6E5RCMYV.js → session-memory-QKWYDORW.js} +3 -3
- package/dist/{setup-config-ZIEZCZQS.js → setup-config-VFHABXQ6.js} +3 -3
- package/dist/{setup-custom-api-X5UQWWW6.js → setup-custom-api-BXJHOOPR.js} +4 -4
- package/dist/setup-data-dir-WU2FW33B.js +29 -0
- package/dist/{tool-memory-DC2NWW44.js → tool-memory-B5F2ZYR2.js} +7 -7
- package/dist/{tool-memory-registry-adapters-OUOO7OLE.js → tool-memory-registry-adapters-TP6U27K3.js} +3 -3
- package/dist/{unified-registry-ZURARKTX.js → unified-registry-OBDYGBM6.js} +10 -10
- package/dist/{weather-report-QWH6RRAX.js → weather-report-XEYT7LOW.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-YK4AB4OO.js.map +0 -1
- package/dist/chunk-YYJFZ7TO.js.map +0 -1
- package/dist/issue-triage-P532TIKZ.js +0 -17
- package/dist/setup-data-dir-3Q3P5V4B.js +0 -29
- /package/dist/{ast-rule-runner-ODGZ3JZY.js.map → ast-rule-runner-ENNFRPS4.js.map} +0 -0
- /package/dist/{child-mcp-config-L73W5MCX.js.map → child-mcp-config-Q3HTTXMZ.js.map} +0 -0
- /package/dist/{chunk-ZII57VK4.js.map → chunk-2KEKNZOO.js.map} +0 -0
- /package/dist/{chunk-A5MQ5FF4.js.map → chunk-2LO5BVCH.js.map} +0 -0
- /package/dist/{chunk-H2BNQMYK.js.map → chunk-2QWHJXZ6.js.map} +0 -0
- /package/dist/{chunk-P7BPGBJM.js.map → chunk-3IPZ5SPC.js.map} +0 -0
- /package/dist/{chunk-JDSL3BGM.js.map → chunk-3WAYKX2L.js.map} +0 -0
- /package/dist/{chunk-4H27PBKV.js.map → chunk-7RO52LJF.js.map} +0 -0
- /package/dist/{chunk-FIG75K2B.js.map → chunk-7YM5D4F2.js.map} +0 -0
- /package/dist/{chunk-X7ETIOZG.js.map → chunk-A7RVICRW.js.map} +0 -0
- /package/dist/{chunk-FBBVRDK4.js.map → chunk-ATG4RSEH.js.map} +0 -0
- /package/dist/{chunk-SBLNWD5V.js.map → chunk-AZSKRFB7.js.map} +0 -0
- /package/dist/{chunk-3NAZYISV.js.map → chunk-DMFWCAXB.js.map} +0 -0
- /package/dist/{chunk-HP4HIBBD.js.map → chunk-E5MTVRMV.js.map} +0 -0
- /package/dist/{chunk-ALTDIXUX.js.map → chunk-EWEAJBFB.js.map} +0 -0
- /package/dist/{chunk-23SIYJ56.js.map → chunk-HPG5SZOX.js.map} +0 -0
- /package/dist/{chunk-W7AXQJNR.js.map → chunk-HPH77QTD.js.map} +0 -0
- /package/dist/{chunk-II7NLF4Q.js.map → chunk-I2NOD7GW.js.map} +0 -0
- /package/dist/{chunk-FK5THULN.js.map → chunk-IPMZAEPZ.js.map} +0 -0
- /package/dist/{chunk-MSMKCCAD.js.map → chunk-JAUJ7PB4.js.map} +0 -0
- /package/dist/{chunk-5H7SPGK7.js.map → chunk-KI4OIDBV.js.map} +0 -0
- /package/dist/{chunk-732JANNS.js.map → chunk-KTLNUNDU.js.map} +0 -0
- /package/dist/{chunk-VW3NK2DE.js.map → chunk-MIFCNJO6.js.map} +0 -0
- /package/dist/{chunk-GPWTORER.js.map → chunk-NDH6MQMM.js.map} +0 -0
- /package/dist/{chunk-WEXA77OT.js.map → chunk-NM3KSTH7.js.map} +0 -0
- /package/dist/{chunk-HXQ3VKUO.js.map → chunk-NW4WPWZM.js.map} +0 -0
- /package/dist/{chunk-ZOU55MYG.js.map → chunk-QMZWUJ2I.js.map} +0 -0
- /package/dist/{chunk-LFL2I5R7.js.map → chunk-RL3TZ4Y3.js.map} +0 -0
- /package/dist/{chunk-FTLZG37P.js.map → chunk-RSLWBU7D.js.map} +0 -0
- /package/dist/{chunk-V4RF47LZ.js.map → chunk-SEDQA6N5.js.map} +0 -0
- /package/dist/{chunk-L6NP4YNS.js.map → chunk-SGIR6SBV.js.map} +0 -0
- /package/dist/{chunk-DUF6QPTO.js.map → chunk-VP56PBMN.js.map} +0 -0
- /package/dist/{chunk-Y633U7EJ.js.map → chunk-VY5V6GUW.js.map} +0 -0
- /package/dist/{chunk-WTVA7SRV.js.map → chunk-YUMC7FOS.js.map} +0 -0
- /package/dist/{chunk-M4Y2KBKB.js.map → chunk-ZUCCHUPM.js.map} +0 -0
- /package/dist/{cli-circuit-breaker-BACT7C5F.js.map → cli-circuit-breaker-43R3IQPV.js.map} +0 -0
- /package/dist/{composite-router-HYLUXT7U.js.map → composite-router-DT5FHIOJ.js.map} +0 -0
- /package/dist/{consensus-vote-2YSLQTV2.js.map → consensus-vote-SPHM3DDZ.js.map} +0 -0
- /package/dist/{context-retriever-UOSFEX4E.js.map → context-retriever-4VEN5UT3.js.map} +0 -0
- /package/dist/{dist-TJCQ3JLP.js.map → dist-SAZAWYVP.js.map} +0 -0
- /package/dist/{doctor-deep-SQQ4H2OV.js.map → doctor-deep-Z4MGK2BP.js.map} +0 -0
- /package/dist/{doctor-live-DXYZSIPM.js.map → doctor-live-UGUWXT6Z.js.map} +0 -0
- /package/dist/{expert-bridge-T2K3ZHIL.js.map → expert-bridge-C42WPTF6.js.map} +0 -0
- /package/dist/{factory-I5BUOCTX.js.map → factory-NASBYAKW.js.map} +0 -0
- /package/dist/{factory-MI6JZRQL.js.map → factory-UA5DZGHC.js.map} +0 -0
- /package/dist/{improvement-review-3FTC27AP.js.map → improvement-review-2TLBC74T.js.map} +0 -0
- /package/dist/{init-opencode-VF4BC2HK.js.map → init-opencode-UTZY6BYY.js.map} +0 -0
- /package/dist/{issue-triage-P532TIKZ.js.map → issue-triage-PTD5H4PZ.js.map} +0 -0
- /package/dist/{pr-reviewer-helpers-IQIXZKXH.js.map → pr-reviewer-helpers-LQSGP46N.js.map} +0 -0
- /package/dist/{registry-command-PLFFH6YS.js.map → registry-command-AWBOBXU2.js.map} +0 -0
- /package/dist/{repo-security-plan-DZIBNTDL.js.map → repo-security-plan-TQVUCCQR.js.map} +0 -0
- /package/dist/{research-helpers-synthesize-WWHRP2T3.js.map → research-helpers-synthesize-YABA2P4Q.js.map} +0 -0
- /package/dist/{routing-memory-CCCVR5UQ.js.map → routing-memory-MWZHQWDB.js.map} +0 -0
- /package/dist/{session-memory-6E5RCMYV.js.map → session-memory-QKWYDORW.js.map} +0 -0
- /package/dist/{setup-config-ZIEZCZQS.js.map → setup-config-VFHABXQ6.js.map} +0 -0
- /package/dist/{setup-custom-api-X5UQWWW6.js.map → setup-custom-api-BXJHOOPR.js.map} +0 -0
- /package/dist/{setup-data-dir-3Q3P5V4B.js.map → setup-data-dir-WU2FW33B.js.map} +0 -0
- /package/dist/{tool-memory-DC2NWW44.js.map → tool-memory-B5F2ZYR2.js.map} +0 -0
- /package/dist/{tool-memory-registry-adapters-OUOO7OLE.js.map → tool-memory-registry-adapters-TP6U27K3.js.map} +0 -0
- /package/dist/{unified-registry-ZURARKTX.js.map → unified-registry-OBDYGBM6.js.map} +0 -0
- /package/dist/{weather-report-QWH6RRAX.js.map → weather-report-XEYT7LOW.js.map} +0 -0
|
@@ -31,17 +31,20 @@ function truncate(value, limit) {
|
|
|
31
31
|
}
|
|
32
32
|
return s.length > limit ? `${s.slice(0, limit - 1)}\u2026` : s;
|
|
33
33
|
}
|
|
34
|
+
function emptyCounter(domain, op) {
|
|
35
|
+
return { domain, op, count: 0, errorCount: 0, hitCount: 0, totalDurationMs: 0, maxDurationMs: 0 };
|
|
36
|
+
}
|
|
34
37
|
function updateCounter(event) {
|
|
35
38
|
const ck = counterKey(event.domain, event.op);
|
|
36
|
-
const
|
|
37
|
-
const hitDelta = event.hit === true ? 1 : 0;
|
|
39
|
+
const prev = counters.get(ck) ?? emptyCounter(event.domain, event.op);
|
|
38
40
|
counters.set(ck, {
|
|
39
|
-
domain:
|
|
40
|
-
op:
|
|
41
|
-
count:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
domain: prev.domain,
|
|
42
|
+
op: prev.op,
|
|
43
|
+
count: prev.count + 1,
|
|
44
|
+
errorCount: prev.errorCount + (event.error !== void 0 ? 1 : 0),
|
|
45
|
+
hitCount: prev.hitCount + (event.hit === true ? 1 : 0),
|
|
46
|
+
totalDurationMs: prev.totalDurationMs + event.durationMs,
|
|
47
|
+
maxDurationMs: Math.max(prev.maxDurationMs, event.durationMs)
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
function buildPublicEvent(event, audit) {
|
|
@@ -49,6 +52,9 @@ function buildPublicEvent(event, audit) {
|
|
|
49
52
|
domain: event.domain,
|
|
50
53
|
op: event.op,
|
|
51
54
|
durationMs: event.durationMs,
|
|
55
|
+
// #5965: without this the counter records a failure the subscriber never
|
|
56
|
+
// sees — two instruments disagreeing about the same operation.
|
|
57
|
+
...event.error !== void 0 && { error: event.error },
|
|
52
58
|
...event.cli !== void 0 && { cli: event.cli },
|
|
53
59
|
...event.hit !== void 0 && { hit: event.hit },
|
|
54
60
|
...audit && event.key !== void 0 && {
|
|
@@ -85,6 +91,22 @@ function resetMemoryTelemetry() {
|
|
|
85
91
|
counters.clear();
|
|
86
92
|
listeners.clear();
|
|
87
93
|
}
|
|
94
|
+
function recordFailedMemoryOp(context, start, body) {
|
|
95
|
+
try {
|
|
96
|
+
return body();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
recordMemoryEvent({
|
|
99
|
+
domain: context.domain,
|
|
100
|
+
op: context.op,
|
|
101
|
+
...context.cli !== void 0 && { cli: context.cli },
|
|
102
|
+
durationMs: Date.now() - start,
|
|
103
|
+
// Message only — a validation error's detail can quote the value that
|
|
104
|
+
// failed, and that value is caller payload.
|
|
105
|
+
error: error instanceof Error ? error.message : String(error)
|
|
106
|
+
});
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
88
110
|
var MemoryValidationError = class extends Error {
|
|
89
111
|
constructor(domain, cause) {
|
|
90
112
|
super(`nexus-memory: write rejected for domain "${domain}": ${String(cause)}`);
|
|
@@ -140,18 +162,27 @@ var InMemoryBackend = class {
|
|
|
140
162
|
}
|
|
141
163
|
}
|
|
142
164
|
async read(key) {
|
|
143
|
-
this.assertOpen();
|
|
144
165
|
const start = Date.now();
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
return recordFailedMemoryOp(
|
|
167
|
+
{
|
|
168
|
+
domain: this.domain,
|
|
169
|
+
op: "read"
|
|
170
|
+
},
|
|
171
|
+
start,
|
|
172
|
+
() => {
|
|
173
|
+
this.assertOpen();
|
|
174
|
+
const row = this.rows.get(key);
|
|
175
|
+
recordMemoryEvent({
|
|
176
|
+
domain: this.domain,
|
|
177
|
+
op: "read",
|
|
178
|
+
hit: row !== void 0,
|
|
179
|
+
durationMs: Date.now() - start,
|
|
180
|
+
key,
|
|
181
|
+
result: row?.value
|
|
182
|
+
});
|
|
183
|
+
return Promise.resolve(row?.value);
|
|
184
|
+
}
|
|
185
|
+
);
|
|
155
186
|
}
|
|
156
187
|
validate(value) {
|
|
157
188
|
if (value === void 0) {
|
|
@@ -164,72 +195,110 @@ var InMemoryBackend = class {
|
|
|
164
195
|
}
|
|
165
196
|
}
|
|
166
197
|
async write(key, value, meta) {
|
|
167
|
-
this.assertOpen();
|
|
168
198
|
const start = Date.now();
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
199
|
+
return recordFailedMemoryOp(
|
|
200
|
+
{
|
|
201
|
+
domain: this.domain,
|
|
202
|
+
op: "write",
|
|
203
|
+
...meta?.cli !== void 0 && { cli: meta.cli }
|
|
204
|
+
},
|
|
205
|
+
start,
|
|
206
|
+
() => {
|
|
207
|
+
this.assertOpen();
|
|
208
|
+
this.validate(value);
|
|
209
|
+
this.rows.set(key, buildInMemoryRow(value, meta));
|
|
210
|
+
recordMemoryEvent({
|
|
211
|
+
domain: this.domain,
|
|
212
|
+
op: "write",
|
|
213
|
+
...meta?.cli !== void 0 && { cli: meta.cli },
|
|
214
|
+
durationMs: Date.now() - start,
|
|
215
|
+
key,
|
|
216
|
+
payload: value
|
|
217
|
+
});
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
}
|
|
220
|
+
);
|
|
180
221
|
}
|
|
181
222
|
async query(filter) {
|
|
182
|
-
this.assertOpen();
|
|
183
223
|
const start = Date.now();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
224
|
+
return recordFailedMemoryOp(
|
|
225
|
+
{
|
|
226
|
+
domain: this.domain,
|
|
227
|
+
op: "query",
|
|
228
|
+
...filter?.cli !== void 0 && { cli: filter.cli }
|
|
229
|
+
},
|
|
230
|
+
start,
|
|
231
|
+
() => {
|
|
232
|
+
this.assertOpen();
|
|
233
|
+
let rows = [...this.rows.values()];
|
|
234
|
+
if (filter?.cli !== void 0) {
|
|
235
|
+
rows = rows.filter((r) => r.cli === filter.cli);
|
|
236
|
+
}
|
|
237
|
+
const values = applyInMemoryFilter(
|
|
238
|
+
rows.map((r) => r.value),
|
|
239
|
+
filter
|
|
240
|
+
);
|
|
241
|
+
recordMemoryEvent({
|
|
242
|
+
domain: this.domain,
|
|
243
|
+
op: "query",
|
|
244
|
+
hit: values.length > 0,
|
|
245
|
+
...filter?.cli !== void 0 && { cli: filter.cli },
|
|
246
|
+
durationMs: Date.now() - start,
|
|
247
|
+
key: filter,
|
|
248
|
+
result: { count: values.length }
|
|
249
|
+
});
|
|
250
|
+
return Promise.resolve(values);
|
|
251
|
+
}
|
|
191
252
|
);
|
|
192
|
-
recordMemoryEvent({
|
|
193
|
-
domain: this.domain,
|
|
194
|
-
op: "query",
|
|
195
|
-
hit: values.length > 0,
|
|
196
|
-
...filter?.cli !== void 0 && { cli: filter.cli },
|
|
197
|
-
durationMs: Date.now() - start,
|
|
198
|
-
key: filter,
|
|
199
|
-
result: { count: values.length }
|
|
200
|
-
});
|
|
201
|
-
return Promise.resolve(values);
|
|
202
253
|
}
|
|
203
254
|
async delete(key) {
|
|
204
|
-
this.assertOpen();
|
|
205
255
|
const start = Date.now();
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
256
|
+
return recordFailedMemoryOp(
|
|
257
|
+
{
|
|
258
|
+
domain: this.domain,
|
|
259
|
+
op: "delete"
|
|
260
|
+
},
|
|
261
|
+
start,
|
|
262
|
+
() => {
|
|
263
|
+
this.assertOpen();
|
|
264
|
+
const removed = this.rows.delete(key);
|
|
265
|
+
recordMemoryEvent({
|
|
266
|
+
domain: this.domain,
|
|
267
|
+
op: "delete",
|
|
268
|
+
hit: removed,
|
|
269
|
+
durationMs: Date.now() - start,
|
|
270
|
+
key
|
|
271
|
+
});
|
|
272
|
+
return Promise.resolve(removed);
|
|
273
|
+
}
|
|
274
|
+
);
|
|
215
275
|
}
|
|
216
276
|
async stats() {
|
|
217
|
-
this.assertOpen();
|
|
218
277
|
const start = Date.now();
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
278
|
+
return recordFailedMemoryOp(
|
|
279
|
+
{
|
|
280
|
+
domain: this.domain,
|
|
281
|
+
op: "stats"
|
|
282
|
+
},
|
|
283
|
+
start,
|
|
284
|
+
() => {
|
|
285
|
+
this.assertOpen();
|
|
286
|
+
const timestamps = [...this.rows.values()].map((r) => r.timestamp);
|
|
287
|
+
const result = {
|
|
288
|
+
domain: this.domain,
|
|
289
|
+
count: this.rows.size,
|
|
290
|
+
oldestTimestamp: timestamps.length > 0 ? Math.min(...timestamps) : null,
|
|
291
|
+
newestTimestamp: timestamps.length > 0 ? Math.max(...timestamps) : null
|
|
292
|
+
};
|
|
293
|
+
recordMemoryEvent({
|
|
294
|
+
domain: this.domain,
|
|
295
|
+
op: "stats",
|
|
296
|
+
durationMs: Date.now() - start,
|
|
297
|
+
result
|
|
298
|
+
});
|
|
299
|
+
return Promise.resolve(result);
|
|
300
|
+
}
|
|
301
|
+
);
|
|
233
302
|
}
|
|
234
303
|
async close() {
|
|
235
304
|
this.closed = true;
|
|
@@ -377,20 +446,29 @@ var SqliteBackend = class {
|
|
|
377
446
|
};
|
|
378
447
|
}
|
|
379
448
|
async read(key) {
|
|
380
|
-
this.assertOpen();
|
|
381
449
|
const start = Date.now();
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
450
|
+
return recordFailedMemoryOp(
|
|
451
|
+
{
|
|
452
|
+
domain: this.domain,
|
|
453
|
+
op: "read"
|
|
454
|
+
},
|
|
455
|
+
start,
|
|
456
|
+
() => {
|
|
457
|
+
this.assertOpen();
|
|
458
|
+
const row = this.stmts.read.get(keyToString(key));
|
|
459
|
+
const value = row !== void 0 ? JSON.parse(row.value) : void 0;
|
|
460
|
+
recordMemoryEvent({
|
|
461
|
+
domain: this.domain,
|
|
462
|
+
op: "read",
|
|
463
|
+
hit: value !== void 0,
|
|
464
|
+
...row?.cli !== null && row?.cli !== void 0 && { cli: row.cli },
|
|
465
|
+
durationMs: Date.now() - start,
|
|
466
|
+
key,
|
|
467
|
+
result: value
|
|
468
|
+
});
|
|
469
|
+
return Promise.resolve(value);
|
|
470
|
+
}
|
|
471
|
+
);
|
|
394
472
|
}
|
|
395
473
|
validate(value) {
|
|
396
474
|
if (value === void 0) {
|
|
@@ -403,72 +481,110 @@ var SqliteBackend = class {
|
|
|
403
481
|
}
|
|
404
482
|
}
|
|
405
483
|
async write(key, value, meta) {
|
|
406
|
-
this.assertOpen();
|
|
407
484
|
const start = Date.now();
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
485
|
+
return recordFailedMemoryOp(
|
|
486
|
+
{
|
|
487
|
+
domain: this.domain,
|
|
488
|
+
op: "write",
|
|
489
|
+
...meta?.cli !== void 0 && { cli: meta.cli }
|
|
490
|
+
},
|
|
491
|
+
start,
|
|
492
|
+
() => {
|
|
493
|
+
this.assertOpen();
|
|
494
|
+
this.validate(value);
|
|
495
|
+
this.stmts.write.run(buildWriteRow(key, value, meta));
|
|
496
|
+
recordMemoryEvent({
|
|
497
|
+
domain: this.domain,
|
|
498
|
+
op: "write",
|
|
499
|
+
...meta?.cli !== void 0 && { cli: meta.cli },
|
|
500
|
+
durationMs: Date.now() - start,
|
|
501
|
+
key,
|
|
502
|
+
payload: value
|
|
503
|
+
});
|
|
504
|
+
return Promise.resolve();
|
|
505
|
+
}
|
|
506
|
+
);
|
|
419
507
|
}
|
|
420
508
|
async query(filter) {
|
|
421
|
-
this.assertOpen();
|
|
422
509
|
const start = Date.now();
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
510
|
+
return recordFailedMemoryOp(
|
|
511
|
+
{
|
|
512
|
+
domain: this.domain,
|
|
513
|
+
op: "query",
|
|
514
|
+
...filter?.cli !== void 0 && { cli: filter.cli }
|
|
515
|
+
},
|
|
516
|
+
start,
|
|
517
|
+
() => {
|
|
518
|
+
this.assertOpen();
|
|
519
|
+
let rows = this.stmts.queryAll.all();
|
|
520
|
+
if (filter?.cli !== void 0) {
|
|
521
|
+
rows = rows.filter((r) => r.cli === filter.cli);
|
|
522
|
+
}
|
|
523
|
+
let values = rows.map((r) => JSON.parse(r.value));
|
|
524
|
+
values = applyQueryFilter(values, filter);
|
|
525
|
+
recordMemoryEvent({
|
|
526
|
+
domain: this.domain,
|
|
527
|
+
op: "query",
|
|
528
|
+
hit: values.length > 0,
|
|
529
|
+
...filter?.cli !== void 0 && { cli: filter.cli },
|
|
530
|
+
durationMs: Date.now() - start,
|
|
531
|
+
key: filter,
|
|
532
|
+
result: { count: values.length }
|
|
533
|
+
});
|
|
534
|
+
return Promise.resolve(values);
|
|
535
|
+
}
|
|
536
|
+
);
|
|
439
537
|
}
|
|
440
538
|
async delete(key) {
|
|
441
|
-
this.assertOpen();
|
|
442
539
|
const start = Date.now();
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
540
|
+
return recordFailedMemoryOp(
|
|
541
|
+
{
|
|
542
|
+
domain: this.domain,
|
|
543
|
+
op: "delete"
|
|
544
|
+
},
|
|
545
|
+
start,
|
|
546
|
+
() => {
|
|
547
|
+
this.assertOpen();
|
|
548
|
+
const result = this.stmts.delete.run(keyToString(key));
|
|
549
|
+
const removed = result.changes > 0;
|
|
550
|
+
recordMemoryEvent({
|
|
551
|
+
domain: this.domain,
|
|
552
|
+
op: "delete",
|
|
553
|
+
hit: removed,
|
|
554
|
+
durationMs: Date.now() - start,
|
|
555
|
+
key
|
|
556
|
+
});
|
|
557
|
+
return Promise.resolve(removed);
|
|
558
|
+
}
|
|
559
|
+
);
|
|
453
560
|
}
|
|
454
561
|
async stats() {
|
|
455
|
-
this.assertOpen();
|
|
456
562
|
const start = Date.now();
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
563
|
+
return recordFailedMemoryOp(
|
|
564
|
+
{
|
|
565
|
+
domain: this.domain,
|
|
566
|
+
op: "stats"
|
|
567
|
+
},
|
|
568
|
+
start,
|
|
569
|
+
() => {
|
|
570
|
+
this.assertOpen();
|
|
571
|
+
const countRow = this.stmts.count.get();
|
|
572
|
+
const boundsRow = this.stmts.bounds.get();
|
|
573
|
+
const result = {
|
|
574
|
+
domain: this.domain,
|
|
575
|
+
count: countRow.count,
|
|
576
|
+
oldestTimestamp: boundsRow.oldest,
|
|
577
|
+
newestTimestamp: boundsRow.newest
|
|
578
|
+
};
|
|
579
|
+
recordMemoryEvent({
|
|
580
|
+
domain: this.domain,
|
|
581
|
+
op: "stats",
|
|
582
|
+
durationMs: Date.now() - start,
|
|
583
|
+
result
|
|
584
|
+
});
|
|
585
|
+
return Promise.resolve(result);
|
|
586
|
+
}
|
|
587
|
+
);
|
|
472
588
|
}
|
|
473
589
|
async close() {
|
|
474
590
|
if (this.closed) return Promise.resolve();
|
|
@@ -668,4 +784,4 @@ export {
|
|
|
668
784
|
runImporters,
|
|
669
785
|
backupSourceFile
|
|
670
786
|
};
|
|
671
|
-
//# sourceMappingURL=chunk-
|
|
787
|
+
//# sourceMappingURL=chunk-PMOHJXRA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../nexus-memory/src/telemetry.ts","../../nexus-memory/src/backends/memory.ts","../../nexus-memory/src/backends/open-database.ts","../../nexus-memory/src/backends/sqlite.ts","../../nexus-memory/src/registry.ts","../../nexus-memory/src/factory.ts","../../nexus-memory/src/importer.ts"],"sourcesContent":["/**\n * Memory telemetry — aggregated counters (default) + opt-in full-audit mode.\n *\n * Phase 2 vote (#2768) settled on **C**: per-`{domain, op}` counters in\n * steady state, full per-event payloads when `NEXUS_MEMORY_AUDIT_MODE=audit`.\n *\n * The catfish-mitigation requirement is honored: audit mode emits\n * `{ op, keySummary, payloadSummary, resultSummary, cli, durationMs, hit }`\n * — not just counters — so an incident replay can reconstruct individual\n * ops. Summaries are truncated to keep emission cheap.\n *\n * @module nexus-memory/telemetry\n */\n\nimport type { CliName, MemoryEvent, MemoryEventCounters, MemoryEventListener } from './types.js';\n\nconst KEY_SUMMARY_LIMIT = 120;\nconst PAYLOAD_SUMMARY_LIMIT = 240;\n\n/** Per-`{domain, op}` rolling counters. */\nconst counters = new Map<string, MemoryEventCounters>();\nconst listeners = new Set<MemoryEventListener>();\n\n/** Audit mode is opt-in via env. Checked once per emission so the env\n * can be toggled at runtime by tests via `process.env`. */\nfunction isAuditMode(): boolean {\n return process.env['NEXUS_MEMORY_AUDIT_MODE'] === 'audit';\n}\n\nfunction counterKey(domain: string, op: MemoryEvent['op']): string {\n return `${domain}::${op}`;\n}\n\nfunction truncate(value: unknown, limit: number): string {\n let s: string;\n if (typeof value === 'string') {\n s = value;\n } else if (value === undefined) {\n s = '<undefined>';\n } else if (value === null) {\n s = '<null>';\n } else {\n try {\n s = JSON.stringify(value);\n } catch {\n s = '<unserializable>';\n }\n }\n return s.length > limit ? `${s.slice(0, limit - 1)}…` : s;\n}\n\ninterface RecordedEvent extends Omit<\n MemoryEvent,\n 'keySummary' | 'payloadSummary' | 'resultSummary'\n> {\n readonly key?: unknown;\n readonly payload?: unknown;\n readonly result?: unknown;\n}\n\n/** The zero row a domain/op starts from — every field named, none defaulted implicitly. */\nfunction emptyCounter(domain: string, op: MemoryEvent['op']): MemoryEventCounters {\n return { domain, op, count: 0, errorCount: 0, hitCount: 0, totalDurationMs: 0, maxDurationMs: 0 };\n}\n\nfunction updateCounter(event: RecordedEvent): void {\n const ck = counterKey(event.domain, event.op);\n const prev = counters.get(ck) ?? emptyCounter(event.domain, event.op);\n counters.set(ck, {\n domain: prev.domain,\n op: prev.op,\n count: prev.count + 1,\n errorCount: prev.errorCount + (event.error !== undefined ? 1 : 0),\n hitCount: prev.hitCount + (event.hit === true ? 1 : 0),\n totalDurationMs: prev.totalDurationMs + event.durationMs,\n maxDurationMs: Math.max(prev.maxDurationMs, event.durationMs),\n });\n}\n\nfunction buildPublicEvent(event: RecordedEvent, audit: boolean): MemoryEvent {\n return {\n domain: event.domain,\n op: event.op,\n durationMs: event.durationMs,\n // #5965: without this the counter records a failure the subscriber never\n // sees — two instruments disagreeing about the same operation.\n ...(event.error !== undefined && { error: event.error }),\n ...(event.cli !== undefined && { cli: event.cli }),\n ...(event.hit !== undefined && { hit: event.hit }),\n ...(audit &&\n event.key !== undefined && {\n keySummary: truncate(event.key, KEY_SUMMARY_LIMIT),\n }),\n ...(audit &&\n event.payload !== undefined && {\n payloadSummary: truncate(event.payload, PAYLOAD_SUMMARY_LIMIT),\n }),\n ...(audit &&\n event.result !== undefined && {\n resultSummary: truncate(event.result, PAYLOAD_SUMMARY_LIMIT),\n }),\n };\n}\n\n/**\n * Record a memory operation, successful or not. Updates counters always;\n * emits the event to subscribers always (subscribers get the full event in\n * audit mode, the aggregate-only event otherwise).\n *\n * \"Always\" is load-bearing and was not true until #5965: every backend called\n * this AFTER the work, so a throw skipped it entirely.\n *\n * Implementation note: the `op` argument is the typed `MemoryEvent['op']`\n * literal — backends never pass an unknown string here.\n */\nexport function recordMemoryEvent(event: RecordedEvent): void {\n updateCounter(event);\n const publicEvent = buildPublicEvent(event, isAuditMode());\n for (const listener of listeners) {\n try {\n listener(publicEvent);\n } catch {\n // Subscriber failures must never affect memory operations.\n }\n }\n}\n\n/** Snapshot of current counters. Returned array is a copy. */\nexport function getMemoryEventCounters(): readonly MemoryEventCounters[] {\n return [...counters.values()];\n}\n\n/** Subscribe to the per-event stream. Returns an unsubscribe function. */\nexport function subscribeToMemoryEvents(listener: MemoryEventListener): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\n/**\n * Reset counters + drop all subscribers. Tests should call this in\n * `beforeEach` to keep state from leaking.\n */\nexport function resetMemoryTelemetry(): void {\n counters.clear();\n listeners.clear();\n}\n\n/**\n * Runs one backend operation and records it even when it throws (#5965).\n *\n * The record call used to sit after the work, so a `MemoryValidationError`, a\n * SQLite constraint or disk error, or a call on a closed backend produced no\n * event and no counter row at all — a domain rejecting every write looked\n * exactly like a domain nobody was using. The event is emitted BEFORE the\n * error is re-thrown, so the caller's own error handling is unchanged.\n *\n * The success event stays at each call site: only the caller knows the `hit`,\n * `key`, `payload` and `result` a successful op should carry.\n */\nexport function recordFailedMemoryOp<T>(\n context: { readonly domain: string; readonly op: MemoryEvent['op']; readonly cli?: CliName },\n start: number,\n body: () => T\n): T {\n try {\n return body();\n } catch (error) {\n recordMemoryEvent({\n domain: context.domain,\n op: context.op,\n ...(context.cli !== undefined && { cli: context.cli }),\n durationMs: Date.now() - start,\n // Message only — a validation error's detail can quote the value that\n // failed, and that value is caller payload.\n error: error instanceof Error ? error.message : String(error),\n });\n throw error;\n }\n}\n","/**\n * In-memory backend — primarily for tests, but also used as the cold-archive\n * fallback when no `dbPath` is provided.\n *\n * Implements {@link IMemoryBackend}; passes the same contract test as\n * {@link SqliteBackend}.\n *\n * @module nexus-memory/backends/memory\n */\n\nimport type { z } from 'zod';\nimport { recordFailedMemoryOp, recordMemoryEvent } from '../telemetry.js';\nimport type { BackendStats, IMemoryBackend, QueryFilter, WriteMeta } from '../types.js';\n\ninterface Row<TValue> {\n readonly value: TValue;\n readonly cli?: string;\n readonly source?: string;\n readonly timestamp: number;\n readonly trustTier?: 1 | 2 | 3 | 4;\n}\n\nexport interface InMemoryBackendOptions<TValue> {\n readonly domain: string;\n /**\n * Optional Zod schema. Phase 2 vote mitigation #1 (security dissent):\n * when supplied, every `write()` validates the value first; invalid\n * payloads throw `MemoryValidationError`.\n */\n readonly schema?: z.ZodType<TValue>;\n}\n\nexport class MemoryValidationError extends Error {\n constructor(domain: string, cause: unknown) {\n super(`nexus-memory: write rejected for domain \"${domain}\": ${String(cause)}`);\n this.name = 'MemoryValidationError';\n }\n}\n\nfunction buildInMemoryRow<TValue>(value: TValue, meta: WriteMeta | undefined): Row<TValue> {\n return {\n value,\n ...(meta?.cli !== undefined && { cli: meta.cli }),\n ...(meta?.source !== undefined && { source: meta.source }),\n timestamp: meta?.timestamp ?? Date.now(),\n ...(meta?.trustTier !== undefined && { trustTier: meta.trustTier }),\n };\n}\n\n/** Apply `where`, `orderBy`, `limit` to an in-memory row set. Extracted from\n * `query` to satisfy the eslint complexity gate. */\nfunction applyInMemoryFilter<T>(values: T[], filter?: QueryFilter<T>): T[] {\n let out = values;\n if (filter?.where !== undefined) {\n const where = filter.where;\n out = out.filter((v) => {\n for (const [k, expected] of Object.entries(where)) {\n if ((v as Record<string, unknown>)[k] !== expected) return false;\n }\n return true;\n });\n }\n if (filter?.orderBy !== undefined) {\n const orderBy = filter.orderBy;\n const dir = filter.orderDir === 'desc' ? -1 : 1;\n out = [...out].sort((a, b) => {\n const av = (a as Record<string | symbol | number, unknown>)[orderBy];\n const bv = (b as Record<string | symbol | number, unknown>)[orderBy];\n if (av === bv) return 0;\n if (av === undefined || av === null) return 1;\n if (bv === undefined || bv === null) return -1;\n return (av < bv ? -1 : 1) * dir;\n });\n }\n if (filter?.limit !== undefined) {\n out = out.slice(0, filter.limit);\n }\n return out;\n}\n\nexport class InMemoryBackend<TKey, TValue> implements IMemoryBackend<TKey, TValue> {\n readonly domain: string;\n private readonly rows = new Map<TKey, Row<TValue>>();\n private readonly schema?: z.ZodType<TValue>;\n private closed = false;\n\n constructor(options: InMemoryBackendOptions<TValue>) {\n this.domain = options.domain;\n if (options.schema !== undefined) {\n this.schema = options.schema;\n }\n }\n\n async read(key: TKey): Promise<TValue | undefined> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'read',\n },\n start,\n () => {\n this.assertOpen();\n const row = this.rows.get(key);\n recordMemoryEvent({\n domain: this.domain,\n op: 'read',\n hit: row !== undefined,\n durationMs: Date.now() - start,\n key,\n result: row?.value,\n });\n return Promise.resolve(row?.value);\n }\n );\n }\n\n private validate(value: TValue): void {\n // #4021: reject `undefined` uniformly (before the optional schema check) so\n // both backends behave identically. Previously this backend stored a phantom\n // row for `write(key, undefined)` while SqliteBackend threw a cryptic NOT NULL\n // bind error — a contract divergence. `undefined` is the missing-key sentinel\n // `read` returns; an explicit `undefined` write is a caller bug — use `null`.\n if (value === undefined) {\n throw new MemoryValidationError(this.domain, 'value must not be undefined (use null)');\n }\n if (this.schema === undefined) return;\n const result = this.schema.safeParse(value);\n if (!result.success) {\n throw new MemoryValidationError(this.domain, result.error);\n }\n }\n\n async write(key: TKey, value: TValue, meta?: WriteMeta): Promise<void> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'write',\n ...(meta?.cli !== undefined && { cli: meta.cli }),\n },\n start,\n () => {\n this.assertOpen();\n this.validate(value);\n this.rows.set(key, buildInMemoryRow(value, meta));\n recordMemoryEvent({\n domain: this.domain,\n op: 'write',\n ...(meta?.cli !== undefined && { cli: meta.cli }),\n durationMs: Date.now() - start,\n key,\n payload: value,\n });\n return Promise.resolve();\n }\n );\n }\n\n async query(filter?: QueryFilter<TValue>): Promise<readonly TValue[]> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'query',\n ...(filter?.cli !== undefined && { cli: filter.cli }),\n },\n start,\n () => {\n this.assertOpen();\n let rows = [...this.rows.values()];\n if (filter?.cli !== undefined) {\n rows = rows.filter((r) => r.cli === filter.cli);\n }\n const values = applyInMemoryFilter(\n rows.map((r) => r.value),\n filter\n );\n recordMemoryEvent({\n domain: this.domain,\n op: 'query',\n hit: values.length > 0,\n ...(filter?.cli !== undefined && { cli: filter.cli }),\n durationMs: Date.now() - start,\n key: filter,\n result: { count: values.length },\n });\n return Promise.resolve(values);\n }\n );\n }\n\n async delete(key: TKey): Promise<boolean> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'delete',\n },\n start,\n () => {\n this.assertOpen();\n const removed = this.rows.delete(key);\n recordMemoryEvent({\n domain: this.domain,\n op: 'delete',\n hit: removed,\n durationMs: Date.now() - start,\n key,\n });\n return Promise.resolve(removed);\n }\n );\n }\n\n async stats(): Promise<BackendStats> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'stats',\n },\n start,\n () => {\n this.assertOpen();\n const timestamps = [...this.rows.values()].map((r) => r.timestamp);\n const result: BackendStats = {\n domain: this.domain,\n count: this.rows.size,\n oldestTimestamp: timestamps.length > 0 ? Math.min(...timestamps) : null,\n newestTimestamp: timestamps.length > 0 ? Math.max(...timestamps) : null,\n };\n recordMemoryEvent({\n domain: this.domain,\n op: 'stats',\n durationMs: Date.now() - start,\n result,\n });\n return Promise.resolve(result);\n }\n );\n }\n\n async close(): Promise<void> {\n this.closed = true;\n this.rows.clear();\n return Promise.resolve();\n }\n\n private assertOpen(): void {\n if (this.closed) {\n throw new Error(`nexus-memory: backend \"${this.domain}\" is closed`);\n }\n }\n}\n","/**\n * Shared helper for opening a SQLite connection on disk.\n *\n * Centralizes the two pre-#3995 concerns that were duplicated at every\n * `new Database(dbPath)` site in this package:\n *\n * 1. **Auto-create the parent directory.** SQLite throws\n * `SQLITE_CANTOPEN` when the parent directory of `dbPath` does not exist\n * (the classic fresh-install regression — the resolver hands back a path\n * under `~/.nexus-agents/memory/` that nobody has created yet). We\n * `mkdirSync(dirname(dbPath), { recursive: true })` first so opening the\n * DB never throws merely because the directory is missing. `:memory:`\n * (and the empty string) are pure in-memory handles with no parent dir, so\n * they skip the mkdir.\n * 2. **WAL journal mode.** Keeps concurrent MCP-server + CLI readers coherent.\n *\n * Kept dep-free on purpose: nexus-memory must stay free of inter-package\n * imports so `nexus-eval-*` repos can reuse it. The canonical\n * `nexusDataPath` resolver lives in nexus-agents and injects the path here as\n * a plain string (see `getMemoryRegistry` wiring in nexus-agents). This helper\n * only guarantees that whatever absolute path it is handed is openable.\n *\n * @module nexus-memory/backends/open-database\n */\n\nimport { createRequire } from 'node:module';\n\n/**\n * Loaded through `createRequire`, not a static import (#5392).\n *\n * A static `import ... from 'node:sqlite'` is HOISTED by the bundler to the top\n * of the emitted chunk, so it evaluates before any consumer code can run. Node\n * emits the SQLite `ExperimentalWarning` at IMPORT time, so that ordering made\n * the CLI's warning filter unable to fire at all. `createRequire` keeps the load\n * synchronous — which is why node:sqlite was chosen — while deferring it to\n * first call. Node caches the module, so repeat calls are free.\n */\nconst requireFromHere = createRequire(import.meta.url);\n\nfunction loadSqlite(): typeof import('node:sqlite') {\n return requireFromHere('node:sqlite') as typeof import('node:sqlite');\n}\n\n/**\n * Result of running a prepared statement. Mirrors what both `node:sqlite` and\n * better-sqlite3 return, so consumers did not have to change (#5388).\n */\nexport interface SqliteRunResult {\n readonly changes: number | bigint;\n readonly lastInsertRowid: number | bigint;\n}\n\n/** Minimal prepared-statement surface this package actually uses. */\nexport interface SqliteStatement {\n run(...params: unknown[]): SqliteRunResult;\n get(...params: unknown[]): unknown;\n all(...params: unknown[]): unknown[];\n}\n\n/**\n * Minimal database surface this package actually uses.\n *\n * Declared locally rather than imported: nexus-memory stays free of\n * inter-package imports so `nexus-eval-*` repos can reuse it, and since #5388\n * there is no dependency to import a type FROM — `node:sqlite` is a builtin.\n */\nexport interface SqliteDatabase {\n exec(sql: string): void;\n prepare(sql: string): SqliteStatement;\n close(): void;\n}\nimport { mkdirSync } from 'node:fs';\nimport { dirname } from 'node:path';\n\n/**\n * Open a SQLite database at `dbPath`, creating the parent directory\n * first (for on-disk paths) and enabling WAL journal mode.\n *\n * @param dbPath Absolute SQLite file path, or `':memory:'` / `''` for an\n * in-memory database (no directory is created in that case).\n */\nexport function openSqliteDatabase(dbPath: string): SqliteDatabase {\n if (dbPath !== ':memory:' && dbPath !== '') {\n // Fresh-install robustness (#3995): opening under a missing parent throws SQLITE_CANTOPEN\n // when the parent dir is missing. Create it up front, idempotently.\n mkdirSync(dirname(dbPath), { recursive: true });\n }\n const { DatabaseSync } = loadSqlite();\n const db = new DatabaseSync(dbPath);\n // `node:sqlite` has no `.pragma()` helper, so WAL goes through `exec`.\n db.exec('PRAGMA journal_mode = WAL');\n\n const narrowed = db as unknown as SqliteDatabase;\n return {\n exec: (sql: string) => {\n db.exec(sql);\n },\n prepare: narrowed.prepare.bind(narrowed),\n // better-sqlite3's `close()` is idempotent; `DatabaseSync`'s throws\n // `database is not open` on a second call, and shutdown paths here are\n // reentrant. Preserve the contract callers were written against (#5388).\n close: () => {\n if (db.isOpen) db.close();\n },\n };\n}\n","/**\n * SQLite backend — async wrapper over `node:sqlite` (which is sync).\n *\n * One table per domain (Phase 2 vote shape C, hot-table side). The schema\n * is intentionally minimal: `key`, `value` (JSON-serialized), `cli`,\n * `source`, `timestamp`, `trust_tier`. Hot-path backends extending this\n * will add typed columns and indexes for query performance.\n *\n * Async surface: every method returns `Promise<T>` so we can swap in a\n * network-backed implementation later without changing callers. The\n * actual SQLite ops are sync inside.\n *\n * @module nexus-memory/backends/sqlite\n */\n\nimport type {\n SqliteDatabase as DatabaseType,\n SqliteStatement as Statement,\n} from './open-database.js';\nimport type { z } from 'zod';\nimport { recordFailedMemoryOp, recordMemoryEvent } from '../telemetry.js';\nimport type { BackendStats, IMemoryBackend, QueryFilter, WriteMeta } from '../types.js';\nimport { MemoryValidationError } from './memory.js';\nimport { openSqliteDatabase } from './open-database.js';\n\nexport interface SqliteBackendOptions<TValue> {\n readonly domain: string;\n /** Absolute path to the SQLite file. Use `':memory:'` for tests. */\n readonly dbPath: string;\n /**\n * Zod schema for cold-archive validation (Phase 2 vote mitigation #1).\n * When supplied, every `write()` validates first.\n */\n readonly schema?: z.ZodType<TValue>;\n /** Pre-existing database handle. Used by `MemoryRegistry` to share a single connection. */\n readonly db?: DatabaseType;\n}\n\ninterface SqliteRow {\n readonly key: string;\n readonly value: string;\n readonly cli: string | null;\n readonly source: string | null;\n readonly timestamp: number;\n readonly trust_tier: number | null;\n}\n\nfunction buildWriteRow(\n key: unknown,\n value: unknown,\n meta: WriteMeta | undefined\n): Record<string, string | number | null> {\n return {\n key: keyToString(key),\n value: JSON.stringify(value),\n cli: meta?.cli ?? null,\n source: meta?.source ?? null,\n timestamp: meta?.timestamp ?? Date.now(),\n trust_tier: meta?.trustTier ?? null,\n };\n}\n\n/** Stringify a key so SQLite primary-key lookups stay simple. */\nfunction keyToString(key: unknown): string {\n if (typeof key === 'string') return key;\n if (typeof key === 'number' || typeof key === 'boolean') return String(key);\n return JSON.stringify(key);\n}\n\n/** Apply `where`, `orderBy`, `limit` to an in-memory row set. Extracted from\n * `query` to satisfy the eslint complexity gate. */\nfunction applyQueryFilter<T>(values: T[], filter?: QueryFilter<T>): T[] {\n let out = values;\n if (filter?.where !== undefined) {\n const where = filter.where;\n out = out.filter((v) => {\n for (const [k, expected] of Object.entries(where)) {\n if ((v as Record<string, unknown>)[k] !== expected) return false;\n }\n return true;\n });\n }\n if (filter?.orderBy !== undefined) {\n const orderBy = filter.orderBy;\n const dir = filter.orderDir === 'desc' ? -1 : 1;\n out = [...out].sort((a, b) => {\n const av = (a as Record<string | symbol | number, unknown>)[orderBy];\n const bv = (b as Record<string | symbol | number, unknown>)[orderBy];\n if (av === bv) return 0;\n if (av === undefined || av === null) return 1;\n if (bv === undefined || bv === null) return -1;\n return (av < bv ? -1 : 1) * dir;\n });\n }\n if (filter?.limit !== undefined) {\n out = out.slice(0, filter.limit);\n }\n return out;\n}\n\nexport class SqliteBackend<TKey, TValue> implements IMemoryBackend<TKey, TValue> {\n readonly domain: string;\n private readonly db: DatabaseType;\n private readonly ownsDb: boolean;\n private readonly schema?: z.ZodType<TValue>;\n private readonly stmts: {\n read: Statement;\n write: Statement;\n delete: Statement;\n count: Statement;\n bounds: Statement;\n queryAll: Statement;\n };\n private closed = false;\n\n constructor(options: SqliteBackendOptions<TValue>) {\n this.domain = options.domain;\n if (options.db !== undefined) {\n this.db = options.db;\n this.ownsDb = false;\n } else {\n // #3995: open via the shared helper, which creates the parent dir\n // first (fresh-install robustness) and enables WAL mode.\n this.db = openSqliteDatabase(options.dbPath);\n this.ownsDb = true;\n }\n if (options.schema !== undefined) {\n this.schema = options.schema;\n }\n this.ensureTable();\n this.stmts = this.prepareStatements();\n }\n\n private ensureTable(): void {\n // Table name = domain. Domain comes from in-tree code, never untrusted input,\n // so direct interpolation is safe; still validate the shape defensively.\n if (!/^[a-z][a-z0-9_]{0,63}$/i.test(this.domain)) {\n throw new Error(\n `nexus-memory: invalid domain \"${this.domain}\" — must match [a-zA-Z][a-zA-Z0-9_]{0,63}`\n );\n }\n this.db.exec(`\n CREATE TABLE IF NOT EXISTS ${this.domain} (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL,\n cli TEXT,\n source TEXT,\n timestamp INTEGER NOT NULL,\n trust_tier INTEGER\n );\n CREATE INDEX IF NOT EXISTS ${this.domain}_cli ON ${this.domain}(cli);\n CREATE INDEX IF NOT EXISTS ${this.domain}_timestamp ON ${this.domain}(timestamp);\n `);\n }\n\n private prepareStatements(): SqliteBackend<TKey, TValue>['stmts'] {\n return {\n read: this.db.prepare(\n `SELECT key, value, cli, source, timestamp, trust_tier FROM ${this.domain} WHERE key = ?`\n ),\n write: this.db.prepare(\n `INSERT INTO ${this.domain} (key, value, cli, source, timestamp, trust_tier)\n VALUES (@key, @value, @cli, @source, @timestamp, @trust_tier)\n ON CONFLICT(key) DO UPDATE SET\n value = excluded.value,\n cli = excluded.cli,\n source = excluded.source,\n timestamp = excluded.timestamp,\n trust_tier = excluded.trust_tier`\n ),\n delete: this.db.prepare(`DELETE FROM ${this.domain} WHERE key = ?`),\n count: this.db.prepare(`SELECT COUNT(*) AS count FROM ${this.domain}`),\n bounds: this.db.prepare(\n `SELECT MIN(timestamp) AS oldest, MAX(timestamp) AS newest FROM ${this.domain}`\n ),\n queryAll: this.db.prepare(\n `SELECT key, value, cli, source, timestamp, trust_tier FROM ${this.domain}`\n ),\n };\n }\n\n async read(key: TKey): Promise<TValue | undefined> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'read',\n },\n start,\n () => {\n this.assertOpen();\n const row = this.stmts.read.get(keyToString(key)) as SqliteRow | undefined;\n const value = row !== undefined ? (JSON.parse(row.value) as TValue) : undefined;\n recordMemoryEvent({\n domain: this.domain,\n op: 'read',\n hit: value !== undefined,\n ...(row?.cli !== null && row?.cli !== undefined && { cli: row.cli as never }),\n durationMs: Date.now() - start,\n key,\n result: value,\n });\n return Promise.resolve(value);\n }\n );\n }\n\n private validate(value: TValue): void {\n // #4021: reject `undefined` uniformly (before the optional schema check) so\n // both backends behave identically. Previously SqliteBackend threw a cryptic\n // NOT NULL bind error for `write(key, undefined)` while InMemoryBackend stored\n // a phantom row. `undefined` is the missing-key sentinel; use `null` for an\n // explicit absent value.\n if (value === undefined) {\n throw new MemoryValidationError(this.domain, 'value must not be undefined (use null)');\n }\n if (this.schema === undefined) return;\n const result = this.schema.safeParse(value);\n if (!result.success) {\n throw new MemoryValidationError(this.domain, result.error);\n }\n }\n\n async write(key: TKey, value: TValue, meta?: WriteMeta): Promise<void> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'write',\n ...(meta?.cli !== undefined && { cli: meta.cli }),\n },\n start,\n () => {\n this.assertOpen();\n this.validate(value);\n this.stmts.write.run(buildWriteRow(key, value, meta));\n recordMemoryEvent({\n domain: this.domain,\n op: 'write',\n ...(meta?.cli !== undefined && { cli: meta.cli }),\n durationMs: Date.now() - start,\n key,\n payload: value,\n });\n return Promise.resolve();\n }\n );\n }\n\n async query(filter?: QueryFilter<TValue>): Promise<readonly TValue[]> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'query',\n ...(filter?.cli !== undefined && { cli: filter.cli }),\n },\n start,\n () => {\n this.assertOpen();\n // Phase 3 keeps query simple — full table scan with in-process filter.\n // Hot-path backends will override or extend with indexed columns.\n let rows = this.stmts.queryAll.all() as SqliteRow[];\n if (filter?.cli !== undefined) {\n rows = rows.filter((r) => r.cli === filter.cli);\n }\n let values = rows.map((r) => JSON.parse(r.value) as TValue);\n values = applyQueryFilter(values, filter);\n recordMemoryEvent({\n domain: this.domain,\n op: 'query',\n hit: values.length > 0,\n ...(filter?.cli !== undefined && { cli: filter.cli }),\n durationMs: Date.now() - start,\n key: filter,\n result: { count: values.length },\n });\n return Promise.resolve(values);\n }\n );\n }\n\n async delete(key: TKey): Promise<boolean> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'delete',\n },\n start,\n () => {\n this.assertOpen();\n const result = this.stmts.delete.run(keyToString(key));\n const removed = result.changes > 0;\n recordMemoryEvent({\n domain: this.domain,\n op: 'delete',\n hit: removed,\n durationMs: Date.now() - start,\n key,\n });\n return Promise.resolve(removed);\n }\n );\n }\n\n async stats(): Promise<BackendStats> {\n const start = Date.now();\n return recordFailedMemoryOp(\n {\n domain: this.domain,\n op: 'stats',\n },\n start,\n () => {\n this.assertOpen();\n const countRow = this.stmts.count.get() as { count: number };\n const boundsRow = this.stmts.bounds.get() as {\n oldest: number | null;\n newest: number | null;\n };\n const result: BackendStats = {\n domain: this.domain,\n count: countRow.count,\n oldestTimestamp: boundsRow.oldest,\n newestTimestamp: boundsRow.newest,\n };\n recordMemoryEvent({\n domain: this.domain,\n op: 'stats',\n durationMs: Date.now() - start,\n result,\n });\n return Promise.resolve(result);\n }\n );\n }\n\n async close(): Promise<void> {\n if (this.closed) return Promise.resolve();\n this.closed = true;\n if (this.ownsDb) this.db.close();\n return Promise.resolve();\n }\n\n private assertOpen(): void {\n if (this.closed) {\n throw new Error(`nexus-memory: backend \"${this.domain}\" is closed`);\n }\n }\n}\n","/**\n * MemoryRegistry — the single entry point for accessing memory backends.\n *\n * Every concept-space (experience, outcomes, beliefs, …) registers a\n * backend; callers reach it via `registry.get('experience')` or, more\n * commonly, the typed accessors that wrap the registry.\n *\n * Sharing a SQLite connection across backends keeps WAL-mode behavior\n * coherent — one writer thread, many tables.\n *\n * @module nexus-memory/registry\n */\n\nimport type { SqliteDatabase as DatabaseType } from './backends/open-database.js';\nimport type { z } from 'zod';\nimport { InMemoryBackend } from './backends/memory.js';\nimport { openSqliteDatabase } from './backends/open-database.js';\nimport { SqliteBackend } from './backends/sqlite.js';\nimport type { IMemoryBackend } from './types.js';\n\nexport interface MemoryRegistryOptions {\n /**\n * SQLite file path. Use `':memory:'` for tests. When omitted, the\n * registry creates `InMemoryBackend` instances and never touches disk\n * — the standard test-isolation pattern (Phase 2 acceptance criterion).\n */\n readonly dbPath?: string;\n}\n\nexport interface RegisterBackendOptions<TValue> {\n /** Stable domain identifier. Becomes the SQLite table name. */\n readonly domain: string;\n /** Optional Zod schema for cold-archive validation. */\n readonly schema?: z.ZodType<TValue>;\n}\n\n/**\n * The registry. One per `dbPath` (or one in-memory registry per test).\n * `MemoryRegistry.get(domain)` is `O(1)` after registration.\n */\nexport class MemoryRegistry {\n private readonly backends = new Map<string, IMemoryBackend<unknown, unknown>>();\n private readonly db?: DatabaseType;\n private closed = false;\n\n constructor(options: MemoryRegistryOptions = {}) {\n if (options.dbPath !== undefined) {\n // #3995: open via the shared helper, which creates the parent dir\n // first (fresh-install robustness) and enables WAL mode.\n this.db = openSqliteDatabase(options.dbPath);\n }\n }\n\n /**\n * Register a backend for `domain`. Throws on duplicate domain.\n *\n * When the registry has a `dbPath`, the new backend is SQLite-backed\n * and shares the registry's connection. Otherwise, an `InMemoryBackend`\n * is created (used for tests).\n */\n register<TKey, TValue>(options: RegisterBackendOptions<TValue>): IMemoryBackend<TKey, TValue> {\n this.assertOpen();\n if (this.backends.has(options.domain)) {\n throw new Error(`nexus-memory: domain \"${options.domain}\" already registered`);\n }\n const backend: IMemoryBackend<TKey, TValue> =\n this.db !== undefined\n ? new SqliteBackend<TKey, TValue>({\n domain: options.domain,\n dbPath: '<shared>', // unused when db is supplied\n db: this.db,\n ...(options.schema !== undefined && { schema: options.schema }),\n })\n : new InMemoryBackend<TKey, TValue>({\n domain: options.domain,\n ...(options.schema !== undefined && { schema: options.schema }),\n });\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TypeScript narrows the union type here, but the Map needs the lifted IMemoryBackend<unknown, unknown>; the assertion documents the variance and survives future contract changes.\n this.backends.set(options.domain, backend as IMemoryBackend<unknown, unknown>);\n return backend;\n }\n\n /**\n * Attach an externally-managed {@link IMemoryBackend}. Use this when the\n * backend owns its own storage (e.g., a pre-existing SQLite file under\n * `~/.nexus-agents/memory/agentic.db`) and you want it discoverable\n * through the registry without changing its persistence.\n *\n * Phase 5–7 of the memory-unification epic use this to bring the\n * tool-memory backends (`agentic`, `adaptive`, `typed`, `belief`),\n * OutcomeStore, SICA, skills, etc. under a unified observability\n * contract without rewriting their internals. Each attached backend\n * still owns its own `.db` (or JSONL, etc.) until a follow-up migration\n * folds the storage in fully.\n */\n attach<TKey, TValue>(\n domain: string,\n backend: IMemoryBackend<TKey, TValue>\n ): IMemoryBackend<TKey, TValue> {\n this.assertOpen();\n if (this.backends.has(domain)) {\n throw new Error(`nexus-memory: domain \"${domain}\" already registered`);\n }\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- See `register`.\n this.backends.set(domain, backend as IMemoryBackend<unknown, unknown>);\n return backend;\n }\n\n /**\n * Get a previously-registered backend. Returns `undefined` if the\n * domain isn't registered — callers should treat that as \"not yet\n * migrated to the unified contract.\"\n */\n get<TKey, TValue>(domain: string): IMemoryBackend<TKey, TValue> | undefined {\n this.assertOpen();\n const backend = this.backends.get(domain);\n return backend as IMemoryBackend<TKey, TValue> | undefined;\n }\n\n /** List all registered domains. Useful for `memory_stats`-style readers. */\n domains(): readonly string[] {\n return [...this.backends.keys()];\n }\n\n /**\n * Close every registered backend and the shared SQLite handle. After\n * `close()` the registry rejects all further operations.\n */\n async close(): Promise<void> {\n if (this.closed) return;\n this.closed = true;\n for (const backend of this.backends.values()) {\n await backend.close();\n }\n this.backends.clear();\n if (this.db !== undefined) this.db.close();\n }\n\n private assertOpen(): void {\n if (this.closed) {\n throw new Error('nexus-memory: registry is closed');\n }\n }\n}\n\n// ============================================================================\n// Singleton accessor\n// ============================================================================\n\nlet sharedRegistry: MemoryRegistry | null = null;\n\n/**\n * Get the process-wide shared registry. Initializes on first call with\n * `dbPath` from `NEXUS_DATA_DIR` (defaults to `~/.nexus-agents/memory/memory.db`)\n * unless `setMemoryRegistry` was called first.\n *\n * Test code should call `setMemoryRegistry(createInMemoryMemoryRegistry())`\n * in `beforeEach` — this matches the existing `setOutcomeStore` pattern.\n */\nexport function getMemoryRegistry(): MemoryRegistry {\n if (sharedRegistry === null) {\n // Default path resolution happens here, NOT at module load — so tests\n // that call `setMemoryRegistry` before any `getMemoryRegistry` see\n // their in-memory instance, not a side-effectful production path.\n const dbPath = resolveDefaultDbPath();\n sharedRegistry = new MemoryRegistry({ dbPath });\n }\n return sharedRegistry;\n}\n\n/**\n * Inject a registry. Used by tests to swap in `InMemoryBackend`-backed\n * registries. After test, call again with `null` to reset, or call\n * `closeMemoryRegistry()` to dispose.\n */\nexport function setMemoryRegistry(registry: MemoryRegistry | null): void {\n sharedRegistry = registry;\n}\n\n/**\n * True when the shared registry has already been constructed or injected.\n * Lets nexus-agents inject the canonical {@link nexusDataPath}-resolved DB\n * path (#3995) WITHOUT clobbering a registry a test already set, and without\n * triggering the lazy default-path resolution that `getMemoryRegistry()`\n * would. Read-only — keeps nexus-memory dep-free.\n */\nexport function hasMemoryRegistry(): boolean {\n return sharedRegistry !== null;\n}\n\n/** Close + null out the shared registry. Idempotent. */\nexport async function closeMemoryRegistry(): Promise<void> {\n if (sharedRegistry !== null) {\n await sharedRegistry.close();\n sharedRegistry = null;\n }\n}\n\nfunction resolveDefaultDbPath(): string {\n // Match `nexus-agents`'s `nexusDataPath` convention without importing it\n // (keep nexus-memory free of inter-package deps for nexus-eval-* reuse).\n const root = process.env['NEXUS_DATA_DIR'] ?? `${process.env['HOME'] ?? '/tmp'}/.nexus-agents`;\n return `${root}/memory/memory.db`;\n}\n","/**\n * Test factories. Production code uses {@link getMemoryRegistry} from\n * `./registry.js`; tests use these helpers to avoid touching disk.\n *\n * @module nexus-memory/factory\n */\n\nimport { MemoryRegistry } from './registry.js';\n\n/**\n * Create a registry that lives entirely in memory. Every `register()`\n * call returns an {@link InMemoryBackend}; nothing is persisted.\n *\n * Use this in `beforeEach`:\n *\n * ```ts\n * beforeEach(() => {\n * setMemoryRegistry(createInMemoryMemoryRegistry());\n * });\n * afterEach(async () => {\n * await closeMemoryRegistry();\n * });\n * ```\n */\nexport function createInMemoryMemoryRegistry(): MemoryRegistry {\n return new MemoryRegistry({\n /* no dbPath → InMemoryBackend per domain */\n });\n}\n\n/**\n * Create a SQLite-backed registry rooted at `dbPath`. Pass `':memory:'`\n * for tests that need to exercise the SQLite code path (e.g.,\n * migration tests, parity tests).\n */\nexport function createSqliteMemoryRegistry(dbPath: string): MemoryRegistry {\n return new MemoryRegistry({ dbPath });\n}\n","/**\n * One-shot importer scaffold. Each Phase 4+ migration registers its own\n * importer here; the registry runs them on first launch (after a marker\n * file check) and renames source files to `.bak.<timestamp>` once\n * complete.\n *\n * This file ships the skeleton + the marker-file logic; concrete\n * importers (MobiMem JSON, OutcomeStore JSONL, agentic.db, etc.) plug in\n * during their respective migration phases.\n *\n * @module nexus-memory/importer\n */\n\nimport { existsSync, mkdirSync, renameSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport type { MemoryRegistry } from './registry.js';\n\nexport interface ImporterRun {\n readonly domain: string;\n readonly rowsImported: number;\n readonly sourcePathBackup: string | null;\n}\n\nexport interface Importer {\n /** Stable identifier — used in the marker filename to track completion. */\n readonly id: string;\n /** Logical domain this importer targets in the registry. */\n readonly domain: string;\n /**\n * Run the import. Implementations: (1) check if source data exists,\n * (2) parse + validate it, (3) write rows into the registry's backend,\n * (4) rename source to `.bak.<timestamp>` and return the backup path.\n * Idempotent — if marker file says we already ran, the registry skips it.\n */\n run(registry: MemoryRegistry): Promise<ImporterRun>;\n}\n\nconst importers = new Map<string, Importer>();\n\n/** Register an importer. Phase 4+ migrations call this at module load. */\nexport function registerImporter(importer: Importer): void {\n if (importers.has(importer.id)) {\n throw new Error(`nexus-memory: importer \"${importer.id}\" already registered`);\n }\n importers.set(importer.id, importer);\n}\n\n/** For tests: clear all registered importers. */\nexport function resetImporters(): void {\n importers.clear();\n}\n\n/** Snapshot of registered importer IDs. */\nexport function listImporters(): readonly string[] {\n return [...importers.keys()];\n}\n\nexport interface RunImportersOptions {\n /**\n * Directory holding `.imported-{id}` marker files. Defaults to the\n * registry's data dir; tests should override.\n */\n readonly markerDir: string;\n /** Skip the marker check (forces re-run). Tests only. */\n readonly force?: boolean;\n}\n\n/**\n * Run every registered importer that hasn't yet completed (per marker\n * file). Returns the list of runs that actually executed.\n *\n * Failures are NOT fatal — a single importer's exception is logged via\n * the returned `errors` array; other importers still get a chance to run.\n */\nexport async function runImporters(\n registry: MemoryRegistry,\n options: RunImportersOptions\n): Promise<{ runs: readonly ImporterRun[]; errors: readonly { id: string; error: Error }[] }> {\n mkdirSync(options.markerDir, { recursive: true });\n const runs: ImporterRun[] = [];\n const errors: { id: string; error: Error }[] = [];\n for (const importer of importers.values()) {\n const marker = join(options.markerDir, `.imported-${importer.id}`);\n if (options.force !== true && existsSync(marker)) continue;\n try {\n const run = await importer.run(registry);\n writeMarker(marker, run);\n runs.push(run);\n } catch (err) {\n errors.push({ id: importer.id, error: err instanceof Error ? err : new Error(String(err)) });\n }\n }\n return { runs, errors };\n}\n\nfunction writeMarker(path: string, run: ImporterRun): void {\n mkdirSync(dirname(path), { recursive: true });\n writeFileSync(\n path,\n JSON.stringify({ ...run, completedAt: new Date().toISOString() }, null, 2),\n 'utf-8'\n );\n}\n\n/**\n * Rename a source file to `.bak.<unix-timestamp>`. Used by concrete\n * importers after a successful migration. Returns the backup path, or\n * `null` when the source doesn't exist.\n */\nexport function backupSourceFile(sourcePath: string): string | null {\n if (!existsSync(sourcePath)) return null;\n const backup = `${sourcePath}.bak.${String(Date.now())}`;\n renameSync(sourcePath, backup);\n return backup;\n}\n"],"mappings":";AEyBA,SAAS,qBAAqB;AA8C9B,SAAS,iBAAiB;AAC1B,SAAS,eAAe;AI3DxB,SAAS,YAAY,aAAAA,YAAW,YAAY,qBAAqB;AACjE,SAAS,WAAAC,UAAS,YAAY;ANE9B,IAAM,oBAAoB;AAC1B,IAAM,wBAAwB;AAG9B,IAAM,WAAW,oBAAI,IAAiC;AACtD,IAAM,YAAY,oBAAI,IAAyB;AAI/C,SAAS,cAAuB;AAC9B,SAAO,QAAQ,IAAI,yBAAyB,MAAM;AACpD;AAEA,SAAS,WAAW,QAAgB,IAA+B;AACjE,SAAO,GAAG,MAAM,KAAK,EAAE;AACzB;AAEA,SAAS,SAAS,OAAgB,OA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