#!/usr/bin/env python3 """ GNS-2 Agent Protocol Validator Validates that agents follow Gitea-Nervous-System v2.0 protocol. """ import re import sys import yaml import glob CHECKPOINT_PATTERN = re.compile(r'## GNS Checkpoint\s*```yaml\s*(.*?)```', re.DOTALL) EVENT_PATTERN = re.compile(r'', re.DOTALL) def validate_agent_file(path): with open(path) as f: content = f.read() errors = [] agent_name = path.split('/')[-1].replace('.md', '') # Check frontmatter if not content.startswith('---'): errors.append('Missing YAML frontmatter') else: parts = content.split('---') if len(parts) >= 2: try: fm = yaml.safe_load(parts[1]) if not fm.get('description'): errors.append('Missing description in frontmatter') if 'mode' not in fm: errors.append('Missing mode in frontmatter') if 'task' not in str(fm.get('permission', {})): errors.append('Missing task permission') except Exception as e: errors.append(f'Invalid YAML frontmatter: {e}') # Check GNS protocol sections if 'GNS Checkpoint' not in content: errors.append('Missing GNS Checkpoint section') if 'GNS_EVENT' not in content: errors.append('Missing GNS_EVENT footer example') if 'gns-agent-protocol' not in content.lower() and 'GNS' not in content: errors.append('Agent not updated for GNS-2 protocol') return errors def main(): print("GNS-2 Agent Protocol Validator") print() all_valid = True for path in glob.glob('.kilo/agents/*.md'): errors = validate_agent_file(path) agent_name = path.split('/')[-1].replace('.md', '') if errors: print(f"❌ {agent_name}: {len(errors)} errors") for err in errors: print(f" - {err}") all_valid = False else: print(f"✅ {agent_name}") print() if all_valid: print("All agents pass GNS-2 validation") return 0 else: print("Some agents need GNS-2 protocol update") return 1 if __name__ == '__main__': sys.exit(main())