@hilbras/remembra 3.2.0 → 3.4.0
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/CHANGELOG.md +84 -0
- package/README.md +1 -0
- package/dist/backend.d.ts +29 -0
- package/dist/backend.js +2 -0
- package/dist/backend.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.js +60 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.js +13 -6
- package/dist/http.js.map +1 -1
- package/dist/index.js +56 -24
- package/dist/index.js.map +1 -1
- package/dist/retrieval.d.ts +14 -6
- package/dist/retrieval.js +22 -12
- package/dist/retrieval.js.map +1 -1
- package/dist/service.d.ts +6 -4
- package/dist/service.js +96 -6
- package/dist/service.js.map +1 -1
- package/dist/store.d.ts +40 -6
- package/dist/store.js +327 -89
- package/dist/store.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -1
- package/docs/architecture.md +98 -0
- package/docs/clients.md +2 -0
- package/docs/memory-model.md +26 -9
- package/docs/security.md +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,90 @@ Format follows [Keep a Changelog](https://keepachangelog.com/).
|
|
|
7
7
|
> (3.0.0 = v3). Earlier releases used independent semver: 0.1.0 = v1,
|
|
8
8
|
> 0.2.0 = v1.5, 0.3.0 = v2, 0.4.0 = v3.
|
|
9
9
|
|
|
10
|
+
## [3.4.0] — 2026-09-23
|
|
11
|
+
|
|
12
|
+
**Phase 4 of the deep audit** — retrieval & memory quality.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- **Exponential recency decay** — ~30-day half-life replaces the linear ramp
|
|
16
|
+
that hit a hard zero at 60 days (audit #20): a 60-day-old memory now earns
|
|
17
|
+
~5 points instead of 0, and old-but-important facts stop falling off a
|
|
18
|
+
cliff. Future-dated files clamp to "fresh"; invalid dates score 0.
|
|
19
|
+
- **Importance normalized across modes** — keyword mode drops ×10 → ×4 to
|
|
20
|
+
match semantic mode (audit: "same memory ranks differently depending on
|
|
21
|
+
embedding enablement"). The delta for importance 1→5 is now identical
|
|
22
|
+
(+16) in both modes.
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
- **Provenance weighting** (audit: "source stored but never ranked") —
|
|
26
|
+
memories carry `provenance: explicit | auto` in frontmatter: direct
|
|
27
|
+
tool/API stores are `explicit` (+10 in ranking, both modes), digest
|
|
28
|
+
extractions are `auto`. Pre-3.4.0 files have no field and score neutrally.
|
|
29
|
+
Preserved through export/import.
|
|
30
|
+
- **Fuzzy dedup fast path** (audit: "dedup tolerance for fuzzy matches") —
|
|
31
|
+
three dedup tiers now: exact → textual near-identity (Sørensen–Dice ≥ 0.9
|
|
32
|
+
over bigrams; punctuation/case/typos) skipped **without an LLM call** →
|
|
33
|
+
LLM merge for everything semantically evolved. Changed quantities
|
|
34
|
+
(100→500 rpm, v2→v3) are explicitly *not* near-duplicates — they always
|
|
35
|
+
reach the merge arbiter. Works against active, revives archived, and
|
|
36
|
+
dedupes within a single digest batch.
|
|
37
|
+
- `docs/memory-model.md`: dedup tiers, corrected ranking weights, provenance
|
|
38
|
+
row, stale "8-char id"/"embeddings planned for v2" text fixed.
|
|
39
|
+
|
|
40
|
+
### Deferred (recorded, not dropped)
|
|
41
|
+
- **Lazy loading for >10K stores** (audit Phase 4, P2) — the mechanism that
|
|
42
|
+
actually serves this is the parsed-memory cache scheduled for Phase 5
|
|
43
|
+
(performance); building a separate metadata index now would duplicate it.
|
|
44
|
+
Tracked here per scope decision.
|
|
45
|
+
|
|
46
|
+
### Added (tests)
|
|
47
|
+
10 Phase-4 tests: decay curve + half-life + no-cliff, importance-delta
|
|
48
|
+
equality across modes, provenance deltas + ordering + persistence + snapshot
|
|
49
|
+
round trip, fuzzy skip (punctuation/typo/quantity guard), in-batch dedup,
|
|
50
|
+
archived revive, cross-scope isolation. **96/96 total.**
|
|
51
|
+
|
|
52
|
+
## [3.3.0] — 2026-09-23
|
|
53
|
+
|
|
54
|
+
**Phase 3 of the deep audit** — architecture: swappable backend, cross-process
|
|
55
|
+
locking, crash recovery, structured errors.
|
|
56
|
+
|
|
57
|
+
### Added
|
|
58
|
+
- **`MemoryBackend` interface** (`src/backend.ts`) — `MemoryService` now
|
|
59
|
+
depends on the storage contract, not the file store; a DB backend can be
|
|
60
|
+
dropped in without touching service/transport code. Tested against an
|
|
61
|
+
in-memory implementation. Fixes audit Phase 3 item.
|
|
62
|
+
- **Advisory file locking** — `<root>/.remembra.lock` (`O_EXCL` create) around
|
|
63
|
+
every mutation *including its read*, plus an in-process FIFO queue. Stale
|
|
64
|
+
locks (dead pid or older than `REMEMBRA_LOCK_STALE_MS`) are stolen;
|
|
65
|
+
waiters fail with typed `LOCK_TIMEOUT` after `REMEMBRA_LOCK_TIMEOUT_MS`.
|
|
66
|
+
Fixes audit Phase 2 item (concurrent writers) and closes the
|
|
67
|
+
touch-vs-archive resurrection window.
|
|
68
|
+
- **Crash-recovery pass** (the audit's "journal", recovery-pass flavor —
|
|
69
|
+
documented rationale in `docs/architecture.md`): on first access per
|
|
70
|
+
process, deletes orphaned `*.tmp` files and reconciles ids left in *both*
|
|
71
|
+
active and archived trees by an interrupted archive/revive (finding #19);
|
|
72
|
+
newest `updatedAt` wins. Logged when it does anything.
|
|
73
|
+
- **Structured error classification** — `RemembraError` with stable codes
|
|
74
|
+
(`INVALID_INPUT`, `SNAPSHOT_INVALID`, `SCOPE_ESCAPES_ROOT`, `NOT_FOUND`,
|
|
75
|
+
`CONFLICT`, `LOCK_TIMEOUT`, `IO_ERROR`, `LLM_ERROR`). HTTP maps codes →
|
|
76
|
+
statuses and includes `code` in error bodies (423 for locked, 502 for LLM
|
|
77
|
+
failures); MCP tools return `[CODE] message` with `isError: true`; raw fs
|
|
78
|
+
failures wrap as `IO_ERROR`. Fixes audit Phase 2 item.
|
|
79
|
+
- **`docs/architecture.md`** — backend seam, locking model, recovery pass,
|
|
80
|
+
error-code table, schema-versioning notes.
|
|
81
|
+
|
|
82
|
+
### Changed
|
|
83
|
+
- `archive()` now bumps `updatedAt` (state change updates recency; also makes
|
|
84
|
+
crash-recovery tie-breaks deterministic).
|
|
85
|
+
- All six MCP tool handlers catch and classify failures instead of throwing
|
|
86
|
+
through the SDK.
|
|
87
|
+
|
|
88
|
+
### Added (tests)
|
|
89
|
+
15 Phase-3 tests: non-file backend swappability, lock release/steal/timeout,
|
|
90
|
+
HTTP 423, mixed-concurrency single-tree invariant, tmp + both recovery
|
|
91
|
+
directions, error codes on every boundary, `formatToolError`/`statusFor`
|
|
92
|
+
units. **86/86 total.**
|
|
93
|
+
|
|
10
94
|
## [3.2.0] — 2026-09-23
|
|
11
95
|
|
|
12
96
|
**Phase 2 of the deep audit** — data integrity, portability, and shared schemas.
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ Full reference: **[docs/tools.md](docs/tools.md)**
|
|
|
139
139
|
| [AI providers](docs/providers.md) | Digest LLM + embeddings configuration |
|
|
140
140
|
| [Lifecycle](docs/lifecycle.md) | Decay, archiving, auto-delete, contradiction merging |
|
|
141
141
|
| [Security](docs/security.md) | Trust model, enforced protections, deployment checklist |
|
|
142
|
+
| [Architecture](docs/architecture.md) | Backend interface, locking, crash recovery, error codes |
|
|
142
143
|
| [Contributing](CONTRIBUTING.md) | Dev workflow and guidelines |
|
|
143
144
|
| [Changelog](CHANGELOG.md) | Release history |
|
|
144
145
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Memory, StoreInput } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Storage abstraction (audit: Phase 3 — separate MemoryStore abstraction to
|
|
4
|
+
* enable a future DB swap).
|
|
5
|
+
*
|
|
6
|
+
* `MemoryService` only ever talks to this contract. `MemoryStore` is the
|
|
7
|
+
* file-backed implementation shipped today; a SQLite/vector-DB backend would
|
|
8
|
+
* only need to satisfy this interface (see docs/architecture.md).
|
|
9
|
+
*
|
|
10
|
+
* Concurrency contract for implementations:
|
|
11
|
+
* - mutating calls must be safe under same-process concurrency (queueing) and
|
|
12
|
+
* cross-process concurrency (advisory lock) — a caller may issue `touch()`
|
|
13
|
+
* while another process runs `archive()`;
|
|
14
|
+
* - a memory id must exist in exactly one tree at rest;
|
|
15
|
+
* - `importMemory` must refuse ids that already exist (return false).
|
|
16
|
+
*/
|
|
17
|
+
export interface MemoryBackend {
|
|
18
|
+
store(input: StoreInput, embedding?: number[], opts?: {
|
|
19
|
+
provenance?: Memory["provenance"];
|
|
20
|
+
}): Promise<Memory>;
|
|
21
|
+
get(id: string): Promise<Memory | null>;
|
|
22
|
+
all(includeArchived?: boolean): Promise<Memory[]>;
|
|
23
|
+
update(memory: Memory): Promise<Memory>;
|
|
24
|
+
archive(id: string): Promise<Memory | null>;
|
|
25
|
+
revive(id: string): Promise<Memory | null>;
|
|
26
|
+
touch(id: string): Promise<void>;
|
|
27
|
+
forget(id: string): Promise<boolean>;
|
|
28
|
+
importMemory(m: Memory): Promise<boolean>;
|
|
29
|
+
}
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":""}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error classification (audit: Phase 2 — structured error
|
|
3
|
+
* classification for store operations).
|
|
4
|
+
*
|
|
5
|
+
* Every failure that callers should react to carries a stable `code`.
|
|
6
|
+
* HTTP maps codes to statuses; MCP tools surface them as `[CODE] message`.
|
|
7
|
+
*/
|
|
8
|
+
export type ErrorCode = "INVALID_INPUT" | "SNAPSHOT_INVALID" | "SCOPE_ESCAPES_ROOT" | "NOT_FOUND" | "CONFLICT" | "LOCK_TIMEOUT" | "IO_ERROR" | "LLM_ERROR";
|
|
9
|
+
export declare class RemembraError extends Error {
|
|
10
|
+
readonly code: ErrorCode;
|
|
11
|
+
constructor(code: ErrorCode, message: string, options?: {
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
export declare function isRemembraError(err: unknown): err is RemembraError;
|
|
16
|
+
export declare function statusFor(err: RemembraError): number;
|
|
17
|
+
/** Re-throw Zod failures as a classified error; pass anything else through. */
|
|
18
|
+
export declare function inputError(err: unknown, code: "INVALID_INPUT" | "SNAPSHOT_INVALID"): unknown;
|
|
19
|
+
/** Uniform single-line rendering for MCP tool failures. */
|
|
20
|
+
export declare function formatToolError(err: unknown): string;
|
|
21
|
+
/** MCP tool error result shape (structural — no SDK import needed). */
|
|
22
|
+
export declare function toolFail(err: unknown): {
|
|
23
|
+
content: {
|
|
24
|
+
type: "text";
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
isError: true;
|
|
28
|
+
};
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error classification (audit: Phase 2 — structured error
|
|
3
|
+
* classification for store operations).
|
|
4
|
+
*
|
|
5
|
+
* Every failure that callers should react to carries a stable `code`.
|
|
6
|
+
* HTTP maps codes to statuses; MCP tools surface them as `[CODE] message`.
|
|
7
|
+
*/
|
|
8
|
+
export class RemembraError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
constructor(code, message, options) {
|
|
11
|
+
super(message, options);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.name = "RemembraError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function isRemembraError(err) {
|
|
17
|
+
return err instanceof RemembraError;
|
|
18
|
+
}
|
|
19
|
+
const HTTP_STATUS = {
|
|
20
|
+
INVALID_INPUT: 400,
|
|
21
|
+
SNAPSHOT_INVALID: 400,
|
|
22
|
+
SCOPE_ESCAPES_ROOT: 400,
|
|
23
|
+
NOT_FOUND: 404,
|
|
24
|
+
CONFLICT: 409,
|
|
25
|
+
LOCK_TIMEOUT: 423, // Locked
|
|
26
|
+
IO_ERROR: 500,
|
|
27
|
+
LLM_ERROR: 502,
|
|
28
|
+
};
|
|
29
|
+
export function statusFor(err) {
|
|
30
|
+
return HTTP_STATUS[err.code] ?? 500;
|
|
31
|
+
}
|
|
32
|
+
function zodSummary(err) {
|
|
33
|
+
const issues = err.issues ?? [];
|
|
34
|
+
const first = issues[0];
|
|
35
|
+
const where = first ? first.path.join(".") || "(root)" : "input";
|
|
36
|
+
const what = first ? first.message : "invalid input";
|
|
37
|
+
return issues.length > 1 ? `${where}: ${what} (+${issues.length - 1} more)` : `${where}: ${what}`;
|
|
38
|
+
}
|
|
39
|
+
function isZodLike(err) {
|
|
40
|
+
return typeof err === "object" && err !== null && err.name === "ZodError";
|
|
41
|
+
}
|
|
42
|
+
/** Re-throw Zod failures as a classified error; pass anything else through. */
|
|
43
|
+
export function inputError(err, code) {
|
|
44
|
+
if (isZodLike(err))
|
|
45
|
+
return new RemembraError(code, zodSummary(err), { cause: err });
|
|
46
|
+
return err;
|
|
47
|
+
}
|
|
48
|
+
/** Uniform single-line rendering for MCP tool failures. */
|
|
49
|
+
export function formatToolError(err) {
|
|
50
|
+
if (isRemembraError(err))
|
|
51
|
+
return `[${err.code}] ${err.message}`;
|
|
52
|
+
if (isZodLike(err))
|
|
53
|
+
return `[INVALID_INPUT] ${zodSummary(err)}`;
|
|
54
|
+
return `[INTERNAL] ${err instanceof Error ? err.message : String(err)}`;
|
|
55
|
+
}
|
|
56
|
+
/** MCP tool error result shape (structural — no SDK import needed). */
|
|
57
|
+
export function toolFail(err) {
|
|
58
|
+
return { content: [{ type: "text", text: formatToolError(err) }], isError: true };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAE3B;IADX,YACW,IAAe,EACxB,OAAe,EACf,OAA6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IAAI,GAAG,KAAK,IAAI,IAAK,GAA0B,CAAC,IAAI,KAAK,UAAU,CAAC;AACpG,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,IAA0C;IACjF,IAAI,SAAS,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACpF,OAAO,GAAG,CAAC;AACb,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,eAAe,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;IAChE,IAAI,SAAS,CAAC,GAAG,CAAC;QAAE,OAAO,mBAAmB,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;IAChE,OAAO,cAAc,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,GAAY;IAInC,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AACpF,CAAC"}
|
package/dist/http.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
2
|
import { timingSafeEqual } from "node:crypto";
|
|
3
3
|
import { DigestInput } from "./types.js";
|
|
4
|
+
import { isRemembraError, statusFor } from "./errors.js";
|
|
4
5
|
const DEFAULT_MAX_BODY = 10 * 1024 * 1024; // transcripts can be large — 10 MiB
|
|
5
6
|
/**
|
|
6
7
|
* Listen policy (P1 audit: default-deny):
|
|
@@ -95,12 +96,18 @@ export function createHttpServer(service, opts = {}) {
|
|
|
95
96
|
}
|
|
96
97
|
catch (err) {
|
|
97
98
|
const name = err.name;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
99
|
+
// Structured classification: typed errors carry a stable code → status.
|
|
100
|
+
const status = isRemembraError(err)
|
|
101
|
+
? statusFor(err)
|
|
102
|
+
: name === "ZodError" || name === "BadRequestError"
|
|
103
|
+
? 400
|
|
104
|
+
: name === "PayloadTooLarge"
|
|
105
|
+
? 413
|
|
106
|
+
: 500;
|
|
107
|
+
send(res, status, {
|
|
108
|
+
error: err instanceof Error ? err.message : String(err),
|
|
109
|
+
...(isRemembraError(err) ? { code: err.code } : {}),
|
|
110
|
+
});
|
|
104
111
|
}
|
|
105
112
|
});
|
|
106
113
|
const port = opts.port ?? Number(process.env.REMEMBRA_PORT ?? 8787);
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAYzD,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,oCAAoC;AAE/E;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAwB,EACxB,MAA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AAG,GAAG,IAAI,KAAK,CAAC,iCAAiC,QAAQ,SAAS,CAAC,CAAC;gBAC1E,GAAG,CAAC,IAAI,GAAG,iBAAiB,CAAC;gBAC7B,MAAM,CAAC,GAAG,CAAC,CAAC;gBACZ,GAAG,CAAC,OAAO,EAAE,CAAC;gBACd,OAAO;YACT,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;YACjB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnD,IAAI,CAAC,GAAG;gBAAE,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC;YAC7B,IAAI,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACzC,CAAC,CAAC,IAAI,GAAG,iBAAiB,CAAC;gBAC3B,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { MemoryStore } from "./store.js";
|
|
|
6
6
|
import { MemoryService } from "./service.js";
|
|
7
7
|
import { createHttpServer } from "./http.js";
|
|
8
8
|
import { DigestInput, storeInputShape, digestInputShape, searchInputShape, listInputShape, forgetInputShape, } from "./types.js";
|
|
9
|
+
import { toolFail } from "./errors.js";
|
|
9
10
|
const store = new MemoryStore(MemoryStore.defaultRoot());
|
|
10
11
|
const service = new MemoryService(store);
|
|
11
12
|
const argv = process.argv.slice(2);
|
|
@@ -77,7 +78,7 @@ else {
|
|
|
77
78
|
await startMcp();
|
|
78
79
|
}
|
|
79
80
|
async function startMcp() {
|
|
80
|
-
const server = new McpServer({ name: "remembra", version: "3.
|
|
81
|
+
const server = new McpServer({ name: "remembra", version: "3.4.0" });
|
|
81
82
|
server.registerTool("memory_store", {
|
|
82
83
|
title: "Store a memory",
|
|
83
84
|
description: "Persist a fact, decision, role or history entry so it survives context window resets. " +
|
|
@@ -85,21 +86,32 @@ async function startMcp() {
|
|
|
85
86
|
"'role' for standing instructions/roles, 'history' for condensed chronology of past work.",
|
|
86
87
|
inputSchema: storeInputShape,
|
|
87
88
|
}, async (args) => {
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
try {
|
|
90
|
+
const result = await service.store(args);
|
|
91
|
+
return { content: [{ type: "text", text: result.message }] };
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
return toolFail(err);
|
|
95
|
+
}
|
|
90
96
|
});
|
|
91
97
|
server.registerTool("memory_digest", {
|
|
92
98
|
title: "Digest a session",
|
|
93
99
|
description: "Extract facts, decisions, roles and history from a conversation transcript and store " +
|
|
94
|
-
"them automatically (exact duplicates are skipped
|
|
100
|
+
"them automatically (exact and near-identical duplicates are skipped; changed "
|
|
101
|
+
+ "quantities go to the LLM merge). Call at the end of a session with " +
|
|
95
102
|
"the transcript or a detailed summary of it. Requires REMEMBRA_LLM + an API key.",
|
|
96
103
|
inputSchema: digestInputShape,
|
|
97
104
|
}, async (args) => {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
105
|
+
try {
|
|
106
|
+
const result = await service.digest(DigestInput.parse(args));
|
|
107
|
+
const text = `Digest complete: ${result.extracted} extracted, ${result.stored.length} stored, ` +
|
|
108
|
+
`${result.merged} merged/revived, ${result.skippedDuplicates} duplicates skipped.` +
|
|
109
|
+
(result.ids.length ? `\nStored ids: ${result.ids.join(", ")}` : "");
|
|
110
|
+
return { content: [{ type: "text", text }] };
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return toolFail(err);
|
|
114
|
+
}
|
|
103
115
|
});
|
|
104
116
|
server.registerTool("memory_maintain", {
|
|
105
117
|
title: "Run maintenance",
|
|
@@ -108,12 +120,17 @@ async function startMcp() {
|
|
|
108
120
|
"missing embedding vectors. Roles never decay. Safe to call anytime.",
|
|
109
121
|
inputSchema: {},
|
|
110
122
|
}, async () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
123
|
+
try {
|
|
124
|
+
const result = await service.maintain();
|
|
125
|
+
const text = `Maintenance complete: ${result.archived.length} archived, ` +
|
|
126
|
+
`${result.deleted.length} deleted, ${result.embedded} vectors backfilled.` +
|
|
127
|
+
(result.archived.length ? `\nArchived: ${result.archived.join(", ")}` : "") +
|
|
128
|
+
(result.deleted.length ? `\nDeleted: ${result.deleted.join(", ")}` : "");
|
|
129
|
+
return { content: [{ type: "text", text }] };
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
return toolFail(err);
|
|
133
|
+
}
|
|
117
134
|
});
|
|
118
135
|
server.registerTool("memory_search", {
|
|
119
136
|
title: "Search memories",
|
|
@@ -121,27 +138,42 @@ async function startMcp() {
|
|
|
121
138
|
"(or whenever prior context might exist) to recover facts, decisions, roles and history.",
|
|
122
139
|
inputSchema: searchInputShape,
|
|
123
140
|
}, async (args) => {
|
|
124
|
-
|
|
125
|
-
|
|
141
|
+
try {
|
|
142
|
+
const result = await service.search(args);
|
|
143
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
return toolFail(err);
|
|
147
|
+
}
|
|
126
148
|
});
|
|
127
149
|
server.registerTool("memory_list", {
|
|
128
150
|
title: "List memories",
|
|
129
151
|
description: "List stored memories, optionally filtered by scope or type.",
|
|
130
152
|
inputSchema: listInputShape,
|
|
131
153
|
}, async (args) => {
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
try {
|
|
155
|
+
const result = await service.list(args);
|
|
156
|
+
return { content: [{ type: "text", text: result.text }] };
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
return toolFail(err);
|
|
160
|
+
}
|
|
134
161
|
});
|
|
135
162
|
server.registerTool("memory_forget", {
|
|
136
163
|
title: "Delete a memory",
|
|
137
164
|
description: "Permanently delete a memory by its id.",
|
|
138
165
|
inputSchema: forgetInputShape,
|
|
139
166
|
}, async ({ id }) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
167
|
+
try {
|
|
168
|
+
const result = await service.forget(id);
|
|
169
|
+
return {
|
|
170
|
+
content: [{ type: "text", text: result.text }],
|
|
171
|
+
isError: !result.ok,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
return toolFail(err);
|
|
176
|
+
}
|
|
145
177
|
});
|
|
146
178
|
const transport = new StdioServerTransport();
|
|
147
179
|
await server.connect(transport);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,GACjB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index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ACH,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,YAAY,CACjB,eAAe,EACf;QACE,KAAK,EAAE,iBAAiB;QACxB,WAAW,EAAE,wCAAwC;QACrD,WAAW,EAAE,gBAAgB;KAC9B,EACD,KAAK,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE;QACf,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACxC,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC9C,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE;aACpB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,sEAAsE;IACtE,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,WAAW,WAAW,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3F,OAAO,CAAC,KAAK,CAAC,8BAA8B,QAAQ,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/retrieval.d.ts
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import { Memory, SearchQuery } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
* Layered retrieval (decisions Q4 + v2-Q3):
|
|
3
|
+
* Layered retrieval (decisions Q4 + v2-Q3, Phase 4 quality pass):
|
|
4
4
|
*
|
|
5
5
|
* Hard gates (never bypassed by scores):
|
|
6
6
|
* - roles always pass (+1000)
|
|
7
7
|
* - other scopes' memories are excluded entirely
|
|
8
8
|
*
|
|
9
|
-
* Ranking
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
9
|
+
* Ranking (additive terms are identical in keyword and semantic mode so a
|
|
10
|
+
* memory ranks consistently whether embeddings are on or off — audit #2):
|
|
11
|
+
* - provenance: deliberate `explicit` stores +10 over auto-extracted (#4)
|
|
12
|
+
* - importance: importance × 4 (both modes)
|
|
13
|
+
* - recency: exponential decay, ~30-day half-life, no cliff (#1)
|
|
14
|
+
* - keywords (keyword mode) / cosine similarity (semantic mode)
|
|
14
15
|
*/
|
|
15
16
|
export declare function search(memories: Memory[], q: SearchQuery, queryVec?: number[] | null): Memory[];
|
|
17
|
+
/** Scored exposed for tests — the full layered formula for one memory. */
|
|
18
|
+
export declare function score(m: Memory, terms: string[], scope: string | undefined, now: number, queryVec?: number[] | null): number;
|
|
19
|
+
/**
|
|
20
|
+
* Exponential recency decay (audit #20): ~30-day half-life, never a hard
|
|
21
|
+
* cutoff — a 60-day-old memory keeps ~5 points instead of dropping to 0.
|
|
22
|
+
*/
|
|
23
|
+
export declare function recencyScore(m: Memory, now: number): number;
|
package/dist/retrieval.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { cosine } from "./embeddings.js";
|
|
2
2
|
/**
|
|
3
|
-
* Layered retrieval (decisions Q4 + v2-Q3):
|
|
3
|
+
* Layered retrieval (decisions Q4 + v2-Q3, Phase 4 quality pass):
|
|
4
4
|
*
|
|
5
5
|
* Hard gates (never bypassed by scores):
|
|
6
6
|
* - roles always pass (+1000)
|
|
7
7
|
* - other scopes' memories are excluded entirely
|
|
8
8
|
*
|
|
9
|
-
* Ranking
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* -
|
|
9
|
+
* Ranking (additive terms are identical in keyword and semantic mode so a
|
|
10
|
+
* memory ranks consistently whether embeddings are on or off — audit #2):
|
|
11
|
+
* - provenance: deliberate `explicit` stores +10 over auto-extracted (#4)
|
|
12
|
+
* - importance: importance × 4 (both modes)
|
|
13
|
+
* - recency: exponential decay, ~30-day half-life, no cliff (#1)
|
|
14
|
+
* - keywords (keyword mode) / cosine similarity (semantic mode)
|
|
14
15
|
*/
|
|
15
16
|
export function search(memories, q, queryVec) {
|
|
16
17
|
const now = Date.now();
|
|
@@ -25,7 +26,8 @@ export function search(memories, q, queryVec) {
|
|
|
25
26
|
.sort((a, b) => b.score - a.score || b.m.updatedAt.localeCompare(a.m.updatedAt));
|
|
26
27
|
return scored.slice(0, q.limit ?? 10).map(({ m }) => m);
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
/** Scored exposed for tests — the full layered formula for one memory. */
|
|
30
|
+
export function score(m, terms, scope, now, queryVec) {
|
|
29
31
|
let s = 0;
|
|
30
32
|
// --- hard gates ---
|
|
31
33
|
if (m.type === "role")
|
|
@@ -36,6 +38,9 @@ function score(m, terms, scope, now, queryVec) {
|
|
|
36
38
|
s += 100;
|
|
37
39
|
if (scope && m.scope === scope)
|
|
38
40
|
s += 150;
|
|
41
|
+
// --- provenance (Phase 4 / audit #4): deliberate stores beat auto-extracts ---
|
|
42
|
+
if (m.provenance === "explicit")
|
|
43
|
+
s += 10;
|
|
39
44
|
// --- semantic mode (embeddings on) ---
|
|
40
45
|
if (queryVec && queryVec.length > 0) {
|
|
41
46
|
if (m.embedding && m.embedding.length > 0) {
|
|
@@ -50,13 +55,13 @@ function score(m, terms, scope, now, queryVec) {
|
|
|
50
55
|
// Memory without a vector: fall back to keyword scoring for it.
|
|
51
56
|
s += keywordScore(m, terms);
|
|
52
57
|
}
|
|
53
|
-
// Modifiers
|
|
58
|
+
// Modifiers — same weights as keyword mode (normalized, audit #2).
|
|
54
59
|
s += m.importance * 4;
|
|
55
60
|
s += recencyScore(m, now) * 0.5;
|
|
56
61
|
return s;
|
|
57
62
|
}
|
|
58
63
|
// --- keyword mode (embeddings off — v1 behavior) ---
|
|
59
|
-
s += m.importance *
|
|
64
|
+
s += m.importance * 4;
|
|
60
65
|
s += recencyScore(m, now);
|
|
61
66
|
if (terms.length > 0)
|
|
62
67
|
s += keywordScore(m, terms);
|
|
@@ -64,11 +69,16 @@ function score(m, terms, scope, now, queryVec) {
|
|
|
64
69
|
s += 10; // no query: everything eligible scores a little
|
|
65
70
|
return s;
|
|
66
71
|
}
|
|
67
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Exponential recency decay (audit #20): ~30-day half-life, never a hard
|
|
74
|
+
* cutoff — a 60-day-old memory keeps ~5 points instead of dropping to 0.
|
|
75
|
+
*/
|
|
76
|
+
export function recencyScore(m, now) {
|
|
68
77
|
const ageDays = (now - Date.parse(m.updatedAt)) / 86_400_000;
|
|
69
|
-
if (Number.
|
|
78
|
+
if (!Number.isFinite(ageDays))
|
|
70
79
|
return 0;
|
|
71
|
-
|
|
80
|
+
const age = Math.max(0, ageDays); // future-dated files count as fresh
|
|
81
|
+
return 20 * Math.pow(2, -age / 30);
|
|
72
82
|
}
|
|
73
83
|
function keywordScore(m, terms) {
|
|
74
84
|
if (terms.length === 0)
|
package/dist/retrieval.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC
|
|
1
|
+
{"version":3,"file":"retrieval.js","sourceRoot":"","sources":["../src/retrieval.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,QAAkB,EAAE,CAAc,EAAE,QAA0B;IACnF,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;SAC1B,WAAW,EAAE;SACb,KAAK,CAAC,KAAK,CAAC;SACZ,MAAM,CAAC,CAAC,C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
-
import {
|
|
1
|
+
import type { MemoryBackend } from "./backend.js";
|
|
2
2
|
import { MemoryType, Memory } from "./types.js";
|
|
3
3
|
import { EmbeddingProvider } from "./embeddings.js";
|
|
4
4
|
import { LlmProvider, ExtractedMemory } from "./llm.js";
|
|
@@ -44,7 +44,7 @@ interface ServiceDeps {
|
|
|
44
44
|
* call into this module, so behavior is guaranteed to match.
|
|
45
45
|
*/
|
|
46
46
|
export declare class MemoryService {
|
|
47
|
-
readonly db:
|
|
47
|
+
readonly db: MemoryBackend;
|
|
48
48
|
private readonly embedFn?;
|
|
49
49
|
private readonly extractFn;
|
|
50
50
|
private readonly mergeFn;
|
|
@@ -53,10 +53,12 @@ export declare class MemoryService {
|
|
|
53
53
|
private readonly archiveTtlDays;
|
|
54
54
|
private lastDecayRun;
|
|
55
55
|
private decayRunning;
|
|
56
|
-
constructor(db:
|
|
56
|
+
constructor(db: MemoryBackend, deps?: ServiceDeps);
|
|
57
57
|
get embeddingsEnabled(): boolean;
|
|
58
58
|
private maybeEmbed;
|
|
59
|
-
store(input: unknown
|
|
59
|
+
store(input: unknown, opts?: {
|
|
60
|
+
provenance?: Memory["provenance"];
|
|
61
|
+
}): Promise<{
|
|
60
62
|
id: string;
|
|
61
63
|
message: string;
|
|
62
64
|
memory: Memory;
|