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.
Files changed (32) hide show
  1. {code_memory-1.0.2 → code_memory-1.0.3}/PKG-INFO +1 -1
  2. {code_memory-1.0.2 → code_memory-1.0.3}/pyproject.toml +1 -1
  3. {code_memory-1.0.2 → code_memory-1.0.3}/server.py +155 -56
  4. {code_memory-1.0.2 → code_memory-1.0.3}/.github/workflows/ci.yml +0 -0
  5. {code_memory-1.0.2 → code_memory-1.0.3}/.github/workflows/publish.yml +0 -0
  6. {code_memory-1.0.2 → code_memory-1.0.3}/.gitignore +0 -0
  7. {code_memory-1.0.2 → code_memory-1.0.3}/.python-version +0 -0
  8. {code_memory-1.0.2 → code_memory-1.0.3}/CHANGELOG.md +0 -0
  9. {code_memory-1.0.2 → code_memory-1.0.3}/CONTRIBUTING.md +0 -0
  10. {code_memory-1.0.2 → code_memory-1.0.3}/LICENSE +0 -0
  11. {code_memory-1.0.2 → code_memory-1.0.3}/Makefile +0 -0
  12. {code_memory-1.0.2 → code_memory-1.0.3}/README.md +0 -0
  13. {code_memory-1.0.2 → code_memory-1.0.3}/db.py +0 -0
  14. {code_memory-1.0.2 → code_memory-1.0.3}/doc_parser.py +0 -0
  15. {code_memory-1.0.2 → code_memory-1.0.3}/errors.py +0 -0
  16. {code_memory-1.0.2 → code_memory-1.0.3}/git_search.py +0 -0
  17. {code_memory-1.0.2 → code_memory-1.0.3}/logging_config.py +0 -0
  18. {code_memory-1.0.2 → code_memory-1.0.3}/parser.py +0 -0
  19. {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_1.xml +0 -0
  20. {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_2.xml +0 -0
  21. {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_3.xml +0 -0
  22. {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_4.xml +0 -0
  23. {code_memory-1.0.2 → code_memory-1.0.3}/prompts/milestone_5.xml +0 -0
  24. {code_memory-1.0.2 → code_memory-1.0.3}/queries.py +0 -0
  25. {code_memory-1.0.2 → code_memory-1.0.3}/tests/__init__.py +0 -0
  26. {code_memory-1.0.2 → code_memory-1.0.3}/tests/conftest.py +0 -0
  27. {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_errors.py +0 -0
  28. {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_logging.py +0 -0
  29. {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_tools.py +0 -0
  30. {code_memory-1.0.2 → code_memory-1.0.3}/tests/test_validation.py +0 -0
  31. {code_memory-1.0.2 → code_memory-1.0.3}/uv.lock +0 -0
  32. {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.2
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "code-memory"
7
- version = "1.0.2"
7
+ version = "1.0.3"
8
8
  description = "A deterministic, high-precision code intelligence MCP server"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -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
- """Check if the codebase has been indexed and get indexing statistics.
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 BEFORE using search tools to determine if indexing is needed.
60
- If symbols_indexed is 0, you MUST call index_codebase first.
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: The directory to check (default: current directory).
78
+ directory: Directory path to check (default "." for current directory).
64
79
 
65
80
  Returns:
66
- Dictionary with indexing status including:
67
- - indexed: boolean indicating if code has been indexed
68
- - symbols_indexed: number of code symbols in the index
69
- - doc_chunks_indexed: number of documentation chunks
70
- - suggestion: "index_codebase" if indexing is needed, "ready" otherwise
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
- """Search the indexed codebase for definitions, references, or file structure.
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
- IMPORTANT: This tool requires indexing first. If you get empty results or
113
- haven't indexed recently, call `index_codebase(directory=".")` before searching.
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
- Uses hybrid retrieval (BM25 keyword search + dense vector semantic search)
116
- with Reciprocal Rank Fusion.
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 or semantic description of what you're looking for.
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 matching results with file paths, line numbers, and source text.
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
- """Indexes or re-indexes source files and documentation in the given directory.
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
- Run this before using search_code or search_docs to ensure the database
179
- is up to date. Uses tree-sitter for language-agnostic structural extraction
180
- and generates embeddings for semantic search. Supports Python, JavaScript/
181
- TypeScript, Java, Kotlin, Go, Rust, C/C++, Ruby, and more.
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
- Also indexes markdown documentation files and extracts docstrings from
184
- indexed code symbols. Unchanged files (by mtime) are automatically skipped.
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 (recursively).
237
+ directory: The root directory to index (default "."). Must be a valid path.
188
238
 
189
239
  Returns:
190
- Summary of indexing results including code and documentation stats.
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 to understand the codebase conceptually.
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 tool requires indexing first. If you get empty results or
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
- Ideal for questions like:
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
- Searches markdown files, READMEs, and docstrings using hybrid retrieval
277
- (BM25 + semantic search with RRF fusion).
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 about the codebase.
281
- top_k: Maximum number of results to return (default 10).
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' containing matching documentation chunks
285
- with source attribution (file, section, line numbers) and relevance score.
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
- """Search local Git history to debug regressions, understand developer
329
- intent, or find out WHY a specific change was made.
330
-
331
- **search_type options:**
332
-
333
- - ``commits`` Search commit messages for *query* (case-insensitive).
334
- Optionally filter to commits that touched *target_file*.
335
- - ``file_history`` Show the commit log for *target_file* (follows
336
- renames). *target_file* is required; *query* is ignored.
337
- - ``blame`` — Run ``git blame`` on *target_file*, optionally limited to
338
- *line_start*–*line_end*. *target_file* is required.
339
- - ``commit_detail`` — Get full metadata and diff for one commit.
340
- Pass the commit hash as *query*. Optionally set *target_file* to
341
- restrict the diff to that file.
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