analyze_python_ast
Perform AST-level precise analysis of Python code to find symbols, fields, strings, calls, and imports with contextual function names and confidence scores, enabling accurate code searches beyond grep.
Instructions
对 Python 代码做 AST 级别精确分析,比 grep 更准确。支持多种搜索目标,可同时指定多类:
symbols: 任何标识符(变量名、类名、常量名)
field_names: 字段/属性名(捕获 obj.field / obj['field'] / obj.get('field'))
string_values: 字符串字面量值(捕获代码中的字符串常量)
call_names: 函数/方法调用名
import_names: 导入的模块或符号名 每个命中都标注所在函数名、访问方式和置信度,适合需要精确上下文的场景。返回按文件聚合的 JSON:{total_found, returned, truncated, files:[{file:相对路径, hits:[{line, kind, value, extra, function, confidence}]}]}。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbols | No | 标识符名列表,如 ['AllEq', 'DEFAULT_TTL'] | |
| call_names | No | 函数/方法调用名列表,如 ['get_eq_partition'] | |
| field_names | No | 字段/属性名列表,如 ['x', 'y', 'status'] | |
| max_results | No | 最大返回结果数,默认 500;truncated=true 时可增大后重试 | |
| exclude_dirs | No | 排除目录,不传则使用默认排除列表,传 [] 则不排除任何目录 | |
| import_names | No | 导入符号/模块名列表,如 ['plogen_tools'] | |
| project_path | Yes | Python 项目根目录绝对路径 | |
| string_values | No | 字符串字面量值列表,如 ['success', 'failed'] |