Skip to content

gaia-research/gaia-skill-tree / .agents/skills/graphify-triage

graphify-triage

Verified

Use this skill when the user wants to turn code graph analysis into tracked GitHub issues — "audit the architecture", "find god nodes", "triage architectural debt", "run graphify and log issues", "what's over-coupled in this codebase", "create issues from graphify findings", "check for structural problems", "scan for architectural smells", or any request that combines codebase topology analysis with issue tracking. This skill runs graphify to build a dependency graph, parses GRAPH_REPORT.md for god nodes and structural patterns, converts findings into GitHub issue payloads, and optionally pushes them to the repo. It bridges static analysis and project management in a single automated pass. Requires graphify and gh CLI.

FileKindSize
SKILL.mdskill md3.8 KB
resources/templates/gaia_node.jsonconfig417 B
scripts/triage.pyscript5.7 KB

scripts/triage.py

View on GitHub
import argparse
import json
import os
import subprocess
import sys
import re
from pathlib import Path

import shlex

def run_command(cmd, capture_output=True):
    """Helper to run shell commands safely without shell=True to prevent command injection."""
    try:
        # If cmd is a string, safely split it (assuming no complex shell interpolations are intended)
        if isinstance(cmd, str):
            cmd = shlex.split(cmd)
        result = subprocess.run(
            cmd,
            check=True,
            capture_output=capture_output,
            text=True
        )
        return result.stdout.strip() if result.stdout else None
    except subprocess.CalledProcessError as e:
        print(f"Error running command: {cmd}\n{e.stderr}", file=sys.stderr)
        return None

def check_gh_auth():
    """Verify GitHub CLI is authenticated."""
    result = run_command(["gh", "auth", "status"])
    if result is None:
        print("GitHub CLI not authenticated. Please run 'gh auth login'.", file=sys.stderr)
        return False
    return True

def parse_graph_report(report_path):
    """Extract actionable sections from GRAPH_REPORT.md."""
    if not os.path.exists(report_path):
        return None
    
    content = Path(report_path).read_text(encoding='utf-8')
    
    sections = {
        "god_nodes": [],
        "surprises": [],
        "questions": []
    }
    
    # Simple regex parsing for standard graphify report sections
    god_match = re.search(r"## God Nodes.*?\n(.*?)(?=\n##|$)", content, re.S)
    if god_match:
        sections["god_nodes"] = [l.strip("- ").strip() for l in god_match.group(1).strip().split("\n") if l.strip()]

    surprise_match = re.search(r"## Surprising Connections.*?\n(.*?)(?=\n##|$)", content, re.S)
    if surprise_match:
        sections["surprises"] = [l.strip("- ").strip() for l in surprise_match.group(1).strip().split("\n") if l.strip()]

    question_match = re.search(r"## Suggested Questions.*?\n(.*?)(?=\n##|$)", content, re.S)
    if question_match:
        lines = question_match.group(1).strip().split("\n")
        current_q = None
        for line in lines:
            if line.startswith("- **"):
                if current_q: sections["questions"].append(current_q)
                current_q = {"title": line.strip("- ").strip(), "context": ""}
            elif current_q and line.strip().startswith("_"):
                current_q["context"] = line.strip("_ ")
        if current_q: sections["questions"].append(current_q)
        
    return sections

def create_issue_payloads(sections):
    """Convert parsed sections into GH issue payloads."""
    payloads = []
    
    # 1. God Node Optimization
    if sections["god_nodes"]:
        nodes_str = "\n".join([f"- {n}" for n in sections["god_nodes"][:3]])
        payloads.append({
            "title": "[Architectural Refactor] Decouple God Nodes identified by Graphify",
            "body": f"The following nodes have high centrality and may be bottlenecks or over-coupled abstractions:\n\n{nodes_str}\n\n### Tasks\n1. Analyze dependencies of these nodes.\n2. Extract sub-modules to improve cohesion.\n3. Verify with `graphify cluster-only`.",
            "labels": ["enhancement", "architecture"]
        })
    
    # 2. Suggested Research/Audit Questions
    for q in sections["questions"]:
        payloads.append({
            "title": f"[Audit] {q['title']}",
            "body": f"{q['context']}\n\nThis issue was automatically generated based on architectural patterns detected by Graphify.",
            "labels": ["audit", "question"]
        })
        
    return payloads

def main():
    parser = argparse.ArgumentParser(description='Graphify Triage Orchestrator')
    subparsers = parser.add_subparsers(dest='command', required=True)

    # Audit command
    p_audit = subparsers.add_parser('audit', help='Run graphify and generate issue payloads')
    p_audit.add_argument('--path', default='.', help='Path to scan')
    p_audit.add_argument('--output', required=True, help='Path to save payloads JSON')

    # Sync command
    p_sync = subparsers.add_parser('sync', help='Push payloads to GitHub as issues')
    p_sync.add_argument('--input', required=True, help='Path to payloads JSON')
    p_sync.add_argument('--repo', help='Target repo (owner/repo). Defaults to current origin.')

    args = parser.parse_args()

    if args.command == 'audit':
        print(f"Running graphify on {args.path}...")
        run_command(["graphify", ".", "--update"], capture_output=False)
        
        report_path = os.path.join(args.path, "graphify-out/GRAPH_REPORT.md")
        sections = parse_graph_report(report_path)
        
        if not sections:
            print("No report found or parsing failed.", file=sys.stderr)
            sys.exit(1)
            
        payloads = create_issue_payloads(sections)
        
        with open(args.output, 'w', encoding='utf-8') as f:
            json.dump(payloads, f, indent=2)
        print(f"Audit complete. {len(payloads)} proposed issues saved to {args.output}")

    elif args.command == 'sync':
        if not check_gh_auth():
            sys.exit(1)
            
        with open(args.input, 'r', encoding='utf-8') as f:
            payloads = json.load(f)
            
        for p in payloads:
            print(f"Creating issue: {p['title']}")
            cmd = ["gh", "issue", "create"]

            if args.repo:
                cmd.extend(["-R", args.repo])

            cmd.extend(["--title", p['title'], "--body", p['body']])

            for lbl in p.get("labels", []):
                cmd.extend(["--label", lbl])
            
            run_command(cmd, capture_output=False)
        
        print(f"Sync complete. {len(payloads)} issues created.")

if __name__ == '__main__':
    main()
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall