analyze_code
Detect resource leaks, security vulnerabilities, and logic flaws in Python code via static AST analysis. Use before committing or running to catch defects without executing code.
Instructions
Performs static AST code analysis using Tree-sitter to detect resource leaks (such as unclosed file handles), security vulnerabilities, and logic flaws with bounded execution limits and precise LSP UTF-16 coordinates.
• Side Effects: None. Strictly read-only analysis of in-memory code; does not execute code, spawn subprocesses, or write to disk. • Auth & Permissions: None required. Fully offline, in-memory parser. • Rate Limits: None. Bounded to 1MB max source size, 128 max AST depth, and 50,000 max node visits per call. • Return Shape: Returns a JSON object containing 'language', 'findings_count', 'duration_ms' (latency metric), and 'findings' (array of objects with rule_id, message, severity, line [1-indexed], column [1-indexed UTF-16 code units], and remediation). • Failure Modes: Returns findings: [] if the code contains no detected defects. Returns an error message if the language is unsupported or if source code exceeds the 1MB or 128 AST depth limits. • When to use: Use proactively before committing or running code, or when reviewing Python files for unclosed file handles, resource leaks, or AST defects. • When NOT to use: Do NOT use when you have an active runtime crash log (use get_error_context instead), and do NOT use to apply fixes automatically (use apply_code_patch instead). • Prerequisites: Supported languages currently include Python ('python', 'py').
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Raw source code string to analyze. Must not exceed 1,000,000 bytes (1MB). Does not execute runtime code; strictly parsed via Tree-sitter AST. | |
| language | Yes | Programming language identifier for the code snippet. Case-insensitive. Supported values: 'python', 'py'. |