Skip to content

Commit 9015557

Browse files
committed
feat(tools): add detailed code structure analysis tool
- Implemented `code-structure.ts` to extract imports, exports, dependencies, and call graphs from source files using tree-sitter. - Added functions for extracting imports, exports, and function calls for TypeScript, JavaScript, Python, Go, and Rust. - Created a `getCodeStructure` function to return a structured overview of the code file. feat(tools): create project initializer for Context+ setup - Introduced `init.ts` to initialize Context+ projects with necessary directories and default files. - Added functionality to generate initial embeddings and context tree snapshots. feat(tools): unify research capabilities across code, memory, and ACP - Developed `research.ts` to aggregate search results from codebase, memory, and ACP sources. - Implemented `discoverRelated` function to find related files and memories based on a given file path. feat(tools): enhance search functionality with hybrid capabilities - Created `search.ts` to combine semantic and keyword search modes for identifiers and files. - Added support for customizable search options including weights and score thresholds. test: add memory graph fixtures for testing - Created a sample `graph.json` file to serve as a fixture for memory graph tests.
1 parent a3c0bcc commit 9015557

41 files changed

Lines changed: 4924 additions & 1216 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.contextplus/embeddings/vectors.db

16 KB
Binary file not shown.

INSTRUCTIONS.md

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ The MCP server is built with TypeScript and communicates over stdio using the Mo
1313
- `parser.ts` - Multi-language symbol extraction via tree-sitter AST with regex fallback. Supports 14+ languages.
1414
- `tree-sitter.ts` - WASM grammar loader for 43 file extensions using web-tree-sitter 0.20.8.
1515
- `walker.ts` - Gitignore-aware recursive directory traversal with depth and target path control.
16-
- `embeddings.ts` - Ollama vector embedding engine with disk cache, cosine similarity search, and API key support.
16+
- `embeddings.ts` - Ollama/OpenAI-compatible vector embedding engine backed by vector DB persistence.
1717

1818
**Tools Layer** (`src/tools/`):
1919

20-
- `context-tree.ts` - Token-aware structural tree with symbol line ranges and Level 0/1/2 pruning.
21-
- `file-skeleton.ts` - Function signatures with line ranges, without reading full bodies.
22-
- `semantic-search.ts` - Ollama-powered semantic file search with symbol definition lines and 60s cache TTL.
23-
- `semantic-identifiers.ts` - Identifier-level semantic search returning ranked definitions + call chains with line numbers.
24-
- `semantic-navigate.ts` - Browse-by-meaning navigator using spectral clustering and Ollama labeling.
20+
- `context-tree.ts` - `tree` tool implementation for token-aware structural mapping.
21+
- `file-skeleton.ts` - `skeleton` tool implementation for signatures and type surfaces.
22+
- `search.ts` - Unified `search` tool for file and identifier retrieval.
23+
- `semantic-navigate.ts` - `cluster` tool implementation for spectral semantic grouping.
2524
- `blast-radius.ts` - Symbol usage tracer across the entire codebase.
26-
- `static-analysis.ts` - Native linter runner (tsc, eslint, py_compile, cargo check, go vet).
27-
- `propose-commit.ts` - Code gatekeeper validating headers, FEATURE tag, no inline comments, nesting, file length.
28-
- `feature-hub.ts` - Obsidian-style feature hub navigator with bundled skeleton views.
29-
- `memory-tools.ts` - Memory graph MCP wrappers (upsert, relate, search, prune, interlink, traverse).
25+
- `static-analysis.ts` - `lint` runner with project/file skill scoring output.
26+
- `propose-commit.ts` - `checkpoint` tool for validated writes with local restore points.
27+
- `feature-hub.ts` - `find_hub` ranking and full-project hub context fallback.
28+
- `memory-tools.ts` - Memory graph wrappers for create/search/explore/bulk/update/delete flows.
29+
- `init.ts` - Project bootstrap tool for `.contextplus` directories and context snapshot.
3030

31-
The memory graph is a **Retrieval-Augmented Generation (RAG)** system. Agents MUST use `search_memory_graph` at the start of every task to retrieve prior context, and persist learnings with `upsert_memory_node` and `create_relation` after completing work. This prevents redundant exploration and builds cumulative knowledge across sessions.
31+
The memory graph is a **Retrieval-Augmented Generation (RAG)** system. Agents SHOULD use `search_memory` early in each task to retrieve prior context, and persist learnings with `create_memory` and `create_relation` after completing work. Stale links are pruned automatically before graph access.
3232

3333
**Core Layer** (continued):
3434

3535
- `hub.ts` - Wikilink parser for `[[path]]` links, cross-link tags, hub discovery, orphan detection.
36-
- `memory-graph.ts` - In-memory property graph with JSON persistence, decay scoring, and auto-similarity edges.
36+
- `memory-graph.ts` - Graph metadata + markdown node files + vector DB-backed semantic retrieval.
3737

3838
**Git Layer** (`src/git/`):
3939

4040
- `shadow.ts` - Shadow restore point system for undo without touching git history.
4141

42-
**Entry Point**: `src/index.ts` registers 17 MCP tools and starts the stdio transport. Accepts an optional CLI argument for the target project root directory (defaults to `process.cwd()`).
42+
**Entry Point**: `src/index.ts` registers 18 MCP tools and starts the stdio transport. Accepts an optional CLI argument for the target project root directory (defaults to `process.cwd()`).
4343

4444
## Environment Variables
4545

