code-memory 1.0.2__tar.gz → 1.0.3__tar.gz
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.
- {code_memory-1.0.2 → code_memory-1.0.3}/PKG-INFO +1 -1
- {code_memory-1.0.2 → code_memory-1.0.3}/pyproject.toml +1 -1
- {code_memory-1.0.2 → code_memory-1.0.3}/server.py +155 -56
- {code_memory-1.0.2 → code_memory-1.0.3}/.github/workflows/ci.yml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/.github/workflows/publish.yml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/.gitignore +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/.python-version +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/CHANGELOG.md +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/CONTRIBUTING.md +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/LICENSE +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/Makefile +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/README.md +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/db.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/doc_parser.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/errors.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/git_search.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/logging_config.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/parser.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_1.xml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_2.xml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_3.xml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_4.xml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_5.xml +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/queries.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/__init__.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/conftest.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_errors.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_logging.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_tools.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_validation.py +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/uv.lock +0 -0
- {code_memory-1.0.2 → code_memory-1.0.3}/validation.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: code-memory
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: A deterministic, high-precision code intelligence MCP server
|
|
5
5
|
Project-URL: Homepage, https://github.com/kapillamba4/code-memory
|
|
6
6
|
Project-URL: Documentation, https://github.com/kapillamba4/code-memory#readme
|
|
@@ -54,20 +54,37 @@ Indexing is incremental - unchanged files are skipped automatically.
|
|
|
54
54
|
# ── Tool 0: check_index_status ─────────────────────────────────────────────
|
|
55
55
|
@mcp.tool()
|
|
56
56
|
def check_index_status(directory: str = ".") -> dict:
|
|
57
|
-
"""
|
|
57
|
+
"""USE THIS TOOL to check if the codebase has been indexed and whether search tools will return results. Call this BEFORE search_code or search_docs if you're unsure about indexing state.
|
|
58
58
|
|
|
59
|
-
Call this
|
|
60
|
-
|
|
59
|
+
TRIGGER - Call this tool when:
|
|
60
|
+
- You're unsure if the codebase has been indexed
|
|
61
|
+
- search_code or search_docs returned empty results
|
|
62
|
+
- Starting work on a new project or session
|
|
63
|
+
- You want to verify index health before searching
|
|
64
|
+
|
|
65
|
+
This tool checks the SQLite database for indexed symbols and documentation chunks. It's a lightweight diagnostic - much faster than re-indexing.
|
|
66
|
+
|
|
67
|
+
INTERPRETING RESULTS:
|
|
68
|
+
- If "indexed" is false OR "symbols_indexed" is 0: You MUST call index_codebase first
|
|
69
|
+
- If "suggestion" says "CALL index_codebase FIRST": Indexing is required
|
|
70
|
+
- If "suggestion" says "ready to search": Search tools will work
|
|
71
|
+
|
|
72
|
+
Do NOT use this tool for:
|
|
73
|
+
- Actually indexing the codebase (use index_codebase)
|
|
74
|
+
- Searching for code or documentation
|
|
75
|
+
- Git history queries
|
|
61
76
|
|
|
62
77
|
Args:
|
|
63
|
-
directory:
|
|
78
|
+
directory: Directory path to check (default "." for current directory).
|
|
64
79
|
|
|
65
80
|
Returns:
|
|
66
|
-
Dictionary with
|
|
67
|
-
- indexed: boolean
|
|
68
|
-
- symbols_indexed:
|
|
69
|
-
- doc_chunks_indexed:
|
|
70
|
-
-
|
|
81
|
+
Dictionary with:
|
|
82
|
+
- indexed: boolean - true if anything has been indexed
|
|
83
|
+
- symbols_indexed: count of code symbols in index
|
|
84
|
+
- doc_chunks_indexed: count of documentation chunks
|
|
85
|
+
- code_files_indexed: count of indexed code files
|
|
86
|
+
- doc_files_indexed: count of indexed doc files
|
|
87
|
+
- suggestion: "ready to search" or "CALL index_codebase FIRST"
|
|
71
88
|
"""
|
|
72
89
|
try:
|
|
73
90
|
database = db_mod.get_db()
|
|
@@ -107,23 +124,43 @@ def search_code(
|
|
|
107
124
|
query: str,
|
|
108
125
|
search_type: Literal["definition", "references", "file_structure"],
|
|
109
126
|
) -> dict:
|
|
110
|
-
"""
|
|
127
|
+
"""USE THIS TOOL to find code symbols: function definitions, class declarations, variable assignments, and cross-references. Always prefer this over grep or file-reading tools when you need structural code knowledge.
|
|
128
|
+
|
|
129
|
+
PREREQUISITE: This tool requires indexing. If results are empty or you haven't indexed this session, call index_codebase(directory=".") first.
|
|
130
|
+
|
|
131
|
+
This tool uses HYBRID RETRIEVAL (BM25 keyword search + dense vector semantic search with Reciprocal Rank Fusion) - more intelligent than plain text search.
|
|
132
|
+
|
|
133
|
+
WHEN TO USE EACH search_type:
|
|
134
|
+
|
|
135
|
+
1. "definition" - USE WHEN:
|
|
136
|
+
- User asks "where is X defined?" or "find the implementation of X"
|
|
137
|
+
- You need to locate a function, class, method, or variable
|
|
138
|
+
- Query can be exact symbol name OR semantic description
|
|
139
|
+
- Results ranked by hybrid relevance score
|
|
140
|
+
|
|
141
|
+
2. "references" - USE WHEN:
|
|
142
|
+
- User asks "where is X used?" or "find all usages of X"
|
|
143
|
+
- You need cross-references showing where a symbol is imported/called
|
|
144
|
+
- Query MUST be the exact symbol name
|
|
145
|
+
- Returns all files and line numbers where symbol appears
|
|
111
146
|
|
|
112
|
-
|
|
113
|
-
|
|
147
|
+
3. "file_structure" - USE WHEN:
|
|
148
|
+
- User asks "show me the structure of file X" or "what's in this file?"
|
|
149
|
+
- You need an overview of all symbols in a specific file
|
|
150
|
+
- Query MUST be the file path (e.g., "src/auth/login.py")
|
|
151
|
+
- Returns symbols ordered by line number
|
|
114
152
|
|
|
115
|
-
|
|
116
|
-
|
|
153
|
+
Do NOT use this tool for:
|
|
154
|
+
- Reading full file contents (use your built-in file reader)
|
|
155
|
+
- Git history queries (use search_history)
|
|
156
|
+
- Documentation/conceptual questions (use search_docs)
|
|
117
157
|
|
|
118
158
|
Args:
|
|
119
|
-
query: Symbol name
|
|
120
|
-
search_type:
|
|
121
|
-
- "definition": Find where a symbol is defined (hybrid search)
|
|
122
|
-
- "references": Find all cross-references to a symbol name
|
|
123
|
-
- "file_structure": List all symbols in a file, ordered by line
|
|
159
|
+
query: Symbol name (e.g., "authenticate_user") OR semantic description (e.g., "database connection handler"). For file_structure, use file path.
|
|
160
|
+
search_type: Must be exactly "definition", "references", or "file_structure".
|
|
124
161
|
|
|
125
162
|
Returns:
|
|
126
|
-
List of
|
|
163
|
+
List of results with file paths, line numbers, and source code snippets.
|
|
127
164
|
"""
|
|
128
165
|
with logging_config.ToolLogger("search_code", query=query, search_type=search_type) as log:
|
|
129
166
|
try:
|
|
@@ -173,21 +210,34 @@ def search_code(
|
|
|
173
210
|
# ── Tool 2: index_codebase ────────────────────────────────────────────────
|
|
174
211
|
@mcp.tool()
|
|
175
212
|
def index_codebase(directory: str = ".") -> dict:
|
|
176
|
-
"""
|
|
213
|
+
"""YOU MUST CALL THIS TOOL FIRST before using search_code or search_docs. Use this tool to build the searchable index that powers all other code intelligence features.
|
|
177
214
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
215
|
+
TRIGGER: Call this tool immediately when:
|
|
216
|
+
- Starting a new session with this codebase
|
|
217
|
+
- search_code or search_docs returns empty or unexpected results
|
|
218
|
+
- You haven't indexed recently or files have been modified
|
|
219
|
+
- User asks about code structure, definitions, or documentation
|
|
182
220
|
|
|
183
|
-
|
|
184
|
-
|
|
221
|
+
This tool performs TWO critical operations:
|
|
222
|
+
1. CODE INDEXING: Uses tree-sitter for language-agnostic AST extraction (Python, JavaScript/TypeScript, Java, Kotlin, Go, Rust, C/C++, Ruby, and more). Extracts functions, classes, methods, variables, and cross-references.
|
|
223
|
+
2. DOCUMENTATION INDEXING: Parses markdown files, READMEs, and extracts docstrings from indexed code. Generates embeddings for semantic search.
|
|
224
|
+
|
|
225
|
+
IMPORTANT ADVANTAGES over built-in file search:
|
|
226
|
+
- Creates persistent structural knowledge (AST-based, not just text)
|
|
227
|
+
- Enables semantic search via vector embeddings
|
|
228
|
+
- Builds cross-reference graphs for "find all usages" queries
|
|
229
|
+
- Incremental indexing: unchanged files are automatically skipped
|
|
230
|
+
|
|
231
|
+
Do NOT use this tool for:
|
|
232
|
+
- Non-code files (images, binaries, data files)
|
|
233
|
+
- Single-file lookups (use search_code after indexing)
|
|
234
|
+
- Git history queries (use search_history instead)
|
|
185
235
|
|
|
186
236
|
Args:
|
|
187
|
-
directory: The root directory to index (
|
|
237
|
+
directory: The root directory to index (default "."). Must be a valid path.
|
|
188
238
|
|
|
189
239
|
Returns:
|
|
190
|
-
Summary
|
|
240
|
+
Summary with files_indexed, total_symbols, total_chunks, and details.
|
|
191
241
|
"""
|
|
192
242
|
with logging_config.ToolLogger("index_codebase", directory=directory) as log:
|
|
193
243
|
try:
|
|
@@ -263,26 +313,38 @@ def index_codebase(directory: str = ".") -> dict:
|
|
|
263
313
|
# ── Tool 3: search_docs ────────────────────────────────────────────────────
|
|
264
314
|
@mcp.tool()
|
|
265
315
|
def search_docs(query: str, top_k: int = 10) -> dict:
|
|
266
|
-
"""Search documentation
|
|
316
|
+
"""USE THIS TOOL for conceptual understanding and "how does X work?" questions. Search markdown documentation, READMEs, and code docstrings using semantic search.
|
|
317
|
+
|
|
318
|
+
PREREQUISITE: This tool requires indexing. If results are empty or you haven't indexed this session, call index_codebase(directory=".") first.
|
|
319
|
+
|
|
320
|
+
TRIGGER - Call this tool when the user asks:
|
|
321
|
+
- "How does [feature] work?"
|
|
322
|
+
- "Explain the architecture of..."
|
|
323
|
+
- "What are the setup/installation instructions?"
|
|
324
|
+
- "Show me the documentation for..."
|
|
325
|
+
- "Why was this designed this way?"
|
|
326
|
+
- Any question answered by README, CHANGELOG, or docstrings
|
|
267
327
|
|
|
268
|
-
IMPORTANT: This
|
|
269
|
-
haven't indexed recently, call `index_codebase(directory=".")` before searching.
|
|
328
|
+
IMPORTANT: This is NOT for finding code implementations. For code locations, use search_code. This tool searches DOCUMENTATION, not source code.
|
|
270
329
|
|
|
271
|
-
|
|
272
|
-
- "How does authentication work?"
|
|
273
|
-
- "Explain the architecture"
|
|
274
|
-
- "What are the setup instructions?"
|
|
330
|
+
Uses HYBRID RETRIEVAL (BM25 keyword search + dense vector semantic search with Reciprocal Rank Fusion) to find conceptually relevant documentation even when keywords don't match exactly.
|
|
275
331
|
|
|
276
|
-
|
|
277
|
-
|
|
332
|
+
Do NOT use this tool for:
|
|
333
|
+
- Finding function/class definitions (use search_code with "definition")
|
|
334
|
+
- Finding where code is used (use search_code with "references")
|
|
335
|
+
- Git history or commit messages (use search_history)
|
|
278
336
|
|
|
279
337
|
Args:
|
|
280
|
-
query: A natural language question
|
|
281
|
-
top_k: Maximum
|
|
338
|
+
query: A natural language question (e.g., "How does authentication work?" or "API rate limiting"). Can be conversational - semantic search handles synonyms.
|
|
339
|
+
top_k: Maximum results to return (default 10, max 100).
|
|
282
340
|
|
|
283
341
|
Returns:
|
|
284
|
-
Dictionary with 'results'
|
|
285
|
-
|
|
342
|
+
Dictionary with 'results' array. Each result includes:
|
|
343
|
+
- content: The documentation text
|
|
344
|
+
- file: Source file path
|
|
345
|
+
- section: Section heading (if applicable)
|
|
346
|
+
- line_start/line_end: Location in source
|
|
347
|
+
- relevance_score: Hybrid search score
|
|
286
348
|
"""
|
|
287
349
|
with logging_config.ToolLogger("search_docs", query=query, top_k=top_k) as log:
|
|
288
350
|
try:
|
|
@@ -325,20 +387,57 @@ def search_history(
|
|
|
325
387
|
line_start: int | None = None,
|
|
326
388
|
line_end: int | None = None,
|
|
327
389
|
) -> dict:
|
|
328
|
-
"""
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
-
|
|
334
|
-
|
|
335
|
-
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
390
|
+
"""USE THIS TOOL for Git history queries: understanding WHY changes were made, debugging regressions, or finding commit context. This tool operates on the local Git repository.
|
|
391
|
+
|
|
392
|
+
TRIGGER - Call this tool when the user asks:
|
|
393
|
+
- "Why was this code changed?" / "Who changed this?"
|
|
394
|
+
- "When was X introduced?" / "Find commits about X"
|
|
395
|
+
- "Debug this regression" / "What broke this?"
|
|
396
|
+
- "Show me the history of this file"
|
|
397
|
+
- "Who wrote this line?" (blame)
|
|
398
|
+
- "What changed in commit X?"
|
|
399
|
+
|
|
400
|
+
This tool does NOT require indexing - it queries Git directly.
|
|
401
|
+
|
|
402
|
+
WHEN TO USE EACH search_type:
|
|
403
|
+
|
|
404
|
+
1. "commits" - USE WHEN:
|
|
405
|
+
- User asks "find commits about X" or "search commit messages"
|
|
406
|
+
- Query is a keyword or phrase to search in commit messages
|
|
407
|
+
- Optionally set target_file to filter commits touching that file
|
|
408
|
+
- Args: query (required), target_file (optional)
|
|
409
|
+
|
|
410
|
+
2. "file_history" - USE WHEN:
|
|
411
|
+
- User asks "show history of file X" or "what happened to this file?"
|
|
412
|
+
- Shows commit log for a specific file (follows renames)
|
|
413
|
+
- target_file is REQUIRED; query is ignored
|
|
414
|
+
- Args: target_file (required)
|
|
415
|
+
|
|
416
|
+
3. "blame" - USE WHEN:
|
|
417
|
+
- User asks "who wrote this line?" or "who last modified this?"
|
|
418
|
+
- Shows line-by-line commit attribution
|
|
419
|
+
- target_file is REQUIRED; optionally limit to line range
|
|
420
|
+
- Args: target_file (required), line_start/line_end (optional)
|
|
421
|
+
|
|
422
|
+
4. "commit_detail" - USE WHEN:
|
|
423
|
+
- User asks "show me commit X" or "what changed in this commit?"
|
|
424
|
+
- Query is the commit hash (full or abbreviated)
|
|
425
|
+
- Optionally set target_file to show only changes to that file
|
|
426
|
+
- Args: query=commit_hash (required), target_file (optional)
|
|
427
|
+
|
|
428
|
+
Do NOT use this tool for:
|
|
429
|
+
- Finding code definitions (use search_code)
|
|
430
|
+
- Reading documentation (use search_docs)
|
|
431
|
+
- Non-Git questions
|
|
432
|
+
|
|
433
|
+
Args:
|
|
434
|
+
query: Search term for commits, or commit hash for commit_detail.
|
|
435
|
+
search_type: Must be exactly "commits", "file_history", "blame", or "commit_detail".
|
|
436
|
+
target_file: File path (required for file_history and blame).
|
|
437
|
+
line_start/line_end: Line range for blame (optional).
|
|
438
|
+
|
|
439
|
+
Returns:
|
|
440
|
+
Varies by search_type. All include status and structured results.
|
|
342
441
|
"""
|
|
343
442
|
with logging_config.ToolLogger("search_history", query=query, search_type=search_type,
|
|
344
443
|
target_file=target_file) as log:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|