opencode-fractal-memory 0.3.0 → 0.4.1
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/mcp/server.js +9 -1
- package/dist/mcp-server.js +6 -1
- package/dist/plugin/index.js +18 -0
- package/dist/plugin/init.js +17 -1
- package/dist/tools/version.js +7 -1
- package/package.json +1 -1
package/dist/mcp/server.js
CHANGED
|
@@ -3,10 +3,18 @@ import { z } from "zod";
|
|
|
3
3
|
import { createSqliteMemoryStore } from "../storage/sqlite";
|
|
4
4
|
import { withMcpLogging, mcpLog } from "./logging";
|
|
5
5
|
import { nodeToPlain, ensureScope, resourceStats } from "./transform";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../../package.json"), "utf-8"));
|
|
6
12
|
let store;
|
|
7
13
|
export async function createMemoryMcpServer(projectDir, globalDbPath) {
|
|
14
|
+
mcpLog("info", "Creating memory store", { projectDir });
|
|
8
15
|
store = createSqliteMemoryStore(projectDir, globalDbPath);
|
|
9
|
-
|
|
16
|
+
mcpLog("info", "Memory store created");
|
|
17
|
+
const server = new McpServer({ name: "opencode-fractal-memory", version: pkg.version }, { capabilities: { tools: {}, resources: {} } });
|
|
10
18
|
server.registerTool("memory_search", {
|
|
11
19
|
description: "Search memory nodes by text, embedding similarity, or BM25 score",
|
|
12
20
|
inputSchema: {
|
package/dist/mcp-server.js
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import * as os from "node:os";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
4
6
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
7
|
import { createMemoryMcpServer } from "./mcp/server";
|
|
6
8
|
import { mcpLog } from "./mcp/logging";
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = path.dirname(__filename);
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../package.json"), "utf-8"));
|
|
7
12
|
const projectDir = process.env.MGMT_PROJECT_DIR || process.cwd();
|
|
8
13
|
const globalDbPath = path.join(os.homedir(), ".config", "opencode", "memory.db");
|
|
9
14
|
async function main() {
|
|
10
|
-
mcpLog("info", "MCP server starting", { name: "opencode-fractal-memory", version:
|
|
15
|
+
mcpLog("info", "MCP server starting", { name: "opencode-fractal-memory", version: pkg.version });
|
|
11
16
|
const server = await createMemoryMcpServer(projectDir, globalDbPath);
|
|
12
17
|
const transport = new StdioServerTransport();
|
|
13
18
|
await server.connect(transport);
|
package/dist/plugin/index.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { initStorage, loadPluginConfig, seedRuleNodes, backfillData, scheduleBackgroundEmbeddings, setupJournal, startManagementIfEnabled, createAutoRetrieveIfEnabled } from "./init";
|
|
2
2
|
import { createHookHandlers } from "./hooks";
|
|
3
3
|
import { createToolMap } from "./tools";
|
|
4
|
+
import { memLog, perfNow } from "../logging";
|
|
4
5
|
export const MemoryPlugin = async (ctx) => {
|
|
5
6
|
const { directory, client } = ctx;
|
|
7
|
+
const t0 = perfNow();
|
|
8
|
+
memLog("info", "init", "Plugin initialization started", { directory });
|
|
9
|
+
let t = perfNow();
|
|
6
10
|
const store = await initStorage(directory);
|
|
11
|
+
memLog("info", "init", "Storage initialized", { durationMs: perfNow() - t });
|
|
12
|
+
t = perfNow();
|
|
7
13
|
const memConfig = await loadPluginConfig(directory);
|
|
14
|
+
memLog("info", "init", "Config loaded", { durationMs: perfNow() - t });
|
|
15
|
+
t = perfNow();
|
|
8
16
|
await seedRuleNodes(store);
|
|
17
|
+
memLog("info", "init", "Seed nodes completed", { durationMs: perfNow() - t });
|
|
18
|
+
t = perfNow();
|
|
9
19
|
await backfillData(store);
|
|
20
|
+
memLog("info", "init", "Backfill completed", { durationMs: perfNow() - t });
|
|
21
|
+
t = perfNow();
|
|
10
22
|
scheduleBackgroundEmbeddings(store);
|
|
23
|
+
memLog("info", "init", "Background embeddings scheduled", { durationMs: perfNow() - t });
|
|
24
|
+
t = perfNow();
|
|
11
25
|
const journalTools = await setupJournal(directory);
|
|
26
|
+
memLog("info", "init", "Journal setup completed", { durationMs: perfNow() - t });
|
|
27
|
+
t = perfNow();
|
|
12
28
|
startManagementIfEnabled(store, directory);
|
|
29
|
+
memLog("info", "init", "Management server check completed", { durationMs: perfNow() - t });
|
|
13
30
|
const ruleCache = new Map();
|
|
14
31
|
const ruleCacheDirty = { value: true };
|
|
15
32
|
const sessionInjectionLock = new Map();
|
|
@@ -17,6 +34,7 @@ export const MemoryPlugin = async (ctx) => {
|
|
|
17
34
|
const autoRetrieveHook = createAutoRetrieveIfEnabled(store, memConfig);
|
|
18
35
|
const handlers = createHookHandlers(store, client, memConfig, ruleCache, ruleCacheDirty, sessionInjectionLock, latestUserMessage);
|
|
19
36
|
const toolMap = createToolMap(store, journalTools, client);
|
|
37
|
+
memLog("info", "init", "Plugin initialization completed", { totalDurationMs: perfNow() - t0 });
|
|
20
38
|
return {
|
|
21
39
|
...handlers,
|
|
22
40
|
...(autoRetrieveHook || {}),
|
package/dist/plugin/init.js
CHANGED
|
@@ -12,10 +12,15 @@ import { memLog } from "../logging";
|
|
|
12
12
|
import { setCacheConfig } from "../cache";
|
|
13
13
|
import { setHighContextThreshold, setCriticalContextThreshold, setMaxInjectionTokens, setCoreInjectionTokens, setAutoCompressThreshold } from "./state";
|
|
14
14
|
export async function initStorage(directory) {
|
|
15
|
+
memLog("info", "init", "Creating memory store", { directory });
|
|
15
16
|
const store = createMemoryStore(directory);
|
|
17
|
+
memLog("info", "init", "Ensuring seed nodes");
|
|
16
18
|
await store.ensureSeed();
|
|
19
|
+
memLog("info", "init", "Ensuring models");
|
|
17
20
|
await ensureModels();
|
|
21
|
+
memLog("info", "init", "Ensuring agent files");
|
|
18
22
|
await ensureAgentFiles().catch(() => { });
|
|
23
|
+
memLog("info", "init", "Ensuring command files");
|
|
19
24
|
await ensureCommandFiles().catch(() => { });
|
|
20
25
|
return store;
|
|
21
26
|
}
|
|
@@ -31,6 +36,7 @@ export async function loadPluginConfig(directory) {
|
|
|
31
36
|
return memConfig;
|
|
32
37
|
}
|
|
33
38
|
export async function seedRuleNodes(store) {
|
|
39
|
+
let created = 0;
|
|
34
40
|
for (const seed of SEED_NODES) {
|
|
35
41
|
try {
|
|
36
42
|
await store.getNodeByLabel("global", seed.label);
|
|
@@ -48,15 +54,21 @@ export async function seedRuleNodes(store) {
|
|
|
48
54
|
importance: 1,
|
|
49
55
|
metadata: seed.metadata ?? null,
|
|
50
56
|
});
|
|
57
|
+
created++;
|
|
51
58
|
}
|
|
52
59
|
}
|
|
60
|
+
memLog("info", "init", "Seed nodes checked", { total: SEED_NODES.length, created });
|
|
53
61
|
}
|
|
54
62
|
export async function backfillData(store) {
|
|
55
63
|
for (const scope of ["global", "project"]) {
|
|
64
|
+
memLog("info", "init", `Backfilling links for ${scope}`);
|
|
56
65
|
await store.backfillLinks(scope);
|
|
66
|
+
memLog("info", "init", `Backfilling embeddings and BM25 for ${scope}`);
|
|
57
67
|
await store.backfillBinaryEmbeddingsAndBM25(scope);
|
|
58
68
|
}
|
|
69
|
+
memLog("info", "init", "Rebuilding HNSW index");
|
|
59
70
|
await store.rebuildHNSWIndex();
|
|
71
|
+
memLog("info", "init", "HNSW index rebuilt");
|
|
60
72
|
}
|
|
61
73
|
export function scheduleBackgroundEmbeddings(store) {
|
|
62
74
|
setTimeout(async () => {
|
|
@@ -94,9 +106,13 @@ export function startManagementIfEnabled(store, directory) {
|
|
|
94
106
|
loadConfig().then(c => {
|
|
95
107
|
const mgmtConfig = c.management;
|
|
96
108
|
if (mgmtConfig?.enabled === true) {
|
|
109
|
+
memLog("info", "init", "Starting management server", { port: mgmtConfig.port ?? 8787 });
|
|
97
110
|
startManagementServer(store, directory, { enabled: true, port: mgmtConfig?.port ?? 8787 });
|
|
98
111
|
}
|
|
99
|
-
|
|
112
|
+
else {
|
|
113
|
+
memLog("info", "init", "Management server disabled");
|
|
114
|
+
}
|
|
115
|
+
}).catch(() => { memLog("info", "init", "Management server config not available"); });
|
|
100
116
|
}
|
|
101
117
|
export function createAutoRetrieveIfEnabled(store, memConfig) {
|
|
102
118
|
return memConfig?.autoRetrieve?.enabled
|
package/dist/tools/version.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { tool } from "@opencode-ai/plugin";
|
|
2
2
|
import { wrapWithTracking } from "./shared";
|
|
3
|
-
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const pkg = JSON.parse(fs.readFileSync(path.resolve(__dirname, "../../package.json"), "utf-8"));
|
|
9
|
+
const VERSION = pkg.version;
|
|
4
10
|
export function MemoryVersion(store) {
|
|
5
11
|
const t = tool({
|
|
6
12
|
description: "Show the installed version of the Fractal Memory plugin.",
|