| 1 | # log.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `log.py` helper module. |
| 6 | - This module owns chat log items, outputs, truncation, and dirty-state integration. |
| 7 | - Keep this file-level DOX profile synchronized with `log.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `log.py` owns the runtime implementation. |
| 12 | - `log.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `LogItem` (no explicit base class) |
| 15 | - `update(self, type: Type | None=..., heading: str | None=..., content: str | None=..., kvps: dict | None=..., update_progress: ProgressUpdate | None=..., **kwargs)` |
| 16 | - `stream(self, heading: str | None=..., content: str | None=..., **kwargs)` |
| 17 | - `output(self)` |
| 18 | - `LogOutput` (no explicit base class) |
| 19 | - `Log` (no explicit base class) |
| 20 | - `log(self, type: Type, heading: str | None=..., content: str | None=..., kvps: dict | None=..., update_progress: ProgressUpdate | None=..., id: Optional[str]=..., **kwargs) -> LogItem` |
| 21 | - `set_progress(self, progress: str, no: int=..., active: bool=...)` |
| 22 | - `set_initial_progress(self)` |
| 23 | - `output(self, start=..., end=...)` |
| 24 | - `reset(self)` |
| 25 | - Top-level functions: |
| 26 | - `_lazy_mark_dirty_all(reason: str | None=...) -> None` |
| 27 | - `_lazy_mark_dirty_for_context(context_id: str, reason: str | None=...) -> None` |
| 28 | - `_truncate_heading(text: str | None) -> str` |
| 29 | - `_truncate_progress(text: str | None) -> str` |
| 30 | - `_truncate_key(text: str) -> str` |
| 31 | - `_truncate_value(val: T) -> T` |
| 32 | - `_truncate_content(text: str | None, type: Type) -> str` |
| 33 | - Notable constants/configuration names: `_MARK_DIRTY_ALL`, `_MARK_DIRTY_FOR_CONTEXT`, `T`, `HEADING_MAX_LEN`, `CONTENT_MAX_LEN`, `RESPONSE_CONTENT_MAX_LEN`, `KEY_MAX_LEN`, `VALUE_MAX_LEN`, `PROGRESS_MAX_LEN`. |
| 34 | |
| 35 | ## Runtime Contracts |
| 36 | |
| 37 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 38 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 39 | - Observed side-effect areas: filesystem writes, filesystem deletion, settings/state persistence, secret handling, scheduler state. |
| 40 | - Imported dependency areas include: `collections`, `copy`, `dataclasses`, `helpers.secrets`, `helpers.strings`, `json`, `threading`, `time`, `typing`, `uuid`. |
| 41 | |
| 42 | ## Key Concepts |
| 43 | |
| 44 | - Important called helpers/classes observed in the source: `TypeVar`, `dataclass`, `_MARK_DIRTY_ALL`, `_MARK_DIRTY_FOR_CONTEXT`, `truncate_text_by_ratio`, `cast`, `threading.RLock`, `self.set_initial_progress`, `self._update_item`, `self._notify_state_monitor`, `_lazy_mark_dirty_all`, `_lazy_mark_dirty_for_context`, `self._mask_recursive`, `_truncate_progress`, `self.set_progress`, `LogOutput`, `_truncate_value`, `json.dumps`, `time.time`, `self.log._update_item`. |
| 45 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 46 | - Keyword KVP updates use the same recursive key/value truncation as an explicit `kvps` mapping, preventing streamed reasoning and other live fields from bypassing payload limits. |
| 47 | - Existing log-item and progress updates mark only the selected context stream dirty and explicitly omit unchanged context/task collections; creating a new log item still broadcasts a full collection refresh. |
| 48 | |
| 49 | ## Work Guidance |
| 50 | |
| 51 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 52 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 53 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 54 | |
| 55 | ## Verification |
| 56 | |
| 57 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 58 | - Related tests observed by source search: |
| 59 | - `tests/test_browser_agent_regressions.py` |
| 60 | - `tests/test_chat_compaction.py` |
| 61 | - `tests/test_error_retry_plugin.py` |
| 62 | - `tests/test_fasta2a_client.py` |
| 63 | - `tests/test_file_tree_visualize.py` |
| 64 | - `tests/test_history_compression_wait.py` |
| 65 | - `tests/test_http_auth_csrf.py` |
| 66 | - `tests/test_mcp_handler_multimodal.py` |
| 67 | |
| 68 | ## Child DOX Index |
| 69 | |
| 70 | No child DOX files. |