从配置中解析 hooks
(merged: dict)
| 167 | |
| 168 | @staticmethod |
| 169 | def _parse_hooks(merged: dict) -> dict[str, list[str]]: |
| 170 | """从配置中解析 hooks""" |
| 171 | hooks_raw = merged.get("hooks", {}) |
| 172 | result = {"pre_tool_use": [], "post_tool_use": []} |
| 173 | |
| 174 | for hook_def in hooks_raw.get("PreToolUse", []): |
| 175 | if isinstance(hook_def, dict) and "command" in hook_def: |
| 176 | result["pre_tool_use"].append(hook_def["command"]) |
| 177 | elif isinstance(hook_def, str): |
| 178 | result["pre_tool_use"].append(hook_def) |
| 179 | |
| 180 | for hook_def in hooks_raw.get("PostToolUse", []): |
| 181 | if isinstance(hook_def, dict) and "command" in hook_def: |
| 182 | result["post_tool_use"].append(hook_def["command"]) |
| 183 | elif isinstance(hook_def, str): |
| 184 | result["post_tool_use"].append(hook_def) |
| 185 | |
| 186 | return result |
| 187 | |
| 188 | |
| 189 | # ============================================================ |