tldr-deep

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TLDR 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

分析层级

LayerPurposeCommand
L1: ASTStructure
tldr extract <file>
L2: Call GraphNavigation
tldr context <func> --depth 2
L3: CFGComplexity
tldr cfg <file> <func>
L4: DFGData flow
tldr dfg <file> <func>
L5: SliceDependencies
tldr slice <file> <func> <line>
层级用途命令
L1: AST结构分析
tldr extract <file>
L2: Call Graph调用关系导航
tldr context <func> --depth 2
L3: CFG复杂度分析
tldr cfg <file> <func>
L4: DFG数据流分析
tldr dfg <file> <func>
L5: Slice依赖分析
tldr slice <file> <func> <line>

Execution

执行步骤

Given a function name, run all layers:
bash
undefined
给定函数名称后,运行所有层级分析:
bash
undefined

First 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
undefined
tldr 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: 程序切片
undefined

Output Format

输出格式

undefined
undefined

Deep 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%)
undefined

When to Use

使用场景

  1. Debugging - Need to understand all paths through a function
  2. Refactoring - Need to know what depends on what
  3. Code review - Analyzing complex functions
  4. Performance - Finding hot spots (high cyclomatic complexity)
  1. 调试 - 需要理解函数的所有执行路径
  2. 重构 - 需要了解代码间的依赖关系
  3. 代码评审 - 分析复杂函数的实现逻辑
  4. 性能优化 - 查找高圈复杂度的热点代码

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)
undefined
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)
undefined