defimport_skill(self,resolved:ResolvedSkill,*,with_scripts:bool=False,force:bool=False,)->ImportResult:"""Install *resolved* into ``<target_root>/<source>/<name>/``. Returns an :class:`ImportResult` with status, paths, translated tools, untranslated tools, and warnings. """result=ImportResult()target_dir=self._target_root/resolved.source/resolved.nameresult.target_path=target_dir# Skip if already installed and force is Falseiftarget_dir.exists()andnotforce:result.skipped=Trueresult.warnings.append(f"Skill already installed at {target_dir} (use force=True to overwrite)")returnresult# 1. Parse source SKILL.mdsource_md=resolved.path/"SKILL.md"ifnotsource_md.exists():source_md=resolved.path/"skill.md"ifnotsource_md.exists():result.success=Falseresult.warnings.append(f"No SKILL.md found in {resolved.path}")returnresulttry:frontmatter,body=self._read_skill_md(source_md)self._parser.parse_frontmatter(frontmatter,markdown_content=body)exceptExceptionasexc:result.success=Falseresult.warnings.append(f"Parse error: {exc}")returnresult# 2. Translate tool referencestranslated_body,untranslated=self._translator.translate_markdown(body)result.untranslated_tools=untranslated# Compute the list of translations actually appliedapplied:List[str]=[]forext,internalinself._translator._table.items():ifextinbodyandextnotintranslated_body:applied.append(f"{ext}->{internal}")result.translated_tools=applied# 3. Write the target directoryiftarget_dir.exists():shutil.rmtree(target_dir)target_dir.mkdir(parents=True)# 3a. Translated SKILL.mdnew_md=self._render_skill_md(frontmatter,translated_body)(target_dir/"SKILL.md").write_text(new_md,encoding="utf-8")# 3b. Always-copied subdirsforsubdirinCOPIED_SUBDIRS:src_sub=resolved.path/subdirifsrc_sub.exists():shutil.copytree(src_sub,target_dir/subdir)# 3c. Scripts (gated by with_scripts)scripts_src=resolved.path/"scripts"ifscripts_src.exists()andwith_scripts:shutil.copytree(scripts_src,target_dir/"scripts")result.scripts_imported=Trueelifscripts_src.exists():result.warnings.append("Skipped scripts/ directory (use with_scripts=True to import)")# 4. Write .source metadataself._write_source_metadata(target_dir,resolved,result)returnresult