claude-mpm 4.4.0__py3-none-any.whl → 4.4.4__py3-none-any.whl
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.
- claude_mpm/VERSION +1 -1
- claude_mpm/agents/WORKFLOW.md +2 -14
- claude_mpm/agents/agent_loader.py +3 -2
- claude_mpm/agents/agent_loader_integration.py +2 -1
- claude_mpm/agents/async_agent_loader.py +2 -2
- claude_mpm/agents/base_agent_loader.py +2 -2
- claude_mpm/agents/frontmatter_validator.py +1 -0
- claude_mpm/agents/system_agent_config.py +2 -1
- claude_mpm/cli/commands/configure.py +2 -29
- claude_mpm/cli/commands/doctor.py +44 -5
- claude_mpm/cli/commands/mpm_init.py +117 -63
- claude_mpm/cli/parsers/configure_parser.py +6 -15
- claude_mpm/cli/startup_logging.py +1 -3
- claude_mpm/config/agent_config.py +1 -1
- claude_mpm/config/paths.py +2 -1
- claude_mpm/core/agent_name_normalizer.py +1 -0
- claude_mpm/core/config.py +2 -1
- claude_mpm/core/config_aliases.py +2 -1
- claude_mpm/core/file_utils.py +0 -1
- claude_mpm/core/framework/__init__.py +38 -0
- claude_mpm/core/framework/formatters/__init__.py +11 -0
- claude_mpm/core/framework/formatters/capability_generator.py +367 -0
- claude_mpm/core/framework/formatters/content_formatter.py +288 -0
- claude_mpm/core/framework/formatters/context_generator.py +184 -0
- claude_mpm/core/framework/loaders/__init__.py +13 -0
- claude_mpm/core/framework/loaders/agent_loader.py +206 -0
- claude_mpm/core/framework/loaders/file_loader.py +223 -0
- claude_mpm/core/framework/loaders/instruction_loader.py +161 -0
- claude_mpm/core/framework/loaders/packaged_loader.py +232 -0
- claude_mpm/core/framework/processors/__init__.py +11 -0
- claude_mpm/core/framework/processors/memory_processor.py +230 -0
- claude_mpm/core/framework/processors/metadata_processor.py +146 -0
- claude_mpm/core/framework/processors/template_processor.py +244 -0
- claude_mpm/core/framework_loader.py +298 -1795
- claude_mpm/core/log_manager.py +2 -1
- claude_mpm/core/tool_access_control.py +1 -0
- claude_mpm/core/unified_agent_registry.py +2 -1
- claude_mpm/core/unified_paths.py +1 -0
- claude_mpm/experimental/cli_enhancements.py +1 -0
- claude_mpm/hooks/__init__.py +9 -1
- claude_mpm/hooks/base_hook.py +1 -0
- claude_mpm/hooks/instruction_reinforcement.py +1 -0
- claude_mpm/hooks/kuzu_memory_hook.py +359 -0
- claude_mpm/hooks/validation_hooks.py +1 -1
- claude_mpm/scripts/mpm_doctor.py +1 -0
- claude_mpm/services/agents/loading/agent_profile_loader.py +1 -1
- claude_mpm/services/agents/loading/base_agent_manager.py +1 -1
- claude_mpm/services/agents/loading/framework_agent_loader.py +1 -1
- claude_mpm/services/agents/management/agent_capabilities_generator.py +1 -0
- claude_mpm/services/agents/management/agent_management_service.py +1 -1
- claude_mpm/services/agents/memory/memory_categorization_service.py +0 -1
- claude_mpm/services/agents/memory/memory_file_service.py +6 -2
- claude_mpm/services/agents/memory/memory_format_service.py +0 -1
- claude_mpm/services/agents/registry/deployed_agent_discovery.py +1 -1
- claude_mpm/services/async_session_logger.py +1 -1
- claude_mpm/services/claude_session_logger.py +1 -0
- claude_mpm/services/core/path_resolver.py +2 -0
- claude_mpm/services/diagnostics/checks/__init__.py +2 -0
- claude_mpm/services/diagnostics/checks/installation_check.py +126 -25
- claude_mpm/services/diagnostics/checks/mcp_services_check.py +399 -0
- claude_mpm/services/diagnostics/diagnostic_runner.py +4 -0
- claude_mpm/services/diagnostics/doctor_reporter.py +259 -32
- claude_mpm/services/event_bus/direct_relay.py +2 -1
- claude_mpm/services/event_bus/event_bus.py +1 -0
- claude_mpm/services/event_bus/relay.py +3 -2
- claude_mpm/services/framework_claude_md_generator/content_assembler.py +1 -1
- claude_mpm/services/infrastructure/daemon_manager.py +1 -1
- claude_mpm/services/mcp_config_manager.py +67 -4
- claude_mpm/services/mcp_gateway/core/process_pool.py +320 -0
- claude_mpm/services/mcp_gateway/core/startup_verification.py +2 -2
- claude_mpm/services/mcp_gateway/main.py +3 -13
- claude_mpm/services/mcp_gateway/server/stdio_server.py +4 -10
- claude_mpm/services/mcp_gateway/tools/__init__.py +14 -2
- claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +38 -6
- claude_mpm/services/mcp_gateway/tools/kuzu_memory_service.py +527 -0
- claude_mpm/services/memory/cache/simple_cache.py +1 -1
- claude_mpm/services/project/archive_manager.py +159 -96
- claude_mpm/services/project/documentation_manager.py +64 -45
- claude_mpm/services/project/enhanced_analyzer.py +132 -89
- claude_mpm/services/project/project_organizer.py +225 -131
- claude_mpm/services/response_tracker.py +1 -1
- claude_mpm/services/shared/__init__.py +2 -1
- claude_mpm/services/shared/service_factory.py +8 -5
- claude_mpm/services/socketio/server/eventbus_integration.py +1 -1
- claude_mpm/services/unified/__init__.py +1 -1
- claude_mpm/services/unified/analyzer_strategies/__init__.py +3 -3
- claude_mpm/services/unified/analyzer_strategies/code_analyzer.py +97 -53
- claude_mpm/services/unified/analyzer_strategies/dependency_analyzer.py +81 -40
- claude_mpm/services/unified/analyzer_strategies/performance_analyzer.py +277 -178
- claude_mpm/services/unified/analyzer_strategies/security_analyzer.py +196 -112
- claude_mpm/services/unified/analyzer_strategies/structure_analyzer.py +83 -49
- claude_mpm/services/unified/config_strategies/__init__.py +175 -0
- claude_mpm/services/unified/config_strategies/config_schema.py +735 -0
- claude_mpm/services/unified/config_strategies/context_strategy.py +750 -0
- claude_mpm/services/unified/config_strategies/error_handling_strategy.py +1009 -0
- claude_mpm/services/unified/config_strategies/file_loader_strategy.py +879 -0
- claude_mpm/services/unified/config_strategies/unified_config_service.py +814 -0
- claude_mpm/services/unified/config_strategies/validation_strategy.py +1144 -0
- claude_mpm/services/unified/deployment_strategies/__init__.py +7 -7
- claude_mpm/services/unified/deployment_strategies/base.py +24 -28
- claude_mpm/services/unified/deployment_strategies/cloud_strategies.py +168 -88
- claude_mpm/services/unified/deployment_strategies/local.py +49 -34
- claude_mpm/services/unified/deployment_strategies/utils.py +39 -43
- claude_mpm/services/unified/deployment_strategies/vercel.py +30 -24
- claude_mpm/services/unified/interfaces.py +0 -26
- claude_mpm/services/unified/migration.py +17 -40
- claude_mpm/services/unified/strategies.py +9 -26
- claude_mpm/services/unified/unified_analyzer.py +48 -44
- claude_mpm/services/unified/unified_config.py +21 -19
- claude_mpm/services/unified/unified_deployment.py +21 -26
- claude_mpm/storage/state_storage.py +1 -0
- claude_mpm/utils/agent_dependency_loader.py +18 -6
- claude_mpm/utils/common.py +14 -12
- claude_mpm/utils/database_connector.py +15 -12
- claude_mpm/utils/error_handler.py +1 -0
- claude_mpm/utils/log_cleanup.py +1 -0
- claude_mpm/utils/path_operations.py +1 -0
- claude_mpm/utils/session_logging.py +1 -1
- claude_mpm/utils/subprocess_utils.py +1 -0
- claude_mpm/validation/agent_validator.py +1 -1
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/METADATA +23 -17
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/RECORD +126 -105
- claude_mpm/cli/commands/configure_tui.py +0 -1927
- claude_mpm/services/mcp_gateway/tools/ticket_tools.py +0 -645
- claude_mpm/services/mcp_gateway/tools/unified_ticket_tool.py +0 -602
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/WHEEL +0 -0
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/entry_points.txt +0 -0
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-4.4.0.dist-info → claude_mpm-4.4.4.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,527 @@
|
|
1
|
+
"""
|
2
|
+
Kuzu-Memory MCP Service Integration
|
3
|
+
====================================
|
4
|
+
|
5
|
+
Provides MCP tool wrappers for kuzu-memory knowledge graph operations,
|
6
|
+
enabling the PM agent to store and retrieve memories programmatically.
|
7
|
+
|
8
|
+
WHY: The PM agent needs structured tools to manage conversation memories,
|
9
|
+
allowing it to build up project knowledge over time.
|
10
|
+
|
11
|
+
DESIGN DECISIONS:
|
12
|
+
- Extends ExternalMCPService for consistent integration patterns
|
13
|
+
- Provides high-level tools that abstract kuzu-memory complexity
|
14
|
+
- Includes context enrichment for better memory retrieval
|
15
|
+
- Supports tagging for organized knowledge management
|
16
|
+
"""
|
17
|
+
|
18
|
+
import json
|
19
|
+
import subprocess
|
20
|
+
from pathlib import Path
|
21
|
+
from typing import Any, Dict, List, Optional
|
22
|
+
|
23
|
+
from claude_mpm.services.mcp_gateway.core.interfaces import (
|
24
|
+
MCPToolDefinition,
|
25
|
+
MCPToolInvocation,
|
26
|
+
MCPToolResult,
|
27
|
+
)
|
28
|
+
from claude_mpm.services.mcp_gateway.tools.base_adapter import BaseToolAdapter
|
29
|
+
|
30
|
+
|
31
|
+
class KuzuMemoryService(BaseToolAdapter):
|
32
|
+
"""
|
33
|
+
MCP service wrapper for kuzu-memory knowledge graph.
|
34
|
+
|
35
|
+
Provides tools for:
|
36
|
+
- Storing memories with tags
|
37
|
+
- Retrieving relevant memories
|
38
|
+
- Searching memories by query
|
39
|
+
- Getting enriched context for topics
|
40
|
+
"""
|
41
|
+
|
42
|
+
def __init__(self):
|
43
|
+
"""Initialize kuzu-memory MCP service."""
|
44
|
+
# Define the tool
|
45
|
+
definition = MCPToolDefinition(
|
46
|
+
name="kuzu_memory",
|
47
|
+
description="Knowledge graph memory system for persistent context",
|
48
|
+
input_schema={
|
49
|
+
"type": "object",
|
50
|
+
"properties": {
|
51
|
+
"action": {
|
52
|
+
"type": "string",
|
53
|
+
"enum": ["store", "recall", "search", "context"],
|
54
|
+
"description": "The memory operation to perform",
|
55
|
+
},
|
56
|
+
"content": {
|
57
|
+
"type": "string",
|
58
|
+
"description": "Content for store operation",
|
59
|
+
},
|
60
|
+
"query": {
|
61
|
+
"type": "string",
|
62
|
+
"description": "Query for recall/search/context operations",
|
63
|
+
},
|
64
|
+
"tags": {
|
65
|
+
"type": "array",
|
66
|
+
"items": {"type": "string"},
|
67
|
+
"description": "Tags for filtering or categorization",
|
68
|
+
},
|
69
|
+
"limit": {
|
70
|
+
"type": "integer",
|
71
|
+
"default": 5,
|
72
|
+
"description": "Maximum number of results",
|
73
|
+
},
|
74
|
+
},
|
75
|
+
"required": ["action"],
|
76
|
+
},
|
77
|
+
)
|
78
|
+
super().__init__(definition)
|
79
|
+
|
80
|
+
self.service_name = "kuzu-memory"
|
81
|
+
self.package_name = "kuzu-memory"
|
82
|
+
# Use the current project directory as kuzu-memory works with project-specific databases
|
83
|
+
self.project_path = Path.cwd()
|
84
|
+
self._is_installed = False
|
85
|
+
self.kuzu_cmd = None
|
86
|
+
|
87
|
+
async def _check_installation(self) -> bool:
|
88
|
+
"""Check if kuzu-memory is installed via pipx."""
|
89
|
+
# Check pipx installation first
|
90
|
+
pipx_path = (
|
91
|
+
Path.home()
|
92
|
+
/ ".local"
|
93
|
+
/ "pipx"
|
94
|
+
/ "venvs"
|
95
|
+
/ "kuzu-memory"
|
96
|
+
/ "bin"
|
97
|
+
/ "kuzu-memory"
|
98
|
+
)
|
99
|
+
if pipx_path.exists():
|
100
|
+
self.kuzu_cmd = str(pipx_path)
|
101
|
+
return True
|
102
|
+
|
103
|
+
# Check system PATH
|
104
|
+
import shutil
|
105
|
+
|
106
|
+
kuzu_cmd = shutil.which("kuzu-memory")
|
107
|
+
if kuzu_cmd:
|
108
|
+
self.kuzu_cmd = kuzu_cmd
|
109
|
+
return True
|
110
|
+
|
111
|
+
return False
|
112
|
+
|
113
|
+
async def _install_package(self) -> bool:
|
114
|
+
"""Install kuzu-memory using pipx (preferred over pip)."""
|
115
|
+
try:
|
116
|
+
# Check if pipx is available
|
117
|
+
import shutil
|
118
|
+
|
119
|
+
if not shutil.which("pipx"):
|
120
|
+
self.log_warning(
|
121
|
+
"pipx not found. Install it first: python -m pip install --user pipx"
|
122
|
+
)
|
123
|
+
return False
|
124
|
+
|
125
|
+
self.log_info("Installing kuzu-memory via pipx...")
|
126
|
+
result = subprocess.run(
|
127
|
+
["pipx", "install", "kuzu-memory"],
|
128
|
+
capture_output=True,
|
129
|
+
text=True,
|
130
|
+
timeout=60,
|
131
|
+
check=False,
|
132
|
+
)
|
133
|
+
|
134
|
+
if result.returncode == 0:
|
135
|
+
self.log_info("Successfully installed kuzu-memory via pipx")
|
136
|
+
return await self._check_installation()
|
137
|
+
|
138
|
+
self.log_error(f"Failed to install kuzu-memory: {result.stderr}")
|
139
|
+
return False
|
140
|
+
|
141
|
+
except Exception as e:
|
142
|
+
self.log_error(f"Error installing kuzu-memory: {e}")
|
143
|
+
return False
|
144
|
+
|
145
|
+
async def initialize(self) -> bool:
|
146
|
+
"""Initialize the kuzu-memory service."""
|
147
|
+
try:
|
148
|
+
# Check if package is installed
|
149
|
+
self._is_installed = await self._check_installation()
|
150
|
+
|
151
|
+
if not self._is_installed:
|
152
|
+
self.log_warning(
|
153
|
+
f"{self.package_name} not installed, attempting installation..."
|
154
|
+
)
|
155
|
+
await self._install_package()
|
156
|
+
self._is_installed = await self._check_installation()
|
157
|
+
|
158
|
+
if not self._is_installed:
|
159
|
+
self.log_error(f"Failed to install {self.package_name}")
|
160
|
+
return False
|
161
|
+
|
162
|
+
self.log_info(f"{self.package_name} is available")
|
163
|
+
self._initialized = True
|
164
|
+
return True
|
165
|
+
|
166
|
+
except Exception as e:
|
167
|
+
self.log_error(f"Failed to initialize {self.service_name}: {e}")
|
168
|
+
return False
|
169
|
+
|
170
|
+
async def invoke(self, invocation: MCPToolInvocation) -> MCPToolResult:
|
171
|
+
"""
|
172
|
+
Invoke kuzu-memory tool based on the invocation request.
|
173
|
+
|
174
|
+
Routes to appropriate method based on action parameter.
|
175
|
+
"""
|
176
|
+
params = invocation.parameters
|
177
|
+
action = params.get("action")
|
178
|
+
|
179
|
+
try:
|
180
|
+
if action == "store":
|
181
|
+
result = await self.store_memory(
|
182
|
+
params.get("content"), params.get("tags"), {} # metadata
|
183
|
+
)
|
184
|
+
elif action == "recall":
|
185
|
+
result = await self.recall_memories(
|
186
|
+
params.get("query"), params.get("limit", 5), params.get("tags")
|
187
|
+
)
|
188
|
+
elif action == "search":
|
189
|
+
result = await self.search_memories(
|
190
|
+
params.get("query", ""),
|
191
|
+
"both", # search_type
|
192
|
+
params.get("limit", 10),
|
193
|
+
)
|
194
|
+
elif action == "context":
|
195
|
+
result = await self.get_context(
|
196
|
+
params.get("query", ""), 2, True # depth # include_related
|
197
|
+
)
|
198
|
+
else:
|
199
|
+
return MCPToolResult(success=False, error=f"Unknown action: {action}")
|
200
|
+
|
201
|
+
return MCPToolResult(
|
202
|
+
success=result.get("success", False),
|
203
|
+
data=result,
|
204
|
+
error=result.get("error"),
|
205
|
+
)
|
206
|
+
|
207
|
+
except Exception as e:
|
208
|
+
return MCPToolResult(success=False, error=str(e))
|
209
|
+
|
210
|
+
def validate_parameters(self, parameters: Dict[str, Any]) -> bool:
|
211
|
+
"""Validate tool parameters - basic implementation."""
|
212
|
+
return True # Validation is handled in individual methods
|
213
|
+
|
214
|
+
async def shutdown(self) -> None:
|
215
|
+
"""Shutdown the service."""
|
216
|
+
# No resources to clean up
|
217
|
+
|
218
|
+
async def store_memory(
|
219
|
+
self,
|
220
|
+
content: str,
|
221
|
+
tags: Optional[List[str]] = None,
|
222
|
+
metadata: Optional[Dict[str, Any]] = None,
|
223
|
+
) -> Dict[str, Any]:
|
224
|
+
"""
|
225
|
+
Store a memory in the knowledge graph.
|
226
|
+
|
227
|
+
Args:
|
228
|
+
content: Memory content to store
|
229
|
+
tags: Optional tags for categorization
|
230
|
+
metadata: Optional metadata
|
231
|
+
|
232
|
+
Returns:
|
233
|
+
Result of the storage operation
|
234
|
+
"""
|
235
|
+
if not self._is_installed:
|
236
|
+
return {
|
237
|
+
"success": False,
|
238
|
+
"error": "kuzu-memory not installed",
|
239
|
+
}
|
240
|
+
|
241
|
+
try:
|
242
|
+
# Use remember command for storing memories
|
243
|
+
# kuzu-memory works with project-specific databases in the current working directory
|
244
|
+
cmd = [self.kuzu_cmd, "remember", content]
|
245
|
+
|
246
|
+
# Execute command in project directory
|
247
|
+
result = subprocess.run(
|
248
|
+
cmd,
|
249
|
+
capture_output=True,
|
250
|
+
text=True,
|
251
|
+
timeout=10,
|
252
|
+
cwd=str(self.project_path), check=False,
|
253
|
+
)
|
254
|
+
|
255
|
+
if result.returncode == 0:
|
256
|
+
return {
|
257
|
+
"success": True,
|
258
|
+
"message": "Memory stored successfully",
|
259
|
+
"content": content[:100],
|
260
|
+
"tags": tags or [],
|
261
|
+
}
|
262
|
+
|
263
|
+
return {
|
264
|
+
"success": False,
|
265
|
+
"error": result.stderr or "Failed to store memory",
|
266
|
+
}
|
267
|
+
|
268
|
+
except Exception as e:
|
269
|
+
self.logger.error(f"Error storing memory: {e}")
|
270
|
+
return {
|
271
|
+
"success": False,
|
272
|
+
"error": str(e),
|
273
|
+
}
|
274
|
+
|
275
|
+
async def recall_memories(
|
276
|
+
self,
|
277
|
+
query: str,
|
278
|
+
limit: int = 5,
|
279
|
+
tags: Optional[List[str]] = None,
|
280
|
+
) -> Dict[str, Any]:
|
281
|
+
"""
|
282
|
+
Recall memories relevant to a query.
|
283
|
+
|
284
|
+
Args:
|
285
|
+
query: Query to find relevant memories
|
286
|
+
limit: Maximum number of memories
|
287
|
+
tags: Optional tag filter
|
288
|
+
|
289
|
+
Returns:
|
290
|
+
Retrieved memories
|
291
|
+
"""
|
292
|
+
if not self._is_installed:
|
293
|
+
return {
|
294
|
+
"success": False,
|
295
|
+
"error": "kuzu-memory not installed",
|
296
|
+
"memories": [],
|
297
|
+
}
|
298
|
+
|
299
|
+
try:
|
300
|
+
# Use recall command for retrieving memories
|
301
|
+
# kuzu-memory works with project-specific databases in the current working directory
|
302
|
+
cmd = [
|
303
|
+
self.kuzu_cmd,
|
304
|
+
"recall",
|
305
|
+
query,
|
306
|
+
"--format",
|
307
|
+
"json",
|
308
|
+
"--max-memories",
|
309
|
+
str(limit),
|
310
|
+
]
|
311
|
+
|
312
|
+
# Execute command in project directory
|
313
|
+
result = subprocess.run(
|
314
|
+
cmd,
|
315
|
+
capture_output=True,
|
316
|
+
text=True,
|
317
|
+
timeout=10,
|
318
|
+
cwd=str(self.project_path), check=False,
|
319
|
+
)
|
320
|
+
|
321
|
+
if result.returncode == 0 and result.stdout:
|
322
|
+
memories = json.loads(result.stdout)
|
323
|
+
return {
|
324
|
+
"success": True,
|
325
|
+
"query": query,
|
326
|
+
"count": len(memories),
|
327
|
+
"memories": memories,
|
328
|
+
}
|
329
|
+
|
330
|
+
return {
|
331
|
+
"success": True,
|
332
|
+
"query": query,
|
333
|
+
"count": 0,
|
334
|
+
"memories": [],
|
335
|
+
}
|
336
|
+
|
337
|
+
except Exception as e:
|
338
|
+
self.logger.error(f"Error recalling memories: {e}")
|
339
|
+
return {
|
340
|
+
"success": False,
|
341
|
+
"error": str(e),
|
342
|
+
"memories": [],
|
343
|
+
}
|
344
|
+
|
345
|
+
async def search_memories(
|
346
|
+
self,
|
347
|
+
search_term: str,
|
348
|
+
search_type: str = "both",
|
349
|
+
limit: int = 10,
|
350
|
+
) -> Dict[str, Any]:
|
351
|
+
"""
|
352
|
+
Search memories by using recall with the search term.
|
353
|
+
|
354
|
+
Args:
|
355
|
+
search_term: Term to search for
|
356
|
+
search_type: Type of search (not used, kept for compatibility)
|
357
|
+
limit: Maximum number of results
|
358
|
+
|
359
|
+
Returns:
|
360
|
+
Search results
|
361
|
+
"""
|
362
|
+
if not self._is_installed:
|
363
|
+
return {
|
364
|
+
"success": False,
|
365
|
+
"error": "kuzu-memory not installed",
|
366
|
+
"results": [],
|
367
|
+
}
|
368
|
+
|
369
|
+
try:
|
370
|
+
# Use recall for searching (kuzu-memory doesn't have a separate search command)
|
371
|
+
cmd = [
|
372
|
+
self.kuzu_cmd,
|
373
|
+
"recall",
|
374
|
+
search_term,
|
375
|
+
"--format",
|
376
|
+
"json",
|
377
|
+
"--max-memories",
|
378
|
+
str(limit),
|
379
|
+
]
|
380
|
+
|
381
|
+
# Execute command in project directory
|
382
|
+
result = subprocess.run(
|
383
|
+
cmd,
|
384
|
+
capture_output=True,
|
385
|
+
text=True,
|
386
|
+
timeout=10,
|
387
|
+
cwd=str(self.project_path), check=False,
|
388
|
+
)
|
389
|
+
|
390
|
+
if result.returncode == 0 and result.stdout:
|
391
|
+
# Parse the output
|
392
|
+
results = []
|
393
|
+
if "No relevant memories found" not in result.stdout:
|
394
|
+
# Try to extract memories from output
|
395
|
+
lines = result.stdout.strip().split("\n")
|
396
|
+
for line in lines:
|
397
|
+
if line.strip() and not line.startswith("🔍"):
|
398
|
+
results.append({"content": line.strip()})
|
399
|
+
|
400
|
+
return {
|
401
|
+
"success": True,
|
402
|
+
"search_term": search_term,
|
403
|
+
"count": len(results),
|
404
|
+
"results": results[:limit],
|
405
|
+
}
|
406
|
+
|
407
|
+
return {
|
408
|
+
"success": True,
|
409
|
+
"search_term": search_term,
|
410
|
+
"count": 0,
|
411
|
+
"results": [],
|
412
|
+
}
|
413
|
+
|
414
|
+
except Exception as e:
|
415
|
+
self.log_error(f"Error searching memories: {e}")
|
416
|
+
return {
|
417
|
+
"success": False,
|
418
|
+
"error": str(e),
|
419
|
+
"results": [],
|
420
|
+
}
|
421
|
+
|
422
|
+
async def get_context(
|
423
|
+
self,
|
424
|
+
topic: str,
|
425
|
+
depth: int = 2,
|
426
|
+
include_related: bool = True,
|
427
|
+
) -> Dict[str, Any]:
|
428
|
+
"""
|
429
|
+
Get enriched context for a topic using the enhance command.
|
430
|
+
|
431
|
+
Args:
|
432
|
+
topic: Topic to get context for
|
433
|
+
depth: Maximum memories to include
|
434
|
+
include_related: Not used, kept for compatibility
|
435
|
+
|
436
|
+
Returns:
|
437
|
+
Enriched context for the topic
|
438
|
+
"""
|
439
|
+
if not self._is_installed:
|
440
|
+
return {
|
441
|
+
"success": False,
|
442
|
+
"error": "kuzu-memory not installed",
|
443
|
+
"context": {},
|
444
|
+
}
|
445
|
+
|
446
|
+
try:
|
447
|
+
# Use enhance command for context enrichment
|
448
|
+
cmd = [
|
449
|
+
self.kuzu_cmd,
|
450
|
+
"enhance",
|
451
|
+
topic,
|
452
|
+
"--max-memories",
|
453
|
+
str(depth * 3),
|
454
|
+
"--format",
|
455
|
+
"plain", # Get just the context
|
456
|
+
]
|
457
|
+
|
458
|
+
# Execute command in project directory
|
459
|
+
result = subprocess.run(
|
460
|
+
cmd,
|
461
|
+
capture_output=True,
|
462
|
+
text=True,
|
463
|
+
timeout=15,
|
464
|
+
cwd=str(self.project_path), check=False,
|
465
|
+
)
|
466
|
+
|
467
|
+
if result.returncode == 0 and result.stdout:
|
468
|
+
return {
|
469
|
+
"success": True,
|
470
|
+
"topic": topic,
|
471
|
+
"context": result.stdout.strip(),
|
472
|
+
"memories": [], # Enhanced context is already processed
|
473
|
+
}
|
474
|
+
|
475
|
+
# Fallback to recall if enhance fails
|
476
|
+
self.log_debug("Enhance command failed, falling back to recall")
|
477
|
+
return await self.recall_memories(topic, limit=depth * 3)
|
478
|
+
|
479
|
+
except Exception as e:
|
480
|
+
self.log_error(f"Error getting context: {e}")
|
481
|
+
# Fallback to basic recall
|
482
|
+
return await self.recall_memories(topic, limit=depth * 3)
|
483
|
+
|
484
|
+
|
485
|
+
# Tool function wrappers for MCP Gateway
|
486
|
+
async def store_memory(
|
487
|
+
content: str,
|
488
|
+
tags: Optional[List[str]] = None,
|
489
|
+
metadata: Optional[Dict[str, Any]] = None,
|
490
|
+
) -> Dict[str, Any]:
|
491
|
+
"""Store a memory using the kuzu-memory service."""
|
492
|
+
service = KuzuMemoryService()
|
493
|
+
await service.initialize()
|
494
|
+
return await service.store_memory(content, tags, metadata)
|
495
|
+
|
496
|
+
|
497
|
+
async def recall_memories(
|
498
|
+
query: str,
|
499
|
+
limit: int = 5,
|
500
|
+
tags: Optional[List[str]] = None,
|
501
|
+
) -> Dict[str, Any]:
|
502
|
+
"""Recall memories relevant to a query."""
|
503
|
+
service = KuzuMemoryService()
|
504
|
+
await service.initialize()
|
505
|
+
return await service.recall_memories(query, limit, tags)
|
506
|
+
|
507
|
+
|
508
|
+
async def search_memories(
|
509
|
+
search_term: str,
|
510
|
+
search_type: str = "both",
|
511
|
+
limit: int = 10,
|
512
|
+
) -> Dict[str, Any]:
|
513
|
+
"""Search memories by content or tags."""
|
514
|
+
service = KuzuMemoryService()
|
515
|
+
await service.initialize()
|
516
|
+
return await service.search_memories(search_term, search_type, limit)
|
517
|
+
|
518
|
+
|
519
|
+
async def get_context(
|
520
|
+
topic: str,
|
521
|
+
depth: int = 2,
|
522
|
+
include_related: bool = True,
|
523
|
+
) -> Dict[str, Any]:
|
524
|
+
"""Get enriched context for a topic."""
|
525
|
+
service = KuzuMemoryService()
|
526
|
+
await service.initialize()
|
527
|
+
return await service.get_context(topic, depth, include_related)
|