feat: Analyze now shows which projects would benefit from skill
This commit is contained in:
@@ -113,10 +113,46 @@ export async function GET(req: NextRequest) {
|
||||
// Clean up
|
||||
await execAsync(`rm -rf ${tempPath} 2>/dev/null`);
|
||||
|
||||
// Now analyze project fit
|
||||
const projectsDir = "/root/.openclaw/workspace/projects";
|
||||
const projectMatches: string[] = [];
|
||||
|
||||
try {
|
||||
const { readdirSync } = await import("fs");
|
||||
const { readFile: readFileAsync } = await import("fs/promises");
|
||||
|
||||
const entries = readdirSync(projectsDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".json"))) {
|
||||
const projectPath = path.join(projectsDir, entry.name);
|
||||
const projectContent = await readFileAsync(projectPath, "utf-8");
|
||||
const projectName = entry.name.replace(/\.(md|json)$/, "");
|
||||
|
||||
// Simple keyword matching
|
||||
const skillKeywords = (desc + " " + triggers).toLowerCase();
|
||||
const projectKeywords = projectContent.toLowerCase();
|
||||
|
||||
// Check for keyword overlaps
|
||||
const overlaps: string[] = [];
|
||||
const skillWords = skillKeywords.split(/\s+/).filter(w => w.length > 4);
|
||||
for (const word of skillWords) {
|
||||
if (projectKeywords.includes(word)) {
|
||||
overlaps.push(word);
|
||||
}
|
||||
}
|
||||
|
||||
if (overlaps.length >= 2) {
|
||||
projectMatches.push(`${projectName}: ${overlaps.slice(0, 3).join(", ")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return NextResponse.json({
|
||||
description: desc,
|
||||
triggers: triggers,
|
||||
raw: content.substring(0, 2000)
|
||||
raw: content.substring(0, 2000),
|
||||
projectMatches
|
||||
});
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message, description: "Could not analyze skill" });
|
||||
|
||||
Reference in New Issue
Block a user