@grec0/memory-bank-mcp 0.1.21 → 0.1.23

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.
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { AgentBoard } from "../common/agentBoard.js";
6
6
  import { sessionLogger } from "../common/sessionLogger.js";
7
+ import { sessionState } from "../common/sessionState.js";
7
8
  /**
8
9
  * Searches the Memory Bank for relevant code
9
10
  */
@@ -36,11 +37,12 @@ export async function searchMemory(params, indexManager, workspaceRoot) {
36
37
  filterByFile: params.filterByFile,
37
38
  filterByLanguage: params.filterByLanguage,
38
39
  });
39
- // Session Logging
40
- if (params.agentId && workspaceRoot) {
40
+ // Session Logging via Session State
41
+ const activeAgentId = sessionState.getCurrentAgentId();
42
+ if (activeAgentId && workspaceRoot) {
41
43
  try {
42
44
  const board = new AgentBoard(workspaceRoot, params.projectId);
43
- const sessionId = await board.getSessionId(params.agentId);
45
+ const sessionId = await board.getSessionId(activeAgentId);
44
46
  if (sessionId) {
45
47
  await sessionLogger.logSessionEvent(params.projectId, sessionId, {
46
48
  timestamp: new Date().toISOString(),
@@ -54,7 +56,7 @@ export async function searchMemory(params, indexManager, workspaceRoot) {
54
56
  resultCount: results.length,
55
57
  topResults: results.slice(0, 5).map(r => ({ path: r.filePath, score: r.score }))
56
58
  }
57
- });
59
+ }, activeAgentId);
58
60
  }
59
61
  }
60
62
  catch (logError) {
@@ -4,6 +4,9 @@
4
4
  */
5
5
  import * as fs from "fs";
6
6
  import * as path from "path";
7
+ import { AgentBoard } from "../common/agentBoard.js";
8
+ import { sessionLogger } from "../common/sessionLogger.js";
9
+ import { sessionState } from "../common/sessionState.js";
7
10
  /**
8
11
  * Writes a file and optionally reindexes it
9
12
  */
@@ -13,6 +16,40 @@ export async function writeFile(params, indexManager, workspaceRoot) {
13
16
  const filePath = path.isAbsolute(params.path)
14
17
  ? params.path
15
18
  : path.join(workspaceRoot, params.path);
19
+ // Auto-Locking & Logging via Session State
20
+ const activeAgentId = sessionState.getCurrentAgentId();
21
+ if (activeAgentId) {
22
+ const board = new AgentBoard(workspaceRoot, params.projectId);
23
+ // 1. Check/Claim Lock
24
+ // Normalize path for locking (relative to workspace)
25
+ const relativePath = path.relative(workspaceRoot, filePath).replace(/\\/g, '/');
26
+ const canWrite = await board.claimResource(activeAgentId, relativePath);
27
+ if (!canWrite) {
28
+ return {
29
+ success: false,
30
+ filePath: params.path,
31
+ message: `File is locked by another agent. Write rejected.`
32
+ };
33
+ }
34
+ // 2. Log Session Event
35
+ try {
36
+ const sessionId = await board.getSessionId(activeAgentId);
37
+ if (sessionId) {
38
+ await sessionLogger.logSessionEvent(params.projectId, sessionId, {
39
+ timestamp: new Date().toISOString(),
40
+ type: 'decision',
41
+ data: {
42
+ action: 'write_file',
43
+ path: params.path,
44
+ byteSize: Buffer.byteLength(params.content, "utf-8")
45
+ }
46
+ });
47
+ }
48
+ }
49
+ catch (e) {
50
+ console.error("Failed to log session event:", e);
51
+ }
52
+ }
16
53
  // Ensure directory exists
17
54
  const dir = path.dirname(filePath);
18
55
  if (!fs.existsSync(dir)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grec0/memory-bank-mcp",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "MCP server for semantic code indexing with Memory Bank - AI-powered codebase understanding",
5
5
  "license": "MIT",
6
6
  "author": "@grec0",
@@ -38,7 +38,7 @@
38
38
  "@babel/parser": "^7.23.0",
39
39
  "@babel/traverse": "^7.23.0",
40
40
  "@lancedb/lancedb": "^0.9.0",
41
- "@modelcontextprotocol/sdk": "1.6.1",
41
+ "@modelcontextprotocol/sdk": "1.25.2",
42
42
  "@types/node": "^22",
43
43
  "gpt-tokenizer": "3.4.0",
44
44
  "ignore": "^5.3.0",
@@ -46,12 +46,14 @@
46
46
  "tree-sitter-wasms": "0.1.13",
47
47
  "web-tree-sitter": "0.26.3",
48
48
  "zod": "^3.22.4",
49
- "zod-to-json-schema": "^3.23.5"
49
+ "zod-to-json-schema": "^3.23.5",
50
+ "better-sqlite3": "^11.7.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@jest/globals": "^29.7.0",
53
54
  "@types/babel__parser": "^7.1.1",
54
55
  "@types/babel__traverse": "^7.20.4",
56
+ "@types/better-sqlite3": "^7.6.12",
55
57
  "@types/jest": "^29.5.14",
56
58
  "jest": "^29.7.0",
57
59
  "shx": "^0.3.4",