File size: 2,187 Bytes
7bedc79
 
 
 
0fc6e34
7bedc79
 
 
 
 
 
 
031fd6d
7bedc79
 
031fd6d
 
7bedc79
031fd6d
7bedc79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fc6e34
 
 
7bedc79
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
import { resolve, join } from "node:path";
import type { Rule } from "../../core/types.js";
import { parsers } from "../../parsers/index.js";
import { findAgentFiles } from "../../core/files.js";


export async function scanProject(root: string): Promise<void> {
  const absRoot = resolve(root);
  console.log(`Scanning ${absRoot} for AI agent configs...\n`);

  let foundAny = false;
  const seenFiles = new Set<string>();

  for (const [agentName, parser] of Object.entries(parsers)) {
    // AGENTS.md is shared by several agents — attribute it once (first match wins).
    const files = findAgentFiles(absRoot, agentName).filter((f) => !seenFiles.has(f));
    if (files.length === 0) continue;
    files.forEach((f) => seenFiles.add(f));
    foundAny = true;

    const allRules: Rule[] = [];
    for (const file of files) {
      const content = readFileSync(file, "utf-8");
      allRules.push(...parser.parse(content, file));
    }

    const categoryCounts = new Map<string, number>();
    for (const r of allRules) {
      categoryCounts.set(r.category, (categoryCounts.get(r.category) ?? 0) + 1);
    }

    console.log(`  ✅ ${agentName.toUpperCase()} — ${files.length} file(s), ${allRules.length} rules`);
    for (const file of files) {
      console.log(`     📄 ${file.replace(absRoot, ".")}`);
    }
    const cats = [...categoryCounts.entries()].map(([c, n]) => `${c}(${n})`).join(", ");
    console.log(`     Categories: ${cats}\n`);
  }

  if (!foundAny) {
    console.log("  这个目录里没有找到任何 Agent 规则文件。");
    console.log("  请换一个项目目录(通常包含 CLAUDE.md / AGENTS.md / .cursor/rules)。");
    console.log("  Supported:");
    for (const [name, parser] of Object.entries(parsers)) {
      console.log(`    ${name}: ${parser.filePatterns.join(", ")}`);
    }
    console.log("\n  Tip: run `agentlens install` to set up AgentLens for your agents.");
  } else {
    console.log("  💡 Run `agentlens move --from <agent> --to <agent>` to migrate rules.");
    console.log("  💡 Run `agentlens drift` to check for config drift.");
  }
}