| 1 | # backup.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `backup.py` helper module. |
| 6 | - This module builds, inspects, previews, tests, and restores Agent Zero backup archives. |
| 7 | - Keep this file-level DOX profile synchronized with `backup.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `backup.py` owns the runtime implementation. |
| 12 | - `backup.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `BackupService` (no explicit base class) |
| 15 | - `get_default_backup_metadata(self) -> Dict[str, Any]` |
| 16 | - `async test_patterns(self, metadata: Dict[str, Any], max_files: Optional[int]=...) -> List[Dict[str, Any]]` |
| 17 | - `async create_backup(self, include_patterns: List[str], exclude_patterns: List[str], include_hidden: bool=..., backup_name: str=...) -> str` |
| 18 | - `async inspect_backup(self, backup_file) -> Dict[str, Any]` |
| 19 | - `async preview_restore(self, backup_file, restore_include_patterns: Optional[List[str]]=..., restore_exclude_patterns: Optional[List[str]]=..., overwrite_policy: str=..., clean_before_restore: bool=..., user_edited_metadata: Optional[Dict[str, Any]]=...) -> Dict[str, Any]` |
| 20 | - `async restore_backup(self, backup_file, restore_include_patterns: Optional[List[str]]=..., restore_exclude_patterns: Optional[List[str]]=..., overwrite_policy: str=..., clean_before_restore: bool=..., user_edited_metadata: Optional[Dict[str, Any]]=...) -> Dict[str, Any]` |
| 21 | |
| 22 | ## Runtime Contracts |
| 23 | |
| 24 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 25 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 26 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, settings/state persistence, secret handling. |
| 27 | - Imported dependency areas include: `datetime`, `helpers`, `helpers.localization`, `helpers.print_style`, `json`, `os`, `pathspec`, `platform`, `tempfile`, `typing`, `zipfile`. |
| 28 | - `test_patterns(..., max_files=None)` is the unlimited scan mode. UI preview and dry-run callers may pass bounded limits, but real backup creation and restore clean-before-restore must use unlimited matching so archives and cleanup are not silently truncated. |
| 29 | - Default backup metadata includes persistent `/usr` data but excludes Time Travel shadow history under `usr/.time_travel/**`. |
| 30 | - Restoring `usr/.env` preserves the destination instance's allowed origins while restoring authentication and other portable configuration from the archive. |
| 31 | |
| 32 | ## Key Concepts |
| 33 | |
| 34 | - Important called helpers/classes observed in the source: `self._get_agent_zero_version`, `files.get_abs_path`, `Localization.get.now_iso`, `self._get_default_patterns`, `self._parse_patterns`, `self.agent_zero_root.rstrip`, `patterns.split`, `join`, `file_path.lstrip`, `backed_up_agent_root.rstrip`, `current_agent_root.rstrip`, `self._patterns_to_string`, `self._get_explicit_patterns`, `tempfile.mkdtemp`, `os.path.join`, `self._translate_patterns`, `git.get_git_info`, `line.strip`, `line.startswith`, `getpass.getuser`. |
| 35 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 36 | |
| 37 | ## Work Guidance |
| 38 | |
| 39 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 40 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 41 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 42 | |
| 43 | ## Verification |
| 44 | |
| 45 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 46 | - Related tests observed by source search: |
| 47 | - `tests/test_download_toast_regressions.py` |
| 48 | - `tests/test_office_document_store.py` |
| 49 | - `tests/test_self_update_tag_filter.py` |
| 50 | |
| 51 | ## Child DOX Index |
| 52 | |
| 53 | No child DOX files. |