@@ -148,7 +148,9 @@ def render_frontmatter(fm: dict) -> str:
148148 )
149149 return f"---\n { yaml_str } ---\n "
150150
151- def _adjust_script_paths (self , frontmatter : dict ) -> dict :
151+ def _adjust_script_paths (
152+ self , frontmatter : dict , extension_id : Optional [str ] = None
153+ ) -> dict :
152154 """Normalize script paths in frontmatter to generated project locations.
153155
154156 Rewrites known repo-relative and top-level script paths under the
@@ -158,6 +160,7 @@ def _adjust_script_paths(self, frontmatter: dict) -> dict:
158160
159161 Args:
160162 frontmatter: Frontmatter dictionary
163+ extension_id: Extension id when rendering extension-owned commands.
161164
162165 Returns:
163166 Modified frontmatter with normalized project paths
@@ -168,11 +171,15 @@ def _adjust_script_paths(self, frontmatter: dict) -> dict:
168171 if isinstance (scripts , dict ):
169172 for key , script_path in scripts .items ():
170173 if isinstance (script_path , str ):
171- scripts [key ] = self .rewrite_project_relative_paths (script_path )
174+ scripts [key ] = self .rewrite_project_relative_paths (
175+ script_path , extension_id = extension_id
176+ )
172177 return frontmatter
173178
174179 @staticmethod
175- def rewrite_project_relative_paths (text : str ) -> str :
180+ def rewrite_project_relative_paths (
181+ text : str , extension_id : Optional [str ] = None
182+ ) -> str :
176183 """Rewrite repo-relative paths to their generated project locations."""
177184 if not isinstance (text , str ) or not text :
178185 return text
@@ -184,10 +191,18 @@ def rewrite_project_relative_paths(text: str) -> str:
184191 ):
185192 text = text .replace (old , new )
186193
187- # Only rewrite top-level style references so extension-local paths like
188- # ".specify/extensions/<ext>/scripts/..." remain intact.
194+ # Only rewrite top-level style references so existing generated paths
195+ # like ".specify/extensions/<ext>/scripts/..." remain intact. When
196+ # rendering extension commands, top-level "scripts/" is extension-local.
197+ scripts_replacement = (
198+ f".specify/extensions/{ extension_id } /scripts/"
199+ if extension_id
200+ else ".specify/scripts/"
201+ )
189202 text = re .sub (r'(^|[\s`"\'(])(?:\.?/)?memory/' , r"\1.specify/memory/" , text )
190- text = re .sub (r'(^|[\s`"\'(])(?:\.?/)?scripts/' , r"\1.specify/scripts/" , text )
203+ text = re .sub (
204+ r'(^|[\s`"\'(])(?:\.?/)?scripts/' , rf"\1{ scripts_replacement } " , text
205+ )
191206 text = re .sub (
192207 r'(^|[\s`"\'(])(?:\.?/)?templates/' , r"\1.specify/templates/" , text
193208 )
@@ -312,6 +327,7 @@ def render_skill_command(
312327 source_id : str ,
313328 source_file : str ,
314329 project_root : Path ,
330+ extension_id : Optional [str ] = None ,
315331 ) -> str :
316332 """Render a command override as a SKILL.md file.
317333
@@ -331,7 +347,7 @@ def render_skill_command(
331347 agent_config = self .AGENT_CONFIGS .get (agent_name , {})
332348 if agent_config .get ("extension" ) == "/SKILL.md" :
333349 body = self .resolve_skill_placeholders (
334- agent_name , frontmatter , body , project_root
350+ agent_name , frontmatter , body , project_root , extension_id = extension_id
335351 )
336352
337353 description = frontmatter .get (
@@ -393,7 +409,11 @@ def apply_argument_hint(
393409
394410 @staticmethod
395411 def resolve_skill_placeholders (
396- agent_name : str , frontmatter : dict , body : str , project_root : Path
412+ agent_name : str ,
413+ frontmatter : dict ,
414+ body : str ,
415+ project_root : Path ,
416+ extension_id : Optional [str ] = None ,
397417 ) -> str :
398418 """Resolve script placeholders for skills-backed agents."""
399419 if not isinstance (frontmatter , dict ):
@@ -433,7 +453,9 @@ def resolve_skill_placeholders(
433453
434454 body = body .replace ("{ARGS}" , "$ARGUMENTS" ).replace ("__AGENT__" , agent_name )
435455
436- return CommandRegistrar .rewrite_project_relative_paths (body )
456+ return CommandRegistrar .rewrite_project_relative_paths (
457+ body , extension_id = extension_id
458+ )
437459
438460 def _convert_argument_placeholder (
439461 self , content : str , from_placeholder : str , to_placeholder : str
@@ -528,6 +550,7 @@ def register_commands(
528550 context_note : str = None ,
529551 _resolved_dir : Path = None ,
530552 link_outputs : bool = False ,
553+ extension_id : Optional [str ] = None ,
531554 ) -> List [str ]:
532555 """Register commands for a specific agent.
533556
@@ -545,6 +568,7 @@ def register_commands(
545568 link_outputs: If True, write rendered output to a source-local
546569 dev cache and symlink the agent command file to it. Falls back
547570 to a normal file write when symlinks are unavailable.
571+ extension_id: Extension id when rendering extension-owned commands.
548572
549573 Returns:
550574 List of registered command names
@@ -614,7 +638,9 @@ def register_commands(
614638 frontmatter [key ] = core_frontmatter [key ]
615639 frontmatter .pop ("strategy" , None )
616640
617- frontmatter = self ._adjust_script_paths (frontmatter )
641+ frontmatter = self ._adjust_script_paths (
642+ frontmatter , extension_id = extension_id
643+ )
618644
619645 for key in agent_config .get ("strip_frontmatter_keys" , []):
620646 frontmatter .pop (key , None )
@@ -653,10 +679,11 @@ def register_commands(
653679 source_id ,
654680 cmd_file ,
655681 project_root ,
682+ extension_id = extension_id ,
656683 )
657684 elif agent_config ["format" ] == "markdown" :
658685 body = self .resolve_skill_placeholders (
659- agent_name , frontmatter , body , project_root
686+ agent_name , frontmatter , body , project_root , extension_id = extension_id
660687 )
661688 body = self ._convert_argument_placeholder (
662689 body , "$ARGUMENTS" , agent_config ["args" ]
@@ -666,7 +693,7 @@ def register_commands(
666693 )
667694 elif agent_config ["format" ] == "toml" :
668695 body = self .resolve_skill_placeholders (
669- agent_name , frontmatter , body , project_root
696+ agent_name , frontmatter , body , project_root , extension_id = extension_id
670697 )
671698 body = self ._convert_argument_placeholder (
672699 body , "$ARGUMENTS" , agent_config ["args" ]
@@ -721,6 +748,7 @@ def register_commands(
721748 source_id ,
722749 cmd_file ,
723750 project_root ,
751+ extension_id = extension_id ,
724752 )
725753 elif agent_config ["format" ] == "markdown" :
726754 alias_output = self .render_markdown_command (
@@ -750,6 +778,7 @@ def register_commands(
750778 source_id ,
751779 cmd_file ,
752780 project_root ,
781+ extension_id = extension_id ,
753782 )
754783
755784 alias_file = (
@@ -881,6 +910,7 @@ def register_commands_for_all_agents(
881910 context_note : str = None ,
882911 link_outputs : bool = False ,
883912 create_missing_active_skills_dir : bool = False ,
913+ extension_id : Optional [str ] = None ,
884914 ) -> Dict [str , List [str ]]:
885915 """Register commands for all detected agents in the project.
886916
@@ -897,6 +927,7 @@ def register_commands_for_all_agents(
897927 Recovery requires active skills mode (or Kimi's existing native
898928 skills directory) and is skipped when safe resolution or
899929 creation fails.
930+ extension_id: Extension id when rendering extension-owned commands.
900931
901932 Returns:
902933 Dictionary mapping agent names to list of registered commands
@@ -999,6 +1030,7 @@ def register_commands_for_all_agents(
9991030 context_note = context_note ,
10001031 _resolved_dir = agent_dir ,
10011032 link_outputs = link_outputs ,
1033+ extension_id = extension_id ,
10021034 )
10031035 if registered :
10041036 results [agent_name ] = registered
@@ -1023,6 +1055,7 @@ def register_commands_for_non_skill_agents(
10231055 project_root : Path ,
10241056 context_note : Optional [str ] = None ,
10251057 link_outputs : bool = False ,
1058+ extension_id : Optional [str ] = None ,
10261059 ) -> Dict [str , List [str ]]:
10271060 """Register commands for all non-skill agents in the project.
10281061
@@ -1038,6 +1071,7 @@ def register_commands_for_non_skill_agents(
10381071 context_note: Custom context comment for markdown output
10391072 link_outputs: If True, create dev-mode symlinks for rendered
10401073 command files when supported by the OS.
1074+ extension_id: Extension id when rendering extension-owned commands.
10411075
10421076 Returns:
10431077 Dictionary mapping agent names to list of registered commands
@@ -1066,6 +1100,7 @@ def register_commands_for_non_skill_agents(
10661100 context_note = context_note ,
10671101 _resolved_dir = agent_dir ,
10681102 link_outputs = link_outputs ,
1103+ extension_id = extension_id ,
10691104 )
10701105 if registered :
10711106 results [agent_name ] = registered
0 commit comments