@seanhogg/builderforce-memory-mcp 2026.6.30 → 2026.6.31

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 CHANGED
@@ -95,6 +95,24 @@ write tools; `--local=<dist/bin/stdio.js>` runs a checkout for development.
95
95
  The same launch spec is exported for programmatic use:
96
96
  `buildServerSpec()` / `installMemoryServer()` (see `src/install/`).
97
97
 
98
+ ### Claude Code: the self-driving "memory combo"
99
+
100
+ Registering the server gives Claude Code the memory *tools*. For Claude Code the
101
+ installer ALSO wires hooks so memory is **self-driving instead of advisory** (skip
102
+ with `--no-hooks`):
103
+
104
+ | Hook | Behaviour |
105
+ |------|-----------|
106
+ | `SessionStart` | Inject a digest of the top durable memories. |
107
+ | `PreCompact` | Flush durable learnings before the window is summarised. |
108
+ | `UserPromptSubmit` | **Contextual recall** — score memories against the prompt and inject the relevant ones, so a stored fact is retrieved at the *decision point*, not only at session start. |
109
+ | `Stop` | **Autonomous capture** — if the user's last message was a durable instruction/correction and it wasn't consolidated this turn, BLOCK the stop with a directive to `memory_remember`. Capture flows through the MCP write path (never racing the snapshot); a `stop_hook_active` guard means at most one nudge per turn. |
110
+
111
+ All four point at one generated, dependency-free hook script
112
+ (`~/.claude/builderforce-memory/bfmem-hook.mjs`, four modes) plus a companion
113
+ skill. Idempotent + `.bak`-safe. Source of truth: `src/install/claude-hooks.ts`
114
+ (`installClaudeCombo` / `bfmemHookSource`).
115
+
98
116
  ## Quick start — stdio (any process / language)
99
117
 
