@lotargo/memory_plugin 1.6.4 → 1.6.6
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 +17 -0
- package/mcp-server/benchmarks/fetch_real_corpus.js +351 -0
- package/mcp-server/benchmarks/gpu_profile_benchmark.js +170 -0
- package/mcp-server/benchmarks/policy_dominance_test.js +221 -0
- package/mcp-server/benchmarks/quality_evaluator.js +598 -0
- package/mcp-server/benchmarks/raw_corpus_data.js +613 -0
- package/mcp-server/benchmarks/run_benchmarks.js +366 -0
- package/mcp-server/benchmarks/stress_ingestion.js +195 -0
- package/mcp-server/benchmarks/table_code_retrieval.js +453 -0
- package/mcp-server/benchmarks/test_dual_layer.js +141 -0
- package/mcp-server/memory.js +13 -3
- package/mcp-server/rag_scope.js +83 -0
- package/mcp-server/tools/core/memory_core.js +376 -356
- package/mcp-server/tools/identity_tools.js +4 -2
- package/mcp-server/tools/memory_tools.js +134 -121
- package/mcp-server/tools/rag_tools.js +207 -202
- package/opencode-plugin/index.js +366 -339
- package/package.json +4 -25
- package/skills/using-memory/SKILL.md +93 -89
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { GLOBAL_KEY, projectKey } from "./memory.js";
|
|
2
|
+
|
|
3
|
+
export async function resolveRagScopeKey(scope = "project", ctx = {}) {
|
|
4
|
+
if (scope === "global") return GLOBAL_KEY;
|
|
5
|
+
const dir = ctx.directory || ctx.project || null;
|
|
6
|
+
const key = await projectKey(ctx.worktree ?? null, dir);
|
|
7
|
+
if (!key) {
|
|
8
|
+
if (scope === "project") {
|
|
9
|
+
throw new Error("Project-scoped RAG requires a Git repository. Use scope='global' outside Git.");
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return key;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function resolveRagScopeKeys(scope = "all", ctx = {}) {
|
|
17
|
+
if (scope === "global") return [GLOBAL_KEY];
|
|
18
|
+
const dir = ctx.directory || ctx.project || null;
|
|
19
|
+
const project = await projectKey(ctx.worktree ?? null, dir);
|
|
20
|
+
if (scope === "project") {
|
|
21
|
+
if (!project) {
|
|
22
|
+
throw new Error("Project-scoped RAG requires a Git repository. Use scope='global' outside Git.");
|
|
23
|
+
}
|
|
24
|
+
return [project];
|
|
25
|
+
}
|
|
26
|
+
return project ? [GLOBAL_KEY, project] : [GLOBAL_KEY];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function resolveManageRagScopeKeys(action, scope, ctx = {}) {
|
|
30
|
+
if (action !== "delete" || scope) {
|
|
31
|
+
return await resolveRagScopeKeys(scope || "all", ctx);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Browsing defaults to the combined visible view, but a destructive action
|
|
35
|
+
// defaults to the narrowest current ownership boundary. Inside Git that is
|
|
36
|
+
// the project; outside Git the only visible boundary is global.
|
|
37
|
+
const visible = await resolveRagScopeKeys("all", ctx);
|
|
38
|
+
return visible.length > 1 ? [visible[visible.length - 1]] : visible;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function addDocumentScope(db, docId, scopeKey) {
|
|
42
|
+
const key = scopeKey || GLOBAL_KEY;
|
|
43
|
+
await db
|
|
44
|
+
.prepare(
|
|
45
|
+
"INSERT OR IGNORE INTO document_scopes (doc_id, scope_key, created_at) VALUES (?, ?, ?);"
|
|
46
|
+
)
|
|
47
|
+
.run(docId, key, Date.now());
|
|
48
|
+
return key;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function removeDocumentScopes(db, docId, scopeKeys) {
|
|
52
|
+
const keys = Array.isArray(scopeKeys) ? [...new Set(scopeKeys.filter(Boolean))] : [];
|
|
53
|
+
if (keys.length === 0) return { removedScopes: [], remainingScopes: 0 };
|
|
54
|
+
const placeholders = keys.map(() => "?").join(",");
|
|
55
|
+
const existing = await db
|
|
56
|
+
.prepare(`SELECT scope_key FROM document_scopes WHERE doc_id = ? AND scope_key IN (${placeholders})`)
|
|
57
|
+
.all(docId, ...keys);
|
|
58
|
+
await db
|
|
59
|
+
.prepare(`DELETE FROM document_scopes WHERE doc_id = ? AND scope_key IN (${placeholders})`)
|
|
60
|
+
.run(docId, ...keys);
|
|
61
|
+
const remaining = await db
|
|
62
|
+
.prepare("SELECT COUNT(*) AS cnt FROM document_scopes WHERE doc_id = ?")
|
|
63
|
+
.get(docId);
|
|
64
|
+
const remainingScopes = remaining?.cnt || 0;
|
|
65
|
+
if (existing.length > 0 && remainingScopes > 0) {
|
|
66
|
+
const { queueDocumentSyncIfNeeded } = await import("./graph/knowledge_linker.js");
|
|
67
|
+
await queueDocumentSyncIfNeeded(db, docId);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
removedScopes: existing.map((row) => row.scope_key),
|
|
71
|
+
remainingScopes,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function scopeFilterSql(scopeKeys, column = "ds.scope_key") {
|
|
76
|
+
if (!Array.isArray(scopeKeys) || scopeKeys.length === 0) {
|
|
77
|
+
return { clause: "", params: [] };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
clause: `${column} IN (${scopeKeys.map(() => "?").join(",")})`,
|
|
81
|
+
params: scopeKeys,
|
|
82
|
+
};
|
|
83
|
+
}
|