()
| 1115 | # ============================================================ |
| 1116 | |
| 1117 | def cheatsheet(): |
| 1118 | print("=" * 60) |
| 1119 | print("速查表: 设计模式 → Claude Code 源码 → Python") |
| 1120 | print("=" * 60) |
| 1121 | print(""" |
| 1122 | 模式 Claude Code 源码 Python 等价 |
| 1123 | ───────── ──────────────────────────────── ────────────────── |
| 1124 | 接口 trait ApiClient ABC / Protocol |
| 1125 | 依赖注入 ConversationRuntime<C, T> __init__(client, executor) |
| 1126 | Builder SystemPromptBuilder.with_*() 方法返回 self 链式调用 |
| 1127 | 注册表 StaticToolExecutor.register() dict[str, Callable] |
| 1128 | 策略 PermissionMode 枚举 IntEnum + >= 比较 |
| 1129 | |
| 1130 | mini-claude-code 中的应用: |
| 1131 | ───────────────────────── |
| 1132 | ApiClient(ABC) → 实现 stream() 调 Claude API |
| 1133 | ToolExecutor(ABC) → 注册 bash/read/write/grep 等工具 |
| 1134 | PermissionChecker → 根据模式决定允许/拒绝/询问 |
| 1135 | PromptBuilder → 组装 system prompt (静态+动态) |
| 1136 | AgenticRuntime → 注入以上所有, run_turn() 循环 |
| 1137 | |
| 1138 | 何时用哪个: |
| 1139 | ────────── |
| 1140 | "同一个动作, 多种实现" → 接口 + 策略 |
| 1141 | "对象太复杂, 参数太多" → Builder |
| 1142 | "按名字找处理函数" → 注册表 |
| 1143 | "内部不该知道外部实现" → 依赖注入 |
| 1144 | """) |
| 1145 | |
| 1146 | |
| 1147 | # ============================================================ |
no outgoing calls
no test coverage detected