main
md 72 lines 3.91 KB
Rendered Raw
1 # watchdog.py DOX
2
3 ## Purpose
4
5 - Own the `watchdog.py` helper module.
6 - This module registers filesystem watchdogs with debouncing and path filtering.
7 - Keep this file-level DOX profile synchronized with `watchdog.py` because this directory is intentionally flat.
8
9 ## Ownership
10
11 - `watchdog.py` owns the runtime implementation.
12 - `watchdog.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation.
13 - Classes:
14 - `_DispatchHandler` (no explicit base class)
15 - `dispatch(self, event: Any)`
16 - `_Watch` (no explicit base class)
17 - `_PendingBatch` (no explicit base class)
18 - `_WatchRegistry` (no explicit base class)
19 - `add(self, id: str, roots: list[str], patterns: list[str] | None, ignore_patterns: list[str] | None, events: WatchEvents, debounce: float, handler: WatchHandler) -> None`
20 - `remove(self, id: str) -> bool`
21 - `clear(self) -> None`
22 - `start(self) -> None`
23 - `stop(self) -> None`
24 - `dispatch(self, scheduled_root: str, event: Any) -> None`
25 - Top-level functions:
26 - `_normalize_root(root: str) -> str`
27 - `_normalize_roots(roots: list[str]) -> list[str]`
28 - `_normalize_patterns(patterns: list[str] | None, default: list[str] | None=...) -> list[str]`
29 - `_normalize_events(events: WatchEvents) -> frozenset[WatchEvent]`
30 - `_map_event_type(event_type: str) -> WatchEvent | None`
31 - `_normalize_debounce(debounce: float) -> float`
32 - `_covering_roots(roots: Iterable[str]) -> set[str]`
33 - `_is_same_or_nested(path: str, root: str) -> bool`
34 - `_is_under_watch(path: str, watch: _Watch) -> bool`
35 - `_compile_matcher(root: str, patterns: list[str], ignore_patterns: list[str]) -> PatternMatcher`
36 - `_compile_single_matcher(root: str, patterns: list[str]) -> PatternMatcher`
37 - `add_watchdog(id: str, roots: list[str], patterns: list[str] | None=..., ignore_patterns: list[str] | None=..., events: WatchEvents=..., debounce: float=..., handler: WatchHandler | None=...) -> None`
38 - `remove_watchdog(id: str) -> bool`
39 - `clear_watchdogs() -> None`
40 - `start_watchdog_daemon() -> None`
41 - `stop_watchdog_daemon() -> None`
42 - Notable constants/configuration names: `_DEFAULT_PATTERNS`, `_DEFAULT_IGNORE_PATTERNS`, `_VALID_EVENTS`, `_EVENT_ALIASES`.
43
44 ## Runtime Contracts
45
46 - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.
47 - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.
48 - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion.
49 - Imported dependency areas include: `__future__`, `dataclasses`, `os`, `pathlib`, `threading`, `typing`, `watchdog.observers`.
50
51 ## Key Concepts
52
53 - Important called helpers/classes observed in the source: `frozenset`, `dataclass`, `_WatchRegistry`, `_registry.start`, `os.path.abspath`, `_compile_single_matcher`, `_registry.add`, `_registry.remove`, `_registry.clear`, `_registry.stop`, `self.registry.dispatch`, `threading.RLock`, `self._ensure_watchdog_available`, `_normalize_roots`, `_normalize_patterns`, `_normalize_events`, `_normalize_debounce`, `self._stop_observer`, `_map_event_type`, `_covering_roots`.
54 - Keep request/response, tool, or helper semantics documented here at the same time as source changes.
55
56 ## Work Guidance
57
58 - Preserve public helper APIs used by core code and plugins unless every caller is updated.
59 - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded.
60 - Prefer adding cohesive helper functions here only when behavior is reused across modules.
61
62 ## Verification
63
64 - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers.
65 - Related tests observed by source search:
66 - `tests/test_model_config_api_keys.py`
67 - `tests/test_model_config_project_presets.py`
68 - `tests/test_time_travel.py`
69
70 ## Child DOX Index
71
72 No child DOX files.