feat: Analyze now shows which projects would benefit from skill
This commit is contained in:
+13
-1
@@ -3,7 +3,19 @@
|
|||||||
"skills": {
|
"skills": {
|
||||||
"automation-workflows": {
|
"automation-workflows": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"installedAt": 1774373495681
|
"installedAt": 1774374565991
|
||||||
|
},
|
||||||
|
"competitive-intelligence-market-research": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"installedAt": 1774374441221
|
||||||
|
},
|
||||||
|
"cbo": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"installedAt": 1774374479849
|
||||||
|
},
|
||||||
|
"n8n-workflow-automation": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"installedAt": 1774374686820
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,10 +113,46 @@ export async function GET(req: NextRequest) {
|
|||||||
// Clean up
|
// Clean up
|
||||||
await execAsync(`rm -rf ${tempPath} 2>/dev/null`);
|
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({
|
return NextResponse.json({
|
||||||
description: desc,
|
description: desc,
|
||||||
triggers: triggers,
|
triggers: triggers,
|
||||||
raw: content.substring(0, 2000)
|
raw: content.substring(0, 2000),
|
||||||
|
projectMatches
|
||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return NextResponse.json({ error: e.message, description: "Could not analyze skill" });
|
return NextResponse.json({ error: e.message, description: "Could not analyze skill" });
|
||||||
|
|||||||
@@ -215,10 +215,18 @@ export default function ClawHubMarketplace() {
|
|||||||
description: data.description,
|
description: data.description,
|
||||||
triggers: data.triggers
|
triggers: data.triggers
|
||||||
});
|
});
|
||||||
setOutput(`📋 ${selectedSkill.name}\n\n` +
|
let output = `📋 ${selectedSkill.name}\n\n`;
|
||||||
`Description: ${data.description || "N/A"}\n\n` +
|
output += `Description: ${data.description || "N/A"}\n\n`;
|
||||||
`Triggers: ${data.triggers || "N/A"}\n\n` +
|
output += `Triggers: ${data.triggers || "N/A"}\n\n`;
|
||||||
(data.raw ? `📄 SKILL.md Preview:\n${data.raw.substring(0, 500)}...` : ""));
|
if (data.projectMatches && data.projectMatches.length > 0) {
|
||||||
|
output += `🎯 Project Matches:\n`;
|
||||||
|
data.projectMatches.forEach((m: string) => {
|
||||||
|
output += ` • ${m}\n`;
|
||||||
|
});
|
||||||
|
output += `\n`;
|
||||||
|
}
|
||||||
|
output += (data.raw ? `📄 SKILL.md Preview:\n${data.raw.substring(0, 500)}...` : "");
|
||||||
|
setOutput(output);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setOutput("Error: " + String(e));
|
setOutput("Error: " + String(e));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user