#!/usr/bin/env bash set -uo pipefail SESSION_DIR="/Users/exult/.claude/projects/-Users-exult-claude-workspace" SKILL_DIR="/Users/exult/claude-workspace/.claude/skills" REPORT="/Users/exult/claude-workspace/data/reports/skill-audit-$(date +%Y-%m-%d).md" mkdir -p "$(dirname "$REPORT")" python3 << 'PYEOF' import os, json, glob skill_dir = "/Users/exult/claude-workspace/.claude/skills" session_dir = "/Users/exult/.claude/projects/-Users-exult-claude-workspace" report_lines = ["# Skill Audit Report", ""] # 1. Inventory report_lines.append("## Skills Inventory") report_lines.append("| Skill | Lines | Refs | Has Auth | Has Examples |") report_lines.append("|-------|-------|------|----------|-------------|") skills = {} for d in sorted(os.listdir(skill_dir)): skill_path = os.path.join(skill_dir, d, "SKILL.md") if os.path.isfile(skill_path): with open(skill_path) as f: content = f.read() lines = len(content.split("\n")) refs_dir = os.path.join(skill_dir, d, "references") refs = len(os.listdir(refs_dir)) if os.path.isdir(refs_dir) else 0 has_auth = "auth" in content.lower() or "token" in content.lower() or "jwt" in content.lower() has_examples = content.count("curl") + content.count("```") >= 3 skills[d] = {"lines": lines, "refs": refs, "has_auth": has_auth, "has_examples": has_examples} report_lines.append(f"| {d} | {lines} | {refs} | {'Yes' if has_auth else 'NO'} | {'Yes' if has_examples else 'NO'} |") report_lines.append("") # 2. Session analysis report_lines.append("## Recent Session Analysis") sessions = sorted(glob.glob(os.path.join(session_dir, "*.jsonl")), key=os.path.getmtime, reverse=True)[:5] skill_mentions = {s: 0 for s in skills} total_tools = 0 total_errors = 0 for sf in sessions: with open(sf) as f: content = f.read() total_tools += content.count('"tool_use"') total_errors += content.lower().count('"is_error":true') + content.lower().count('"is_error": true') for s in skills: if s.lower() in content.lower(): skill_mentions[s] += 1 report_lines.append(f"Sessions analyzed: {len(sessions)}") report_lines.append(f"Total tool calls: {total_tools}") report_lines.append(f"Total errors: {total_errors}") report_lines.append(f"Error rate: {total_errors/max(total_tools,1)*100:.1f}%") report_lines.append("") # 3. Usage report_lines.append("## Skill Usage") for s, count in sorted(skill_mentions.items(), key=lambda x: -x[1]): status = f"**{count} sessions**" if count > 0 else "unused" report_lines.append(f"- {s}: {status}") report_lines.append("") # 4. Improvement suggestions report_lines.append("## Improvement Suggestions") for s, info in skills.items(): issues = [] if not info["has_auth"]: issues.append("missing auth recipe") if not info["has_examples"]: issues.append("needs more code examples") if info["lines"] < 40: issues.append(f"too short ({info['lines']} lines)") if skill_mentions.get(s, 0) == 0: issues.append("unused - consider removing or documenting use case") if issues: report_lines.append(f"- **{s}**: {', '.join(issues)}") report = "\n".join(report_lines) with open(os.environ.get("REPORT_PATH", "/tmp/skill-audit.md"), "w") as f: f.write(report) print(report) PYEOF