Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions src/specify_cli/command_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,29 @@ def init(
)
manifest.save()

# Save the init options before the force re-registration
# below: extension registration reads the saved ai /
# ai_skills options to decide skill vs command rendering,
# so a skills-mode re-init must record ai_skills first
# (#5321). All inputs here are already resolved.
init_opts = {
**previous_init_options,
"ai": selected_ai,
"integration": resolved_integration.key,
"here": here,
"script": selected_script,
"feature_numbering": previous_init_options.get("feature_numbering", "sequential"),
"speckit_version": get_speckit_version(),
"allow_symlinks": allow_symlinks,
}
if resolved_integration.is_skills_mode(
integration_parsed_options or None, project_root=project_path
):
init_opts["ai_skills"] = True
else:
init_opts.pop("ai_skills", None)
save_init_options(project_path, init_opts)
Comment thread
mnriem marked this conversation as resolved.
Resolved

if force:
from .integrations._helpers import (
_register_extensions_for_agent,
Expand Down Expand Up @@ -858,24 +881,6 @@ def init(
sanitized_wf = str(wf_err).replace("\n", " ").strip()
tracker.error("workflow", f"install failed: {sanitized_wf[:120]}")

init_opts = {
**previous_init_options,
"ai": selected_ai,
"integration": resolved_integration.key,
"here": here,
"script": selected_script,
"feature_numbering": previous_init_options.get("feature_numbering", "sequential"),
"speckit_version": get_speckit_version(),
"allow_symlinks": allow_symlinks,
}
if resolved_integration.is_skills_mode(
integration_parsed_options or None, project_root=project_path
):
init_opts["ai_skills"] = True
else:
init_opts.pop("ai_skills", None)
save_init_options(project_path, init_opts)

ensure_executable_scripts(project_path, tracker=tracker)

if preset:
Expand Down
35 changes: 35 additions & 0 deletions src/specify_cli/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,27 @@ def _replacement(match: re.Match[str]) -> str:
skill_dir_preexists = (
skill_subdir.exists() or skill_subdir.is_symlink()
)
# Reject symlinked skill destinations before any write. The
# skills root itself is validated, but a symlinked per-skill
# directory would redirect SKILL.md outside the project, and
# the force path bypasses the pre-existing-directory guards
# below. Mirrors _find_extension_skill_dirs, which applies
# the same validation before removal.
from ..shared_infra import _validate_safe_shared_directory

trusted_root = self._extension_skill_trusted_root(skills_dir)
if trusted_root is None:
continue
try:
# Normalize relative destinations before validation: the
# trusted root is absolute, so a relative skill path (for
# example with ExtensionManager(Path("."))) would fail the
# containment check and the skill would be silently skipped.
_validate_safe_shared_directory(
trusted_root, Path(os.path.abspath(skill_subdir))
)
Comment on lines +1644 to +1646
except (OSError, ValueError):
continue
CommandRegistrar._ensure_inside(cache_file, cache_root)
if selected_ai == "generic" and skill_dir_preexists:
metadata = self.registry.get(manifest.id) or {}
Expand Down Expand Up @@ -1711,6 +1732,20 @@ def _replacement(match: re.Match[str]) -> str:
):
skill_content = integration.post_process_skill_content(skill_content)

# A hard-linked SKILL.md shares its inode with other paths, so
# writing it in place would change every linked copy. Drop our
# link first so the write below creates a fresh file instead.
if skill_file.is_file() and not skill_file.is_symlink():
try:
if skill_file.stat().st_nlink > 1:
unlink(skill_file)
except OSError:
# The detach failed (for example, the file lives in a
# non-writable directory), so writing in place would
# modify every hard-linked copy. Skip this skill
# instead of writing through the link.
continue

if use_dev_symlink:
try:
cache_file.parent.mkdir(parents=True, exist_ok=True)
Expand Down
Loading
Loading