@melra/memory 0.3.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +56 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +368 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +322 -0
- package/dist/index.test.js.map +1 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @melra/memory
|
|
2
|
+
|
|
3
|
+
Scoped, redacted local memory for [MELRA](https://github.com/XAGI-Lab/melra):
|
|
4
|
+
put, search, list, delete, and clear, backed by the same SQLite database as
|
|
5
|
+
tasks and workflows.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @melra/memory
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { MemoryOperationSchema } from "@melra/protocol";
|
|
13
|
+
import { LocalMemory, rankMemories } from "@melra/memory";
|
|
14
|
+
|
|
15
|
+
const memory = new LocalMemory(store);
|
|
16
|
+
memory.execute(
|
|
17
|
+
MemoryOperationSchema.parse({
|
|
18
|
+
kind: "memory",
|
|
19
|
+
action: "put",
|
|
20
|
+
key: "deploy-owner",
|
|
21
|
+
value: "platform team",
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`MemoryOperation` is the post-defaults shape, so parse the operation through the
|
|
27
|
+
schema rather than hand-filling `scope`, `confidence`, `tags`, `limit`, and
|
|
28
|
+
`includeSuperseded`.
|
|
29
|
+
|
|
30
|
+
Search is lexical, not embedded — tokenised, ranked by term overlap with exact
|
|
31
|
+
phrase matches promoted. That is a deliberate ceiling: it is deterministic,
|
|
32
|
+
needs no model call, and never sends anything anywhere. `rankMemories` and
|
|
33
|
+
`tokenize` are exported if you want the ranking without the store.
|
|
34
|
+
|
|
35
|
+
Every value passes through `redactMemoryValue` before it is written, so a token
|
|
36
|
+
pasted into a memory entry is not preserved in the database.
|
|
37
|
+
|
|
38
|
+
Reads and deletes are scope-aware: a scope only sees its own entries, so one
|
|
39
|
+
task cannot read what another stored by guessing a key.
|
|
40
|
+
|
|
41
|
+
Expired and superseded records are already invisible to every read path;
|
|
42
|
+
`LocalMemory` reclaims them on the next write to that scope, after
|
|
43
|
+
`MemoryRetention.maxAgeDays` (default 30). Pass `maxPerScope` to also cap live
|
|
44
|
+
memories — that one deletes records you can still read, so it defaults to `0`
|
|
45
|
+
(no ceiling).
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { LocalMemory } from "@melra/memory";
|
|
49
|
+
|
|
50
|
+
const bounded = new LocalMemory(store, { maxAgeDays: 7, maxPerScope: 5_000 });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requires Node.js 22 or newer. Full documentation:
|
|
54
|
+
[github.com/XAGI-Lab/melra](https://github.com/XAGI-Lab/melra)
|
|
55
|
+
|
|
56
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MemoryOperation } from "@melra/protocol";
|
|
2
|
+
import { SqliteStore, type MemoryRecord } from "@melra/storage-sqlite";
|
|
3
|
+
/**
|
|
4
|
+
* How long an unreachable memory row survives before compaction reclaims it,
|
|
5
|
+
* and an optional ceiling on live memories per scope.
|
|
6
|
+
*
|
|
7
|
+
* Expired and superseded rows are already filtered out of every read path, so
|
|
8
|
+
* removing them changes nothing a caller can observe — it only stops the file
|
|
9
|
+
* growing forever. `maxPerScope` is the opposite: it deletes memories that can
|
|
10
|
+
* still be read, so `0` (no ceiling) is the default and an operator opts in.
|
|
11
|
+
*/
|
|
12
|
+
export interface MemoryRetention {
|
|
13
|
+
maxAgeDays: number;
|
|
14
|
+
maxPerScope: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const DEFAULT_MEMORY_RETENTION: MemoryRetention;
|
|
17
|
+
export declare function redactMemoryValue(value: string): {
|
|
18
|
+
value: string;
|
|
19
|
+
redactions: string[];
|
|
20
|
+
};
|
|
21
|
+
export interface RankedMemory extends MemoryRecord {
|
|
22
|
+
score: number;
|
|
23
|
+
scoreBreakdown: {
|
|
24
|
+
lexical: number;
|
|
25
|
+
phrase: number;
|
|
26
|
+
confidence: number;
|
|
27
|
+
freshness: number;
|
|
28
|
+
context: number;
|
|
29
|
+
speaker: number;
|
|
30
|
+
diversityPenalty: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare function tokenize(value: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Deterministic local retrieval with inspectable scoring and no model call.
|
|
36
|
+
*
|
|
37
|
+
* The first pass combines BM25-style term evidence, exact phrase matching,
|
|
38
|
+
* provenance confidence, and freshness. The second pass applies a bounded
|
|
39
|
+
* maximal-marginal-relevance penalty so repeated records do not crowd out
|
|
40
|
+
* distinct evidence. A final bounded pass uses explicit episode order and
|
|
41
|
+
* speaker metadata when the caller supplies them.
|
|
42
|
+
*/
|
|
43
|
+
export declare function rankMemories(records: MemoryRecord[], query: string, limit: number, nowMs?: number): RankedMemory[];
|
|
44
|
+
export declare class LocalMemory {
|
|
45
|
+
private readonly store;
|
|
46
|
+
private readonly retention;
|
|
47
|
+
constructor(store: SqliteStore, retention?: MemoryRetention);
|
|
48
|
+
execute(operation: MemoryOperation): Record<string, unknown>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAS/B;;;;;;;;GAQG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,eAAO,MAAM,wBAAwB,EAAE,eAGtC,CAAC;AAGF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB,CASA;AAED,MAAM,WAAW,YAAa,SAAQ,YAAY;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;CACH;AAUD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEhD;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,YAAY,EAAE,EACvB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,SAAa,GACjB,YAAY,EAAE,CAqNhB;AAED,qBAAa,WAAW;IAEpB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;gBADT,KAAK,EAAE,WAAW,EAClB,SAAS,GAAE,eAA0C;IAGxE,OAAO,CAAC,SAAS,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAqJ7D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
// Copyright 2026 XAGI Labs Private Limited
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
const SECRET_PATTERNS = [
|
|
5
|
+
[/\b(?:sk|pk|api)[-_][a-z0-9_-]{16,}\b/gi, "[REDACTED_API_KEY]"],
|
|
6
|
+
[/\bBearer\s+[A-Za-z0-9._~+/-]+=*\b/gi, "Bearer [REDACTED_TOKEN]"],
|
|
7
|
+
[/\b(password|passwd|secret)\s*[:=]\s*\S+/gi, "$1=[REDACTED]"],
|
|
8
|
+
[/\bgh[opurs]_[A-Za-z0-9]{20,}\b/g, "[REDACTED_GITHUB_TOKEN]"],
|
|
9
|
+
];
|
|
10
|
+
export const DEFAULT_MEMORY_RETENTION = {
|
|
11
|
+
maxAgeDays: 30,
|
|
12
|
+
maxPerScope: 0,
|
|
13
|
+
};
|
|
14
|
+
export function redactMemoryValue(value) {
|
|
15
|
+
let redacted = value;
|
|
16
|
+
const redactions = [];
|
|
17
|
+
for (const [pattern, replacement] of SECRET_PATTERNS) {
|
|
18
|
+
const before = redacted;
|
|
19
|
+
redacted = redacted.replace(pattern, replacement);
|
|
20
|
+
if (redacted !== before)
|
|
21
|
+
redactions.push(replacement);
|
|
22
|
+
}
|
|
23
|
+
return { value: redacted, redactions };
|
|
24
|
+
}
|
|
25
|
+
const DAY_MS = 86_400_000;
|
|
26
|
+
const DEFAULT_HALF_LIFE_DAYS = 30;
|
|
27
|
+
const MAX_CANDIDATES = 5_000;
|
|
28
|
+
const CONTEXT_ANCHORS = 20;
|
|
29
|
+
const CONTEXT_DEPTH = 2;
|
|
30
|
+
const CONTEXT_DECAY = 0.9;
|
|
31
|
+
const SPEAKER_BOOST = 0.1;
|
|
32
|
+
export function tokenize(value) {
|
|
33
|
+
return value.toLocaleLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
34
|
+
}
|
|
35
|
+
function termFrequency(tokens, term) {
|
|
36
|
+
return tokens.reduce((count, token) => count + Number(token === term), 0);
|
|
37
|
+
}
|
|
38
|
+
function jaccard(left, right) {
|
|
39
|
+
if (left.size === 0 && right.size === 0)
|
|
40
|
+
return 1;
|
|
41
|
+
let intersection = 0;
|
|
42
|
+
for (const value of left) {
|
|
43
|
+
if (right.has(value))
|
|
44
|
+
intersection += 1;
|
|
45
|
+
}
|
|
46
|
+
return intersection / (left.size + right.size - intersection);
|
|
47
|
+
}
|
|
48
|
+
function freshness(updatedAt, nowMs) {
|
|
49
|
+
const ageDays = Math.max(0, nowMs - Date.parse(updatedAt)) / DAY_MS;
|
|
50
|
+
return Math.exp((-Math.LN2 * ageDays) / DEFAULT_HALF_LIFE_DAYS);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Deterministic local retrieval with inspectable scoring and no model call.
|
|
54
|
+
*
|
|
55
|
+
* The first pass combines BM25-style term evidence, exact phrase matching,
|
|
56
|
+
* provenance confidence, and freshness. The second pass applies a bounded
|
|
57
|
+
* maximal-marginal-relevance penalty so repeated records do not crowd out
|
|
58
|
+
* distinct evidence. A final bounded pass uses explicit episode order and
|
|
59
|
+
* speaker metadata when the caller supplies them.
|
|
60
|
+
*/
|
|
61
|
+
export function rankMemories(records, query, limit, nowMs = Date.now()) {
|
|
62
|
+
const queryTokens = [...new Set(tokenize(query))];
|
|
63
|
+
if (queryTokens.length === 0)
|
|
64
|
+
return [];
|
|
65
|
+
const queryTokenSet = new Set(queryTokens);
|
|
66
|
+
const documents = records.map((record) => ({
|
|
67
|
+
record,
|
|
68
|
+
tokens: tokenize(`${record.key} ${record.value} ${record.tags.join(" ")}`),
|
|
69
|
+
}));
|
|
70
|
+
const documentFrequency = new Map();
|
|
71
|
+
for (const document of documents) {
|
|
72
|
+
for (const token of new Set(document.tokens)) {
|
|
73
|
+
documentFrequency.set(token, (documentFrequency.get(token) ?? 0) + 1);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const averageLength = documents.reduce((total, document) => total + document.tokens.length, 0) /
|
|
77
|
+
Math.max(1, documents.length);
|
|
78
|
+
const normalizedQuery = query.trim().toLocaleLowerCase();
|
|
79
|
+
const scored = documents
|
|
80
|
+
.map(({ record, tokens }) => {
|
|
81
|
+
let lexical = 0;
|
|
82
|
+
for (const term of queryTokens) {
|
|
83
|
+
const containing = documentFrequency.get(term) ?? 0;
|
|
84
|
+
const idf = Math.log(1 + (documents.length - containing + 0.5) / (containing + 0.5));
|
|
85
|
+
const frequency = termFrequency(tokens, term);
|
|
86
|
+
const denominator = frequency +
|
|
87
|
+
1.2 *
|
|
88
|
+
(1 - 0.75 + 0.75 * (tokens.length / Math.max(1, averageLength)));
|
|
89
|
+
lexical +=
|
|
90
|
+
frequency === 0 ? 0 : idf * ((frequency * 2.2) / denominator);
|
|
91
|
+
}
|
|
92
|
+
const normalizedLexical = lexical / Math.max(1, queryTokens.length);
|
|
93
|
+
const phrase = `${record.key} ${record.value}`
|
|
94
|
+
.toLocaleLowerCase()
|
|
95
|
+
.includes(normalizedQuery)
|
|
96
|
+
? 1
|
|
97
|
+
: 0;
|
|
98
|
+
const fresh = freshness(record.updatedAt, nowMs);
|
|
99
|
+
const base = normalizedLexical * 0.62 +
|
|
100
|
+
phrase * 0.16 +
|
|
101
|
+
record.confidence * 0.14 +
|
|
102
|
+
fresh * 0.08;
|
|
103
|
+
return {
|
|
104
|
+
record,
|
|
105
|
+
tokenSet: new Set(tokens),
|
|
106
|
+
base,
|
|
107
|
+
normalizedLexical,
|
|
108
|
+
phrase,
|
|
109
|
+
fresh,
|
|
110
|
+
};
|
|
111
|
+
})
|
|
112
|
+
.filter((candidate) => candidate.normalizedLexical > 0 || candidate.phrase > 0)
|
|
113
|
+
.sort((left, right) => right.base - left.base ||
|
|
114
|
+
right.record.updatedAt.localeCompare(left.record.updatedAt));
|
|
115
|
+
const selected = [];
|
|
116
|
+
const remaining = scored.map((candidate) => ({
|
|
117
|
+
candidate,
|
|
118
|
+
maxSimilarity: 0,
|
|
119
|
+
}));
|
|
120
|
+
const diversityDepth = Math.min(limit, 20);
|
|
121
|
+
while (remaining.length > 0 && selected.length < diversityDepth) {
|
|
122
|
+
let bestIndex = 0;
|
|
123
|
+
let bestAdjusted = Number.NEGATIVE_INFINITY;
|
|
124
|
+
let bestPenalty = 0;
|
|
125
|
+
for (let index = 0; index < remaining.length; index += 1) {
|
|
126
|
+
const entry = remaining[index];
|
|
127
|
+
const candidate = entry.candidate;
|
|
128
|
+
const penalty = entry.maxSimilarity;
|
|
129
|
+
const adjusted = candidate.base * 0.88 - penalty * 0.12;
|
|
130
|
+
if (adjusted > bestAdjusted ||
|
|
131
|
+
(adjusted === bestAdjusted &&
|
|
132
|
+
candidate.record.updatedAt >
|
|
133
|
+
remaining[bestIndex].candidate.record.updatedAt)) {
|
|
134
|
+
bestIndex = index;
|
|
135
|
+
bestAdjusted = adjusted;
|
|
136
|
+
bestPenalty = penalty;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const [entry] = remaining.splice(bestIndex, 1);
|
|
140
|
+
if (entry === undefined)
|
|
141
|
+
break;
|
|
142
|
+
const candidate = entry.candidate;
|
|
143
|
+
selected.push({
|
|
144
|
+
candidate,
|
|
145
|
+
ranked: {
|
|
146
|
+
...candidate.record,
|
|
147
|
+
score: Number(bestAdjusted.toFixed(6)),
|
|
148
|
+
scoreBreakdown: {
|
|
149
|
+
lexical: Number(candidate.normalizedLexical.toFixed(6)),
|
|
150
|
+
phrase: candidate.phrase,
|
|
151
|
+
confidence: candidate.record.confidence,
|
|
152
|
+
freshness: Number(candidate.fresh.toFixed(6)),
|
|
153
|
+
context: 0,
|
|
154
|
+
speaker: 0,
|
|
155
|
+
diversityPenalty: Number(bestPenalty.toFixed(6)),
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
for (const remainingEntry of remaining) {
|
|
160
|
+
remainingEntry.maxSimilarity = Math.max(remainingEntry.maxSimilarity, jaccard(remainingEntry.candidate.tokenSet, candidate.tokenSet));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
for (let index = 0; index < remaining.length && selected.length < limit; index += 1) {
|
|
164
|
+
const candidate = remaining[index].candidate;
|
|
165
|
+
selected.push({
|
|
166
|
+
candidate,
|
|
167
|
+
ranked: {
|
|
168
|
+
...candidate.record,
|
|
169
|
+
score: Number((candidate.base * 0.88).toFixed(6)),
|
|
170
|
+
scoreBreakdown: {
|
|
171
|
+
lexical: Number(candidate.normalizedLexical.toFixed(6)),
|
|
172
|
+
phrase: candidate.phrase,
|
|
173
|
+
confidence: candidate.record.confidence,
|
|
174
|
+
freshness: Number(candidate.fresh.toFixed(6)),
|
|
175
|
+
context: 0,
|
|
176
|
+
speaker: 0,
|
|
177
|
+
diversityPenalty: 0,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
const rankedById = new Map(selected.map(({ ranked }) => [ranked.id, ranked]));
|
|
183
|
+
const episodeSequence = new Map();
|
|
184
|
+
for (const record of records) {
|
|
185
|
+
if (record.episodeId === undefined || record.sequence === undefined) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const key = `${record.episodeId}\u0000${record.sequence}`;
|
|
189
|
+
const entries = episodeSequence.get(key) ?? [];
|
|
190
|
+
entries.push(record);
|
|
191
|
+
episodeSequence.set(key, entries);
|
|
192
|
+
}
|
|
193
|
+
for (const { ranked: anchor } of selected.slice(0, CONTEXT_ANCHORS)) {
|
|
194
|
+
if (anchor.episodeId === undefined || anchor.sequence === undefined) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
for (let distance = 1; distance <= CONTEXT_DEPTH; distance += 1) {
|
|
198
|
+
for (const direction of [-1, 1]) {
|
|
199
|
+
const key = `${anchor.episodeId}\u0000${anchor.sequence + direction * distance}`;
|
|
200
|
+
for (const neighbor of episodeSequence.get(key) ?? []) {
|
|
201
|
+
const context = anchor.score * CONTEXT_DECAY ** distance;
|
|
202
|
+
const existing = rankedById.get(neighbor.id);
|
|
203
|
+
if (existing === undefined) {
|
|
204
|
+
rankedById.set(neighbor.id, {
|
|
205
|
+
...neighbor,
|
|
206
|
+
score: Number(context.toFixed(6)),
|
|
207
|
+
scoreBreakdown: {
|
|
208
|
+
lexical: 0,
|
|
209
|
+
phrase: 0,
|
|
210
|
+
confidence: neighbor.confidence,
|
|
211
|
+
freshness: Number(freshness(neighbor.updatedAt, nowMs).toFixed(6)),
|
|
212
|
+
context: Number(context.toFixed(6)),
|
|
213
|
+
speaker: 0,
|
|
214
|
+
diversityPenalty: 0,
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else if (context > existing.scoreBreakdown.context) {
|
|
219
|
+
existing.score = Number(Math.max(existing.score, context).toFixed(6));
|
|
220
|
+
existing.scoreBreakdown.context = Number(context.toFixed(6));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
for (const ranked of rankedById.values()) {
|
|
227
|
+
if (ranked.speaker !== undefined &&
|
|
228
|
+
tokenize(ranked.speaker).some((token) => queryTokenSet.has(token))) {
|
|
229
|
+
ranked.score = Number((ranked.score + SPEAKER_BOOST).toFixed(6));
|
|
230
|
+
ranked.scoreBreakdown.speaker = SPEAKER_BOOST;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return [...rankedById.values()]
|
|
234
|
+
.sort((left, right) => right.score - left.score ||
|
|
235
|
+
right.updatedAt.localeCompare(left.updatedAt))
|
|
236
|
+
.slice(0, limit);
|
|
237
|
+
}
|
|
238
|
+
export class LocalMemory {
|
|
239
|
+
store;
|
|
240
|
+
retention;
|
|
241
|
+
constructor(store, retention = DEFAULT_MEMORY_RETENTION) {
|
|
242
|
+
this.store = store;
|
|
243
|
+
this.retention = retention;
|
|
244
|
+
}
|
|
245
|
+
execute(operation) {
|
|
246
|
+
switch (operation.action) {
|
|
247
|
+
case "put": {
|
|
248
|
+
if (operation.key === undefined || operation.value === undefined) {
|
|
249
|
+
throw new Error("memory_put_requires_key_and_value");
|
|
250
|
+
}
|
|
251
|
+
const now = new Date().toISOString();
|
|
252
|
+
const redacted = redactMemoryValue(operation.value);
|
|
253
|
+
const redactedSpeaker = operation.speaker === undefined
|
|
254
|
+
? undefined
|
|
255
|
+
: redactMemoryValue(operation.speaker);
|
|
256
|
+
const redactedEpisodeId = operation.episodeId === undefined
|
|
257
|
+
? undefined
|
|
258
|
+
: redactMemoryValue(operation.episodeId);
|
|
259
|
+
const existing = operation.id === undefined
|
|
260
|
+
? undefined
|
|
261
|
+
: this.store.getMemory(operation.id);
|
|
262
|
+
if (existing !== undefined && existing.scope !== operation.scope) {
|
|
263
|
+
throw new Error("memory_scope_mismatch");
|
|
264
|
+
}
|
|
265
|
+
if (existing?.supersededBy !== undefined) {
|
|
266
|
+
throw new Error("memory_superseded_record_immutable");
|
|
267
|
+
}
|
|
268
|
+
const superseded = operation.supersedesId === undefined
|
|
269
|
+
? undefined
|
|
270
|
+
: this.store.getMemory(operation.supersedesId);
|
|
271
|
+
if (operation.supersedesId !== undefined &&
|
|
272
|
+
(superseded === undefined ||
|
|
273
|
+
superseded.scope !== operation.scope ||
|
|
274
|
+
operation.supersedesId === operation.id)) {
|
|
275
|
+
throw new Error("memory_supersedes_target_invalid");
|
|
276
|
+
}
|
|
277
|
+
const memory = {
|
|
278
|
+
id: operation.id ?? randomUUID(),
|
|
279
|
+
scope: operation.scope,
|
|
280
|
+
key: operation.key,
|
|
281
|
+
value: redacted.value,
|
|
282
|
+
source: operation.source ?? "mcp-client",
|
|
283
|
+
confidence: operation.confidence,
|
|
284
|
+
tags: operation.tags,
|
|
285
|
+
...(redactedSpeaker === undefined
|
|
286
|
+
? {}
|
|
287
|
+
: { speaker: redactedSpeaker.value }),
|
|
288
|
+
...(redactedEpisodeId === undefined
|
|
289
|
+
? {}
|
|
290
|
+
: { episodeId: redactedEpisodeId.value }),
|
|
291
|
+
...(operation.sequence === undefined
|
|
292
|
+
? {}
|
|
293
|
+
: { sequence: operation.sequence }),
|
|
294
|
+
...(operation.expiresAt === undefined
|
|
295
|
+
? {}
|
|
296
|
+
: { expiresAt: operation.expiresAt }),
|
|
297
|
+
...(operation.supersedesId === undefined
|
|
298
|
+
? {}
|
|
299
|
+
: { supersedesId: operation.supersedesId }),
|
|
300
|
+
createdAt: existing?.createdAt ?? now,
|
|
301
|
+
updatedAt: now,
|
|
302
|
+
};
|
|
303
|
+
this.store.putMemory(memory);
|
|
304
|
+
if (operation.supersedesId !== undefined &&
|
|
305
|
+
!this.store.supersedeMemory(operation.supersedesId, operation.scope, memory.id)) {
|
|
306
|
+
this.store.deleteMemory(memory.id, memory.scope);
|
|
307
|
+
throw new Error("memory_supersedes_target_invalid");
|
|
308
|
+
}
|
|
309
|
+
// Compact on the write path rather than on a timer: a scope only grows
|
|
310
|
+
// when something is put into it, so this is the one moment reclaiming
|
|
311
|
+
// is worth doing, and a local store is small enough that the cost is a
|
|
312
|
+
// few deletes against an indexed column.
|
|
313
|
+
const compacted = this.store.compactMemories(memory.scope, this.retention);
|
|
314
|
+
return {
|
|
315
|
+
stored: true,
|
|
316
|
+
id: memory.id,
|
|
317
|
+
scope: memory.scope,
|
|
318
|
+
key: memory.key,
|
|
319
|
+
tags: memory.tags,
|
|
320
|
+
speaker: memory.speaker ?? null,
|
|
321
|
+
episodeId: memory.episodeId ?? null,
|
|
322
|
+
sequence: memory.sequence ?? null,
|
|
323
|
+
expiresAt: memory.expiresAt ?? null,
|
|
324
|
+
supersedesId: memory.supersedesId ?? null,
|
|
325
|
+
redactions: [
|
|
326
|
+
...new Set([
|
|
327
|
+
...redacted.redactions,
|
|
328
|
+
...(redactedSpeaker?.redactions ?? []),
|
|
329
|
+
...(redactedEpisodeId?.redactions ?? []),
|
|
330
|
+
]),
|
|
331
|
+
],
|
|
332
|
+
compacted,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
case "search": {
|
|
336
|
+
if (operation.query === undefined) {
|
|
337
|
+
throw new Error("memory_search_requires_query");
|
|
338
|
+
}
|
|
339
|
+
const candidates = this.store.memoryCandidates(operation.scope, MAX_CANDIDATES, operation.includeSuperseded);
|
|
340
|
+
return {
|
|
341
|
+
memories: rankMemories(candidates, operation.query, operation.limit),
|
|
342
|
+
candidateCount: candidates.length,
|
|
343
|
+
ranking: "melra-hybrid-v2",
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
case "list":
|
|
347
|
+
return {
|
|
348
|
+
memories: this.store.listMemories(operation.scope, operation.limit, operation.includeSuperseded),
|
|
349
|
+
};
|
|
350
|
+
case "delete": {
|
|
351
|
+
if (operation.id === undefined) {
|
|
352
|
+
throw new Error("memory_delete_requires_id");
|
|
353
|
+
}
|
|
354
|
+
return {
|
|
355
|
+
deleted: this.store.deleteMemory(operation.id, operation.scope),
|
|
356
|
+
id: operation.id,
|
|
357
|
+
scope: operation.scope,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
case "clear":
|
|
361
|
+
return {
|
|
362
|
+
cleared: this.store.clearMemories(operation.scope),
|
|
363
|
+
scope: operation.scope,
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,eAAe,GAA4B;IAC/C,CAAC,wCAAwC,EAAE,oBAAoB,CAAC;IAChE,CAAC,qCAAqC,EAAE,yBAAyB,CAAC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IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC;oBAC/D,EAAE,EAAE,SAAS,CAAC,EAAE;oBAChB,KAAK,EAAE,SAAS,CAAC,KAAK;iBACvB,CAAC;YACJ,CAAC;YACD,KAAK,OAAO;gBACV,OAAO;oBACL,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC;oBAClD,KAAK,EAAE,SAAS,CAAC,KAAK;iBACvB,CAAC;QACN,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// Copyright 2026 XAGI Labs Private Limited
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { MemoryOperationSchema } from "@melra/protocol";
|
|
5
|
+
import { SqliteStore } from "@melra/storage-sqlite";
|
|
6
|
+
import { LocalMemory, rankMemories, redactMemoryValue, } from "./index.js";
|
|
7
|
+
let store;
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
store?.close();
|
|
10
|
+
store = undefined;
|
|
11
|
+
});
|
|
12
|
+
describe("LocalMemory", () => {
|
|
13
|
+
it("redacts common secret formats before persistence", () => {
|
|
14
|
+
const fakeGithubToken = ["ghp", "123456789012345678901234"].join("_");
|
|
15
|
+
const result = redactMemoryValue(`token ${fakeGithubToken} and password=hunter2`);
|
|
16
|
+
expect(result.value).not.toContain("hunter2");
|
|
17
|
+
expect(result.value).not.toContain("ghp_123");
|
|
18
|
+
expect(result.redactions.length).toBeGreaterThan(0);
|
|
19
|
+
});
|
|
20
|
+
it("redacts speaker and episode metadata before persistence", () => {
|
|
21
|
+
store = new SqliteStore(":memory:");
|
|
22
|
+
const memory = new LocalMemory(store);
|
|
23
|
+
const fakeGithubToken = ["ghp", "123456789012345678901234"].join("_");
|
|
24
|
+
const result = memory.execute(MemoryOperationSchema.parse({
|
|
25
|
+
kind: "memory",
|
|
26
|
+
action: "put",
|
|
27
|
+
id: "00000000-0000-4000-8000-000000000041",
|
|
28
|
+
scope: "workspace",
|
|
29
|
+
key: "turn",
|
|
30
|
+
value: "Safe value",
|
|
31
|
+
speaker: "Alex password=hunter2",
|
|
32
|
+
episodeId: fakeGithubToken,
|
|
33
|
+
sequence: 1,
|
|
34
|
+
}));
|
|
35
|
+
const persisted = store.getMemory("00000000-0000-4000-8000-000000000041");
|
|
36
|
+
expect(persisted?.speaker).not.toContain("hunter2");
|
|
37
|
+
expect(persisted?.episodeId).not.toContain("ghp_123");
|
|
38
|
+
expect(result.redactions.length).toBeGreaterThanOrEqual(2);
|
|
39
|
+
});
|
|
40
|
+
it("keeps memory isolated by scope", () => {
|
|
41
|
+
store = new SqliteStore(":memory:");
|
|
42
|
+
const memory = new LocalMemory(store);
|
|
43
|
+
memory.execute(MemoryOperationSchema.parse({
|
|
44
|
+
kind: "memory",
|
|
45
|
+
action: "put",
|
|
46
|
+
scope: "workspace",
|
|
47
|
+
key: "product",
|
|
48
|
+
value: "MELRA",
|
|
49
|
+
}));
|
|
50
|
+
const workspace = memory.execute(MemoryOperationSchema.parse({
|
|
51
|
+
kind: "memory",
|
|
52
|
+
action: "search",
|
|
53
|
+
scope: "workspace",
|
|
54
|
+
query: "melra",
|
|
55
|
+
}));
|
|
56
|
+
const user = memory.execute(MemoryOperationSchema.parse({
|
|
57
|
+
kind: "memory",
|
|
58
|
+
action: "search",
|
|
59
|
+
scope: "user",
|
|
60
|
+
query: "melra",
|
|
61
|
+
}));
|
|
62
|
+
expect(workspace.memories).toHaveLength(1);
|
|
63
|
+
expect(user.memories).toHaveLength(0);
|
|
64
|
+
});
|
|
65
|
+
it("uses persisted episode and speaker metadata during search", () => {
|
|
66
|
+
store = new SqliteStore(":memory:");
|
|
67
|
+
const memory = new LocalMemory(store);
|
|
68
|
+
memory.execute(MemoryOperationSchema.parse({
|
|
69
|
+
kind: "memory",
|
|
70
|
+
action: "put",
|
|
71
|
+
id: "00000000-0000-4000-8000-000000000031",
|
|
72
|
+
scope: "workspace",
|
|
73
|
+
key: "prompt",
|
|
74
|
+
value: "What topic did you research?",
|
|
75
|
+
speaker: "Jordan",
|
|
76
|
+
episodeId: "conversation-a",
|
|
77
|
+
sequence: 10,
|
|
78
|
+
}));
|
|
79
|
+
memory.execute(MemoryOperationSchema.parse({
|
|
80
|
+
kind: "memory",
|
|
81
|
+
action: "put",
|
|
82
|
+
id: "00000000-0000-4000-8000-000000000032",
|
|
83
|
+
scope: "workspace",
|
|
84
|
+
key: "answer",
|
|
85
|
+
value: "Adoption agencies.",
|
|
86
|
+
speaker: "Alex",
|
|
87
|
+
episodeId: "conversation-a",
|
|
88
|
+
sequence: 11,
|
|
89
|
+
}));
|
|
90
|
+
const result = memory.execute(MemoryOperationSchema.parse({
|
|
91
|
+
kind: "memory",
|
|
92
|
+
action: "search",
|
|
93
|
+
scope: "workspace",
|
|
94
|
+
query: "What did Alex research?",
|
|
95
|
+
}));
|
|
96
|
+
expect(result.memories.map((entry) => entry.id)).toContain("00000000-0000-4000-8000-000000000032");
|
|
97
|
+
expect(result.memories.find((entry) => entry.id === "00000000-0000-4000-8000-000000000032")?.scoreBreakdown.speaker).toBeGreaterThan(0);
|
|
98
|
+
});
|
|
99
|
+
it("ranks rare exact evidence ahead of generic duplicates", () => {
|
|
100
|
+
const now = "2026-07-28T00:00:00.000Z";
|
|
101
|
+
const ranked = rankMemories([
|
|
102
|
+
{
|
|
103
|
+
id: "00000000-0000-4000-8000-000000000001",
|
|
104
|
+
scope: "workspace",
|
|
105
|
+
key: "release",
|
|
106
|
+
value: "The launch codename is aurora.",
|
|
107
|
+
source: "test",
|
|
108
|
+
confidence: 0.95,
|
|
109
|
+
tags: ["launch"],
|
|
110
|
+
createdAt: now,
|
|
111
|
+
updatedAt: now,
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "00000000-0000-4000-8000-000000000002",
|
|
115
|
+
scope: "workspace",
|
|
116
|
+
key: "generic",
|
|
117
|
+
value: "The release process has a launch checklist.",
|
|
118
|
+
source: "test",
|
|
119
|
+
confidence: 1,
|
|
120
|
+
tags: [],
|
|
121
|
+
createdAt: now,
|
|
122
|
+
updatedAt: now,
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "00000000-0000-4000-8000-000000000003",
|
|
126
|
+
scope: "workspace",
|
|
127
|
+
key: "duplicate",
|
|
128
|
+
value: "The release process has a launch checklist.",
|
|
129
|
+
source: "test",
|
|
130
|
+
confidence: 1,
|
|
131
|
+
tags: [],
|
|
132
|
+
createdAt: now,
|
|
133
|
+
updatedAt: now,
|
|
134
|
+
},
|
|
135
|
+
], "launch codename aurora", 3, Date.parse(now));
|
|
136
|
+
expect(ranked[0]?.id).toBe("00000000-0000-4000-8000-000000000001");
|
|
137
|
+
expect(ranked[0]?.scoreBreakdown.lexical).toBeGreaterThan(0);
|
|
138
|
+
expect(ranked[2]?.scoreBreakdown.diversityPenalty).toBeGreaterThan(0);
|
|
139
|
+
});
|
|
140
|
+
it("propagates relevance only to adjacent records in the same episode", () => {
|
|
141
|
+
const now = "2026-07-28T00:00:00.000Z";
|
|
142
|
+
const ranked = rankMemories([
|
|
143
|
+
{
|
|
144
|
+
id: "00000000-0000-4000-8000-000000000011",
|
|
145
|
+
scope: "workspace",
|
|
146
|
+
key: "prompt",
|
|
147
|
+
value: "What topic did you research?",
|
|
148
|
+
source: "test",
|
|
149
|
+
confidence: 1,
|
|
150
|
+
tags: [],
|
|
151
|
+
episodeId: "conversation-a",
|
|
152
|
+
sequence: 10,
|
|
153
|
+
createdAt: now,
|
|
154
|
+
updatedAt: now,
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
id: "00000000-0000-4000-8000-000000000012",
|
|
158
|
+
scope: "workspace",
|
|
159
|
+
key: "answer",
|
|
160
|
+
value: "Adoption agencies.",
|
|
161
|
+
source: "test",
|
|
162
|
+
confidence: 1,
|
|
163
|
+
tags: [],
|
|
164
|
+
episodeId: "conversation-a",
|
|
165
|
+
sequence: 11,
|
|
166
|
+
createdAt: now,
|
|
167
|
+
updatedAt: now,
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: "00000000-0000-4000-8000-000000000013",
|
|
171
|
+
scope: "workspace",
|
|
172
|
+
key: "unrelated",
|
|
173
|
+
value: "Private banking.",
|
|
174
|
+
source: "test",
|
|
175
|
+
confidence: 1,
|
|
176
|
+
tags: [],
|
|
177
|
+
episodeId: "conversation-b",
|
|
178
|
+
sequence: 11,
|
|
179
|
+
createdAt: now,
|
|
180
|
+
updatedAt: now,
|
|
181
|
+
},
|
|
182
|
+
], "What did Alex research?", 3, Date.parse(now));
|
|
183
|
+
expect(ranked.map((memory) => memory.id)).toContain("00000000-0000-4000-8000-000000000012");
|
|
184
|
+
expect(ranked.map((memory) => memory.id)).not.toContain("00000000-0000-4000-8000-000000000013");
|
|
185
|
+
});
|
|
186
|
+
it("boosts a record spoken by the entity named in the query", () => {
|
|
187
|
+
const now = "2026-07-28T00:00:00.000Z";
|
|
188
|
+
const ranked = rankMemories([
|
|
189
|
+
{
|
|
190
|
+
id: "00000000-0000-4000-8000-000000000021",
|
|
191
|
+
scope: "workspace",
|
|
192
|
+
key: "turn-one",
|
|
193
|
+
value: "I enjoy hiking and painting.",
|
|
194
|
+
source: "test",
|
|
195
|
+
confidence: 1,
|
|
196
|
+
tags: [],
|
|
197
|
+
speaker: "Jordan",
|
|
198
|
+
createdAt: now,
|
|
199
|
+
updatedAt: now,
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
id: "00000000-0000-4000-8000-000000000022",
|
|
203
|
+
scope: "workspace",
|
|
204
|
+
key: "turn-two",
|
|
205
|
+
value: "I enjoy hiking and painting.",
|
|
206
|
+
source: "test",
|
|
207
|
+
confidence: 1,
|
|
208
|
+
tags: [],
|
|
209
|
+
speaker: "Alex",
|
|
210
|
+
createdAt: now,
|
|
211
|
+
updatedAt: now,
|
|
212
|
+
},
|
|
213
|
+
], "What does Alex enjoy?", 2, Date.parse(now));
|
|
214
|
+
expect(ranked[0]?.id).toBe("00000000-0000-4000-8000-000000000022");
|
|
215
|
+
});
|
|
216
|
+
it("supports expiry and scoped supersession", () => {
|
|
217
|
+
store = new SqliteStore(":memory:");
|
|
218
|
+
const memory = new LocalMemory(store);
|
|
219
|
+
const first = memory.execute(MemoryOperationSchema.parse({
|
|
220
|
+
kind: "memory",
|
|
221
|
+
action: "put",
|
|
222
|
+
scope: "workspace",
|
|
223
|
+
key: "runtime",
|
|
224
|
+
value: "Use version one",
|
|
225
|
+
}));
|
|
226
|
+
memory.execute(MemoryOperationSchema.parse({
|
|
227
|
+
kind: "memory",
|
|
228
|
+
action: "put",
|
|
229
|
+
scope: "workspace",
|
|
230
|
+
key: "runtime",
|
|
231
|
+
value: "Use version two",
|
|
232
|
+
supersedesId: first.id,
|
|
233
|
+
}));
|
|
234
|
+
memory.execute(MemoryOperationSchema.parse({
|
|
235
|
+
kind: "memory",
|
|
236
|
+
action: "put",
|
|
237
|
+
scope: "workspace",
|
|
238
|
+
key: "expired",
|
|
239
|
+
value: "Do not retrieve this",
|
|
240
|
+
expiresAt: "2020-01-01T00:00:00.000Z",
|
|
241
|
+
}));
|
|
242
|
+
const current = memory.execute(MemoryOperationSchema.parse({
|
|
243
|
+
kind: "memory",
|
|
244
|
+
action: "search",
|
|
245
|
+
scope: "workspace",
|
|
246
|
+
query: "runtime version",
|
|
247
|
+
}));
|
|
248
|
+
expect(current.memories).toHaveLength(1);
|
|
249
|
+
expect(JSON.stringify(current)).toContain("version two");
|
|
250
|
+
expect(JSON.stringify(current)).not.toContain("version one");
|
|
251
|
+
expect(JSON.stringify(current)).not.toContain("Do not retrieve");
|
|
252
|
+
expect(() => memory.execute(MemoryOperationSchema.parse({
|
|
253
|
+
kind: "memory",
|
|
254
|
+
action: "put",
|
|
255
|
+
scope: "workspace",
|
|
256
|
+
id: first.id,
|
|
257
|
+
key: "runtime",
|
|
258
|
+
value: "Try to revive version one",
|
|
259
|
+
}))).toThrow("memory_superseded_record_immutable");
|
|
260
|
+
});
|
|
261
|
+
it("cannot delete or overwrite a record through a different scope", () => {
|
|
262
|
+
store = new SqliteStore(":memory:");
|
|
263
|
+
const memory = new LocalMemory(store);
|
|
264
|
+
const inserted = memory.execute(MemoryOperationSchema.parse({
|
|
265
|
+
kind: "memory",
|
|
266
|
+
action: "put",
|
|
267
|
+
scope: "workspace",
|
|
268
|
+
key: "isolated",
|
|
269
|
+
value: "workspace only",
|
|
270
|
+
}));
|
|
271
|
+
const wrongScopeDelete = memory.execute(MemoryOperationSchema.parse({
|
|
272
|
+
kind: "memory",
|
|
273
|
+
action: "delete",
|
|
274
|
+
scope: "user",
|
|
275
|
+
id: inserted.id,
|
|
276
|
+
}));
|
|
277
|
+
expect(wrongScopeDelete.deleted).toBe(false);
|
|
278
|
+
expect(store.getMemory(inserted.id)?.value).toBe("workspace only");
|
|
279
|
+
expect(() => memory.execute(MemoryOperationSchema.parse({
|
|
280
|
+
kind: "memory",
|
|
281
|
+
action: "put",
|
|
282
|
+
scope: "user",
|
|
283
|
+
id: inserted.id,
|
|
284
|
+
key: "isolated",
|
|
285
|
+
value: "cross-scope overwrite",
|
|
286
|
+
}))).toThrow("memory_scope_mismatch");
|
|
287
|
+
});
|
|
288
|
+
it("reclaims unreachable records on the next write", () => {
|
|
289
|
+
store = new SqliteStore(":memory:");
|
|
290
|
+
const memory = new LocalMemory(store, { maxAgeDays: 0, maxPerScope: 0 });
|
|
291
|
+
store.putMemory({
|
|
292
|
+
id: "00000000-0000-4000-8000-0000000000e1",
|
|
293
|
+
scope: "workspace",
|
|
294
|
+
key: "stale",
|
|
295
|
+
value: "already expired",
|
|
296
|
+
source: "test",
|
|
297
|
+
confidence: 0.5,
|
|
298
|
+
tags: [],
|
|
299
|
+
expiresAt: "2000-01-01T00:00:00.000Z",
|
|
300
|
+
createdAt: "2000-01-01T00:00:00.000Z",
|
|
301
|
+
updatedAt: "2000-01-01T00:00:00.000Z",
|
|
302
|
+
});
|
|
303
|
+
// Nothing reads it, but until a write happens nothing removes it either.
|
|
304
|
+
expect(store.listMemories("workspace", 10)).toHaveLength(0);
|
|
305
|
+
expect(store.getMemory("00000000-0000-4000-8000-0000000000e1")).toBeDefined();
|
|
306
|
+
const result = memory.execute(MemoryOperationSchema.parse({
|
|
307
|
+
kind: "memory",
|
|
308
|
+
action: "put",
|
|
309
|
+
scope: "workspace",
|
|
310
|
+
key: "fresh",
|
|
311
|
+
value: "still here",
|
|
312
|
+
}));
|
|
313
|
+
expect(result.compacted).toEqual({
|
|
314
|
+
expired: 1,
|
|
315
|
+
superseded: 0,
|
|
316
|
+
evicted: 0,
|
|
317
|
+
});
|
|
318
|
+
expect(store.getMemory("00000000-0000-4000-8000-0000000000e1")).toBeUndefined();
|
|
319
|
+
expect(store.listMemories("workspace", 10)).toHaveLength(1);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,sCAAsC;AAEtC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,GAElB,MAAM,YAAY,CAAC;AAEpB,IAAI,KAA8B,CAAC;AAEnC,SAAS,CAAC,GAAG,EAAE;IACb,KAAK,EAAE,KAAK,EAAE,CAAC;IACf,KAAK,GAAG,SAAS,CAAC;AACp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OAAO;YACZ,KAAK,EAAE,YAAY;SACpB,CAAC,CACH,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC;YAC/B,OAAO,EAAE,CAAC;YACV,UAAU,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;SACX,CAAC,CAAC;QACH,MAAM,CACJ,KAAK,CAAC,SAAS,CAAC,sCAAsC,CAAC,CACxD,CAAC,aAAa,EAAE,CAAC;QAClB,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@melra/memory",
|
|
3
|
+
"version": "0.3.0-alpha.10",
|
|
4
|
+
"description": "Scoped and redacted operational memory for the MELRA kernel.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/XAGI-Lab/melra.git",
|
|
9
|
+
"directory": "packages/memory"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/XAGI-Lab/melra#readme",
|
|
12
|
+
"bugs": "https://github.com/XAGI-Lab/melra/issues",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@melra/protocol": "0.3.0-alpha.10",
|
|
25
|
+
"@melra/storage-sqlite": "0.3.0-alpha.10"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
32
|
+
}
|
|
33
|
+
}
|