| 1 | # files.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `files.py` helper module. |
| 6 | - This module owns repository/user path helpers and file read/write/parsing primitives. |
| 7 | - Keep this file-level DOX profile synchronized with `files.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `files.py` owns the runtime implementation. |
| 12 | - `files.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `VariablesPlugin` (`ABC`) |
| 15 | - `get_variables(self, file: str, backup_dirs: list[str] | None=..., **kwargs) -> dict[str, Any]` |
| 16 | - Top-level functions: |
| 17 | - `load_plugin_variables(file: str, backup_dirs: list[str] | None=..., **kwargs) -> dict[str, Any]` |
| 18 | - `parse_file(_filename: str, _directories: list[str] | None=..., _encoding=..., **kwargs)` |
| 19 | - `read_prompt_file(_file: str, _directories: list[str] | None=..., _encoding=..., **kwargs)` |
| 20 | - `evaluate_text_conditions(_content: str, **kwargs)` |
| 21 | - `read_file(relative_path: str, encoding=...)` |
| 22 | - `read_file_json(relative_path: str, encoding=...)` |
| 23 | - `read_file_yaml(relative_path: str, encoding=...)` |
| 24 | - `read_file_bin(relative_path: str)` |
| 25 | - `read_file_base64(relative_path)` |
| 26 | - `is_probably_binary_bytes(data: bytes, threshold: float=...) -> bool`: Binary detection. |
| 27 | - `is_probably_binary_file(file_path: str, sample_size: int=..., threshold: float=...) -> bool`: Binary detection by reading only the first ~sample_size bytes of a file. |
| 28 | - `replace_placeholders_text(_content: str, **kwargs)` |
| 29 | - `replace_placeholders_json(_content: str, **kwargs)` |
| 30 | - `replace_placeholders_dict(_content: dict, **kwargs)` |
| 31 | - `process_includes(_content: str, _directories: list[str], _source_file: str=..., _source_dir: str=..., **kwargs)` |
| 32 | - `_get_dirs_after(_directories: list[str], _source_dir: str) -> list[str]`: Return directories after _source_dir in the priority list. |
| 33 | - `find_file_in_dirs(_filename: str, _directories: list[str])`: This function searches for a filename in a list of directories in order. |
| 34 | - `get_unique_filenames_in_dirs(dir_paths: list[str], pattern: str=..., type: Literal['file', 'dir', 'any']=...)` |
| 35 | - `find_existing_paths_by_pattern(pattern: str)` |
| 36 | - `remove_code_fences(text, language: str | None=...)`: Remove every code fence, or only fences for one language while preserving their contents. |
| 37 | - `is_full_json_template(text)` |
| 38 | - `write_file(relative_path: str, content: str, encoding: str=...)` |
| 39 | - `delete_file(relative_path: str)` |
| 40 | - `write_file_bin(relative_path: str, content: bytes)` |
| 41 | - `write_file_base64(relative_path: str, content: str)` |
| 42 | - `delete_dir(relative_path: str)` |
| 43 | - `move_dir(old_path: str, new_path: str)` |
| 44 | - `move_dir_safe(src, dst, rename_format=...)` |
| 45 | - `create_dir_safe(dst, rename_format=...)` |
| 46 | - `create_dir(relative_path: str)` |
| 47 | - Notable constants/configuration names: `AGENTS_DIR`, `PLUGINS_DIR`, `PROJECTS_DIR`, `EXTENSIONS_DIR`, `USER_DIR`, `TEMP_DIR`, `API_DIR`. |
| 48 | |
| 49 | ## Runtime Contracts |
| 50 | |
| 51 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 52 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 53 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, subprocess/runtime control, plugin state, settings/state persistence, secret handling. |
| 54 | - Imported dependency areas include: `abc`, `base64`, `fnmatch`, `glob`, `helpers`, `helpers.strings`, `json`, `mimetypes`, `os`, `re`, `shutil`, `simpleeval`, `tempfile`, `typing`, `zipfile`. |
| 55 | |
| 56 | ## Key Concepts |
| 57 | |
| 58 | - Important called helpers/classes observed in the source: `os.path.dirname`, `os.path.abspath`, `find_file_in_dirs`, `is_full_json_template`, `remove_code_fences`, `evaluate_text_conditions`, `replace_placeholders_text`, `process_includes`, `re.compile`, `re.escape`, `_process`, `get_abs_path`, `is_probably_binary_bytes`, `replace_value`, `re.sub`, `os.path.normpath`, `FileNotFoundError`, `result.sort`, `glob.glob`, `matches.sort`, `re.fullmatch`. |
| 59 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 60 | |
| 61 | ## Work Guidance |
| 62 | |
| 63 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 64 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 65 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 66 | |
| 67 | ## Verification |
| 68 | |
| 69 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 70 | - Related tests observed by source search: |
| 71 | - `tests/test_a0_connector_prompt_gating.py` |
| 72 | - `tests/test_browser_agent_regressions.py` |
| 73 | - `tests/test_default_prompt_budget.py` |
| 74 | - `tests/test_document_query_plugin.py` |
| 75 | - `tests/test_download_toast_regressions.py` |
| 76 | - `tests/test_file_tree_visualize.py` |
| 77 | - `tests/test_host_browser_connector.py` |
| 78 | - `tests/test_image_get_security.py` |
| 79 | |
| 80 | ## Child DOX Index |
| 81 | |
| 82 | No child DOX files. |