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11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
"""
Debug Tools Module

Comprehensive set of tools for advanced code debugging and analysis.
Provides code search, structure analysis, type checking, coverage analysis, and dependency inspection.
"""

DEBUG_TOOLS = [
    {
        "name": "search_code",
        "description": """Search for code patterns across files in the task directory.

        Searches for text or regex patterns across source files, useful for locating
        where functions are called, variable usage, or specific error patterns.
        Similar to grep/rg operations but integrated for debugging workflow.

        Required Parameters:
          - pattern: Text or regex pattern to search for (case-insensitive by default)
          - file_types: Optional. Filter by file type (default: "py" for Python files only)
                        Enum: "py" (Python), "all" (all files), "txt", "json", etc.

        Optional Parameters:
          - case_sensitive: Whether to match case (default: false)
          - max_results: Maximum number of matches to return (default: 50, max: 500)
          - context_lines: Lines of context around each match (default: 2, max: 10)

        Search Behavior:
          - Returns matches with line numbers, filenames, and surrounding context
          - Sorted by filename then line number
          - If pattern contains regex special chars, it's treated as regex
          - Matches are highlighted with context for easy reading
          - Path traversal protection: only searches within task directory

        Response Structure:
          - matches: Array of match objects, each containing:
            * filename: File containing the match
            * line_number: Line number (1-indexed)
            * line_content: The matching line
            * before: Context lines before (array)
            * after: Context lines after (array)
            * match_position: Column where match starts
          - total_matches: Total number of matches found
          - files_searched: Number of files examined
          - search_time_ms: Search execution time

        Status Codes:
          - 200: Success - Search completed (may have 0 matches)
          - 400: Bad Request - Invalid pattern or parameters
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "pattern": {
                    "type": "string",
                    "description": "Text or regex pattern to search for",
                    "minLength": 1,
                    "maxLength": 500,
                },
                "file_types": {
                    "type": "string",
                    "description": "File type filter (py, all, txt, json, etc.)",
                    "enum": ["py", "all", "txt", "json", "md"],
                    "default": "py",
                },
                "case_sensitive": {
                    "type": "boolean",
                    "description": "Whether to match case",
                    "default": False,
                },
                "max_results": {
                    "type": "integer",
                    "description": "Maximum number of matches to return",
                    "minimum": 1,
                    "maximum": 500,
                    "default": 50,
                },
                "context_lines": {
                    "type": "integer",
                    "description": "Lines of context around each match",
                    "minimum": 0,
                    "maximum": 10,
                    "default": 2,
                },
            },
            "required": ["pattern"],
        },
    },
    {
        "name": "get_file_structure",
        "description": """Parse and return the structure (AST) of a Python file.

        Analyzes the Abstract Syntax Tree of a Python file to extract functions,
        classes, methods, imports, and their locations. Useful for understanding
        code organization before editing.

        Required Parameters:
          - path: File path relative to task directory (e.g., 'broken_code.py')

        Optional Parameters:
          - include_docstrings: Include docstrings in output (default: true)
          - include_signatures: Include function/method signatures (default: true)
          - max_depth: Maximum nesting depth to analyze (default: unlimited)

        Structure Analysis:
          - Extracts top-level functions and classes
          - For each class: lists methods, attributes, parent classes
          - For each function: shows parameters, return type hint (if present)
          - Shows decorators (@property, @staticmethod, etc.)
          - Identifies imports (from/import statements)
          - Groups by section (imports, classes, functions, constants)

        Response Structure:
          - filename: The analyzed file
          - imports: Array of import statements with line numbers
            * module: Imported module
            * items: What was imported (function/class/constant names)
            * line_number: Where imported
          - classes: Array of class definitions
            * name: Class name
            * line_number: Definition line
            * methods: Array of method names with line numbers
            * attributes: Instance attributes with types (if annotated)
            * docstring: Class docstring (if present)
          - functions: Array of top-level functions
            * name: Function name
            * line_number: Definition line
            * parameters: Param names and types (if annotated)
            * return_type: Return type hint (if present)
            * docstring: Function docstring (if present)
          - constants: Module-level constants
            * name: Constant name
            * line_number: Definition line
            * value: Literal value (if simple)

        Status Codes:
          - 200: Success - File structure extracted
          - 400: Bad Request - Invalid Python syntax or file not found
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "File path relative to task directory",
                    "minLength": 1,
                    "maxLength": 255,
                },
                "include_docstrings": {
                    "type": "boolean",
                    "description": "Include docstrings in output",
                    "default": True,
                },
                "include_signatures": {
                    "type": "boolean",
                    "description": "Include function/method signatures",
                    "default": True,
                },
                "max_depth": {
                    "type": "integer",
                    "description": "Maximum nesting depth to analyze (0 for unlimited)",
                    "minimum": 0,
                    "default": 0,
                },
            },
            "required": ["path"],
        },
    },
    {
        "name": "run_type_check",
        "description": """Run static type checking (mypy) on Python files.

        Executes mypy type checker on specified file or directory to identify
        type errors, missing annotations, and type incompatibilities.
        Useful for catching type-related bugs before runtime.

        Required Parameters:
          - path: File or directory path relative to task directory
                  (e.g., 'broken_code.py' or '.')

        Optional Parameters:
          - strict: Enable strict mode (all optional checks, default: false)
          - ignore_missing_imports: Ignore errors from untyped libraries (default: true)
          - show_error_codes: Show error codes in output (default: true)
          - max_errors: Maximum errors to report (default: 100)

        Type Check Behavior:
          - Analyzes type annotations and infers types
          - Reports missing type hints where inferred types conflict
          - Checks function argument types against signatures
          - Validates attribute access on typed objects
          - Catches common type errors (None checks, incompatible operations)
          - Produces detailed error messages with suggestions

        Response Structure:
          - path: File/directory analyzed
          - status: "success" or "errors_found"
          - error_count: Total number of type errors
          - errors: Array of error objects
            * file: File containing error
            * line: Line number (1-indexed)
            * column: Column number (1-indexed)
            * message: Detailed error message
            * error_code: mypy error code (e.g., "var-annotated")
            * suggestion: Suggested fix (if available)
          - success_count: Number of successfully type-checked items
          - check_time_ms: Type check execution time

        Status Codes:
          - 200: Success - Type check completed (may report errors)
          - 400: Bad Request - Invalid path or mypy configuration
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "File or directory path relative to task directory",
                    "minLength": 1,
                    "maxLength": 255,
                },
                "strict": {
                    "type": "boolean",
                    "description": "Enable strict type checking mode",
                    "default": False,
                },
                "ignore_missing_imports": {
                    "type": "boolean",
                    "description": "Ignore errors from untyped third-party libraries",
                    "default": True,
                },
                "show_error_codes": {
                    "type": "boolean",
                    "description": "Show mypy error codes in output",
                    "default": True,
                },
                "max_errors": {
                    "type": "integer",
                    "description": "Maximum errors to report before stopping",
                    "minimum": 1,
                    "maximum": 500,
                    "default": 100,
                },
            },
            "required": ["path"],
        },
    },
    {
        "name": "get_test_coverage",
        "description": """Analyze test coverage for Python files.

        Runs coverage.py to measure which lines of code are executed by tests.
        Shows coverage percentage per file/function, identifying untested code paths.
        Useful for understanding test completeness and finding missing edge cases.

        Required Parameters:
          - path: File or directory path relative to task directory (optional, default: '.')

        Optional Parameters:
          - branch_coverage: Include branch coverage (if/else paths, default: false)
          - include_missing: Show which lines are not covered (default: true)
          - fail_under: Minimum coverage % required (0-100, default: 0)

        Coverage Behavior:
          - Runs test suite and tracks line execution
          - Shows coverage for each file
          - Shows coverage for each function/class
          - Identifies completely uncovered functions/methods
          - Can detect dead code (0% coverage)
          - Branch coverage shows if/else branches taken

        Response Structure:
          - total_coverage: Overall coverage percentage (0-100)
          - files: Array of file coverage objects
            * filename: File path
            * coverage: Coverage percentage
            * lines_total: Total executable lines
            * lines_covered: Lines executed by tests
            * missing_lines: Array of uncovered line numbers (if include_missing)
          - functions: Array of function coverage objects
            * name: Function name
            * file: File containing function
            * coverage: Coverage percentage (0 or 100 for line coverage)
            * line_number: Function definition line
          - status: "covered", "partially_covered", or "uncovered" based on fail_under
          - check_time_ms: Coverage analysis time

        Status Codes:
          - 200: Success - Coverage analyzed
          - 400: Bad Request - Invalid path or coverage configuration
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "File or directory path relative to task directory",
                    "minLength": 1,
                    "maxLength": 255,
                    "default": ".",
                },
                "branch_coverage": {
                    "type": "boolean",
                    "description": "Include branch (if/else) coverage analysis",
                    "default": False,
                },
                "include_missing": {
                    "type": "boolean",
                    "description": "Show which lines are not covered",
                    "default": True,
                },
                "fail_under": {
                    "type": "integer",
                    "description": "Minimum required coverage percentage (0-100)",
                    "minimum": 0,
                    "maximum": 100,
                    "default": 0,
                },
            },
            "required": [],
        },
    },
    {
        "name": "list_directory",
        "description": """List files and directories in the task working directory.

        Returns a directory tree showing file structure, sizes, types, and metadata.
        Useful for understanding what files exist and their organization before
        starting to debug or edit code.

        Required Parameters: None (default: current task directory)

        Optional Parameters:
          - path: Subdirectory path relative to task root (default: '.')
          - recursive: Include subdirectories recursively (default: true)
          - max_depth: Maximum directory nesting depth (default: unlimited)
          - include_hidden: Include hidden files/folders starting with . (default: false)
          - file_types: Filter by file type (py, all, test, etc.)

        Directory Listing:
          - Shows files and folders in hierarchical structure
          - Includes file size in bytes
          - Shows file type/extension
          - Marks executable files
          - Marks test files separately
          - Indicates if file is readable/writable

        Response Structure:
          - root_path: Base directory path
          - total_files: Total number of files (excluding directories)
          - total_directories: Total number of subdirectories
          - items: Array of directory entry objects
            * name: File or directory name
            * type: "file" or "directory"
            * path: Full path relative to task root
            * size_bytes: File size in bytes (for files)
            * is_test: Whether file matches test pattern (test_*.py)
            * is_executable: Whether file is executable
            * contents: Array of child items (for directories if recursive)
          - tree_depth: Maximum nesting depth found

        Status Codes:
          - 200: Success - Directory listed
          - 404: Not Found - Directory path does not exist
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "Subdirectory path relative to task root",
                    "default": ".",
                    "maxLength": 255,
                },
                "recursive": {
                    "type": "boolean",
                    "description": "Include subdirectories recursively",
                    "default": True,
                },
                "max_depth": {
                    "type": "integer",
                    "description": "Maximum directory nesting depth (0 for unlimited)",
                    "minimum": 0,
                    "default": 0,
                },
                "include_hidden": {
                    "type": "boolean",
                    "description": "Include hidden files/folders starting with .",
                    "default": False,
                },
                "file_types": {
                    "type": "string",
                    "description": "Filter by file type",
                    "enum": ["py", "all", "test", "source"],
                    "default": "all",
                },
            },
            "required": [],
        },
    },
    {
        "name": "get_dependencies",
        "description": """Extract and analyze Python import dependencies.

        Parses import statements to build a dependency graph showing what modules/files
        depend on each other. Useful for understanding code relationships and identifying
        circular dependencies or unexpected coupling.

        Required Parameters:
          - path: File or directory path relative to task directory (e.g., 'broken_code.py' or '.')

        Optional Parameters:
          - include_stdlib: Include Python standard library imports (default: false)
          - include_external: Include third-party library imports (default: true)
          - direction: Show imports "to" (what this imports) or "from" (what imports this)
                       (default: "to")
          - depth: Maximum depth to follow dependencies (default: 1)

        Dependency Analysis:
          - Extracts all import statements (import x, from x import y)
          - Categorizes imports (local, stdlib, external)
          - Builds dependency graph showing import relationships
          - Detects circular dependencies (A imports B, B imports A)
          - Shows unused imports
          - Maps relative imports to absolute module paths

        Response Structure:
          - path: File or directory analyzed
          - direct_dependencies: Array of direct imports
            * module: Module being imported
            * type: "import" or "from...import"
            * items: What was imported (if from...import)
            * source_file: File being imported FROM (if local import)
            * is_local: Whether importing from task code
            * line_number: Import statement line number
          - indirect_dependencies: Array of transitive dependencies (if depth > 1)
            * module: Module name
            * via: Path showing how it's imported
            * chain_length: Number of imports deep
          - circular_dependencies: Array of detected cycles
            * cycle: Array of module names forming cycle
            * files: File paths involved in cycle
          - unused_imports: Imports that appear to be unused
            * module: Imported but never referenced
            * file: File with unused import
            * line_number: Import location
          - dependency_count: Total number of dependencies

        Status Codes:
          - 200: Success - Dependencies extracted
          - 400: Bad Request - Invalid path or syntax error in files
          - 500: Internal Server Error
        """,
        "inputSchema": {
            "type": "object",
            "properties": {
                "path": {
                    "type": "string",
                    "description": "File or directory path relative to task directory",
                    "minLength": 1,
                    "maxLength": 255,
                },
                "include_stdlib": {
                    "type": "boolean",
                    "description": "Include Python standard library imports",
                    "default": False,
                },
                "include_external": {
                    "type": "boolean",
                    "description": "Include third-party library imports",
                    "default": True,
                },
                "direction": {
                    "type": "string",
                    "description": "Show imports 'to' (what this imports) or 'from' (what imports this)",
                    "enum": ["to", "from"],
                    "default": "to",
                },
                "depth": {
                    "type": "integer",
                    "description": "Maximum depth to follow dependencies",
                    "minimum": 1,
                    "maximum": 5,
                    "default": 1,
                },
            },
            "required": ["path"],
        },
    },
]