| 1 | # extension.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `extension.py` helper module. |
| 6 | - This module discovers and dispatches Python and WebUI extension hooks. |
| 7 | - Keep this file-level DOX profile synchronized with `extension.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `extension.py` owns the runtime implementation. |
| 12 | - `extension.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `_Unset` (no explicit base class) |
| 15 | - `Extension` (no explicit base class) |
| 16 | - `execute(self, **kwargs) -> None | Awaitable[None]` |
| 17 | - Top-level functions: |
| 18 | - `_log_extension_call(name: str)` |
| 19 | - `extensible(func)`: Make a function emit two implicit extension points around its execution. |
| 20 | - `async call_extensions_async(extension_point: str, agent: 'Agent|None'=..., **kwargs)` |
| 21 | - `call_extensions_sync(extension_point: str, agent: 'Agent|None'=..., **kwargs)` |
| 22 | - `get_webui_extensions(agent: 'Agent | None', extension_point: str, filters: list[str] | None=...)` |
| 23 | - `get_webui_extension_manifest(agent: 'Agent | None') -> dict[str, dict[str, list[str]]]` |
| 24 | - `_get_extension_classes(extension_point: str, agent: 'Agent|None'=..., **kwargs) -> list[Type[Extension]]` |
| 25 | - `_get_file_from_module(module_name: str) -> str` |
| 26 | - `_get_extensions(folder: str)` |
| 27 | - `register_extensions_watchdogs()` |
| 28 | - Notable constants/configuration names: `DEFAULT_EXTENSIONS_FOLDER`, `USER_EXTENSIONS_FOLDER`, `_EXTENSIONS_CACHE_AREA`, `_CLASSES_CACHE_AREA`, `_WEBUI_MANIFEST_CACHE_AREA`, `_WEBUI_MANIFEST_SUFFIXES`, `_UNSET`, `_EXTENSIONS_LOG_COUNTS`. |
| 29 | |
| 30 | ## Runtime Contracts |
| 31 | |
| 32 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 33 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 34 | - `Extension` defines `execute(...)`. |
| 35 | - Observed side-effect areas: filesystem reads, WebSocket state, plugin state. |
| 36 | - Imported dependency areas include: `abc`, `functools`, `helpers`, `helpers.print_style`, `inspect`, `os`, `typing`. |
| 37 | |
| 38 | ## Key Concepts |
| 39 | |
| 40 | - Important called helpers/classes observed in the source: `_Unset`, `inspect.iscoroutinefunction`, `wraps`, `_log_extension_call`, `_get_extension_classes`, `subagents.get_paths`, `cache.determine_cache_key`, `cache.add`, `files.get_abs_path`, `modules.load_classes_from_folder`, `watchdog.add_watchdog`, `os.path.join`, `_get_agent`, `_prepare_inputs`, `_process_result`, `call_extensions_sync`, `cls.execute`, `files.deabsolute_path`, `_get_file_from_module`, `module_name.split`. |
| 41 | - `get_webui_extension_manifest()` scans enabled WebUI extension roots once, preserves root/filter ordering, groups URLs into `html` and `js` maps by extension point, and caches under extension/plugin invalidation scopes for injection into the rendered index. |
| 42 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 43 | |
| 44 | ## Work Guidance |
| 45 | |
| 46 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 47 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 48 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 49 | |
| 50 | ## Verification |
| 51 | |
| 52 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 53 | - Related tests observed by source search: |
| 54 | - `tests/test_a0_connector_prompt_gating.py` |
| 55 | - `tests/test_api_chat_lifetime.py` |
| 56 | - `tests/test_browser_agent_regressions.py` |
| 57 | - `tests/test_error_retry_plugin.py` |
| 58 | - `tests/test_extensions_stress.py` |
| 59 | - `tests/test_history_compression_wait.py` |
| 60 | - `tests/test_model_config_api_keys.py` |
| 61 | - `tests/test_oauth_codex.py` |
| 62 | |
| 63 | ## Child DOX Index |
| 64 | |
| 65 | No child DOX files. |