@@ -1358,6 +1358,7 @@ def _target_relative_path(
13581358 source_path : Path ,
13591359 current : SkillSource ,
13601360 skills : list [SkillSource ],
1361+ source_file : Path ,
13611362) -> str :
13621363 resolved = source_path .resolve ()
13631364 owner = next (
@@ -1378,8 +1379,10 @@ def _target_relative_path(
13781379 generated_resource = (
13791380 Path (owner .target_name ) / resolved .relative_to (owner .source_dir .resolve ())
13801381 )
1382+ source_relative = source_file .resolve ().relative_to (current .source_dir .resolve ())
1383+ generated_current = Path (current .target_name ) / source_relative .parent
13811384 return Path (
1382- os .path .relpath (generated_resource , Path ( current . target_name ) )
1385+ os .path .relpath (generated_resource , generated_current )
13831386 ).as_posix ()
13841387
13851388
@@ -1398,7 +1401,7 @@ def replace_skill_dir(match: re.Match[str]) -> str:
13981401 source_path = current .source_dir / raw_path
13991402 if not source_path .exists ():
14001403 raise ValueError (f"{ source_file } : missing referenced resource { source_path } " )
1401- return _target_relative_path (source_path , current , skills )
1404+ return _target_relative_path (source_path , current , skills , source_file )
14021405
14031406 def replace_plugin_root (match : re .Match [str ]) -> str :
14041407 raw_path = match .group (1 )
@@ -1411,19 +1414,19 @@ def replace_plugin_root(match: re.Match[str]) -> str:
14111414 raise ValueError (
14121415 f"{ source_file } : unsupported CLAUDE_PLUGIN_ROOT resource { source_path } "
14131416 )
1414- return _target_relative_path (source_path , current , skills )
1417+ return _target_relative_path (source_path , current , skills , source_file )
14151418
14161419 def replace_bare_sibling (match : re .Match [str ]) -> str :
14171420 source_path = current .source_dir .parent / match .group (1 ) / match .group (2 )
14181421 if "<" in match .group (0 ) or ">" in match .group (0 ) or not source_path .exists ():
14191422 return match .group (0 )
1420- return _target_relative_path (source_path , current , skills )
1423+ return _target_relative_path (source_path , current , skills , source_file )
14211424
14221425 def replace_canonical_skill_path (match : re .Match [str ]) -> str :
14231426 source_path = current .source_dir .parent / match .group (1 ) / match .group (2 )
14241427 if "<" in match .group (0 ) or ">" in match .group (0 ) or not source_path .exists ():
14251428 return match .group (0 )
1426- return _target_relative_path (source_path , current , skills )
1429+ return _target_relative_path (source_path , current , skills , source_file )
14271430
14281431 def replace_bare_skill_path (match : re .Match [str ]) -> str :
14291432 source_skill = current .source_dir .parent / match .group (1 )
@@ -1435,7 +1438,7 @@ def replace_bare_skill_path(match: re.Match[str]) -> str:
14351438 or not source_path .exists ()
14361439 ):
14371440 return match .group (0 )
1438- return _target_relative_path (source_path , current , skills )
1441+ return _target_relative_path (source_path , current , skills , source_file )
14391442
14401443 text = SKILL_DIR_TOKEN_RE .sub (replace_skill_dir , text )
14411444 text = PLUGIN_ROOT_TOKEN_RE .sub (replace_plugin_root , text )
0 commit comments