| 1 | # subagents.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `subagents.py` helper module. |
| 6 | - This module discovers, merges, loads, and saves agent profile definitions. |
| 7 | - Keep this file-level DOX profile synchronized with `subagents.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `subagents.py` owns the runtime implementation. |
| 12 | - `subagents.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `SubAgentListItem` (`BaseModel`) |
| 15 | - `post_validator(self)` |
| 16 | - `SubAgent` (`SubAgentListItem`) |
| 17 | - Profile metadata includes optional avatar metadata and merges by key presence: |
| 18 | a missing key inherits, while a present empty value explicitly clears it. |
| 19 | - Top-level functions: |
| 20 | - `get_agents_list(project_name: str | None=...) -> list[SubAgentListItem]` |
| 21 | - `get_agents_dict(project_name: str | None=...) -> dict[str, SubAgentListItem]` |
| 22 | - `_get_agents_list_from_dir(dir: str, origin: Origin) -> dict[str, SubAgentListItem]` |
| 23 | - `load_agent_data(name: str, project_name: str | None=...) -> SubAgent` |
| 24 | - `save_agent_data(name: str, subagent: SubAgent) -> None` |
| 25 | - `delete_agent_data(name: str) -> None` |
| 26 | - `_load_agent_data_from_dir(dir: str, name: str, origin: Origin) -> SubAgent | None` |
| 27 | - `_read_agent_definition(dir: str, name: str) -> dict` |
| 28 | - `_merge_agent(base: SubAgent | None, override: SubAgent | None) -> SubAgent | None` |
| 29 | - `_merge_agent_list_item(base: SubAgentListItem, override: SubAgentListItem) -> SubAgentListItem` |
| 30 | - `_merge_agent_metadata(base: SubAgentListItem, override: SubAgentListItem) -> dict` |
| 31 | - `get_agents_roots() -> list[str]` |
| 32 | - `get_all_agents_list() -> list[dict[str, str]]` |
| 33 | - `get_default_promp_file_names() -> list[str]` |
| 34 | - `get_available_agents_dict(project_name: str | None) -> dict[str, SubAgentListItem]` |
| 35 | - `get_paths(agent: 'Agent|None', *subpaths, must_exist_completely: bool=..., include_project: bool=..., include_user: bool=..., include_default: bool=..., include_plugins: bool=..., default_root: str=...) -> list[str]`: Returns list of file paths for the given agent and subpaths, searched in order of priority: |
| 36 | - Notable constants/configuration names: `GLOBAL_DIR`, `USER_DIR`, `DEFAULT_AGENTS_DIR`, `USER_AGENTS_DIR`, `PATHS_CACHE_AREA`. |
| 37 | |
| 38 | ## Runtime Contracts |
| 39 | |
| 40 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 41 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 42 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, plugin state, settings/state persistence. |
| 43 | - Nonexistent profile layers return `None` instead of synthesizing empty overrides. |
| 44 | - Imported dependency areas include: `helpers`, `json`, `os`, `pydantic`, `typing`. |
| 45 | |
| 46 | ## Key Concepts |
| 47 | |
| 48 | - Presence-aware merging uses Pydantic's `model_dump(exclude_unset=True)` so |
| 49 | missing keys inherit while explicitly empty values remain overrides. Runtime |
| 50 | `name`, `path`, `origin`, and `prompts` fields are handled separately; derived |
| 51 | title fallbacks do not become authored overrides. |
| 52 | - Available-profile resolution includes definitions from the selected project, |
| 53 | then applies that project's sparse `agents.json` availability overrides. |
| 54 | - `get_all_agents_list()` is the shared presentation catalog and omits the exact |
| 55 | `default` utility profile. Runtime discovery and loading remain unchanged. |
| 56 | - Bundled directories require an authored profile definition; the `_example` |
| 57 | reference directory is never selectable. Every real profile, including |
| 58 | `Default`, follows the same Global and project availability rules. |
| 59 | - Important called helpers/classes observed in the source: `cache.toggle_area`, `model_validator`, `_get_agents_list_from_dir`, `plugins.get_enabled_plugin_paths`, `_merge_agent_dicts`, `files.get_subdirectories`, `_load_agent_data_from_dir`, `_merge_agent`, `files.write_file`, `files.delete_dir`, `SubAgent`, `SubAgentListItem`, `files.find_existing_paths_by_pattern`, `get_agents_roots`, `files.list_files`, `get_agents_dict`, `cache.determine_cache_key`, `cache.add`, `projects.get_project_meta`, `FileNotFoundError`. |
| 60 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 61 | |
| 62 | ## Work Guidance |
| 63 | |
| 64 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 65 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 66 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 67 | |
| 68 | ## Verification |
| 69 | |
| 70 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 71 | - Related tests observed by source search: |
| 72 | - `tests/test_skills_runtime.py` |
| 73 | - `tests/test_subagent_metadata_merge.py` |
| 74 | |
| 75 | ## Child DOX Index |
| 76 | |
| 77 | No child DOX files. |