tldr-deep
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTLDR Deep Analysis
TLDR深度分析
Full 5-layer analysis of a specific function. Use when debugging or deeply understanding code.
针对特定函数的完整5层分析。用于调试或深度理解代码场景。
Trigger
触发方式
/tldr-deep <function_name>- "analyze function X in detail"
- "I need to deeply understand how Y works"
- Debugging complex functions
/tldr-deep <function_name>- "深度分析函数X"
- "我需要深度理解Y的工作原理"
- 调试复杂函数
Layers
分析层级
| Layer | Purpose | Command |
|---|---|---|
| L1: AST | Structure | |
| L2: Call Graph | Navigation | |
| L3: CFG | Complexity | |
| L4: DFG | Data flow | |
| L5: Slice | Dependencies | |
| 层级 | 用途 | 命令 |
|---|---|---|
| L1: AST | 结构分析 | |
| L2: Call Graph | 调用关系导航 | |
| L3: CFG | 复杂度分析 | |
| L4: DFG | 数据流分析 | |
| L5: Slice | 依赖分析 | |
Execution
执行步骤
Given a function name, run all layers:
bash
undefined给定函数名称后,运行所有层级分析:
bash
undefinedFirst find the file
首先找到文件
tldr search "def <function_name>" .
tldr search "def <function_name>" .
Then run each layer
然后运行每个层级的分析
tldr extract <found_file> # L1: Full file structure
tldr context <function_name> --project . --depth 2 # L2: Call graph
tldr cfg <found_file> <function_name> # L3: Control flow
tldr dfg <found_file> <function_name> # L4: Data flow
tldr slice <found_file> <function_name> <target_line> # L5: Slice
undefinedtldr extract <found_file> # L1: 完整文件结构
tldr context <function_name> --project . --depth 2 # L2: 调用图
tldr cfg <found_file> <function_name> # L3: 控制流
tldr dfg <found_file> <function_name> # L4: 数据流
tldr slice <found_file> <function_name> <target_line> # L5: 程序切片
undefinedOutput Format
输出格式
undefinedundefinedDeep Analysis: {function_name}
深度分析: {function_name}
L1: Structure (AST)
L1: 结构分析 (AST)
File: {file_path}
Signature: {signature}
Docstring: {docstring}
文件路径: {file_path}
函数签名: {signature}
文档字符串: {docstring}
L2: Call Graph
L2: 调用图
Calls: {list of functions this calls}
Called by: {list of functions that call this}
调用的函数: {list of functions this calls}
被以下函数调用: {list of functions that call this}
L3: Control Flow (CFG)
L3: 控制流 (CFG)
Blocks: {N}
Cyclomatic Complexity: {M}
[Hot if M > 10]
Branches:
- if: line X
- for: line Y
- ...
代码块数量: {N}
圈复杂度: {M}
[若M>10则为高复杂度热点]
分支点:
- if: 第X行
- for: 第Y行
- ...
L4: Data Flow (DFG)
L4: 数据流 (DFG)
Variables defined:
- {var1} @ line X
- {var2} @ line Y Variables used:
- {var1} @ lines [A, B, C]
- {var2} @ lines [D, E]
定义的变量:
- {var1} @ 第X行
- {var2} @ 第Y行 使用的变量:
- {var1} @ 第[A, B, C]行
- {var2} @ 第[D, E]行
L5: Program Slice (affecting line {target})
L5: 程序切片(影响第{target}行)
Lines in slice: {N}
Key dependencies:
- line X → line Y (data)
- line A → line B (control)
Total: ~{tokens} tokens (95% savings vs raw file)
undefined切片包含的行数: {N}
关键依赖:
- 第X行 → 第Y行 (数据依赖)
- 第A行 → 第B行 (控制依赖)
总Token数: ~{tokens}个(相比原始文件节省95%)
undefinedWhen to Use
使用场景
- Debugging - Need to understand all paths through a function
- Refactoring - Need to know what depends on what
- Code review - Analyzing complex functions
- Performance - Finding hot spots (high cyclomatic complexity)
- 调试 - 需要理解函数的所有执行路径
- 重构 - 需要了解代码间的依赖关系
- 代码评审 - 分析复杂函数的实现逻辑
- 性能优化 - 查找高圈复杂度的热点代码
Programmatic API
程序化API
python
from tldr.api import (
extract_file,
get_relevant_context,
get_cfg_context,
get_dfg_context,
get_slice
)python
from tldr.api import (
extract_file,
get_relevant_context,
get_cfg_context,
get_dfg_context,
get_slice
)All layers for one function
针对单个函数的全层级分析
file_info = extract_file("src/processor.py")
context = get_relevant_context("src/", "process_data", depth=2)
cfg = get_cfg_context("src/processor.py", "process_data")
dfg = get_dfg_context("src/processor.py", "process_data")
slice_lines = get_slice("src/processor.py", "process_data", target_line=42)
undefinedfile_info = extract_file("src/processor.py")
context = get_relevant_context("src/", "process_data", depth=2)
cfg = get_cfg_context("src/processor.py", "process_data")
dfg = get_dfg_context("src/processor.py", "process_data")
slice_lines = get_slice("src/processor.py", "process_data", target_line=42)
undefined