|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Diagnostic script for SubAgentConfig skill_dirs issue. |
| 4 | +
|
| 5 | +This script helps diagnose why skills are not being found by sub-agents. |
| 6 | +""" |
| 7 | + |
| 8 | +import os |
| 9 | +import sys |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | +print("=" * 70) |
| 13 | +print("SubAgentConfig skill_dirs Diagnostic Tool") |
| 14 | +print("=" * 70) |
| 15 | + |
| 16 | +# Check 1: Verify skill file format |
| 17 | +print("\n1. Checking skill file format...") |
| 18 | +print("-" * 70) |
| 19 | + |
| 20 | +skill_file = input("Enter the full path to your skill file: ").strip() |
| 21 | + |
| 22 | +if not os.path.exists(skill_file): |
| 23 | + print(f"❌ File not found: {skill_file}") |
| 24 | + sys.exit(1) |
| 25 | + |
| 26 | +print(f"✓ File exists: {skill_file}") |
| 27 | + |
| 28 | +with open(skill_file, 'r') as f: |
| 29 | + content = f.read() |
| 30 | + |
| 31 | +print("\nFile content (first 500 chars):") |
| 32 | +print("-" * 70) |
| 33 | +print(content[:500]) |
| 34 | +print("-" * 70) |
| 35 | + |
| 36 | +# Check frontmatter |
| 37 | +if not content.startswith("---"): |
| 38 | + print("❌ ERROR: File must start with '---' (YAML frontmatter)") |
| 39 | + print("\nExpected format:") |
| 40 | + print("""--- |
| 41 | +name: skill-name |
| 42 | +description: What the skill does |
| 43 | +allowed-tools: "read(*), grep(*)" |
| 44 | +kind: instruction |
| 45 | +--- |
| 46 | +# Skill Instructions |
| 47 | +
|
| 48 | +Your skill content here... |
| 49 | +""") |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | +parts = content.split("---") |
| 53 | +if len(parts) < 3: |
| 54 | + print("❌ ERROR: Invalid frontmatter format") |
| 55 | + print(" Frontmatter must be enclosed between two '---' markers") |
| 56 | + sys.exit(1) |
| 57 | + |
| 58 | +frontmatter = parts[1].strip() |
| 59 | +body = parts[2].strip() |
| 60 | + |
| 61 | +print("\n✓ Frontmatter structure is valid") |
| 62 | +print("\nFrontmatter content:") |
| 63 | +print("-" * 70) |
| 64 | +print(frontmatter) |
| 65 | +print("-" * 70) |
| 66 | + |
| 67 | +# Check for required fields |
| 68 | +import re |
| 69 | + |
| 70 | +name_match = re.search(r'^name:\s*(.+)$', frontmatter, re.MULTILINE) |
| 71 | +if not name_match: |
| 72 | + print("❌ ERROR: 'name' field is required in frontmatter") |
| 73 | + sys.exit(1) |
| 74 | + |
| 75 | +skill_name = name_match.group(1).strip() |
| 76 | +print(f"\n✓ Skill name found: '{skill_name}'") |
| 77 | + |
| 78 | +# Check for common formatting issues |
| 79 | +issues = [] |
| 80 | + |
| 81 | +# Check for unclosed quotes |
| 82 | +if frontmatter.count('"') % 2 != 0: |
| 83 | + issues.append("Unclosed double quotes in frontmatter") |
| 84 | + |
| 85 | +if frontmatter.count("'") % 2 != 0: |
| 86 | + issues.append("Unclosed single quotes in frontmatter") |
| 87 | + |
| 88 | +# Check for invalid fields |
| 89 | +valid_fields = ['name', 'description', 'allowed-tools', 'disable-model-invocation', |
| 90 | + 'kind', 'tags', 'version'] |
| 91 | +for line in frontmatter.split('\n'): |
| 92 | + line = line.strip() |
| 93 | + if ':' in line and not line.startswith('#'): |
| 94 | + field = line.split(':')[0].strip() |
| 95 | + if field and field not in valid_fields: |
| 96 | + issues.append(f"Unknown field '{field}' (valid: {', '.join(valid_fields)})") |
| 97 | + |
| 98 | +if issues: |
| 99 | + print("\n⚠️ Potential issues found:") |
| 100 | + for issue in issues: |
| 101 | + print(f" - {issue}") |
| 102 | +else: |
| 103 | + print("\n✓ No obvious formatting issues detected") |
| 104 | + |
| 105 | +# Check 2: Test with a3s_code |
| 106 | +print("\n2. Testing with a3s_code SDK...") |
| 107 | +print("-" * 70) |
| 108 | + |
| 109 | +try: |
| 110 | + from a3s_code import SubAgentConfig |
| 111 | + |
| 112 | + skill_dir = str(Path(skill_file).parent) |
| 113 | + print(f"Skill directory: {skill_dir}") |
| 114 | + |
| 115 | + cfg = SubAgentConfig( |
| 116 | + agent_type="test", |
| 117 | + prompt=f"Call Skill('{skill_name}')", |
| 118 | + workspace=".", |
| 119 | + skill_dirs=[skill_dir] |
| 120 | + ) |
| 121 | + |
| 122 | + print(f"\n✓ SubAgentConfig created successfully") |
| 123 | + print(f" - skill_dirs: {cfg.skill_dirs}") |
| 124 | + print(f" - hasattr(cfg, 'skill_dirs'): {hasattr(cfg, 'skill_dirs')}") |
| 125 | + |
| 126 | +except ImportError as e: |
| 127 | + print(f"❌ Cannot import a3s_code: {e}") |
| 128 | + print(" Make sure the SDK is installed: pip install a3s-code") |
| 129 | + sys.exit(1) |
| 130 | +except Exception as e: |
| 131 | + print(f"❌ Error creating SubAgentConfig: {e}") |
| 132 | + sys.exit(1) |
| 133 | + |
| 134 | +# Check 3: Verify path is absolute |
| 135 | +print("\n3. Checking path format...") |
| 136 | +print("-" * 70) |
| 137 | + |
| 138 | +if not os.path.isabs(skill_dir): |
| 139 | + print(f"⚠️ WARNING: Path is relative: {skill_dir}") |
| 140 | + print(f" Absolute path: {os.path.abspath(skill_dir)}") |
| 141 | + print(" Recommendation: Use absolute paths for skill_dirs") |
| 142 | +else: |
| 143 | + print(f"✓ Path is absolute: {skill_dir}") |
| 144 | + |
| 145 | +# Check 4: Verify file extension |
| 146 | +print("\n4. Checking file extension...") |
| 147 | +print("-" * 70) |
| 148 | + |
| 149 | +if not skill_file.endswith('.md'): |
| 150 | + print(f"❌ ERROR: Skill file must have .md extension") |
| 151 | + print(f" Current: {skill_file}") |
| 152 | + sys.exit(1) |
| 153 | +else: |
| 154 | + print(f"✓ File has .md extension") |
| 155 | + |
| 156 | +# Summary |
| 157 | +print("\n" + "=" * 70) |
| 158 | +print("DIAGNOSTIC SUMMARY") |
| 159 | +print("=" * 70) |
| 160 | + |
| 161 | +print(f""" |
| 162 | +Skill Information: |
| 163 | + - Name: {skill_name} |
| 164 | + - File: {skill_file} |
| 165 | + - Directory: {skill_dir} |
| 166 | + - File size: {len(content)} bytes |
| 167 | +
|
| 168 | +Configuration to use: |
| 169 | + SubAgentConfig( |
| 170 | + agent_type="your-agent-type", |
| 171 | + prompt="Call Skill('{skill_name}')", |
| 172 | + workspace="/your/workspace", |
| 173 | + skill_dirs=["{skill_dir}"], |
| 174 | + permissive=True |
| 175 | + ) |
| 176 | +
|
| 177 | +Next Steps: |
| 178 | + 1. If issues were found above, fix them in your skill file |
| 179 | + 2. Make sure you're using the absolute path for skill_dirs |
| 180 | + 3. Enable debug logging to see skill loading messages: |
| 181 | +
|
| 182 | + import logging |
| 183 | + logging.basicConfig(level=logging.DEBUG) |
| 184 | +
|
| 185 | + 4. Check for warning messages like: |
| 186 | + - "Failed to load session skill dir" |
| 187 | + - "Skill validation failed" |
| 188 | +""") |
| 189 | + |
| 190 | +print("=" * 70) |
0 commit comments