Coverage for little_loops / hooks / pre_tool_use.py: 0%

8 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2026-06-08 15:34 -0500

1"""PreToolUse hook handler: learning-test discoverability gate (FEAT-1742). 

2 

3Dispatches Write/Edit tool calls to the learning_tests_gate for import 

4detection and registry probing. All other tool calls pass through unchanged. 

5 

6The gate is a no-op when ``learning_tests.enabled`` is false (default) or 

7``learning_tests.discoverability.mode`` is ``"off"``. When enabled, it 

8emits a soft nudge (warn mode, exit 0) or blocks (block mode, exit 2) when 

9a file being written imports packages with no proven Learning Test record. 

10 

11Claude Code wires this handler via 

12``hooks/adapters/claude-code/pre-tool-use.sh`` for the ``"Write|Edit"`` 

13matcher in ``hooks/hooks.json``. Codex and OpenCode users opt in separately 

14— see ``hooks/adapters/codex/README.md`` and 

15``hooks/adapters/opencode/README.md``. 

16""" 

17 

18from __future__ import annotations 

19 

20from little_loops.hooks.types import LLHookEvent, LLHookResult 

21 

22 

23def handle(event: LLHookEvent) -> LLHookResult: 

24 """Dispatch Write/Edit to discoverability gate; pass-through for other tools.""" 

25 tool_name = event.payload.get("tool_name", "") 

26 if tool_name in {"Write", "Edit"}: 

27 from little_loops.hooks.learning_tests_gate import gate 

28 

29 return gate(event) 

30 return LLHookResult(exit_code=0)