关于 tldr-deep
tldr-deep 是面向开发者的代码分析 Skill,用于调试或深入理解函数。它通过五个层次检查代码结构、调用关系、控制流、数据流和依赖。
主要功能
- 01五层函数分析
- 02检查 AST 结构
- 03浏览调用图
- 04分析控制流与数据流
- 05切片追踪依赖
- 06通过 Python API 调用
适用场景
- 01追踪复杂函数的执行路径
- 02重构前检查依赖
- 03审查复杂代码
- 04查找高复杂度热点
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ parcadei/ continuous-claude-v3 --skill tldr-deep安装后在 Claude Code 中输入/tldr-deep确认已加载。
详细介绍
TLDR 深度分析
对特定函数进行完整的 5 层分析。适用于调试或深入理解代码。
触发方式
/tldr-deep <function_name>- “详细分析函数 X”
- “我需要深入了解 Y 的工作原理”
- 调试复杂函数
分层
| 层 | 用途 | 命令 |
|---|---|---|
| L1:AST | 结构 | tldr extract <file> |
| L2:调用图 | 导航 | tldr context <func> --depth 2 |
| L3:CFG | 复杂度 | tldr cfg <file> <func> |
| L4:DFG | 数据流 | tldr dfg <file> <func> |
| L5:切片 | 依赖关系 | tldr slice <file> <func> <line> |
执行
给定函数名,运行所有层:
# First find the file
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
输出格式
## Deep Analysis: {function_name}
### L1: Structure (AST)
File: {file_path}
Signature: {signature}
Docstring: {docstring}
### L2: Call Graph
Calls: {list of functions this calls}
Called by: {list of functions that call this}
### L3: Control Flow (CFG)
Blocks: {N}
Cyclomatic Complexity: {M}
[Hot if M > 10]
Branches:
- if: line X
- for: line Y
- ...
### L4: Data Flow (DFG)
Variables defined:
- {var1} @ line X
- {var2} @ line Y
Variables used:
- {var1} @ lines [A, B, C]
- {var2} @ lines [D, E]
### L5: Program Slice (affecting line {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)
适用场景
- 调试 - 需要了解函数的所有执行路径
- 重构 - 需要了解各项内容之间的依赖关系
- 代码审查 - 分析复杂函数
- 性能 - 查找热点(圈复杂度高)
编程 API
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)
评论
支持 Markdown