@remnic/core 10.0.105 → 10.0.107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-admin-ops-surface.js +28 -28
- package/dist/access-cli.js +28 -28
- package/dist/access-extraction-force-flush.js +28 -28
- package/dist/access-http-briefing.js +28 -28
- package/dist/access-http-query.js +28 -28
- package/dist/access-http.js +28 -28
- package/dist/access-identity-continuity-surface.js +28 -28
- package/dist/access-lcm-surface.js +28 -28
- package/dist/access-mcp.js +28 -28
- package/dist/access-observe-write-surface.js +28 -28
- package/dist/access-operations-batch.js +28 -28
- package/dist/access-operations.js +28 -28
- package/dist/access-recall-concurrency.js +28 -28
- package/dist/access-recall-response.js +28 -28
- package/dist/access-recall-surface.js +28 -28
- package/dist/access-service.js +28 -28
- package/dist/active-recall.js +1 -1
- package/dist/briefing.js +2 -2
- package/dist/causal-consolidation.js +3 -3
- package/dist/{chunk-6RW5TONS.js → chunk-2BXPAOOR.js} +7 -7
- package/dist/{chunk-XP5CKXFV.js → chunk-4ANH42MO.js} +7 -7
- package/dist/{chunk-TFI2Y5AR.js → chunk-5VWN3FJS.js} +2 -2
- package/dist/{chunk-CCQEANCY.js → chunk-63OWJXGW.js} +2 -2
- package/dist/{chunk-E3YHIAO3.js → chunk-7HNQR5MV.js} +3 -3
- package/dist/{chunk-RXL67CV6.js → chunk-7QIRIF3Z.js} +2 -2
- package/dist/{chunk-OTSRGZRU.js → chunk-7SW6EBEF.js} +2 -2
- package/dist/{chunk-6VAIFSDG.js → chunk-AY535ZIM.js} +2 -2
- package/dist/{chunk-UG54AEUG.js → chunk-AZYUG2HW.js} +2 -2
- package/dist/{chunk-YCQMNW3F.js → chunk-B3LGXOM5.js} +2 -2
- package/dist/{chunk-3WDFQKB4.js → chunk-BP7LNNWG.js} +2 -2
- package/dist/{chunk-T3X4CCHC.js → chunk-CCFGLUSC.js} +33 -30
- package/dist/{chunk-T3X4CCHC.js.map → chunk-CCFGLUSC.js.map} +1 -1
- package/dist/{chunk-CH2N4XCJ.js → chunk-E55J2NFL.js} +2 -2
- package/dist/{chunk-A2D5WZRO.js → chunk-EDVVW655.js} +2 -2
- package/dist/{chunk-SW3WUUYA.js → chunk-FV2B6XE6.js} +2 -2
- package/dist/{chunk-EHJ2RYR7.js → chunk-GT2TH7FZ.js} +2 -2
- package/dist/{chunk-PWATRW3H.js → chunk-H4XPEXWA.js} +2 -2
- package/dist/{chunk-KCRHFW3N.js → chunk-IOGYSADY.js} +2 -2
- package/dist/{chunk-B2BMTXIF.js → chunk-JODSN3V5.js} +2 -2
- package/dist/{chunk-SFZEJJ6V.js → chunk-K32VAS5B.js} +2 -2
- package/dist/{chunk-KI7E3N6Q.js → chunk-LYR57GEF.js} +3 -3
- package/dist/{chunk-ECC6AAEE.js → chunk-OEVJH66T.js} +3 -3
- package/dist/{chunk-D6WJNWZG.js → chunk-OIOKDTZU.js} +4 -4
- package/dist/chunk-OIOKDTZU.js.map +1 -0
- package/dist/{chunk-MXXTU4R2.js → chunk-QIGEWFXE.js} +2 -2
- package/dist/{chunk-D77I4MD4.js → chunk-QZPXXABV.js} +3 -3
- package/dist/{chunk-VRBTZDQ5.js → chunk-UOIVXBNS.js} +2 -2
- package/dist/{chunk-3DQZ2GAY.js → chunk-WCKLRFGF.js} +2 -2
- package/dist/{chunk-FVPWQWIK.js → chunk-YD4D4EVO.js} +2 -2
- package/dist/{chunk-FHQ5SPMD.js → chunk-YU3TOAXV.js} +2 -2
- package/dist/cli.js +28 -28
- package/dist/coding/export-okf-codegraph.js +1 -1
- package/dist/compounding/engine.js +3 -3
- package/dist/config.js +1 -1
- package/dist/connectors/codex-materialize-runner.js +2 -2
- package/dist/connectors/index.js +2 -2
- package/dist/convergence-refresh.js +4 -4
- package/dist/corpus-watermark.js +4 -4
- package/dist/entity-retrieval.js +2 -2
- package/dist/explicit-capture.js +28 -28
- package/dist/extraction.js +2 -2
- package/dist/harmonic-retrieval.js +2 -2
- package/dist/index.js +28 -28
- package/dist/location/index.js +3 -3
- package/dist/maintenance/memory-governance.js +2 -2
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +2 -2
- package/dist/maintenance/rebuild-memory-projection-runner.js +4 -4
- package/dist/maintenance/rebuild-memory-projection.js +3 -3
- package/dist/namespaces/migrate.js +3 -3
- package/dist/namespaces/storage.js +2 -2
- package/dist/operator-doctor-corpus.js +5 -5
- package/dist/operator-toolkit.js +8 -8
- package/dist/orchestration/backlog-scheduler.js +29 -29
- package/dist/orchestration/buffer-drain-runner.js +29 -29
- package/dist/orchestration/maintenance.js +10 -10
- package/dist/orchestrator.js +28 -28
- package/dist/recall-navigation.d.ts.map +1 -1
- package/dist/recall-navigation.js +28 -28
- package/dist/resume-bundles.js +1 -1
- package/dist/semantic-consolidation.js +3 -3
- package/dist/semantic-rule-promotion.js +2 -2
- package/dist/semantic-rule-verifier.js +2 -2
- package/dist/source-agent-qualifier.js +2 -2
- package/dist/standup/build.js +2 -2
- package/dist/storage.js +1 -1
- package/dist/transfer/export-okf.js +2 -2
- package/dist/verified-recall.js +2 -2
- package/dist/who-knows-cli.js +3 -3
- package/dist/who-knows.js +2 -2
- package/package.json +2 -2
- package/src/recall-navigation.test.ts +127 -0
- package/src/recall-navigation.ts +9 -13
- package/src/storage-memory-write-collision.test.ts +108 -0
- package/src/storage.ts +3 -3
- package/dist/chunk-D6WJNWZG.js.map +0 -1
- /package/dist/{chunk-6RW5TONS.js.map → chunk-2BXPAOOR.js.map} +0 -0
- /package/dist/{chunk-XP5CKXFV.js.map → chunk-4ANH42MO.js.map} +0 -0
- /package/dist/{chunk-TFI2Y5AR.js.map → chunk-5VWN3FJS.js.map} +0 -0
- /package/dist/{chunk-CCQEANCY.js.map → chunk-63OWJXGW.js.map} +0 -0
- /package/dist/{chunk-E3YHIAO3.js.map → chunk-7HNQR5MV.js.map} +0 -0
- /package/dist/{chunk-RXL67CV6.js.map → chunk-7QIRIF3Z.js.map} +0 -0
- /package/dist/{chunk-OTSRGZRU.js.map → chunk-7SW6EBEF.js.map} +0 -0
- /package/dist/{chunk-6VAIFSDG.js.map → chunk-AY535ZIM.js.map} +0 -0
- /package/dist/{chunk-UG54AEUG.js.map → chunk-AZYUG2HW.js.map} +0 -0
- /package/dist/{chunk-YCQMNW3F.js.map → chunk-B3LGXOM5.js.map} +0 -0
- /package/dist/{chunk-3WDFQKB4.js.map → chunk-BP7LNNWG.js.map} +0 -0
- /package/dist/{chunk-CH2N4XCJ.js.map → chunk-E55J2NFL.js.map} +0 -0
- /package/dist/{chunk-A2D5WZRO.js.map → chunk-EDVVW655.js.map} +0 -0
- /package/dist/{chunk-SW3WUUYA.js.map → chunk-FV2B6XE6.js.map} +0 -0
- /package/dist/{chunk-EHJ2RYR7.js.map → chunk-GT2TH7FZ.js.map} +0 -0
- /package/dist/{chunk-PWATRW3H.js.map → chunk-H4XPEXWA.js.map} +0 -0
- /package/dist/{chunk-KCRHFW3N.js.map → chunk-IOGYSADY.js.map} +0 -0
- /package/dist/{chunk-B2BMTXIF.js.map → chunk-JODSN3V5.js.map} +0 -0
- /package/dist/{chunk-SFZEJJ6V.js.map → chunk-K32VAS5B.js.map} +0 -0
- /package/dist/{chunk-KI7E3N6Q.js.map → chunk-LYR57GEF.js.map} +0 -0
- /package/dist/{chunk-ECC6AAEE.js.map → chunk-OEVJH66T.js.map} +0 -0
- /package/dist/{chunk-MXXTU4R2.js.map → chunk-QIGEWFXE.js.map} +0 -0
- /package/dist/{chunk-D77I4MD4.js.map → chunk-QZPXXABV.js.map} +0 -0
- /package/dist/{chunk-VRBTZDQ5.js.map → chunk-UOIVXBNS.js.map} +0 -0
- /package/dist/{chunk-3DQZ2GAY.js.map → chunk-WCKLRFGF.js.map} +0 -0
- /package/dist/{chunk-FVPWQWIK.js.map → chunk-YD4D4EVO.js.map} +0 -0
- /package/dist/{chunk-FHQ5SPMD.js.map → chunk-YU3TOAXV.js.map} +0 -0
|
@@ -4,13 +4,13 @@ import {
|
|
|
4
4
|
exportOkfBundle,
|
|
5
5
|
firstHeading,
|
|
6
6
|
parseIncludeStatus
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-UOIVXBNS.js";
|
|
8
8
|
import {
|
|
9
9
|
OKF_EXPORT_VERSION
|
|
10
10
|
} from "../chunk-I7TR2OCU.js";
|
|
11
11
|
import "../chunk-D24OXEPB.js";
|
|
12
12
|
import "../chunk-3UXOZBHV.js";
|
|
13
|
-
import "../chunk-
|
|
13
|
+
import "../chunk-OIOKDTZU.js";
|
|
14
14
|
import "../chunk-QGVCFVX6.js";
|
|
15
15
|
import "../chunk-UHVXE24Y.js";
|
|
16
16
|
import "../chunk-O3JG4PD3.js";
|
package/dist/verified-recall.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
compareVerifiedEpisodeResults,
|
|
3
3
|
searchVerifiedEpisodes
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YD4D4EVO.js";
|
|
5
5
|
import "./chunk-B7RWBZXW.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-OIOKDTZU.js";
|
|
7
7
|
import "./chunk-QGVCFVX6.js";
|
|
8
8
|
import "./chunk-UHVXE24Y.js";
|
|
9
9
|
import "./chunk-O3JG4PD3.js";
|
package/dist/who-knows-cli.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
renderWhoKnows,
|
|
5
5
|
renderWhoKnowsJson,
|
|
6
6
|
renderWhoKnowsText
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-QIGEWFXE.js";
|
|
8
|
+
import "./chunk-7QIRIF3Z.js";
|
|
9
|
+
import "./chunk-OIOKDTZU.js";
|
|
10
10
|
import "./chunk-QGVCFVX6.js";
|
|
11
11
|
import "./chunk-UHVXE24Y.js";
|
|
12
12
|
import "./chunk-O3JG4PD3.js";
|
package/dist/who-knows.js
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
loadWhoKnowsEntities,
|
|
10
10
|
tokenizeTopic,
|
|
11
11
|
validateWhoKnowsInput
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-7QIRIF3Z.js";
|
|
13
|
+
import "./chunk-OIOKDTZU.js";
|
|
14
14
|
import "./chunk-QGVCFVX6.js";
|
|
15
15
|
import "./chunk-UHVXE24Y.js";
|
|
16
16
|
import "./chunk-O3JG4PD3.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remnic/core",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.107",
|
|
4
4
|
"description": "Framework-agnostic Remnic memory engine — orchestrator, storage, extraction, search, trust zones",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -3386,7 +3386,7 @@
|
|
|
3386
3386
|
"core"
|
|
3387
3387
|
],
|
|
3388
3388
|
"peerDependencies": {
|
|
3389
|
-
"@remnic/coding-graph": "^10.0.
|
|
3389
|
+
"@remnic/coding-graph": "^10.0.107"
|
|
3390
3390
|
},
|
|
3391
3391
|
"peerDependenciesMeta": {
|
|
3392
3392
|
"@remnic/coding-graph": {
|
|
@@ -14,7 +14,9 @@ import path from "node:path";
|
|
|
14
14
|
import test from "node:test";
|
|
15
15
|
|
|
16
16
|
import { EngramAccessInputError } from "./access-errors.js";
|
|
17
|
+
import { normalizeProjectionPreview } from "./memory-projection-format.js";
|
|
17
18
|
import { renderHandle } from "./recall-handles.js";
|
|
19
|
+
import { estimateRecallTokens, summarizeDisclosureTokens } from "./recall-xray.js";
|
|
18
20
|
import { runRecallNavigation, type RecallNavigationDeps } from "./recall-navigation.js";
|
|
19
21
|
import { RECALL_NAVIGATION_CONFIG_DEFAULTS } from "./recall-navigation-config.js";
|
|
20
22
|
import { RecallHandleHistoryStore } from "./recall-state.js";
|
|
@@ -252,6 +254,131 @@ test("budget caps expansion output and reports disclosure spend", async () => {
|
|
|
252
254
|
}
|
|
253
255
|
});
|
|
254
256
|
|
|
257
|
+
test("shrinks a raw item when final size accounting crosses the budget cap", async () => {
|
|
258
|
+
const f = await fixture({ recallBudgetChars: 800 });
|
|
259
|
+
try {
|
|
260
|
+
const storage = f.storages.default!;
|
|
261
|
+
const calibrationId = await writeMemory(storage, "x".repeat(500));
|
|
262
|
+
await f.history.record(SESSION, [calibrationId]);
|
|
263
|
+
const calibration = await runRecallNavigation(f.depsFor({ recallBudgetChars: 100_000 }), {
|
|
264
|
+
action: "expand",
|
|
265
|
+
memoryId: calibrationId,
|
|
266
|
+
sessionKey: SESSION,
|
|
267
|
+
disclosure: "raw",
|
|
268
|
+
});
|
|
269
|
+
assert.ok(calibration.ok);
|
|
270
|
+
|
|
271
|
+
const originalItem = calibration.items[0];
|
|
272
|
+
assert.ok(originalItem);
|
|
273
|
+
const { rendered: _calibrationRendered, ...calibrationStructured } = calibration;
|
|
274
|
+
let content: string | undefined;
|
|
275
|
+
for (let length = 1; length <= 500; length += 1) {
|
|
276
|
+
const candidateContent = `${"x".repeat(length)} `;
|
|
277
|
+
const estimatedTokens = estimateRecallTokens(candidateContent);
|
|
278
|
+
const candidateItem = {
|
|
279
|
+
...originalItem,
|
|
280
|
+
preview: normalizeProjectionPreview(candidateContent),
|
|
281
|
+
content: candidateContent,
|
|
282
|
+
estimatedTokens,
|
|
283
|
+
};
|
|
284
|
+
const candidate = {
|
|
285
|
+
...calibrationStructured,
|
|
286
|
+
items: [candidateItem],
|
|
287
|
+
truncated: false,
|
|
288
|
+
budget: { chars: 800, used: 0 },
|
|
289
|
+
disclosureSpend: summarizeDisclosureTokens([{ disclosure: "raw", estimatedTokens }]),
|
|
290
|
+
};
|
|
291
|
+
const candidateSize = JSON.stringify(candidate).length;
|
|
292
|
+
if (candidateSize === 800) {
|
|
293
|
+
content = candidateContent;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
assert.ok(content, "the fixture must produce a candidate at the self-reported-size boundary");
|
|
298
|
+
|
|
299
|
+
const id = await writeMemory(storage, content);
|
|
300
|
+
await f.history.record(SESSION, [id]);
|
|
301
|
+
const result = await runRecallNavigation(f.depsFor(), {
|
|
302
|
+
action: "expand",
|
|
303
|
+
memoryId: id,
|
|
304
|
+
sessionKey: SESSION,
|
|
305
|
+
disclosure: "raw",
|
|
306
|
+
});
|
|
307
|
+
assert.ok(result.ok);
|
|
308
|
+
assert.equal(result.budget.chars, 800);
|
|
309
|
+
const { rendered: _rendered, ...structured } = result;
|
|
310
|
+
assert.equal(result.budget.used, JSON.stringify(structured).length);
|
|
311
|
+
assert.ok(result.budget.used <= 800);
|
|
312
|
+
assert.ok(result.truncated);
|
|
313
|
+
assert.equal(result.items.length, 1);
|
|
314
|
+
assert.ok(
|
|
315
|
+
result.items[0]!.content!.length < content.length,
|
|
316
|
+
`expected content to shrink from ${content.length}; got ${result.items[0]!.content!.length} at ${result.budget.used}/800 chars`,
|
|
317
|
+
);
|
|
318
|
+
assert.equal(result.disclosureSpend.raw.count, 1);
|
|
319
|
+
} finally {
|
|
320
|
+
await f.cleanup();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("reports the exact serialized size when used digits cross the cap", async () => {
|
|
325
|
+
const f = await fixture({ recallBudgetChars: 1_000 });
|
|
326
|
+
try {
|
|
327
|
+
const storage = f.storages.default!;
|
|
328
|
+
const calibrationId = await writeMemory(storage, "x".repeat(500));
|
|
329
|
+
await f.history.record(SESSION, [calibrationId]);
|
|
330
|
+
const calibration = await runRecallNavigation(f.depsFor({ recallBudgetChars: 100_000 }), {
|
|
331
|
+
action: "expand",
|
|
332
|
+
memoryId: calibrationId,
|
|
333
|
+
sessionKey: SESSION,
|
|
334
|
+
disclosure: "raw",
|
|
335
|
+
});
|
|
336
|
+
assert.ok(calibration.ok);
|
|
337
|
+
const originalItem = calibration.items[0];
|
|
338
|
+
assert.ok(originalItem);
|
|
339
|
+
const { rendered: _calibrationRendered, ...calibrationStructured } = calibration;
|
|
340
|
+
|
|
341
|
+
let content: string | undefined;
|
|
342
|
+
for (let length = 1; length <= 500; length += 1) {
|
|
343
|
+
const candidateContent = "x".repeat(length);
|
|
344
|
+
const estimatedTokens = estimateRecallTokens(candidateContent);
|
|
345
|
+
const candidate = {
|
|
346
|
+
...calibrationStructured,
|
|
347
|
+
items: [{
|
|
348
|
+
...originalItem,
|
|
349
|
+
preview: normalizeProjectionPreview(candidateContent),
|
|
350
|
+
content: candidateContent,
|
|
351
|
+
estimatedTokens,
|
|
352
|
+
}],
|
|
353
|
+
truncated: false,
|
|
354
|
+
budget: { chars: 1_000, used: 0 },
|
|
355
|
+
disclosureSpend: summarizeDisclosureTokens([{ disclosure: "raw", estimatedTokens }]),
|
|
356
|
+
};
|
|
357
|
+
if (JSON.stringify(candidate).length === 998) {
|
|
358
|
+
content = candidateContent;
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
assert.ok(content, "the fixture must produce a 998-character candidate with used=0");
|
|
363
|
+
|
|
364
|
+
const id = await writeMemory(storage, content);
|
|
365
|
+
await f.history.record(SESSION, [id]);
|
|
366
|
+
const result = await runRecallNavigation(f.depsFor(), {
|
|
367
|
+
action: "expand",
|
|
368
|
+
memoryId: id,
|
|
369
|
+
sessionKey: SESSION,
|
|
370
|
+
disclosure: "raw",
|
|
371
|
+
});
|
|
372
|
+
assert.ok(result.ok);
|
|
373
|
+
const { rendered: _rendered, ...structured } = result;
|
|
374
|
+
const serializedSize = JSON.stringify(structured).length;
|
|
375
|
+
assert.equal(result.budget.used, serializedSize);
|
|
376
|
+
assert.ok(serializedSize <= 1_000, `serialized size ${serializedSize} must respect the cap`);
|
|
377
|
+
} finally {
|
|
378
|
+
await f.cleanup();
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
255
382
|
test("entity neighbors share entityRef, exclude the source, and honor the limit", async () => {
|
|
256
383
|
const f = await fixture();
|
|
257
384
|
try {
|
package/src/recall-navigation.ts
CHANGED
|
@@ -145,7 +145,7 @@ function applyBudget(
|
|
|
145
145
|
let truncated = extras.truncated;
|
|
146
146
|
for (const item of extras.items) {
|
|
147
147
|
const candidate = [...kept, item];
|
|
148
|
-
const cost =
|
|
148
|
+
const cost = measuredUsed(request, extras, candidate, truncated);
|
|
149
149
|
if (!takeNavigateBudget(extras.budgetChars, cost).ok) {
|
|
150
150
|
if (kept.length === 0) {
|
|
151
151
|
const shrunk = shrinkItemToBudget(request, extras, item);
|
|
@@ -199,23 +199,19 @@ function structuredBody(
|
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
function structuredCost(
|
|
203
|
-
request: RecallNavigationRequest,
|
|
204
|
-
extras: { memoryId: string; namespace: string; budgetChars: number },
|
|
205
|
-
items: NavigationItem[],
|
|
206
|
-
truncated: boolean,
|
|
207
|
-
used = 0,
|
|
208
|
-
): number {
|
|
209
|
-
return JSON.stringify(structuredBody(request, extras, items, truncated, used)).length;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
202
|
function measuredUsed(
|
|
213
203
|
request: RecallNavigationRequest,
|
|
214
204
|
extras: { memoryId: string; namespace: string; budgetChars: number },
|
|
215
205
|
items: NavigationItem[],
|
|
216
206
|
truncated: boolean,
|
|
217
207
|
): number {
|
|
218
|
-
|
|
208
|
+
const base = JSON.stringify(structuredBody(request, extras, items, truncated, 0)).length - 1;
|
|
209
|
+
let used = base + 1;
|
|
210
|
+
while (true) {
|
|
211
|
+
const measured = base + String(used).length;
|
|
212
|
+
if (measured === used) return used;
|
|
213
|
+
used = measured;
|
|
214
|
+
}
|
|
219
215
|
}
|
|
220
216
|
|
|
221
217
|
function shrinkItemToBudget(
|
|
@@ -230,7 +226,7 @@ function shrinkItemToBudget(
|
|
|
230
226
|
const candidate: NavigationItem = hasContent
|
|
231
227
|
? { ...item, preview, content }
|
|
232
228
|
: { ...item, preview };
|
|
233
|
-
if (takeNavigateBudget(extras.budgetChars,
|
|
229
|
+
if (takeNavigateBudget(extras.budgetChars, measuredUsed(request, extras, [candidate], true)).ok) {
|
|
234
230
|
return candidate;
|
|
235
231
|
}
|
|
236
232
|
if (content.length > 0) content = content.slice(0, Math.max(0, content.length - 16));
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
|
|
7
|
+
import { resolvePersistedMemoryRelativePath } from "./orchestration/orchestrator-helpers.js";
|
|
8
|
+
import { MEMORY_ID_PATTERN } from "./recall-handles.js";
|
|
9
|
+
import { StorageManager } from "./storage.js";
|
|
10
|
+
|
|
11
|
+
test("concurrent memory writes remain readable when generated IDs collide", async () => {
|
|
12
|
+
const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-memory-write-collision-"));
|
|
13
|
+
const originalNow = Date.now;
|
|
14
|
+
const originalRandom = Math.random;
|
|
15
|
+
try {
|
|
16
|
+
const storage = new StorageManager(dir);
|
|
17
|
+
await storage.ensureDirectories();
|
|
18
|
+
let randomCall = 0;
|
|
19
|
+
Date.now = () => 1_700_000_000_000;
|
|
20
|
+
Math.random = () => {
|
|
21
|
+
const call = randomCall;
|
|
22
|
+
randomCall += 1;
|
|
23
|
+
return call === 45 ? 0.01 : (call + 1) / 100;
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
await Promise.all(
|
|
27
|
+
Array.from({ length: 46 }, (_, index) =>
|
|
28
|
+
storage.writeMemory("fact", `write collision candidate ${index}`, { source: "test" }),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
} finally {
|
|
32
|
+
Date.now = originalNow;
|
|
33
|
+
Math.random = originalRandom;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const memories = (await storage.readAllMemories()).filter((memory) =>
|
|
37
|
+
memory.content.startsWith("write collision candidate "),
|
|
38
|
+
);
|
|
39
|
+
assert.equal(memories.length, 46);
|
|
40
|
+
} finally {
|
|
41
|
+
Date.now = originalNow;
|
|
42
|
+
Math.random = originalRandom;
|
|
43
|
+
StorageManager.clearAllStaticCaches();
|
|
44
|
+
await rm(dir, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("concurrent artifact writes remain readable when generated IDs collide", async () => {
|
|
49
|
+
const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-artifact-write-collision-"));
|
|
50
|
+
const originalNow = Date.now;
|
|
51
|
+
const originalRandom = Math.random;
|
|
52
|
+
try {
|
|
53
|
+
const storage = new StorageManager(dir);
|
|
54
|
+
await storage.ensureDirectories();
|
|
55
|
+
let randomCall = 0;
|
|
56
|
+
Date.now = () => 1_700_000_000_000;
|
|
57
|
+
Math.random = () => {
|
|
58
|
+
const call = randomCall;
|
|
59
|
+
randomCall += 1;
|
|
60
|
+
return call === 45 ? 0.01 : (call + 1) / 100;
|
|
61
|
+
};
|
|
62
|
+
let ids: string[];
|
|
63
|
+
try {
|
|
64
|
+
ids = await Promise.all(
|
|
65
|
+
Array.from({ length: 46 }, (_, index) =>
|
|
66
|
+
storage.writeArtifact(`artifact collision candidate ${index}`),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
} finally {
|
|
70
|
+
Date.now = originalNow;
|
|
71
|
+
Math.random = originalRandom;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
assert.ok(ids.every((id) => MEMORY_ID_PATTERN.test(id)));
|
|
75
|
+
const artifacts = (await storage.searchArtifacts("artifact collision candidate", 100)).filter(
|
|
76
|
+
(artifact) => artifact.content.startsWith("artifact collision candidate "),
|
|
77
|
+
);
|
|
78
|
+
assert.equal(artifacts.length, 46);
|
|
79
|
+
} finally {
|
|
80
|
+
Date.now = originalNow;
|
|
81
|
+
Math.random = originalRandom;
|
|
82
|
+
StorageManager.clearAllStaticCaches();
|
|
83
|
+
await rm(dir, { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("fresh memory IDs resolve to their persisted dated path before path indexing", async () => {
|
|
88
|
+
const dir = await mkdtemp(path.join(os.tmpdir(), "remnic-memory-write-path-"));
|
|
89
|
+
try {
|
|
90
|
+
const storage = new StorageManager(dir);
|
|
91
|
+
await storage.ensureDirectories();
|
|
92
|
+
const written = await storage.writeMemory("fact", "fresh memory path candidate", {
|
|
93
|
+
source: "test",
|
|
94
|
+
});
|
|
95
|
+
const relativePath = resolvePersistedMemoryRelativePath({
|
|
96
|
+
memoryId: written.id,
|
|
97
|
+
pathById: new Map(),
|
|
98
|
+
category: "fact",
|
|
99
|
+
});
|
|
100
|
+
const persisted = await readFile(path.join(dir, relativePath), "utf8");
|
|
101
|
+
assert.equal(path.resolve(dir, relativePath), path.resolve(written.memory.path));
|
|
102
|
+
assert.match(persisted, /fresh memory path candidate/);
|
|
103
|
+
assert.ok(MEMORY_ID_PATTERN.test(written.id));
|
|
104
|
+
} finally {
|
|
105
|
+
StorageManager.clearAllStaticCaches();
|
|
106
|
+
await rm(dir, { recursive: true, force: true });
|
|
107
|
+
}
|
|
108
|
+
});
|
package/src/storage.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
open,
|
|
13
13
|
} from "node:fs/promises";
|
|
14
14
|
import { appendFileSync, createReadStream, mkdirSync, readFileSync, statSync } from "node:fs";
|
|
15
|
-
import { createHash } from "node:crypto";
|
|
15
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
16
16
|
import { computeLegacyContentHash, normalizeContent } from "./content-hash.js";
|
|
17
17
|
import { parseDriftProvenance, serializeDriftProvenance } from "./preferences/drift-types.js";
|
|
18
18
|
import { isAbortError, raceAbort } from "./abort-error.js";
|
|
@@ -3728,7 +3728,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
|
|
|
3728
3728
|
if (refIds) options = entityRefs.canonicalizeEntityRefOption(options, refIds);
|
|
3729
3729
|
const now = new Date();
|
|
3730
3730
|
const today = now.toISOString().slice(0, 10);
|
|
3731
|
-
const id = `${category}-${Date.now()}-${
|
|
3731
|
+
const id = `${category}-${Date.now()}-${randomUUID()}`;
|
|
3732
3732
|
const conf = options.confidence ?? 0.8;
|
|
3733
3733
|
const tier = confidenceTier(conf);
|
|
3734
3734
|
const validAt = normalizeMemoryWriteTimestamp("validAt", options.validAt);
|
|
@@ -4209,7 +4209,7 @@ export class StorageManager extends TombstoneBlockedCaptureIndexHost {
|
|
|
4209
4209
|
const dir = path.join(this.artifactsDir, day);
|
|
4210
4210
|
await mkdir(dir, { recursive: true });
|
|
4211
4211
|
|
|
4212
|
-
const id = `artifact-${Date.now()}-${
|
|
4212
|
+
const id = `artifact-${Date.now()}-${randomUUID()}`;
|
|
4213
4213
|
const fm: MemoryFrontmatter = {
|
|
4214
4214
|
id,
|
|
4215
4215
|
category: "fact",
|