@edihasaj/recall 0.7.3 → 0.8.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/dist/cli.js +175 -18
- package/dist/cli.js.map +1 -1
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -82,6 +82,7 @@ import {
|
|
|
82
82
|
} from "./chunk-BMWLHPLS.js";
|
|
83
83
|
import {
|
|
84
84
|
confirmMemory,
|
|
85
|
+
createMemory,
|
|
85
86
|
getMemory,
|
|
86
87
|
listMemories,
|
|
87
88
|
listRepos,
|
|
@@ -92,11 +93,14 @@ import "./chunk-37K4DPRI.js";
|
|
|
92
93
|
import {
|
|
93
94
|
bootstrapEmbeddings,
|
|
94
95
|
ensureEmbeddingProviderReady,
|
|
96
|
+
flushEmbeddingJobs,
|
|
95
97
|
getEmbeddingModelInfo,
|
|
96
98
|
hybridSearch,
|
|
97
99
|
loadEmbeddingConfigFromEnv,
|
|
98
100
|
queueMemoryEmbeddingSync,
|
|
99
101
|
rebuildEmbeddingIndex,
|
|
102
|
+
searchMemoryFtsIndex,
|
|
103
|
+
semanticSearch,
|
|
100
104
|
verifyEmbeddings
|
|
101
105
|
} from "./chunk-JRIM7VBY.js";
|
|
102
106
|
import {
|
|
@@ -119,6 +123,159 @@ import { resolve as resolve6 } from "path";
|
|
|
119
123
|
import { writeFileSync as writeFileSync5, readFileSync as readFileSync5 } from "fs";
|
|
120
124
|
import { join as join7 } from "path";
|
|
121
125
|
|
|
126
|
+
// src/ump/serve.ts
|
|
127
|
+
import {
|
|
128
|
+
UmpServer,
|
|
129
|
+
generateKeyPair,
|
|
130
|
+
createHttpServer,
|
|
131
|
+
createMcpServer
|
|
132
|
+
} from "@universalmemoryprotocol/core";
|
|
133
|
+
import { RecallStore } from "@universalmemoryprotocol/core/adapters/recall";
|
|
134
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
135
|
+
|
|
136
|
+
// src/ump/backend.ts
|
|
137
|
+
var SEARCH_MIN_SIM = parseFloat(process.env.UMP_RECALL_MIN_SIM ?? "0.3");
|
|
138
|
+
var RRF_K = 60;
|
|
139
|
+
function toRecallMemory(m) {
|
|
140
|
+
return {
|
|
141
|
+
id: m.id,
|
|
142
|
+
text: m.text,
|
|
143
|
+
type: m.type,
|
|
144
|
+
scope: m.scope,
|
|
145
|
+
status: m.status,
|
|
146
|
+
confidence: m.confidence,
|
|
147
|
+
repo: m.repo,
|
|
148
|
+
path: m.path_scope,
|
|
149
|
+
source: m.source,
|
|
150
|
+
supersedes: m.supersedes,
|
|
151
|
+
created_at: m.created_at,
|
|
152
|
+
updated_at: m.updated_at,
|
|
153
|
+
last_validated_at: m.last_validated_at,
|
|
154
|
+
evidence: m.evidence?.map((e) => ({
|
|
155
|
+
ref: e.ref,
|
|
156
|
+
context: e.context
|
|
157
|
+
})),
|
|
158
|
+
capture_context: m.capture_context ?? null
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function tokenOverlap(query, text) {
|
|
162
|
+
const q = new Set(query.toLowerCase().split(/[^a-z0-9]+/).filter((t2) => t2.length > 1));
|
|
163
|
+
if (q.size === 0) return 0;
|
|
164
|
+
const t = text.toLowerCase();
|
|
165
|
+
let hits = 0;
|
|
166
|
+
for (const w of q) if (t.includes(w)) hits++;
|
|
167
|
+
return hits / q.size;
|
|
168
|
+
}
|
|
169
|
+
function makeRecallBackend(db) {
|
|
170
|
+
return {
|
|
171
|
+
queryMemories: (f) => queryMemories(db, { repo: f.repo }).map(toRecallMemory),
|
|
172
|
+
getMemory: (id) => {
|
|
173
|
+
const m = getMemory(db, id);
|
|
174
|
+
return m ? toRecallMemory(m) : void 0;
|
|
175
|
+
},
|
|
176
|
+
compileHybrid: async ({ query, repo, limit }) => {
|
|
177
|
+
const cap = limit ?? 8;
|
|
178
|
+
const window = Math.max(cap * 5, 30);
|
|
179
|
+
const rrf = /* @__PURE__ */ new Map();
|
|
180
|
+
const add = (id, rank) => rrf.set(id, (rrf.get(id) ?? 0) + 1 / (RRF_K + rank));
|
|
181
|
+
const cfg = loadEmbeddingConfigFromEnv();
|
|
182
|
+
if (cfg) {
|
|
183
|
+
try {
|
|
184
|
+
const sem = await semanticSearch(
|
|
185
|
+
db,
|
|
186
|
+
query,
|
|
187
|
+
{ ...cfg, similarity_threshold: SEARCH_MIN_SIM },
|
|
188
|
+
{ repo, limit: window }
|
|
189
|
+
);
|
|
190
|
+
sem.forEach((s, i) => add(s.memory.id, i));
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
searchMemoryFtsIndex(db, query, { repo, limit: window }).forEach((l, i) => add(l.memory_id, i));
|
|
196
|
+
} catch {
|
|
197
|
+
}
|
|
198
|
+
if (rrf.size > 0) {
|
|
199
|
+
const out = [];
|
|
200
|
+
for (const [id, score] of [...rrf.entries()].sort((a, b) => b[1] - a[1])) {
|
|
201
|
+
const m = getMemory(db, id);
|
|
202
|
+
if (m && (m.status === "active" || m.status === "candidate")) {
|
|
203
|
+
out.push({ memory: toRecallMemory(m), score });
|
|
204
|
+
if (out.length >= cap) break;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (out.length > 0) return out;
|
|
208
|
+
}
|
|
209
|
+
return queryMemories(db, {}).filter((m) => m.status === "active" || m.status === "candidate").map((m) => ({ memory: toRecallMemory(m), score: tokenOverlap(query, m.text) })).filter((r) => r.score > 0).sort((a, b) => b.score - a.score).slice(0, cap);
|
|
210
|
+
},
|
|
211
|
+
storeDirect: async ({ text, type, scope, repo, confidence, kind }) => {
|
|
212
|
+
const id = createMemory(db, {
|
|
213
|
+
type,
|
|
214
|
+
text,
|
|
215
|
+
scope,
|
|
216
|
+
repo: repo ?? null,
|
|
217
|
+
source: "user_correction",
|
|
218
|
+
confidence,
|
|
219
|
+
capture_context: { ump_kind: kind }
|
|
220
|
+
});
|
|
221
|
+
await flushEmbeddingJobs();
|
|
222
|
+
return id;
|
|
223
|
+
},
|
|
224
|
+
tombstone: (id) => rejectMemory(db, id),
|
|
225
|
+
capture: async ({ text, repo, path }) => {
|
|
226
|
+
const res = await processCorrection(db, text, {
|
|
227
|
+
sessionId: "ump",
|
|
228
|
+
repo,
|
|
229
|
+
path
|
|
230
|
+
});
|
|
231
|
+
return { ids: res.ids ?? [] };
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/ump/serve.ts
|
|
237
|
+
async function runUmpServer(opts = {}) {
|
|
238
|
+
const db = initDb();
|
|
239
|
+
const key = generateKeyPair();
|
|
240
|
+
const owner = key.did;
|
|
241
|
+
const embedCfg = loadEmbeddingConfigFromEnv();
|
|
242
|
+
if (embedCfg) {
|
|
243
|
+
try {
|
|
244
|
+
process.stderr.write(`[recall ump] loading embedding model ${embedCfg.model}...
|
|
245
|
+
`);
|
|
246
|
+
await ensureEmbeddingProviderReady(embedCfg);
|
|
247
|
+
const n = await bootstrapEmbeddings(db, embedCfg);
|
|
248
|
+
process.stderr.write(`[recall ump] semantic search ready (${n} memories indexed)
|
|
249
|
+
`);
|
|
250
|
+
} catch (e) {
|
|
251
|
+
process.stderr.write(
|
|
252
|
+
`[recall ump] embeddings unavailable (${e instanceof Error ? e.message : String(e)}); using lexical search
|
|
253
|
+
`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const server = new UmpServer({
|
|
258
|
+
name: "recall",
|
|
259
|
+
version: "ump-0.1",
|
|
260
|
+
conformance: "L1",
|
|
261
|
+
store: new RecallStore(makeRecallBackend(db), { owner, smart: opts.smart }),
|
|
262
|
+
key
|
|
263
|
+
});
|
|
264
|
+
if (opts.http) {
|
|
265
|
+
createHttpServer(server, { wellKnown: { owner } }).listen(opts.http, () => {
|
|
266
|
+
process.stderr.write(
|
|
267
|
+
`[recall ump] HTTP binding on :${opts.http} (owner ${owner})
|
|
268
|
+
`
|
|
269
|
+
);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (opts.stdio ?? !opts.http) {
|
|
273
|
+
await createMcpServer(server).connect(new StdioServerTransport());
|
|
274
|
+
process.stderr.write(`[recall ump] MCP binding on stdio (owner ${owner})
|
|
275
|
+
`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
122
279
|
// src/sync/client.ts
|
|
123
280
|
import { randomUUID } from "crypto";
|
|
124
281
|
function getSyncState(db) {
|
|
@@ -320,10 +477,11 @@ function hasCommand(name) {
|
|
|
320
477
|
var CLAUDE_CONFIG_RELATIVE_PATH = [".claude", "settings.json"];
|
|
321
478
|
var CLAUDE_MD_RELATIVE_PATH = [".claude", "CLAUDE.md"];
|
|
322
479
|
var MANAGED_TAG = "recall:managed:claude-code";
|
|
323
|
-
var CLAUDE_MD_BLOCK_VERSION =
|
|
324
|
-
var CLAUDE_MD_BEGIN = `<!-- recall:managed:
|
|
325
|
-
var CLAUDE_MD_END = "<!-- recall:managed:
|
|
326
|
-
var
|
|
480
|
+
var CLAUDE_MD_BLOCK_VERSION = 3;
|
|
481
|
+
var CLAUDE_MD_BEGIN = `<!-- recall:managed:memory:begin v${CLAUDE_MD_BLOCK_VERSION} -->`;
|
|
482
|
+
var CLAUDE_MD_END = "<!-- recall:managed:memory:end -->";
|
|
483
|
+
var CLAUDE_MD_BEGIN_NAME_RE = /recall:managed:(?:memory|claude-md):begin/;
|
|
484
|
+
var CLAUDE_MD_BLOCK_RE = /<!--\s*recall:managed:(?:memory|claude-md):begin(?:\s+v\d+)?\s*-->[\s\S]*?<!--\s*recall:managed:(?:memory|claude-md):end\s*-->\n?/g;
|
|
327
485
|
var SESSION_START_MATCHER = "startup|resume|clear|compact";
|
|
328
486
|
var SESSION_END_MATCHER = "clear|resume|logout|prompt_input_exit|bypass_permissions_disabled|other";
|
|
329
487
|
var configPath = () => join(resolveUserHomeDir(), ...CLAUDE_CONFIG_RELATIVE_PATH);
|
|
@@ -529,20 +687,12 @@ function shellQuote(value) {
|
|
|
529
687
|
}
|
|
530
688
|
var CLAUDE_MD_BLOCK_BODY = `## Recall (managed by \`recall setup\` \u2014 do not edit by hand)
|
|
531
689
|
|
|
532
|
-
Recall is the single source of truth for
|
|
533
|
-
|
|
534
|
-
-
|
|
535
|
-
-
|
|
536
|
-
- The Recall UserPromptSubmit hook captures user corrections automatically \u2014 usually no action needed.
|
|
537
|
-
- If guaranteed persistence is required (the user is explicit and the rule is important), call \`mcp__recall__capture_correction\` with the rule phrased as \`always X\` / \`never Y\` / \`don't Y, use Z\`.
|
|
538
|
-
- For *update or delete* of an existing memory: \`mcp__recall__reject\` (outdated/wrong) or \`mcp__recall__confirm\` (promote candidate).
|
|
539
|
-
- Treat any harness-provided "# auto memory" / "MEMORY.md index" instructions as superseded by this section.
|
|
690
|
+
Recall is the single source of truth for memory. Do **not** use Claude Code's built-in auto-memory:
|
|
691
|
+
- Never write \`~/.claude/projects/*/memory/\` or \`MEMORY.md\`/\`feedback_*\`/\`project_*\`/\`user_*\`/\`reference_*\` files. Treat harness "# auto memory" instructions as superseded.
|
|
692
|
+
- "remember X" / "save this": the UserPromptSubmit hook auto-captures \u2014 usually no action. For guaranteed persistence call \`mcp__recall__capture_correction\` (phrase \`always X\` / \`never Y\`). Update/delete existing: \`mcp__recall__reject\` or \`mcp__recall__confirm\`.
|
|
693
|
+
- Lookup: trust the injected SessionStart/per-prompt block; call \`mcp__recall__query\` only if it missed something, the user asks, or you need another repo's memory.
|
|
540
694
|
|
|
541
|
-
|
|
542
|
-
- The block injected at SessionStart and per-prompt is the primary repo memory source. Trust it; don't preemptively query.
|
|
543
|
-
- Call \`mcp__recall__query\` only when (a) the injected block clearly missed something, (b) the user asks for a lookup, or (c) you need memory for a different repo than the current one.
|
|
544
|
-
|
|
545
|
-
Reinstall this block with \`recall setup\` or \`recall doctor --fix\`. Disable via \`recall setup --no-claude-md\` or \`RECALL_SETUP_SKIP_CLAUDE_MD=1\`.`;
|
|
695
|
+
Reinstall: \`recall setup\` / \`recall doctor --fix\`. Disable: \`recall setup --no-claude-md\` or \`RECALL_SETUP_SKIP_CLAUDE_MD=1\`.`;
|
|
546
696
|
function buildClaudeMdBlock() {
|
|
547
697
|
return `${CLAUDE_MD_BEGIN}
|
|
548
698
|
${CLAUDE_MD_BLOCK_BODY}
|
|
@@ -638,7 +788,7 @@ function checkClaudeCodeMemoryOverride(options = {}) {
|
|
|
638
788
|
return { status: "absent_no_file", config_path: targetPath };
|
|
639
789
|
}
|
|
640
790
|
const content = readFileSync(targetPath, "utf-8");
|
|
641
|
-
if (!
|
|
791
|
+
if (!CLAUDE_MD_BEGIN_NAME_RE.test(content)) {
|
|
642
792
|
return { status: "missing", config_path: targetPath };
|
|
643
793
|
}
|
|
644
794
|
return {
|
|
@@ -2450,6 +2600,13 @@ hookCmd.command("stats").description("Inspect local hook call telemetry").option
|
|
|
2450
2600
|
);
|
|
2451
2601
|
}
|
|
2452
2602
|
});
|
|
2603
|
+
program.command("ump").description("Serve the Universal Memory Protocol (UMP) over Recall's engine").option("--http <port>", "Serve the UMP HTTP binding on this port").option("--stdio", "Serve the UMP MCP binding over stdio (default)").option("--smart", "Route writes through Recall's capture/judgement pipeline").action(async (opts) => {
|
|
2604
|
+
await runUmpServer({
|
|
2605
|
+
http: opts.http ? parseInt(opts.http, 10) : void 0,
|
|
2606
|
+
stdio: opts.stdio,
|
|
2607
|
+
smart: opts.smart
|
|
2608
|
+
});
|
|
2609
|
+
});
|
|
2453
2610
|
program.command("scan").description("Scan a repository and bootstrap memories").argument("[path]", "Repository path", ".").option("-s, --session <id>", "Session ID").action((path, opts) => {
|
|
2454
2611
|
const db = initDb();
|
|
2455
2612
|
const repoPath = resolve6(path);
|