@seanhogg/builderforce-memory-mcp 2026.10.3 → 2026.10.22
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/README.md +22 -5
- package/dist/backend.d.ts +26 -0
- package/dist/backend.d.ts.map +1 -1
- package/dist/backends/memory-store.d.ts +50 -2
- package/dist/backends/memory-store.d.ts.map +1 -1
- package/dist/backends/memory-store.js +88 -10
- package/dist/backends/memory-store.js.map +1 -1
- package/dist/bin/http.js +7 -1
- package/dist/bin/http.js.map +1 -1
- package/dist/bin/install.js +6 -3
- package/dist/bin/install.js.map +1 -1
- package/dist/bin/stdio.d.ts +9 -4
- package/dist/bin/stdio.d.ts.map +1 -1
- package/dist/bin/stdio.js +20 -5
- package/dist/bin/stdio.js.map +1 -1
- package/dist/compaction-tools.d.ts +15 -0
- package/dist/compaction-tools.d.ts.map +1 -0
- package/dist/compaction-tools.js +192 -0
- package/dist/compaction-tools.js.map +1 -0
- package/dist/compaction.d.ts +114 -8
- package/dist/compaction.d.ts.map +1 -1
- package/dist/compaction.js +161 -7
- package/dist/compaction.js.map +1 -1
- package/dist/index.d.ts +13 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/install/claude-hooks.d.ts +5 -0
- package/dist/install/claude-hooks.d.ts.map +1 -1
- package/dist/install/claude-hooks.js +69 -9
- package/dist/install/claude-hooks.js.map +1 -1
- package/dist/install/server-spec.d.ts +33 -7
- package/dist/install/server-spec.d.ts.map +1 -1
- package/dist/install/server-spec.js +59 -9
- package/dist/install/server-spec.js.map +1 -1
- package/dist/model/recall-probe.d.ts +29 -0
- package/dist/model/recall-probe.d.ts.map +1 -0
- package/dist/model/recall-probe.js +72 -0
- package/dist/model/recall-probe.js.map +1 -0
- package/dist/persistence/fact-archive.d.ts +47 -0
- package/dist/persistence/fact-archive.d.ts.map +1 -0
- package/dist/persistence/fact-archive.js +85 -0
- package/dist/persistence/fact-archive.js.map +1 -0
- package/dist/persistence/shared-json-file.d.ts +24 -1
- package/dist/persistence/shared-json-file.d.ts.map +1 -1
- package/dist/persistence/shared-json-file.js +46 -1
- package/dist/persistence/shared-json-file.js.map +1 -1
- package/dist/restore.d.ts +56 -0
- package/dist/restore.d.ts.map +1 -0
- package/dist/restore.js +118 -0
- package/dist/restore.js.map +1 -0
- package/dist/tools.d.ts +13 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +11 -90
- package/dist/tools.js.map +1 -1
- package/package.json +6 -6
- package/server.json +2 -2
- package/src/backend.ts +29 -0
- package/src/backends/memory-store.ts +141 -11
- package/src/bin/http.ts +7 -1
- package/src/bin/install.ts +7 -3
- package/src/bin/stdio.ts +20 -5
- package/src/compaction-tools.ts +206 -0
- package/src/compaction.ts +228 -9
- package/src/index.ts +55 -10
- package/src/install/claude-hooks.ts +72 -9
- package/src/install/server-spec.ts +74 -8
- package/src/model/recall-probe.ts +81 -0
- package/src/persistence/fact-archive.ts +101 -0
- package/src/persistence/shared-json-file.ts +54 -1
- package/src/restore.ts +144 -0
- package/src/tools.ts +24 -93
package/src/tools.ts
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { z } from "zod";
|
|
18
|
-
import type { MemoryBackend, RankedRecall, RecallHit, RecallMethod
|
|
19
|
-
import {
|
|
18
|
+
import type { MemoryBackend, RankedRecall, RecallHit, RecallMethod } from "./backend.js";
|
|
19
|
+
import { CONTENT_LOST_LABEL, type RecallProbe } from "./compaction.js";
|
|
20
|
+
import { appendCompactionTools } from "./compaction-tools.js";
|
|
20
21
|
import { buildExperienceTools } from "./experience/tools.js";
|
|
21
22
|
import type { ExperienceHost } from "./experience/host.js";
|
|
22
23
|
import { appendGatewayCostTools } from "./gateway-tools.js";
|
|
@@ -44,6 +45,18 @@ export interface MemoryToolsOptions {
|
|
|
44
45
|
* beside the memory tools. See {@link createExperienceHost}.
|
|
45
46
|
*/
|
|
46
47
|
experience?: ExperienceHost | null;
|
|
48
|
+
/**
|
|
49
|
+
* The local model `memory_compact` proves absorption with before it stubs a
|
|
50
|
+
* fact (see `planLosslessCompaction`). Null/absent → compaction stubs nothing
|
|
51
|
+
* and says why. The bins pass `lazyRecallProbe()` (the configured Evermind).
|
|
52
|
+
*/
|
|
53
|
+
recallProbe?: RecallProbe | null;
|
|
54
|
+
/**
|
|
55
|
+
* Reads a restore source by path for `memory_restore`. Only hosts that may read
|
|
56
|
+
* their own disk pass it (the stdio bin); without it the tool takes inline JSON
|
|
57
|
+
* only, so a networked server never reads a caller-named file.
|
|
58
|
+
*/
|
|
59
|
+
readRestoreFile?: (path: string) => Promise<string>;
|
|
47
60
|
}
|
|
48
61
|
|
|
49
62
|
const DEFAULT_MAX_RESULTS = 5;
|
|
@@ -62,6 +75,9 @@ const RANKER_LINE: Record<RecallMethod, string> = {
|
|
|
62
75
|
lexical: "Ranked by: lexical recall (fallback - no embedding model loaded).",
|
|
63
76
|
};
|
|
64
77
|
|
|
78
|
+
/** A stub whose original is gone is surfaced WITH the label, never as a plain fact. */
|
|
79
|
+
const lostLabel = (h: RecallHit): string => (h.contentLost ? ` ${CONTENT_LOST_LABEL}` : "");
|
|
80
|
+
|
|
65
81
|
function renderHits(hits: RecallHit[], maxChars: number, method?: RecallMethod): string {
|
|
66
82
|
const ranker = method ? `\n${RANKER_LINE[method]}` : "";
|
|
67
83
|
if (hits.length === 0) return `No matching memories.${ranker}`;
|
|
@@ -70,7 +86,7 @@ function renderHits(hits: RecallHit[], maxChars: number, method?: RecallMethod):
|
|
|
70
86
|
.map((h) => {
|
|
71
87
|
const tags = h.tags?.length ? ` tags=[${h.tags.join(", ")}]` : "";
|
|
72
88
|
const score = h.score != null ? ` score=${h.score.toFixed(3)}` : "";
|
|
73
|
-
return `• ${h.key}${score}${tags}\n ${clip(h.content, maxChars)}`;
|
|
89
|
+
return `• ${h.key}${score}${tags}${lostLabel(h)}\n ${clip(h.content, maxChars)}`;
|
|
74
90
|
})
|
|
75
91
|
.join("\n") + ranker
|
|
76
92
|
);
|
|
@@ -90,19 +106,6 @@ async function rankedRecall(
|
|
|
90
106
|
return { hits: await backend.recall(query, topK) };
|
|
91
107
|
}
|
|
92
108
|
|
|
93
|
-
const SKIP_REASONS: Record<CompactionSkip["reason"], string> = {
|
|
94
|
-
not_found: "not found",
|
|
95
|
-
already_compacted: "already compacted",
|
|
96
|
-
not_smaller: "already shorter than its stub",
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/** One-line compaction receipt: what shrank, what it saved, and what was left alone. */
|
|
100
|
-
function renderCompaction(compacted: number, bytesSaved: number, skipped: CompactionSkip[]): string {
|
|
101
|
-
const lines = [`Compacted ${compacted} memory(ies), ${bytesSaved} character(s) reclaimed.`];
|
|
102
|
-
for (const s of skipped) lines.push(`• skipped ${s.key} — ${SKIP_REASONS[s.reason]}`);
|
|
103
|
-
return lines.join("\n");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
109
|
/**
|
|
107
110
|
* Builds the memory tool set bound to `backend`. Write tools are included only
|
|
108
111
|
* when `writable` is not false AND the backend actually implements them.
|
|
@@ -156,7 +159,9 @@ export function buildMemoryTools(backend: MemoryBackend, opts: MemoryToolsOption
|
|
|
156
159
|
const key = String(args["key"] ?? "");
|
|
157
160
|
if (!key) return fail("key is required.");
|
|
158
161
|
const hit = await backend.get(key);
|
|
159
|
-
return hit
|
|
162
|
+
return hit
|
|
163
|
+
? ok(`• ${hit.key}${lostLabel(hit)}\n ${hit.content}`)
|
|
164
|
+
: ok(`No memory found for key "${key}".`);
|
|
160
165
|
} catch (err) {
|
|
161
166
|
return fail(`get failed: ${String(err)}`);
|
|
162
167
|
}
|
|
@@ -226,82 +231,8 @@ export function buildMemoryTools(backend: MemoryBackend, opts: MemoryToolsOption
|
|
|
226
231
|
});
|
|
227
232
|
}
|
|
228
233
|
|
|
229
|
-
// memory_compact — the
|
|
230
|
-
|
|
231
|
-
// on-disk snapshot agree afterwards. Compacting the snapshot file behind the
|
|
232
|
-
// server's back instead is what races: the server still holds the full bodies and
|
|
233
|
-
// re-snapshots over them on its next write. Requires read + write, so it is
|
|
234
|
-
// registered alongside the other write tools.
|
|
235
|
-
if (writable && backend.remember) {
|
|
236
|
-
tools.push({
|
|
237
|
-
name: "memory_compact",
|
|
238
|
-
description:
|
|
239
|
-
"Shrink memories that have already been absorbed elsewhere (folded into a model, " +
|
|
240
|
-
"summarised into a longer-lived note) down to a one-line pointer stub, reclaiming the " +
|
|
241
|
-
"context they were eating. Call this AFTER something durable has learned the facts — " +
|
|
242
|
-
"never as a way to tidy up, because the full body is gone afterwards. Already-compacted " +
|
|
243
|
-
"keys are skipped, so repeating the call is safe.",
|
|
244
|
-
inputSchema: {
|
|
245
|
-
keys: z.array(z.string()).min(1).describe("Exact keys of the memories to compact."),
|
|
246
|
-
stub: z
|
|
247
|
-
.string()
|
|
248
|
-
.optional()
|
|
249
|
-
.describe(
|
|
250
|
-
"Explicit replacement body applied to every listed key. Omit to generate " +
|
|
251
|
-
"'[absorbed→Evermind vN] <first line>' from each entry's own first line.",
|
|
252
|
-
),
|
|
253
|
-
version: z
|
|
254
|
-
.number()
|
|
255
|
-
.int()
|
|
256
|
-
.min(0)
|
|
257
|
-
.optional()
|
|
258
|
-
.describe("Version of the model that absorbed these facts; appears in the generated stub."),
|
|
259
|
-
maxChars: z
|
|
260
|
-
.number()
|
|
261
|
-
.int()
|
|
262
|
-
.min(20)
|
|
263
|
-
.max(500)
|
|
264
|
-
.optional()
|
|
265
|
-
.describe(`Max characters of the generated pointer line (default ${DEFAULT_STUB_CHARS}).`),
|
|
266
|
-
},
|
|
267
|
-
handler: async (args) => {
|
|
268
|
-
try {
|
|
269
|
-
const raw = args["keys"];
|
|
270
|
-
const keys = Array.isArray(raw) ? raw.map((k) => String(k)).filter(Boolean) : [];
|
|
271
|
-
if (keys.length === 0) return fail("keys is required.");
|
|
272
|
-
|
|
273
|
-
// ONE read pass: the hit carries both the body the plan reasons about
|
|
274
|
-
// and the tags/importance the rewrite must preserve.
|
|
275
|
-
const hits = new Map<string, RecallHit>();
|
|
276
|
-
for (const key of keys) {
|
|
277
|
-
const hit = await backend.get(key);
|
|
278
|
-
if (hit) hits.set(key, hit);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const plan = planCompaction(keys.map((key) => ({ key, content: hits.get(key)?.content })), {
|
|
282
|
-
stub: typeof args["stub"] === "string" ? (args["stub"] as string) : undefined,
|
|
283
|
-
version: args["version"] == null ? undefined : Number(args["version"]),
|
|
284
|
-
maxChars: args["maxChars"] == null ? undefined : Number(args["maxChars"]),
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// Preserve tags/importance — compaction shortens a body, it does not
|
|
288
|
-
// reclassify the fact.
|
|
289
|
-
const writes: RememberInput[] = plan.writes.map((w) => {
|
|
290
|
-
const prev = hits.get(w.key);
|
|
291
|
-
return { key: w.key, content: w.content, tags: prev?.tags, importance: prev?.importance };
|
|
292
|
-
});
|
|
293
|
-
if (writes.length > 0) {
|
|
294
|
-
if (backend.rememberMany) await backend.rememberMany(writes);
|
|
295
|
-
else for (const w of writes) await backend.remember!(w);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return ok(renderCompaction(plan.writes.length, plan.bytesSaved, plan.skipped));
|
|
299
|
-
} catch (err) {
|
|
300
|
-
return fail(`compact failed: ${String(err)}`);
|
|
301
|
-
}
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
}
|
|
234
|
+
// memory_compact + memory_restore — the lossless compaction pair (compaction-tools.ts).
|
|
235
|
+
if (writable && backend.remember) appendCompactionTools(tools, backend, opts);
|
|
305
236
|
|
|
306
237
|
if (writable && backend.forget) {
|
|
307
238
|
tools.push({
|