@@ -53,18 +53,18 @@ The memory graph is a **Retrieval-Augmented Generation (RAG)** system. Agents MU
5353
| `CONTEXTPLUS_EMBED_TRACKER_MAX_FILES` | `8` | Max changed files per tracker tick (hard-capped to 5-10) |
5454
| `CONTEXTPLUS_EMBED_TRACKER_DEBOUNCE_MS` | `700` | Debounce before applying tracker refresh |
5555

56-
Runtime cache: `.mcp_data/` is created at MCP startup and stores reusable embedding vectors for files, identifiers, and call sites. A realtime tracker watches file updates and refreshes changed function/file embeddings incrementally.
56+
Runtime storage: `.contextplus/` is created by `init` and stores hubs, memory graph data, and vector DB embeddings. A realtime tracker can refresh changed function/file embeddings incrementally.
5757

5858
## Fast Execute Mode (Mandatory)
5959

6060
Default to execution-first behavior. Use minimal tokens, minimal narration, and maximum tool leverage.
6161

62-
1. Skip long planning prose. Start with lightweight scoping: `get_context_tree` and `get_file_skeleton`.
62+
1. Skip long planning prose. Start with lightweight scoping: `tree` and `skeleton`.
6363
2. Run independent discovery operations in parallel whenever possible (for example, multiple searches/reads).
6464
3. Prefer structural tools over full-file reads to conserve context.
65-
4. Before modifying or deleting symbols, run `get_blast_radius`.
66-
5. Write changes through `propose_commit` only.
67-
6. Run `run_static_analysis` once after edits, or once per changed module for larger refactors.
65+
4. Before modifying or deleting symbols, run `blast_radius`.
66+
5. Write changes through `checkpoint`.
67+
6. Run `lint` once after edits, or once per changed module for larger refactors.
6868

6969
### Execution Rules
7070

@@ -77,7 +77,7 @@ Default to execution-first behavior. Use minimal tokens, minimal narration, and
7777
### Token-Efficiency Rules
7878

7979
1. Treat 100 effective tokens as better than 1000 vague tokens.
80-
2. Use high-signal tool calls first (`get_file_skeleton`, `get_context_tree`, `get_blast_radius`).
80+
2. Use high-signal tool calls first (`skeleton`, `tree`, `blast_radius`).
8181
3. Read full file bodies only when signatures/structure are insufficient.
8282
4. Avoid repeated scans of unchanged areas.
8383
5. Prefer direct edits + deterministic validation over extended speculative analysis.
@@ -127,25 +127,26 @@ Strict order within every file:
127127

128128
## Tool Reference
129129

130-
| Tool | When to Use |
131-
| ---------------------------- | ---------------------------------------------------------------------------------- |
132-
| `get_context_tree` | Start of every task. Map files + symbols with line ranges. |
133-
| `semantic_navigate` | Browse codebase by meaning, not directory structure. |
134-
| `get_file_skeleton` | MUST run before full reads. Get signatures + line ranges first. |
135-
| `semantic_code_search` | Find relevant files by concept with symbol definition lines. |
136-
| `semantic_identifier_search` | Find closest functions/classes/variables and ranked call chains with line numbers. |
137-
| `get_blast_radius` | Before deleting or modifying any symbol. |
138-
| `run_static_analysis` | After writing code. Catch dead code deterministically. |
139-
| `propose_commit` | The ONLY way to save files. Validates before writing. |
140-
| `list_restore_points` | See undo history. |
141-
| `undo_change` | Revert a bad AI change without touching git. |
142-
| `get_feature_hub` | Browse feature graph hubs. Find orphaned files. |
143-
| `upsert_memory_node` | Create/update memory nodes (concept, file, symbol, note) with auto-embedding. |
144-
| `create_relation` | Create typed edges between memory nodes (depends_on, implements, etc). |
145-
| `search_memory_graph` | Semantic search + graph traversal across 1st/2nd-degree neighbors. |
146-
| `prune_stale_links` | Remove decayed edges (e^(-λt)) and orphan nodes periodically. |
147-
| `add_interlinked_context` | Bulk-add nodes with auto-similarity linking (cosine ≥ 0.72). |
148-
| `retrieve_with_traversal` | Start from a node, walk outward, return scored neighbors by decay and depth. |
130+
| Tool | When to Use |
131+
| ----------------- | ---------------------------------------------------------------------------------- |
132+
| `init` | Bootstrap `.contextplus` structure and context snapshot for a project. |
133+
| `tree` | Start of every task. Map files + symbols with line ranges. |
134+
| `cluster` | Browse codebase by meaning, not directory structure. |
135+
| `skeleton` | Run before full reads. Get signatures + line ranges first. |
136+
| `search` | Unified semantic/keyword search across files, identifiers, or both. |
137+
| `blast_radius` | Before deleting or modifying any symbol. |
138+
| `lint` | After writing code. Catch dead code and get skill scoring. |
139+
| `checkpoint` | Save file changes with validation and local restore-point creation. |
140+
| `restore_points` | See local restore history. |
141+
| `restore` | Revert to a specific restore point without touching git history. |
142+
| `find_hub` | Rank hubs by query or list all hub context when query is omitted. |
143+
| `create_memory` | Create/update memory nodes with embedding refresh. |
144+
| `create_relation` | Create typed edges between memory nodes (depends_on, implements, etc). |
145+
| `search_memory` | Semantic/keyword memory search with neighborhood traversal. |
146+
| `explore_memory` | Traverse outward from a known memory node id. |
147+
| `bulk_memory` | Bulk-add nodes and optional auto-linking. |
148+
| `update_memory` | Update existing memory content and refresh embeddings. |
149+
| `delete_memory` | Delete nodes or relations from the memory graph. |
149150

150151
## Anti-Patterns to Avoid
151152

0 commit comments

Comments
 (0)