100
118
  ```bash
@@ -17,8 +17,10 @@
17
17
  */
18
18
  import os from "node:os";
19
19
  import path from "node:path";
20
+ import nodeFs from "node:fs";
20
21
  import { HOSTS } from "../install/hosts.js";
21
22
  import { installMemoryServer } from "../install/install.js";
23
+ import { installClaudeCombo } from "../install/claude-hooks.js";
22
24
  function argValue(name) {
23
25
  const hit = process.argv.find((a) => a.startsWith(`--${name}=`));
24
26
  return hit ? hit.slice(name.length + 3) : undefined;
@@ -73,6 +75,26 @@ for (const r of results) {
73
75
  if (r.status === "installed" || r.status === "updated")
74
76
  wrote += 1;
75
77
  }
78
+ // ── Claude Code memory combo (hooks + companion skill) ───────────────────────
79
+ // Registering the server above gives Claude Code the TOOLS; this adds the
80
+ // self-driving behaviour (SessionStart digest, contextual recall, autonomous Stop
81
+ // capture). Only for Claude Code, only when present, and skippable via --no-hooks.
82
+ const claudeResult = results.find((r) => r.host === "claude-code");
83
+ const claudePresent = claudeResult && claudeResult.status !== "unsupported" && claudeResult.status !== "error";
84
+ if (claudePresent && !hasFlag("no-hooks")) {
85
+ try {
86
+ const combo = installClaudeCombo({
87
+ fs: nodeFs,
88
+ claudeDir: path.join(os.homedir(), ".claude"),
89
+ memoryFile,
90
+ });
91
+ const what = combo.addedHooks.length ? `added ${combo.addedHooks.join(", ")}` : "already current";
92
+ process.stdout.write(`✓ Claude Code memory combo: hooks ${what}; recall + autonomous capture wired\n`);
93
+ }
94
+ catch (err) {
95
+ process.stderr.write(`✗ Claude Code hooks: ${String(err.message ?? err)}\n`);
96
+ }
97
+ }
76
98
  if (results.length === 0) {
77
99
  process.stdout.write("No MCP hosts detected. Pass --host=all to write configs anyway, or --host=cursor (etc.).\n");
78
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/bin/install.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAqB,MAAM,uBAAuB,CAAC;AAE/E,SAAS,QAAQ,CAAC,IAAY;IAC1B,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,IAAI,GAAG,CAAC,CAAC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AC,OAAO,EAAE,EAAE,SAAS,CAAC;YAC7C,UAAU;SACb,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC;QAClG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,IAAI,uCAAuC,CAAC,CAAC;IAC3G,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,MAAM,CAAE,GAAa,CAAC,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5F,CAAC;AACL,CAAC;AAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,4FAA4F,CAC/F,CAAC;AACN,CAAC;KAAM,CAAC;IACJ,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,YAAY,KAAK,8BAA8B,UAAU,iIAAiI,CAC7L,CAAC;AACN,CAAC"}
package/dist/index.d.ts CHANGED
@@ -24,4 +24,6 @@ export { installMemoryServer } from "./install/install.js";
24
24
  export type { InstallOptions, InstallResult, InstallStatus, HostSelector, FsLike } from "./install/install.js";
25
25
  export { HOSTS, SERVER_KEY, findHost } from "./install/hosts.js";
26
26
  export type { HostAdapter, HostEnv, ConfigFormat } from "./install/hosts.js";
27
+ export { installClaudeCombo, bfmemHookSource, companionSkillMd, claudeComboPaths } from "./install/claude-hooks.js";
28
+ export type { ClaudeComboPaths } from "./install/claude-hooks.js";
27
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,E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,CAAC;AACpH,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -19,4 +19,7 @@ export { createMemoryHttpHandler } from "./transports/http.js";
19
19
  export { buildServerSpec, MCP_PACKAGE, MCP_BIN, RUNTIME_PEERS } from "./install/server-spec.js";
20
20
  export { installMemoryServer } from "./install/install.js";
21
21
  export { HOSTS, SERVER_KEY, findHost } from "./install/hosts.js";
22
+ // Claude Code "memory combo" — hooks (SessionStart/PreCompact/UserPromptSubmit/Stop)
23
+ // + companion skill that make memory self-driving (contextual recall + autonomous capture).
24
+ export { installClaudeCombo, bfmemHookSource, companionSkillMd, claudeComboPaths } from "./install/claude-hooks.js";
22
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,0FAA0F;AAC1F,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAG/F,iFAAiF;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,+EAA+E;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,iFAAiF;AACjF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,0FAA0F;AAC1F,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAG/F,iFAAiF;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,+EAA+E;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,iFAAiF;AACjF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEjE,qFAAqF;AACrF,4FAA4F;AAC5F,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Claude Code "memory combo" — the hooks + companion skill half of the install.
3
+ *
4
+ * Registering the MCP server (install.ts) gives Claude Code the memory TOOLS.
5
+ * This module adds the behaviour that makes memory SELF-DRIVING rather than
6
+ * advisory, so the agent doesn't have to be reminded to use it:
7
+ *
8
+ * SessionStart → inject a digest of the top durable memories.
9
+ * PreCompact → flush durable learnings before the window is summarised.
10
+ * UserPromptSubmit → CONTEXTUAL recall: score memories against the prompt and
11
+ * inject the relevant ones (so a stored fact is retrieved at
12
+ * the decision point, not just at session start).
13
+ * Stop → AUTONOMOUS capture: detect a durable instruction/correction
14
+ * in the user's last message and, if it wasn't consolidated
15
+ * this turn, BLOCK the stop with a directive to memory_remember
16
+ * (capture flows through the MCP write path — never racing the
17
+ * server's snapshot).
18
+ *
19
+ * All four point at one generated, dependency-free hook script (DRY). The combo
20
+ * is idempotent and backup-safe, matching install.ts.
21
+ */
22
+ import type { FsLike } from "./install.js";
23
+ /** The single hook script, four modes. `memoryFile` is the JSON snapshot path. */
24
+ export declare function bfmemHookSource(memoryFile: string): string;
25
+ /** The companion skill doc that teaches the recall/remember discipline. */
26
+ export declare function companionSkillMd(): string;
27
+ /** Files/paths the combo manages, derived from the Claude config dir (~/.claude). */
28
+ export interface ClaudeComboPaths {
29
+ claudeDir: string;
30
+ settingsFile: string;
31
+ hookScript: string;
32
+ companionSkill: string;
33
+ }
34
+ export declare function claudeComboPaths(claudeDir: string): ClaudeComboPaths;
35
+ /**
36
+ * Write the hook script + companion skill and register all four hooks in
37
+ * settings.json. Idempotent (skips a hook command already present) and
38
+ * backup-safe (.bak before overwriting settings). Returns the events it added.
39
+ */
40
+ export declare function installClaudeCombo(opts: {
41
+ fs: FsLike;
42
+ claudeDir: string;
43
+ memoryFile: string;
44
+ }): {
45
+ hookScript: string;
46
+ addedHooks: string[];
47
+ settingsFile: string;
48
+ };
49
+ //# sourceMappingURL=claude-hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-hooks.d.ts","sourceRoot":"","sources":["../../src/install/claude-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA6I1D;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,IAAI,MAAM,CA0BzC;AAED,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAOpE;AASD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAmCrE"}
@@ -0,0 +1,255 @@
1
+ /**
2
+ * Claude Code "memory combo" — the hooks + companion skill half of the install.
3
+ *
4
+ * Registering the MCP server (install.ts) gives Claude Code the memory TOOLS.
5
+ * This module adds the behaviour that makes memory SELF-DRIVING rather than
6
+ * advisory, so the agent doesn't have to be reminded to use it:
7
+ *
8
+ * SessionStart → inject a digest of the top durable memories.
9
+ * PreCompact → flush durable learnings before the window is summarised.
10
+ * UserPromptSubmit → CONTEXTUAL recall: score memories against the prompt and
11
+ * inject the relevant ones (so a stored fact is retrieved at
12
+ * the decision point, not just at session start).
13
+ * Stop → AUTONOMOUS capture: detect a durable instruction/correction
14
+ * in the user's last message and, if it wasn't consolidated
15
+ * this turn, BLOCK the stop with a directive to memory_remember
16
+ * (capture flows through the MCP write path — never racing the
17
+ * server's snapshot).
18
+ *
19
+ * All four point at one generated, dependency-free hook script (DRY). The combo
20
+ * is idempotent and backup-safe, matching install.ts.
21
+ */
22
+ import nodePath from "node:path";
23
+ /** The single hook script, four modes. `memoryFile` is the JSON snapshot path. */
24
+ export function bfmemHookSource(memoryFile) {
25
+ return `#!/usr/bin/env node
26
+ /**
27
+ * builderforce-memory hook — generated by builderforce-memory-install. Dependency-free:
28
+ * reads only the JSON snapshot, never stands up the MCP server.
29
+ * --session SessionStart: inject a small digest of durable memories.
30
+ * --precompact PreCompact: remind to flush learnings before summarisation.
31
+ * --recall UserPromptSubmit: contextual recall — inject memories relevant to the prompt.
32
+ * --capture Stop: autonomous consolidation — block the stop until a detected
33
+ * durable correction is persisted via memory_remember.
34
+ */
35
+ import fs from "node:fs";
36
+
37
+ const FILE = ${JSON.stringify(memoryFile)};
38
+ const mode = process.argv[2] || "--session";
39
+
40
+ function readStdin() {
41
+ try { return fs.readFileSync(0, "utf8"); } catch { return ""; }
42
+ }
43
+ function loadEntries() {
44
+ try { const p = JSON.parse(fs.readFileSync(FILE, "utf8")); return Array.isArray(p) ? p : []; }
45
+ catch { return []; }
46
+ }
47
+ function tokens(s) {
48
+ return String(s || "").toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length >= 3);
49
+ }
50
+
51
+ if (mode === "--precompact") {
52
+ process.stdout.write(
53
+ "[builderforce-memory] Context is about to be compacted. Persist any durable learnings from this session — decisions, fixes, project facts, user preferences — by calling memory_remember with concise one-line facts. Recall them later with memory_recall instead of re-reading files.",
54
+ );
55
+ process.exit(0);
56
+ }
57
+
58
+ if (mode === "--recall") {
59
+ let prompt = "";
60
+ try { const j = JSON.parse(readStdin() || "{}"); prompt = typeof j.prompt === "string" ? j.prompt : ""; } catch { /* no input */ }
61
+ if (!prompt) process.exit(0);
62
+ const entries = loadEntries();
63
+ if (entries.length === 0) process.exit(0);
64
+ const q = new Set(tokens(prompt));
65
+ if (q.size === 0) process.exit(0);
66
+ const scored = entries
67
+ .map((e) => {
68
+ const hay = new Set(tokens([e.key, e.content, (e.tags || []).join(" ")].join(" ")));
69
+ let score = 0;
70
+ for (const t of q) if (hay.has(t)) score++;
71
+ return { e, score };
72
+ })
73
+ .filter((x) => x.score >= 2)
74
+ .sort((a, b) => b.score - a.score)
75
+ .slice(0, 3);
76
+ if (scored.length === 0) process.exit(0);
77
+ const lines = scored.map((x) => "• " + x.e.key + ": " + String(x.e.content || "").slice(0, 240)).join("\\n");
78
+ process.stdout.write(
79
+ "[builderforce-memory] Relevant stored memories for this request — use these instead of re-deriving or re-reading:\\n" + lines,
80
+ );
81
+ process.exit(0);
82
+ }
83
+
84
+ if (mode === "--capture") {
85
+ let input = {};
86
+ try { input = JSON.parse(readStdin() || "{}"); } catch { /* no input */ }
87
+ if (input.stop_hook_active) process.exit(0);
88
+ const tpath = input.transcript_path;
89
+ if (!tpath || typeof tpath !== "string") process.exit(0);
90
+
91
+ let raw = "";
92
+ try {
93
+ const stat = fs.statSync(tpath);
94
+ const want = Math.min(stat.size, 400000);
95
+ const fd = fs.openSync(tpath, "r");
96
+ const buf = Buffer.alloc(want);
97
+ fs.readSync(fd, buf, 0, want, stat.size - want);
98
+ fs.closeSync(fd);
99
+ raw = buf.toString("utf8");
100
+ } catch { process.exit(0); }
101
+
102
+ const msgs = [];
103
+ for (const ln of raw.split("\\n")) { if (ln.trim()) { try { msgs.push(JSON.parse(ln)); } catch { /* partial */ } } }
104
+
105
+ let lastUserText = "";
106
+ let rememberedThisTurn = false;
107
+ for (let i = msgs.length - 1; i >= 0; i--) {
108
+ const m = msgs[i] || {};
109
+ const inner = m.message || m;
110
+ const role = inner.role;
111
+ const content = inner.content;
112
+ if (role === "assistant" && !lastUserText) {
113
+ if (Array.isArray(content)) for (const c of content) {
114
+ if (c && c.type === "tool_use" && typeof c.name === "string" && c.name.includes("memory_remember")) rememberedThisTurn = true;
115
+ }
116
+ }
117
+ if (role === "user" && !lastUserText) {
118
+ let txt = "";
119
+ if (typeof content === "string") txt = content;
120
+ else if (Array.isArray(content)) for (const c of content) {
121
+ if (typeof c === "string") txt += c + " ";
122
+ else if (c && c.type === "text" && typeof c.text === "string") txt += c.text + " ";
123
+ }
124
+ if (txt.trim()) lastUserText = txt;
125
+ }
126
+ }
127
+ if (!lastUserText || rememberedThisTurn) process.exit(0);
128
+
129
+ const lower = lastUserText.toLowerCase();
130
+ const SIGNALS = [
131
+ "you have to", "you should", "you need to", "you must", "from now on", "going forward",
132
+ "always ", "never ", "make sure", "remember to", "don't forget", "do not forget",
133
+ "i keep telling", "i already told", "shouldn't have to", "keep having to remind",
134
+ "you forgot", "you keep", "that's wrong", "you're wrong", "this is wrong", "stop ",
135
+ ];
136
+ const hit = SIGNALS.find((s) => lower.includes(s));
137
+ if (!hit) process.exit(0);
138
+
139
+ const snippet = lastUserText.trim().slice(0, 240);
140
+ const reason =
141
+ "[builderforce-memory] A durable instruction/correction was detected in the user's last message and you did NOT consolidate it this turn. " +
142
+ "Before stopping, call memory_remember with a concise, stable-keyed fact capturing it (reuse the same key to replace a superseded one, or memory_forget it). " +
143
+ "User said: '" + snippet + "'. If it is genuinely not durable (a one-off, or already stored), briefly say why and then stop.";
144
+ process.stdout.write(JSON.stringify({ decision: "block", reason }));
145
+ process.exit(0);
146
+ }
147
+
148
+ const entries = loadEntries();
149
+ if (entries.length === 0) {
150
+ process.stdout.write(
151
+ "[builderforce-memory] Active (memory empty). Store durable facts with memory_remember and retrieve them with memory_recall instead of re-reading files or chat history — that is how token usage stays low.",
152
+ );
153
+ process.exit(0);
154
+ }
155
+ const top = entries
156
+ .map((e) => ({ key: e.key, content: String(e.content ?? ""), importance: typeof e.importance === "number" ? e.importance : 0.5 }))
157
+ .sort((a, b) => b.importance - a.importance)
158
+ .slice(0, 8)
159
+ .map((e) => "• " + e.key + ": " + e.content.slice(0, 200))
160
+ .join("\\n");
161
+ process.stdout.write(
162
+ "[builderforce-memory] Active — token-saving memory loaded. Before re-reading files or history, call memory_recall. Store durable facts with memory_remember.\\nTop memories:\\n" + top,
163
+ );
164
+ `;
165
+ }
166
+ /** The companion skill doc that teaches the recall/remember discipline. */
167
+ export function companionSkillMd() {
168
+ return `---
169
+ name: builderforce-memory
170
+ description: Token-saving persistent memory. Recall durable facts (decisions, fixes, project context, user preferences) instead of re-reading files or chat history, and remember new durable facts as you learn them.
171
+ ---
172
+
173
+ # builderforce-memory — the conductor
174
+
175
+ Persistent memory backed by the \`builderforce-memory\` MCP server. The point is
176
+ **token reduction**: pull a small relevant slice from memory instead of re-reading
177
+ the full file/history. The install also wires hooks so this is largely automatic:
178
+ the SessionStart digest, contextual recall on each prompt, and an autonomous Stop
179
+ capture that won't let a durable correction go unrecorded.
180
+
181
+ ## Tools
182
+ - \`memory_recall(query, [k])\` — top-K relevant memories. First move on a task.
183
+ - \`memory_get(key)\` — exact lookup by key.
184
+ - \`memory_recall_by_tag(tag)\` — everything under a tag.
185
+ - \`memory_remember(key, content, [tags], [importance])\` — store ONE durable fact.
186
+ - \`memory_forget(key)\` — drop a superseded fact.
187
+
188
+ ## Discipline
189
+ Reuse a stable key to REPLACE a fact (write-through), don't append duplicates.
190
+ Store decisions, non-obvious fixes, project constraints, user preferences — one
191
+ tight line each. Not things git already records or one-off turn details.
192
+ `;
193
+ }
194
+ export function claudeComboPaths(claudeDir) {
195
+ return {
196
+ claudeDir,
197
+ settingsFile: nodePath.join(claudeDir, "settings.json"),
198
+ hookScript: nodePath.join(claudeDir, "builderforce-memory", "bfmem-hook.mjs"),
199
+ companionSkill: nodePath.join(claudeDir, "skills", "builderforce-memory", "SKILL.md"),
200
+ };
201
+ }
202
+ const HOOK_EVENTS = [
203
+ { event: "SessionStart", mode: "--session" },
204
+ { event: "PreCompact", mode: "--precompact" },
205
+ { event: "UserPromptSubmit", mode: "--recall" },
206
+ { event: "Stop", mode: "--capture" },
207
+ ];
208
+ /**
209
+ * Write the hook script + companion skill and register all four hooks in
210
+ * settings.json. Idempotent (skips a hook command already present) and
211
+ * backup-safe (.bak before overwriting settings). Returns the events it added.
212
+ */
213
+ export function installClaudeCombo(opts) {
214
+ const { fs, memoryFile } = opts;
215
+ const paths = claudeComboPaths(opts.claudeDir);
216
+ // 1) Hook script.
217
+ const hookDir = nodePath.dirname(paths.hookScript);
218
+ if (!fs.existsSync(hookDir))
219
+ fs.mkdirSync(hookDir, { recursive: true });
220
+ fs.writeFileSync(paths.hookScript, bfmemHookSource(memoryFile));
221
+ // 2) Companion skill.
222
+ const skillDir = nodePath.dirname(paths.companionSkill);
223
+ if (!fs.existsSync(skillDir))
224
+ fs.mkdirSync(skillDir, { recursive: true });
225
+ fs.writeFileSync(paths.companionSkill, companionSkillMd());
226
+ // 3) Merge hooks into settings.json.
227
+ let settings = {};
228
+ if (fs.existsSync(paths.settingsFile)) {
229
+ try {
230
+ settings = JSON.parse(fs.readFileSync(paths.settingsFile, "utf8"));
231
+ }
232
+ catch {
233
+ throw new Error("existing settings.json is not valid JSON");
234
+ }
235
+ fs.copyFileSync(paths.settingsFile, `${paths.settingsFile}.bak`);
236
+ }
237
+ const hooks = (settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {});
238
+ const added = [];
239
+ for (const { event, mode } of HOOK_EVENTS) {
240
+ const command = `node "${paths.hookScript}" ${mode}`;
241
+ const arr = (Array.isArray(hooks[event]) ? hooks[event] : (hooks[event] = []));
242
+ const exists = arr.some((g) => (g.hooks || []).some((h) => h.command === command));
243
+ if (!exists) {
244
+ arr.push({ hooks: [{ type: "command", command }] });
245
+ added.push(event);
246
+ }
247
+ }
248
+ settings.hooks = hooks;
249
+ const settingsDir = nodePath.dirname(paths.settingsFile);
250
+ if (!fs.existsSync(settingsDir))
251
+ fs.mkdirSync(settingsDir, { recursive: true });
252
+ fs.writeFileSync(paths.settingsFile, `${JSON.stringify(settings, null, 2)}\n`);
253
+ return { hookScript: paths.hookScript, addedHooks: added, settingsFile: paths.settingsFile };
254
+ }
255
+ //# sourceMappingURL=claude-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-hooks.js","sourceRoot":"","sources":["../../src/install/claude-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,QAAQ,MAAM,WAAW,CAAC;AAGjC,kFAAkF;AAClF,MAAM,UAAU,eAAe,CAAC,UAAkB;IAC9C,OAAO;;;;;;;;;;;;eAYI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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"version": "2026.6.31",
4
4
  "description": "BuilderForce Agent Memory — MCP transport. Exposes @seanhogg/builderforce-memory to any MCP client (Claude Agent SDK in-process, stdio, or HTTP) over a pluggable MemoryBackend, with token-saving fetch-on-demand recall.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -73,7 +73,7 @@
