Return the active skills directory, creating it on demand when enabled. Reads ``.specify/init-options.json`` to determine whether skills are enabled and which agent was selected. Only ``ai_skills`` set to boolean ``True`` creates the directory safely (symlink/containment checks); when
(project_root: Path)
| 276 | |
| 277 | |
| 278 | def resolve_active_skills_dir(project_root: Path) -> Path | None: |
| 279 | """Return the active skills directory, creating it on demand when enabled. |
| 280 | |
| 281 | Reads ``.specify/init-options.json`` to determine whether skills are |
| 282 | enabled and which agent was selected. Only ``ai_skills`` set to boolean |
| 283 | ``True`` creates the directory safely (symlink/containment checks); when |
| 284 | ``ai_skills`` is not boolean ``True``, only Kimi's native-skills fallback |
| 285 | is honoured, and the native skills directory must already exist. |
| 286 | |
| 287 | Returns: |
| 288 | The skills directory ``Path``, or ``None`` if skills are not active. |
| 289 | |
| 290 | Raises: |
| 291 | ValueError: If the resolved skills path escapes the project root, |
| 292 | a parent component is a symlink, or a path component exists |
| 293 | but is not a directory. |
| 294 | OSError: If the directory cannot be created (e.g. permission denied). |
| 295 | """ |
| 296 | from .shared_infra import _ensure_safe_shared_directory |
| 297 | |
| 298 | opts = load_init_options(project_root) |
| 299 | if not isinstance(opts, dict): |
| 300 | opts = {} |
| 301 | |
| 302 | agent = opts.get("ai") |
| 303 | if not isinstance(agent, str) or not agent: |
| 304 | return None |
| 305 | |
| 306 | ai_skills_enabled = _is_ai_skills_enabled(opts) |
| 307 | if not ai_skills_enabled and agent != "kimi": |
| 308 | return None |
| 309 | |
| 310 | skills_dir = _get_skills_dir(project_root, agent) |
| 311 | |
| 312 | if not ai_skills_enabled: |
| 313 | # Kimi native-skills fallback when ai_skills is not boolean True: |
| 314 | # use the native skills directory only if it already exists. |
| 315 | if not skills_dir.is_dir(): |
| 316 | return None |
| 317 | _ensure_safe_shared_directory( |
| 318 | project_root, skills_dir, |
| 319 | create=False, context="agent skills directory", |
| 320 | ) |
| 321 | return skills_dir |
| 322 | |
| 323 | # ai_skills is boolean True: create the directory safely. |
| 324 | _ensure_safe_shared_directory( |
| 325 | project_root, skills_dir, context="agent skills directory", |
| 326 | ) |
| 327 | return skills_dir |
| 328 | |
| 329 | |
| 330 | def _cli_error_detail(exc: BaseException) -> str: |
no test coverage detected