| 1 | # skills_import.py DOX |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | - Own the `skills_import.py` helper module. |
| 6 | - This module plans and imports skill bundles into user, project, or profile scopes. |
| 7 | - Keep this file-level DOX profile synchronized with `skills_import.py` because this directory is intentionally flat. |
| 8 | |
| 9 | ## Ownership |
| 10 | |
| 11 | - `skills_import.py` owns the runtime implementation. |
| 12 | - `skills_import.py.dox.md` owns durable notes about responsibilities, contracts, side effects, and verification for that implementation. |
| 13 | - Classes: |
| 14 | - `ImportPlanItem` (no explicit base class) |
| 15 | - `ImportResult` (no explicit base class) |
| 16 | - Top-level functions: |
| 17 | - `_is_within(child: Path, parent: Path) -> bool` |
| 18 | - `_derive_namespace(source: Path) -> str` |
| 19 | - `_candidate_skill_roots(source_dir: Path) -> List[Path]`: Heuristics to find likely skill roots inside a repo/pack: |
| 20 | - `_safe_extract_zip(zip_path: Path, target: Path) -> None` |
| 21 | - `extract_skills_zip(zip_path: Path, tmp_subdir: str=..., prefix: str=...) -> tuple[Path, Path]`: Extract a zip into a temp folder inside Agent Zero's tmp directory and return the scan/import root plus cleanup root. |
| 22 | - `_unzip_to_temp_dir(zip_path: Path) -> Path`: Extract a zip into a temp folder under tmp/skill_imports (inside Agent Zero base dir). |
| 23 | - `build_import_plan(source: Path, dest_root: Path, namespace: Optional[str]=...) -> Tuple[List[ImportPlanItem], Path]`: Build a copy plan for importing skills from a source folder. |
| 24 | - `_resolve_conflict(dest: Path, policy: ConflictPolicy) -> Tuple[Path, bool]`: Returns (final_dest_path, should_copy). |
| 25 | - `get_project_skills_folder(project_name: str) -> Path`: Get the skills folder path for a project. |
| 26 | - `get_agent_profile_skills_folder(profile_name: str) -> Path` |
| 27 | - `get_project_agent_profile_skills_folder(project_name: str, profile_name: str) -> Path` |
| 28 | - `resolve_skills_destination_root(project_name: Optional[str], agent_profile: Optional[str]) -> Path` |
| 29 | - `import_skills(source_path: str, namespace: Optional[str]=..., conflict: ConflictPolicy=..., dry_run: bool=..., project_name: Optional[str]=..., agent_profile: Optional[str]=...) -> ImportResult`: Import external Skills into usr/skills/<namespace>/... |
| 30 | - Notable constants/configuration names: `PROJECT_SKILLS_DIR`. |
| 31 | |
| 32 | ## Runtime Contracts |
| 33 | |
| 34 | - Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together. |
| 35 | - Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change. |
| 36 | - Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, plugin state. |
| 37 | - Imported dependency areas include: `__future__`, `dataclasses`, `helpers`, `helpers.skills`, `os`, `pathlib`, `shutil`, `stat`, `tempfile`, `time`, `typing`, `zipfile`. |
| 38 | |
| 39 | ## Key Concepts |
| 40 | |
| 41 | - Zip extraction rejects absolute paths, backslash paths, path traversal, and symlink entries before extraction. |
| 42 | - Important called helpers/classes observed in the source: `dataclass`, `strip`, `plugins.is_dir`, `Path`, `base_tmp.mkdir`, `time.strftime`, `target.mkdir`, `_candidate_skill_roots`, `Path.expanduser`, `resolve_skills_destination_root`, `dest_root.mkdir`, `build_import_plan`, `ImportResult`, `child.resolve.relative_to`, `direct.is_dir`, `discover_skill_md_files`, `plugins.iterdir`, `files.get_abs_path`, `zipfile.ZipFile`, `archive.extractall`, `shutil.rmtree`. |
| 43 | - Keep request/response, tool, or helper semantics documented here at the same time as source changes. |
| 44 | |
| 45 | ## Work Guidance |
| 46 | |
| 47 | - Preserve public helper APIs used by core code and plugins unless every caller is updated. |
| 48 | - Keep path, auth, secret, persistence, network, and subprocess behavior explicit and bounded. |
| 49 | - Prefer adding cohesive helper functions here only when behavior is reused across modules. |
| 50 | |
| 51 | ## Verification |
| 52 | |
| 53 | - Run targeted tests for changed helper behavior; run security regressions for auth, filesystem, WebSocket, tunnel, upload, or secret-handling helpers. |
| 54 | - No direct test reference was found by name search; choose the nearest behavioral test or perform a focused smoke check. |
| 55 | |
| 56 | ## Child DOX Index |
| 57 | |
| 58 | No child DOX files. |