local-agent-memory 1.0.9 → 1.0.11
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 +36 -1
- package/dist/cli/commands/hook.js +11 -5
- package/dist/cli/commands/init.js +111 -46
- package/dist/cli/commands/status.js +24 -0
- package/dist/core/search.d.ts +6 -0
- package/dist/core/search.js +29 -1
- package/dist/db/project.d.ts +25 -0
- package/dist/db/project.js +111 -1
- package/dist/db/registry.js +2 -0
- package/dist/mcp/logger.d.ts +2 -0
- package/dist/mcp/logger.js +45 -0
- package/dist/mcp/server.js +58 -1
- package/dist/mcp/tools.js +408 -151
- package/package.json +2 -2
package/dist/mcp/logger.js
CHANGED
|
@@ -33,10 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getLocalMemoryDir = void 0;
|
|
36
37
|
exports.getMemoryConfig = getMemoryConfig;
|
|
37
38
|
exports.logUsage = logUsage;
|
|
39
|
+
exports.recordMcpEvent = recordMcpEvent;
|
|
38
40
|
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const os = __importStar(require("node:os"));
|
|
39
42
|
const path = __importStar(require("node:path"));
|
|
43
|
+
const project_1 = require("../db/project");
|
|
44
|
+
const getLocalMemoryDir = () => process.env.MEMORY_GLOBAL_DIR || path.join(os.homedir(), ".local_memory");
|
|
45
|
+
exports.getLocalMemoryDir = getLocalMemoryDir;
|
|
40
46
|
function getMemoryConfig(cwd) {
|
|
41
47
|
const configPath = path.join(cwd, ".memory", "config.json");
|
|
42
48
|
if (!fs.existsSync(configPath)) {
|
|
@@ -76,3 +82,42 @@ function logUsage(cwd, action, details) {
|
|
|
76
82
|
// Fail silently to avoid breaking any MCP operation
|
|
77
83
|
}
|
|
78
84
|
}
|
|
85
|
+
async function recordMcpEvent(cwd, eventType, toolName, queryOrSummary, executionTimeMs, success = true) {
|
|
86
|
+
const timestamp = new Date().toISOString();
|
|
87
|
+
// 1. Global log to ~/.local_memory/mcp-events.log
|
|
88
|
+
try {
|
|
89
|
+
const globalDir = (0, exports.getLocalMemoryDir)();
|
|
90
|
+
if (!fs.existsSync(globalDir)) {
|
|
91
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
const globalLog = path.join(globalDir, "mcp-events.log");
|
|
94
|
+
const line = `[${timestamp}] cwd=${cwd} event=${eventType} tool=${toolName || "none"} success=${success}${queryOrSummary ? ` summary="${queryOrSummary.slice(0, 100).replace(/\n/g, " ")}"` : ""}\n`;
|
|
95
|
+
fs.appendFileSync(globalLog, line, "utf8");
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// ignore
|
|
99
|
+
}
|
|
100
|
+
// 2. Project SQLite log (mcp_usage_logs) if project DB exists
|
|
101
|
+
try {
|
|
102
|
+
const localDb = (0, project_1.getLocalDbPath)(cwd);
|
|
103
|
+
if (fs.existsSync(localDb)) {
|
|
104
|
+
await (0, project_1.insertMcpUsageLog)(localDb, {
|
|
105
|
+
project_path: cwd,
|
|
106
|
+
event_type: eventType,
|
|
107
|
+
tool_name: toolName ?? null,
|
|
108
|
+
query_or_summary: queryOrSummary ?? null,
|
|
109
|
+
execution_time_ms: executionTimeMs ?? null,
|
|
110
|
+
success,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// ignore
|
|
116
|
+
}
|
|
117
|
+
// 3. Fallback/compatibility logUsage
|
|
118
|
+
logUsage(cwd, `${eventType}: ${toolName || "event"}`, {
|
|
119
|
+
queryOrSummary,
|
|
120
|
+
executionTimeMs,
|
|
121
|
+
success,
|
|
122
|
+
});
|
|
123
|
+
}
|
package/dist/mcp/server.js
CHANGED
|
@@ -57,7 +57,8 @@ async function setupMCPServer() {
|
|
|
57
57
|
// Ignore write errors to prevent server crash
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
log(
|
|
60
|
+
log(`Starting MCP Server [pid=${process.pid}, cwd=${process.cwd()}, argv=${JSON.stringify(process.argv)}]`);
|
|
61
|
+
(0, logger_1.recordMcpEvent)(process.cwd(), "init", "server_start", `Started MCP Server (pid: ${process.pid})`).catch(() => { });
|
|
61
62
|
const server = new mcp_js_1.McpServer({
|
|
62
63
|
name: "local-agent-memory",
|
|
63
64
|
version: require("../../package.json").version,
|
|
@@ -81,6 +82,43 @@ async function setupMCPServer() {
|
|
|
81
82
|
],
|
|
82
83
|
};
|
|
83
84
|
});
|
|
85
|
+
server.resource("current-project-overview", "memory://current-project/overview", {
|
|
86
|
+
description: "Overview of current project memory, recent decisions, and status",
|
|
87
|
+
}, async (uri) => {
|
|
88
|
+
const { cwd: resolvedCwd } = await (0, utils_1.resolveCwd)();
|
|
89
|
+
(0, logger_1.recordMcpEvent)(resolvedCwd, "resource_read", "current-project-overview").catch(() => { });
|
|
90
|
+
const memoryDir = path.join(resolvedCwd, ".memory");
|
|
91
|
+
const corePath = path.join(memoryDir, "core.md");
|
|
92
|
+
const coreFound = fs.existsSync(corePath);
|
|
93
|
+
const decisionsDir = path.join(memoryDir, "decisions");
|
|
94
|
+
let recentDecisions = [];
|
|
95
|
+
if (fs.existsSync(decisionsDir)) {
|
|
96
|
+
recentDecisions = fs
|
|
97
|
+
.readdirSync(decisionsDir)
|
|
98
|
+
.filter((f) => f.endsWith(".md"))
|
|
99
|
+
.sort()
|
|
100
|
+
.reverse()
|
|
101
|
+
.slice(0, 10);
|
|
102
|
+
}
|
|
103
|
+
const summaryText = [
|
|
104
|
+
`# Project Memory Overview`,
|
|
105
|
+
`- Root: ${resolvedCwd}`,
|
|
106
|
+
`- Core rules: ${coreFound ? "Present" : "Missing"}`,
|
|
107
|
+
`- Decisions logged: ${recentDecisions.length} recent`,
|
|
108
|
+
recentDecisions.length > 0
|
|
109
|
+
? recentDecisions.map((d) => ` * ${d}`).join("\n")
|
|
110
|
+
: " (None recorded yet)",
|
|
111
|
+
].join("\n");
|
|
112
|
+
return {
|
|
113
|
+
contents: [
|
|
114
|
+
{
|
|
115
|
+
uri: uri.href,
|
|
116
|
+
text: summaryText,
|
|
117
|
+
mimeType: "text/markdown",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
};
|
|
121
|
+
});
|
|
84
122
|
server.prompt("agent-guidelines", "Get the agent guidelines and memory core rules", async () => {
|
|
85
123
|
const { cwd: resolvedCwd } = await (0, utils_1.resolveCwd)();
|
|
86
124
|
(0, logger_1.logUsage)(resolvedCwd, "PROMPT_GET: agent-guidelines");
|
|
@@ -100,6 +138,25 @@ async function setupMCPServer() {
|
|
|
100
138
|
],
|
|
101
139
|
};
|
|
102
140
|
});
|
|
141
|
+
server.prompt("contexto-proyecto", "Obtener el contexto activo, reglas de arquitectura y sincronizar la memoria del proyecto", async () => {
|
|
142
|
+
const { cwd: resolvedCwd } = await (0, utils_1.resolveCwd)();
|
|
143
|
+
(0, logger_1.recordMcpEvent)(resolvedCwd, "prompt_get", "contexto-proyecto").catch(() => { });
|
|
144
|
+
const corePath = path.join(resolvedCwd, ".memory", "core.md");
|
|
145
|
+
const text = fs.existsSync(corePath)
|
|
146
|
+
? fs.readFileSync(corePath, "utf8")
|
|
147
|
+
: "No se encontró core.md en este proyecto.";
|
|
148
|
+
return {
|
|
149
|
+
messages: [
|
|
150
|
+
{
|
|
151
|
+
role: "user",
|
|
152
|
+
content: {
|
|
153
|
+
type: "text",
|
|
154
|
+
text: `Por favor sincroniza el contexto local del proyecto e incorpora estas reglas obligatorias:\n\n${text}`,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
};
|
|
159
|
+
});
|
|
103
160
|
(0, tools_1.registerTools)(server);
|
|
104
161
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
105
162
|
transport.onerror = (err) => {
|