73
73
  "fake-indexeddb": "^6.0.0",
74
74
  "typescript": "^6.0.3",
75
75
  "@typescript/native-preview": "7.0.0-dev.20260627.2",
76
- "@seanhogg/builderforce-memory": "2026.6.30"
76
+ "@seanhogg/builderforce-memory": "2026.6.31"
77
77
  },
78
78
  "engines": {
79
79
  "node": ">=18.0.0"
@@ -18,8 +18,10 @@
18
18
 
19
19
  import os from "node:os";
20
20
  import path from "node:path";
21
+ import nodeFs from "node:fs";
21
22
  import { HOSTS } from "../install/hosts.js";
22
23
  import { installMemoryServer, type HostSelector } from "../install/install.js";
24
+ import { installClaudeCombo } from "../install/claude-hooks.js";
23
25
 
24
26
  function argValue(name: string): string | undefined {
25
27
  const hit = process.argv.find((a) => a.startsWith(`--${name}=`));
@@ -83,6 +85,26 @@ for (const r of results) {
83
85
  if (r.status === "installed" || r.status === "updated") wrote += 1;
84
86
  }
85
87
 
88
+ // ── Claude Code memory combo (hooks + companion skill) ───────────────────────
89
+ // Registering the server above gives Claude Code the TOOLS; this adds the
90
+ // self-driving behaviour (SessionStart digest, contextual recall, autonomous Stop
91
+ // capture). Only for Claude Code, only when present, and skippable via --no-hooks.
92
+ const claudeResult = results.find((r) => r.host === "claude-code");
93
+ const claudePresent = claudeResult && claudeResult.status !== "unsupported" && claudeResult.status !== "error";
94
+ if (claudePresent && !hasFlag("no-hooks")) {
95
+ try {
96
+ const combo = installClaudeCombo({
97
+ fs: nodeFs,
98
+ claudeDir: path.join(os.homedir(), ".claude"),
99
+ memoryFile,
100
+ });
101
+ const what = combo.addedHooks.length ? `added ${combo.addedHooks.join(", ")}` : "already current";
102
+ process.stdout.write(`✓ Claude Code memory combo: hooks ${what}; recall + autonomous capture wired\n`);
103
+ } catch (err) {
104
+ process.stderr.write(`✗ Claude Code hooks: ${String((err as Error).message ?? err)}\n`);
105
+ }
106
+ }
107
+
86
108
  if (results.length === 0) {
87
109
  process.stdout.write(
88
110
  "No MCP hosts detected. Pass --host=all to write configs anyway, or --host=cursor (etc.).\n",
package/src/index.ts CHANGED
@@ -37,3 +37,7 @@ export { installMemoryServer } from "./install/install.js";
37
37
  export type { InstallOptions, InstallResult, InstallStatus, HostSelector, FsLike } from "./install/install.js";
38
38
  export { HOSTS, SERVER_KEY, findHost } from "./install/hosts.js";
39
39
  export type { HostAdapter, HostEnv, ConfigFormat } from "./install/hosts.js";
40
+ // Claude Code "memory combo" — hooks (SessionStart/PreCompact/UserPromptSubmit/Stop)
41
+ // + companion skill that make memory self-driving (contextual recall + autonomous capture).
42
+ export { installClaudeCombo, bfmemHookSource, companionSkillMd, claudeComboPaths } from "./install/claude-hooks.js";
43
+ export type { ClaudeComboPaths } from "./install/claude-hooks.js";
@@ -0,0 +1,267 @@
1
+ /**
2
+ * Claude Code "memory combo" — the hooks + companion skill half of the install.
3
+ *
4
+ * Registering the MCP server (install.ts) gives Claude Code the memory TOOLS.
5
+ * This module adds the behaviour that makes memory SELF-DRIVING rather than
6
+ * advisory, so the agent doesn't have to be reminded to use it:
7
+ *
8
+ * SessionStart → inject a digest of the top durable memories.
9
+ * PreCompact → flush durable learnings before the window is summarised.
10
+ * UserPromptSubmit → CONTEXTUAL recall: score memories against the prompt and
11
+ * inject the relevant ones (so a stored fact is retrieved at
12
+ * the decision point, not just at session start).
13
+ * Stop → AUTONOMOUS capture: detect a durable instruction/correction
14
+ * in the user's last message and, if it wasn't consolidated
15
+ * this turn, BLOCK the stop with a directive to memory_remember
16
+ * (capture flows through the MCP write path — never racing the
17
+ * server's snapshot).
18
+ *
19
+ * All four point at one generated, dependency-free hook script (DRY). The combo
20
+ * is idempotent and backup-safe, matching install.ts.
21
+ */
22
+
23
+ import nodePath from "node:path";
24
+ import type { FsLike } from "./install.js";
25
+
26
+ /** The single hook script, four modes. `memoryFile` is the JSON snapshot path. */
27
+ export function bfmemHookSource(memoryFile: string): string {
28
+ return `#!/usr/bin/env node
29
+ /**
30
+ * builderforce-memory hook — generated by builderforce-memory-install. Dependency-free:
31
+ * reads only the JSON snapshot, never stands up the MCP server.
32
+ * --session SessionStart: inject a small digest of durable memories.
33
+ * --precompact PreCompact: remind to flush learnings before summarisation.
34
+ * --recall UserPromptSubmit: contextual recall — inject memories relevant to the prompt.
35
+ * --capture Stop: autonomous consolidation — block the stop until a detected
36
+ * durable correction is persisted via memory_remember.
37
+ */
38
+ import fs from "node:fs";
39
+
40
+ const FILE = ${JSON.stringify(memoryFile)};
41
+ const mode = process.argv[2] || "--session";
42
+
43
+ function readStdin() {
44
+ try { return fs.readFileSync(0, "utf8"); } catch { return ""; }
45
+ }
46
+ function loadEntries() {
47
+ try { const p = JSON.parse(fs.readFileSync(FILE, "utf8")); return Array.isArray(p) ? p : []; }
48
+ catch { return []; }
49
+ }
50
+ function tokens(s) {
51
+ return String(s || "").toLowerCase().split(/[^a-z0-9]+/).filter((t) => t.length >= 3);
52
+ }
53
+
54
+ if (mode === "--precompact") {
55
+ process.stdout.write(
56
+ "[builderforce-memory] Context is about to be compacted. Persist any durable learnings from this session — decisions, fixes, project facts, user preferences — by calling memory_remember with concise one-line facts. Recall them later with memory_recall instead of re-reading files.",
57
+ );
58
+ process.exit(0);
59
+ }
60
+
61
+ if (mode === "--recall") {
62
+ let prompt = "";
63
+ try { const j = JSON.parse(readStdin() || "{}"); prompt = typeof j.prompt === "string" ? j.prompt : ""; } catch { /* no input */ }
64
+ if (!prompt) process.exit(0);
65
+ const entries = loadEntries();
66
+ if (entries.length === 0) process.exit(0);
67
+ const q = new Set(tokens(prompt));
68
+ if (q.size === 0) process.exit(0);
69
+ const scored = entries
70
+ .map((e) => {
71
+ const hay = new Set(tokens([e.key, e.content, (e.tags || []).join(" ")].join(" ")));
72
+ let score = 0;
73
+ for (const t of q) if (hay.has(t)) score++;
74
+ return { e, score };
75
+ })
76
+ .filter((x) => x.score >= 2)
77
+ .sort((a, b) => b.score - a.score)
78
+ .slice(0, 3);
79
+ if (scored.length === 0) process.exit(0);
80
+ const lines = scored.map((x) => "• " + x.e.key + ": " + String(x.e.content || "").slice(0, 240)).join("\\n");
81
+ process.stdout.write(
82
+ "[builderforce-memory] Relevant stored memories for this request — use these instead of re-deriving or re-reading:\\n" + lines,
83
+ );
84
+ process.exit(0);
85
+ }
86
+
87
+ if (mode === "--capture") {
88
+ let input = {};
89
+ try { input = JSON.parse(readStdin() || "{}"); } catch { /* no input */ }
90
+ if (input.stop_hook_active) process.exit(0);
91
+ const tpath = input.transcript_path;
92
+ if (!tpath || typeof tpath !== "string") process.exit(0);
93
+
94
+ let raw = "";
95
+ try {
96
+ const stat = fs.statSync(tpath);
97
+ const want = Math.min(stat.size, 400000);
98
+ const fd = fs.openSync(tpath, "r");
99
+ const buf = Buffer.alloc(want);
100
+ fs.readSync(fd, buf, 0, want, stat.size - want);
101
+ fs.closeSync(fd);
102
+ raw = buf.toString("utf8");
103
+ } catch { process.exit(0); }
104
+
105
+ const msgs = [];
106
+ for (const ln of raw.split("\\n")) { if (ln.trim()) { try { msgs.push(JSON.parse(ln)); } catch { /* partial */ } } }
107
+
108
+ let lastUserText = "";
109
+ let rememberedThisTurn = false;
110
+ for (let i = msgs.length - 1; i >= 0; i--) {
111
+ const m = msgs[i] || {};
112
+ const inner = m.message || m;
113
+ const role = inner.role;
114
+ const content = inner.content;
115
+ if (role === "assistant" && !lastUserText) {
116
+ if (Array.isArray(content)) for (const c of content) {
117
+ if (c && c.type === "tool_use" && typeof c.name === "string" && c.name.includes("memory_remember")) rememberedThisTurn = true;
118
+ }
119
+ }
120
+ if (role === "user" && !lastUserText) {
121
+ let txt = "";
122
+ if (typeof content === "string") txt = content;
123
+ else if (Array.isArray(content)) for (const c of content) {
124
+ if (typeof c === "string") txt += c + " ";
125
+ else if (c && c.type === "text" && typeof c.text === "string") txt += c.text + " ";
126
+ }
127
+ if (txt.trim()) lastUserText = txt;
128
+ }
129
+ }
130
+ if (!lastUserText || rememberedThisTurn) process.exit(0);
131
+
132
+ const lower = lastUserText.toLowerCase();
133
+ const SIGNALS = [
134
+ "you have to", "you should", "you need to", "you must", "from now on", "going forward",
135
+ "always ", "never ", "make sure", "remember to", "don't forget", "do not forget",
136
+ "i keep telling", "i already told", "shouldn't have to", "keep having to remind",
137
+ "you forgot", "you keep", "that's wrong", "you're wrong", "this is wrong", "stop ",
138
+ ];
139
+ const hit = SIGNALS.find((s) => lower.includes(s));
140
+ if (!hit) process.exit(0);
141
+
142
+ const snippet = lastUserText.trim().slice(0, 240);
143
+ const reason =
144
+ "[builderforce-memory] A durable instruction/correction was detected in the user's last message and you did NOT consolidate it this turn. " +
145
+ "Before stopping, call memory_remember with a concise, stable-keyed fact capturing it (reuse the same key to replace a superseded one, or memory_forget it). " +
146
+ "User said: '" + snippet + "'. If it is genuinely not durable (a one-off, or already stored), briefly say why and then stop.";
147
+ process.stdout.write(JSON.stringify({ decision: "block", reason }));
148
+ process.exit(0);
149
+ }
150
+
151
+ const entries = loadEntries();
152
+ if (entries.length === 0) {
153
+ process.stdout.write(
154
+ "[builderforce-memory] Active (memory empty). Store durable facts with memory_remember and retrieve them with memory_recall instead of re-reading files or chat history — that is how token usage stays low.",
155
+ );
156
+ process.exit(0);
157
+ }
158
+ const top = entries
159
+ .map((e) => ({ key: e.key, content: String(e.content ?? ""), importance: typeof e.importance === "number" ? e.importance : 0.5 }))
160
+ .sort((a, b) => b.importance - a.importance)
161
+ .slice(0, 8)
162
+ .map((e) => "• " + e.key + ": " + e.content.slice(0, 200))
163
+ .join("\\n");
164
+ process.stdout.write(
165
+ "[builderforce-memory] Active — token-saving memory loaded. Before re-reading files or history, call memory_recall. Store durable facts with memory_remember.\\nTop memories:\\n" + top,
166
+ );
167
+ `;
168
+ }
169
+
170
+ /** The companion skill doc that teaches the recall/remember discipline. */
171
+ export function companionSkillMd(): string {
172
+ return `---
173
+ name: builderforce-memory
174
+ description: Token-saving persistent memory. Recall durable facts (decisions, fixes, project context, user preferences) instead of re-reading files or chat history, and remember new durable facts as you learn them.
175
+ ---
176
+
177
+ # builderforce-memory — the conductor
178
+
179
+ Persistent memory backed by the \`builderforce-memory\` MCP server. The point is
180
+ **token reduction**: pull a small relevant slice from memory instead of re-reading
181
+ the full file/history. The install also wires hooks so this is largely automatic:
182
+ the SessionStart digest, contextual recall on each prompt, and an autonomous Stop
183
+ capture that won't let a durable correction go unrecorded.
184
+
185
+ ## Tools
186
+ - \`memory_recall(query, [k])\` — top-K relevant memories. First move on a task.
187
+ - \`memory_get(key)\` — exact lookup by key.
188
+ - \`memory_recall_by_tag(tag)\` — everything under a tag.
189
+ - \`memory_remember(key, content, [tags], [importance])\` — store ONE durable fact.
190
+ - \`memory_forget(key)\` — drop a superseded fact.
191
+
192
+ ## Discipline
193
+ Reuse a stable key to REPLACE a fact (write-through), don't append duplicates.
194
+ Store decisions, non-obvious fixes, project constraints, user preferences — one
195
+ tight line each. Not things git already records or one-off turn details.
196
+ `;
197
+ }
198
+
199
+ /** Files/paths the combo manages, derived from the Claude config dir (~/.claude). */
200
+ export interface ClaudeComboPaths {
201
+ claudeDir: string;
202
+ settingsFile: string;
203
+ hookScript: string;
204
+ companionSkill: string;
205
+ }
206
+
207
+ export function claudeComboPaths(claudeDir: string): ClaudeComboPaths {
208
+ return {
209
+ claudeDir,
210
+ settingsFile: nodePath.join(claudeDir, "settings.json"),
211
+ hookScript: nodePath.join(claudeDir, "builderforce-memory", "bfmem-hook.mjs"),
212
+ companionSkill: nodePath.join(claudeDir, "skills", "builderforce-memory", "SKILL.md"),
213
+ };
214
+ }
215
+
216
+ const HOOK_EVENTS = [
217
+ { event: "SessionStart", mode: "--session" },
218
+ { event: "PreCompact", mode: "--precompact" },
219
+ { event: "UserPromptSubmit", mode: "--recall" },
220
+ { event: "Stop", mode: "--capture" },
221
+ ] as const;
222
+
223
+ /**
224
+ * Write the hook script + companion skill and register all four hooks in
225
+ * settings.json. Idempotent (skips a hook command already present) and
226
+ * backup-safe (.bak before overwriting settings). Returns the events it added.
227
+ */
228
+ export function installClaudeCombo(opts: {
229
+ fs: FsLike;
230
+ claudeDir: string;
231
+ memoryFile: string;
232
+ }): { hookScript: string; addedHooks: string[]; settingsFile: string } {
233
+ const { fs, memoryFile } = opts;
234
+ const paths = claudeComboPaths(opts.claudeDir);
235
+
236
+ // 1) Hook script.
237
+ const hookDir = nodePath.dirname(paths.hookScript);
238
+ if (!fs.existsSync(hookDir)) fs.mkdirSync(hookDir, { recursive: true });
239
+ fs.writeFileSync(paths.hookScript, bfmemHookSource(memoryFile));
240
+
241
+ // 2) Companion skill.
242
+ const skillDir = nodePath.dirname(paths.companionSkill);
243
+ if (!fs.existsSync(skillDir)) fs.mkdirSync(skillDir, { recursive: true });
244
+ fs.writeFileSync(paths.companionSkill, companionSkillMd());
245
+
246
+ // 3) Merge hooks into settings.json.
247
+ let settings: Record<string, unknown> = {};
248
+ if (fs.existsSync(paths.settingsFile)) {
249
+ try { settings = JSON.parse(fs.readFileSync(paths.settingsFile, "utf8")) as Record<string, unknown>; }
250
+ catch { throw new Error("existing settings.json is not valid JSON"); }
251
+ fs.copyFileSync(paths.settingsFile, `${paths.settingsFile}.bak`);
252
+ }
253
+ const hooks = (settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {}) as Record<string, unknown>;
254
+ const added: string[] = [];
255
+ for (const { event, mode } of HOOK_EVENTS) {
256
+ const command = `node "${paths.hookScript}" ${mode}`;
257
+ const arr = (Array.isArray(hooks[event]) ? hooks[event] : (hooks[event] = [])) as Array<{ hooks?: Array<{ type?: string; command?: string }> }>;
258
+ const exists = arr.some((g) => (g.hooks || []).some((h) => h.command === command));
259
+ if (!exists) { arr.push({ hooks: [{ type: "command", command }] }); added.push(event); }
260
+ }
261
+ settings.hooks = hooks;
262
+ const settingsDir = nodePath.dirname(paths.settingsFile);
263
+ if (!fs.existsSync(settingsDir)) fs.mkdirSync(settingsDir, { recursive: true });
264
+ fs.writeFileSync(paths.settingsFile, `${JSON.stringify(settings, null, 2)}\n`);
265
+
266
+ return { hookScript: paths.hookScript, addedHooks: added, settingsFile: paths.settingsFile };
267
+ }