|
55 | 55 | ] |
56 | 56 | } |
57 | 57 |
|
| 58 | +# Dependency primitive patterns for .github directory within dependencies. |
| 59 | +# Some packages store primitives in .github/ instead of (or in addition to) .apm/. |
| 60 | +DEPENDENCY_GITHUB_PRIMITIVE_PATTERNS: Dict[str, List[str]] = { |
| 61 | + 'chatmode': [ |
| 62 | + "agents/*.agent.md", |
| 63 | + "chatmodes/*.chatmode.md", |
| 64 | + ], |
| 65 | + 'instruction': ["instructions/*.instructions.md"], |
| 66 | + 'context': [ |
| 67 | + "context/*.context.md", |
| 68 | + "memory/*.memory.md", |
| 69 | + ] |
| 70 | +} |
| 71 | + |
58 | 72 |
|
59 | 73 | def discover_primitives( |
60 | 74 | base_dir: str = ".", |
@@ -297,37 +311,48 @@ def get_dependency_declaration_order(base_dir: str) -> List[str]: |
297 | 311 | return [] |
298 | 312 |
|
299 | 313 |
|
300 | | -def scan_directory_with_source(directory: Path, collection: PrimitiveCollection, source: str) -> None: |
301 | | - """Scan a directory for primitives with a specific source tag. |
302 | | - |
| 314 | +def _scan_patterns(base_dir: Path, patterns: Dict[str, List[str]], collection: PrimitiveCollection, source: str) -> None: |
| 315 | + """Glob-scan-parse loop for one base directory and one patterns dict. |
| 316 | +
|
303 | 317 | Args: |
304 | | - directory (Path): Directory to scan (e.g., apm_modules/package_name). |
| 318 | + base_dir (Path): Directory to scan (e.g., dep/.apm or dep/.github). |
| 319 | + patterns (Dict[str, List[str]]): Primitive-type → glob-pattern mapping. |
305 | 320 | collection (PrimitiveCollection): Collection to add primitives to. |
306 | 321 | source (str): Source identifier for discovered primitives. |
307 | 322 | """ |
308 | | - # Look for .apm directory within the dependency |
309 | | - apm_dir = directory / ".apm" |
310 | | - if not apm_dir.exists(): |
311 | | - # Even without .apm, check for SKILL.md (Claude Skills support) |
312 | | - _discover_skill_in_directory(directory, collection, source) |
313 | | - return |
314 | | - |
315 | | - # Find and parse files for each primitive type |
316 | | - for primitive_type, patterns in DEPENDENCY_PRIMITIVE_PATTERNS.items(): |
317 | | - for pattern in patterns: |
318 | | - full_pattern = str(apm_dir / pattern) |
319 | | - matching_files = glob.glob(full_pattern, recursive=True) |
320 | | - |
321 | | - for file_path_str in matching_files: |
| 323 | + for _primitive_type, type_patterns in patterns.items(): |
| 324 | + for pattern in type_patterns: |
| 325 | + for file_path_str in glob.glob(str(base_dir / pattern), recursive=True): |
322 | 326 | file_path = Path(file_path_str) |
323 | 327 | if file_path.is_file() and _is_readable(file_path): |
324 | 328 | try: |
325 | 329 | primitive = parse_primitive_file(file_path, source=source) |
326 | 330 | collection.add_primitive(primitive) |
327 | 331 | except Exception as e: |
328 | 332 | print(f"Warning: Failed to parse dependency primitive {file_path}: {e}") |
329 | | - |
330 | | - # Also check for SKILL.md in the dependency root |
| 333 | + |
| 334 | + |
| 335 | +def scan_directory_with_source(directory: Path, collection: PrimitiveCollection, source: str) -> None: |
| 336 | + """Scan a directory for primitives with a specific source tag. |
| 337 | +
|
| 338 | + Args: |
| 339 | + directory (Path): Directory to scan (e.g., apm_modules/package_name). |
| 340 | + collection (PrimitiveCollection): Collection to add primitives to. |
| 341 | + source (str): Source identifier for discovered primitives. |
| 342 | + """ |
| 343 | + # Scan .apm directory within the dependency |
| 344 | + apm_dir = directory / ".apm" |
| 345 | + if apm_dir.exists(): |
| 346 | + _scan_patterns(apm_dir, DEPENDENCY_PRIMITIVE_PATTERNS, collection, source) |
| 347 | + |
| 348 | + # Also scan .github directory — some packages store primitives there instead of (or |
| 349 | + # in addition to) .apm/. Without this, dependency instructions in .github/instructions/ |
| 350 | + # are silently skipped in the normal compile path (issue #631). |
| 351 | + github_dir = directory / ".github" |
| 352 | + if github_dir.exists(): |
| 353 | + _scan_patterns(github_dir, DEPENDENCY_GITHUB_PRIMITIVE_PATTERNS, collection, source) |
| 354 | + |
| 355 | + # Check for SKILL.md in the dependency root |
331 | 356 | _discover_skill_in_directory(directory, collection, source) |
332 | 357 |
|
333 | 358 |
|
|
0 commit comments