From b8460107b9d0089f2c4bc1990e2b9f4d6a728cca Mon Sep 17 00:00:00 2001 From: Ed_ Date: Tue, 5 May 2026 19:31:25 -0400 Subject: [PATCH] chore(conductor): Expand Tree-Sitter C/C++ track with new phases for tool parity and robust testing --- conductor/tracks.md | 4 +- .../ts_cpp_tree_sitter_20260308/plan.md | 48 +++++++++++++++++++ .../ts_cpp_tree_sitter_20260308/spec.md | 16 +++++-- src/models.py | 18 ++++++- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/conductor/tracks.md b/conductor/tracks.md index 5b6a738..d2dc8cc 100644 --- a/conductor/tracks.md +++ b/conductor/tracks.md @@ -98,9 +98,9 @@ This file tracks all major tracks for the project. Each track has its own detail ### Additional Language Support -1. [~] **Track: Tree-Sitter C/C++ MCP Tools** +1. [ ] **Track: Tree-Sitter C/C++ MCP Tools** *Link: [./tracks/ts_cpp_tree_sitter_20260308/](./tracks/ts_cpp_tree_sitter_20260308/)* - *Goal: Add tree-sitter C and C++ grammars. Extend ASTParser to support C/C++ skeleton and outline extraction. Add MCP tools ts_c_get_skeleton, ts_cpp_get_skeleton, ts_c_get_code_outline, ts_cpp_get_code_outline.* + *Goal: Add tree-sitter C and C++ grammars. Extend ASTParser to support C/C++ skeleton and outline extraction. Add MCP tools ts_c_get_skeleton, ts_cpp_get_skeleton, ts_c_get_code_outline, ts_cpp_get_code_outline. (Extended: definitions, signatures, and surgical updates).* 2. [ ] **Track: Bootstrap gencpp Python Bindings** *Link: [./tracks/gencpp_python_bindings_20260308/](./tracks/gencpp_python_bindings_20260308/)* diff --git a/conductor/tracks/ts_cpp_tree_sitter_20260308/plan.md b/conductor/tracks/ts_cpp_tree_sitter_20260308/plan.md index a8d3c4e..d1e8515 100644 --- a/conductor/tracks/ts_cpp_tree_sitter_20260308/plan.md +++ b/conductor/tracks/ts_cpp_tree_sitter_20260308/plan.md @@ -41,3 +41,51 @@ Focus: Verify C/C++ tools work correctly - [x] Task 4.2: Write tests for ts_cpp_get_skeleton 3bb850a - [x] Task 4.3: Write tests for code outline tools 3bb850a - [x] Task 4.4: Integration test - verify tools dispatch correctly 3bb850a + +## Phase 5: Parity with Python Tools +Focus: Implement definitions, signatures, and update tools + +- [ ] Task 5.1: Implement get_definition for C and C++ + - WHERE: src/file_cache.py, src/mcp_client.py + - WHAT: Implement `ts_c_get_definition` and `ts_cpp_get_definition` + - HOW: Use AST to find node by name; return source range + - SAFETY: Follow allowlist checks + +- [ ] Task 5.2: Implement get_signature for C and C++ + - WHERE: src/file_cache.py, src/mcp_client.py + - WHAT: Implement `ts_c_get_signature` and `ts_cpp_get_signature` + - HOW: Extract code from start of definition until block start (`{`) or semicolon (`;`) + - SAFETY: Handles multi-line signatures and templates + +- [ ] Task 5.3: Implement update_definition for C and C++ + - WHERE: src/mcp_client.py + - WHAT: Implement `ts_c_update_definition` and `ts_cpp_update_definition` + - HOW: Use AST to find target range; surgically replace lines in file + - SAFETY: Verify AST still parses after edit (optional but recommended) + +- [ ] Task 5.4: Register Phase 5 tools in dispatch and schema + - WHERE: src/mcp_client.py + - WHAT: Add tools to `get_tool_schemas` and `dispatch` + - HOW: Standard registration pattern + +## Phase 6: Robust Testing with gencpp +Focus: Verify against real-world C++ components + +- [ ] Task 6.1: Define test corpus from gencpp samples + - WHERE: tests/assets/gencpp_samples/ + - WHAT: Collect complex C++ headers and implementations (templates, nested namespaces, multi-line macros) + - HOW: Copy selected files from gencpp repo into test assets + +- [ ] Task 6.2: Run exhaustive skeleton/outline tests on gencpp corpus + - WHERE: tests/test_ts_cpp_tools.py + - WHAT: Verify no crashes and accurate extraction for complex C++ constructs + - HOW: Automated test loop over samples + +- [ ] Task 6.3: Verify surgical updates on gencpp components + - WHERE: tests/test_ts_cpp_tools.py + - WHAT: Test `update_definition` on template methods and deeply nested classes + - HOW: Apply change, re-parse, verify integrity + +- [ ] Task 6.4: Final audit and track closure + - WHERE: conductor/tracks.md + - WHAT: Mark track as completed and summarize results diff --git a/conductor/tracks/ts_cpp_tree_sitter_20260308/spec.md b/conductor/tracks/ts_cpp_tree_sitter_20260308/spec.md index 17e7536..78d8a21 100644 --- a/conductor/tracks/ts_cpp_tree_sitter_20260308/spec.md +++ b/conductor/tracks/ts_cpp_tree_sitter_20260308/spec.md @@ -16,6 +16,7 @@ Add tree-sitter-based C and C++ parsing support to the MCP client, providing ske - No C/C++ tree-sitter grammars installed - No C/C++ parsing logic in ASTParser - No MCP tools for C/C++ code extraction +- No MCP tools for C/C++ code modification (Parity with Python `py_update_definition`) ## Goals @@ -23,7 +24,9 @@ Add tree-sitter-based C and C++ parsing support to the MCP client, providing ske 2. Extend ASTParser to support C and C++ languages 3. Implement skeleton and outline generation for C/C++ (functions, structs, enums, classes) 4. Add MCP tools: `ts_c_get_skeleton`, `ts_cpp_get_skeleton`, `ts_c_get_code_outline`, `ts_cpp_get_code_outline` -5. Register tools in mcp_client dispatch +5. Implement definition, signature, and update tools for C/C++ parity +6. Register tools in mcp_client dispatch +7. Validate tools against real-world C++ components from `gencpp` repository ## Functional Requirements @@ -45,11 +48,19 @@ Add tree-sitter-based C and C++ parsing support to the MCP client, providing ske | `ts_cpp_get_skeleton` | Returns C++ file skeleton (above + class methods, templates, namespaces) | | `ts_c_get_code_outline` | Returns hierarchical C outline (functions, structs, enums, globals with line ranges) | | `ts_cpp_get_code_outline` | Returns hierarchical C++ outline (above + classes, templates, namespaces) | +| `ts_c_get_definition` | Get full source code of a specific C function or struct | +| `ts_cpp_get_definition` | Get full source code of a specific C++ class, function, or method | +| `ts_c_get_signature` | Get only the signature part of a C function | +| `ts_cpp_get_signature` | Get only the signature part of a C++ function or method | +| `ts_c_update_definition` | Surgically replace the definition of a C function or struct | +| `ts_cpp_update_definition` | Surgically replace the definition of a C++ class, function, or method | ### Tool Output Format Match existing Python tool formats for consistency: - Skeleton: signatures + docstrings, bodies replaced with `...` - Outline: hierarchical list with `[Class] name (Lines X-Y)` format +- Definition: raw source code of the identified range +- Signature: code from start of definition until start of block/semicolon ## Non-Functional Requirements @@ -68,5 +79,4 @@ Match existing Python tool formats for consistency: - Cross-file symbol resolution (AI uses search tools for this) - Template instantiation analysis - Macro expansion -- gencpp integration (future separate track) -- Writing to C/C++ files (read-only for now) +- gencpp integration (orchestrating gencpp logic itself is a separate track) diff --git a/src/models.py b/src/models.py index a88cac5..7371bd5 100644 --- a/src/models.py +++ b/src/models.py @@ -86,7 +86,11 @@ AGENT_TOOL_NAMES = [ "py_find_usages", "py_get_imports", "py_check_syntax", - "py_get_hierarchy" + "py_get_hierarchy", + "ts_c_get_skeleton", + "ts_cpp_get_skeleton", + "ts_c_get_code_outline", + "ts_cpp_get_code_outline" ] DEFAULT_TOOL_CATEGORIES: Dict[str, List[str]] = { @@ -106,6 +110,18 @@ DEFAULT_TOOL_CATEGORIES: Dict[str, List[str]] = { "Surgical": ["get_file_slice", "set_file_slice", "edit_file"], "Web": ["web_search", "fetch_url"], "Analysis": ["py_find_usages", "py_get_imports", "py_check_syntax", "py_get_hierarchy"], + "C/C++": [ + "ts_c_get_skeleton", + "ts_cpp_get_skeleton", + "ts_c_get_code_outline", + "ts_cpp_get_code_outline", + "ts_c_get_definition", + "ts_cpp_get_definition", + "ts_c_get_signature", + "ts_cpp_get_signature", + "ts_c_update_definition", + "ts_cpp_update_definition" + ], "Runtime": ["run_powershell", "get_ui_performance"] }