Skill: autogame-17/code-stats (version 1.0.0)

--- name: code-stats description: Visualizes repository complexity by counting files, lines of code, and grouping by extension. Use to assess project size or growth. --- # Code Stats Analyzes the current workspace to provide development metrics. ## Usage ```bash node skills/code-stats/index.js [path] ``` Defaults to current working directory if path is omitted. ## Output JSON object with: - `files`: Total file count. - `lines`: Total line count (approximate). - `byExt`: Breakdown by file extension.

path: index.js
content: const fs = require('fs');
const path = require('path');

function getStats(dir, stats = { files: 0, lines: 0, byExt: {} }) {
    try {
        const files = fs.readdirSync(dir);
        for (const file of files) {
            // Skip common ignore patterns
            if (file === '.git' || file === 'node_modules' || file === 'logs' || file === 'temp' || file === 'dist') continue;
            
            const fullPath = path.join(dir, file);
            let stat;
            try {
                stat = fs.statSync(fullPath);
            } catch (e) { continue; }

            if (stat.isDirectory()) {
                getStats(fullPath, stats);
            } else if (stat.isFile()) {
                stats.files++;
                const ext = path.extname(file) || '(no-ext)';
                stats.byExt[ext] = (stats.byExt[ext] || 0) + 1;
                
                // Count lines for text files roughly
                try {
                    // Peek at start to check if binary (heuristic)
                    const fd = fs.openSync(fullPath, 'r');
                    const buffer = Buffer.alloc(100);
                    const bytesRead = fs.readSync(fd, buffer, 0, 100, 0);
                    fs.closeSync(fd);
                    
                    let isBinary = false;
                    for (let i = 0; i < bytesRead; i++) {
                        if (buffer[i] === 0) { isBinary = true; break; }
                    }

                    if (!isBinary) {
                        const content = fs.readFileSync(fullPath, 'utf8');
                        const lines = content.split('\n').length;
                        stats.lines += lines;
                    }
                } catch (e) {}
            }
        }
    } catch (e) {
        console.error(`Error scanning ${dir}: ${e.message}`);
    }
    return stats;
}

if (require.main === module) {
    const root = process.argv[2] || process.cwd();
    console.log(JSON.stringify(getStats(root), null, 2));
}

module.exports = { getStats };


path: package.json
content: {
  "name": "code-stats",
  "version": "1.0.0",
  "description": "Visualizes repo complexity by counting files and lines of code.",
  "main": "index.js",
  "scripts": {
    "test": "node scripts/test.js"
  }
}

path: scripts/test.js
content: const { getStats } = require('../index');
const path = require('path');

console.log("Running code-stats test...");
try {
    // Scan the skill's own directory to verify accuracy on a known set
    const stats = getStats(path.resolve(__dirname, '..'));
    
    // We expect at least package.json, index.js, SKILL.md (not yet written but index exists) and this script
    if (stats.files >= 2 && stats.lines > 0) {
        console.log(`PASS: Scanned ${stats.files} files and ${stats.lines} lines.`);
    } else {
        throw new Error(`Invalid stats: ${JSON.stringify(stats)}`);
    }
} catch (e) {
    console.error("FAIL:", e);
    process.exit(1);
}


Security scan verdicts — ClawScan: clean | static analysis:  | VirusTotal: suspicious | SkillSpector: clean (LOW)