fix: ClawHub - move actions to POST, increase output font size

This commit is contained in:
2026-03-24 19:00:30 +01:00
parent 88506aa423
commit 48a452b994
3 changed files with 68 additions and 108 deletions
+5 -1
View File
@@ -3,7 +3,7 @@
"skills": { "skills": {
"automation-workflows": { "automation-workflows": {
"version": "0.1.0", "version": "0.1.0",
"installedAt": 1774374565991 "installedAt": 1774375118226
}, },
"competitive-intelligence-market-research": { "competitive-intelligence-market-research": {
"version": "1.0.0", "version": "1.0.0",
@@ -16,6 +16,10 @@
"n8n-workflow-automation": { "n8n-workflow-automation": {
"version": "1.0.0", "version": "1.0.0",
"installedAt": 1774374686820 "installedAt": 1774374686820
},
"agentic-workflow-automation": {
"version": "0.1.0",
"installedAt": 1774375021538
} }
} }
} }
+62 -106
View File
@@ -1,8 +1,8 @@
import { NextRequest, NextResponse } from "next/server"; import { NextRequest, NextResponse } from "next/server";
import { exec } from "child_process"; import { exec } from "child_process";
import { promisify } from "util"; import { promisify } from "util";
import { existsSync, readFileSync } from "fs"; import { existsSync } from "fs";
import { readFile, writeFile } from "fs/promises"; import { readFile, writeFile, readdir } from "fs/promises";
import path from "path"; import path from "path";
const execAsync = promisify(exec); const execAsync = promisify(exec);
@@ -55,9 +55,7 @@ export async function GET(req: NextRequest) {
// Sync Horus repo first // Sync Horus repo first
try { try {
await execAsync(`cd ${SKILLS_BASE} && git pull origin main 2>&1`); await execAsync(`cd ${SKILLS_BASE} && git pull origin main 2>&1`);
} catch (e) { } catch {}
// Ignore sync errors
}
const agents = ["horus", "amun", "cleo"]; const agents = ["horus", "amun", "cleo"];
const installed: Record<string, string[]> = {}; const installed: Record<string, string[]> = {};
@@ -83,62 +81,93 @@ export async function GET(req: NextRequest) {
return NextResponse.json({ info: stdout }); return NextResponse.json({ info: stdout });
} }
if (action === "analyze") { return NextResponse.json({ error: "Unknown action" }, { status: 400 });
} catch (e: any) {
return NextResponse.json({ error: e.message || "Failed" }, { status: 500 });
}
}
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const { action, slug, agents = ["horus"], name } = body;
if (action === "install") {
const results: string[] = [];
for (const agent of agents) {
const agentPath = path.join(SKILLS_BASE, agent, slug);
const agentDir = path.join(SKILLS_BASE, agent);
try { await execAsync(`mkdir -p ${agentDir}`); } catch {}
const tempPath = `/tmp/clawhub-install-${slug}-${Date.now()}`;
try {
await execAsync(`${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
await execAsync(`mv ${tempPath} ${agentPath} 2>/dev/null || mv ${tempPath}/${slug} ${agentPath} 2>/dev/null`);
results.push(`${agent}: installed ${slug}`);
} catch (e: any) {
results.push(`${agent}: failed - ${e.message}`);
}
}
return NextResponse.json({ output: results.join("\n") });
}
if (action === "delete") {
const results: string[] = [];
for (const agent of agents) {
const agentPath = path.join(SKILLS_BASE, agent, slug);
if (existsSync(agentPath)) {
await execAsync(`rm -rf ${agentPath}`);
results.push(`${agent}: removed ${slug}`);
} else {
results.push(`- ${agent}: ${slug} not found`);
}
}
return NextResponse.json({ output: results.join("\n") });
}
if (action === "analyze") {
const tempPath = `/tmp/clawhub-analyze-${slug}-${Date.now()}`;
try { try {
// Install to temp for analysis
const tempPath = `/tmp/clawhub-analyze-${slug}`;
await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`); await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
// Read SKILL.md
const skillMdPath = path.join(tempPath, slug, "SKILL.md"); const skillMdPath = path.join(tempPath, slug, "SKILL.md");
let content = ""; let content = "";
if (existsSync(skillMdPath)) { if (existsSync(skillMdPath)) {
content = await readFile(skillMdPath, "utf-8"); content = await readFile(skillMdPath, "utf-8");
} else { } else {
// Try without slug subfolder
const altPath = path.join(tempPath, "SKILL.md"); const altPath = path.join(tempPath, "SKILL.md");
if (existsSync(altPath)) { if (existsSync(altPath)) content = await readFile(altPath, "utf-8");
content = await readFile(altPath, "utf-8");
}
} }
// Extract description
const descMatch = content.match(/description:\s*([^\n]+)/i); const descMatch = content.match(/description:\s*([^\n]+)/i);
const desc = descMatch ? descMatch[1].trim() : "No description available"; const desc = descMatch ? descMatch[1].trim() : "No description available";
// Extract triggers
const triggerMatch = content.match(/triggers?:\s*([^\n]+)/i); const triggerMatch = content.match(/triggers?:\s*([^\n]+)/i);
const triggers = triggerMatch ? triggerMatch[1].trim() : "General use"; const triggers = triggerMatch ? triggerMatch[1].trim() : "General use";
// Clean up
await execAsync(`rm -rf ${tempPath} 2>/dev/null`); await execAsync(`rm -rf ${tempPath} 2>/dev/null`);
// Now analyze project fit // Project matching
const projectsDir = "/root/.openclaw/workspace/projects"; const projectsDir = "/root/.openclaw/workspace/projects";
const projectMatches: string[] = []; const projectMatches: string[] = [];
try { try {
const { readdirSync } = await import("fs"); const entries = await readdir(projectsDir, { withFileTypes: true });
const { readFile: readFileAsync } = await import("fs/promises");
const entries = readdirSync(projectsDir, { withFileTypes: true });
for (const entry of entries) { for (const entry of entries) {
if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".json"))) { if (entry.isFile() && (entry.name.endsWith(".md") || entry.name.endsWith(".json"))) {
const projectPath = path.join(projectsDir, entry.name); const projectPath = path.join(projectsDir, entry.name);
const projectContent = await readFileAsync(projectPath, "utf-8"); const projectContent = await readFile(projectPath, "utf-8");
const projectName = entry.name.replace(/\.(md|json)$/, ""); const projectName = entry.name.replace(/\.(md|json)$/, "");
// Simple keyword matching
const skillKeywords = (desc + " " + triggers).toLowerCase(); const skillKeywords = (desc + " " + triggers).toLowerCase();
const projectKeywords = projectContent.toLowerCase(); const projectKeywords = projectContent.toLowerCase();
// Check for keyword overlaps
const overlaps: string[] = []; const overlaps: string[] = [];
const skillWords = skillKeywords.split(/\s+/).filter(w => w.length > 4); const skillWords = skillKeywords.split(/\s+/).filter((w: string) => w.length > 4);
for (const word of skillWords) { for (const word of skillWords) {
if (projectKeywords.includes(word)) { if (projectKeywords.includes(word)) overlaps.push(word);
overlaps.push(word);
}
} }
if (overlaps.length >= 2) { if (overlaps.length >= 2) {
@@ -148,36 +177,26 @@ export async function GET(req: NextRequest) {
} }
} catch {} } catch {}
return NextResponse.json({ return NextResponse.json({ description: desc, triggers: triggers, raw: content.substring(0, 2000), projectMatches });
description: desc,
triggers: triggers,
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" });
} }
} }
if (action === "clone") { if (action === "clone") {
const tempPath = `/tmp/clawhub-clone-${slug}-${Date.now()}`;
try { try {
// Install to temp
const tempPath = `/tmp/clawhub-clone-${slug}`;
await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`); await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
// Find the skill folder
const entries = await readdir(tempPath); const entries = await readdir(tempPath);
const skillFolder = entries.find(e => e.includes(slug.replace(/-/g, ''))); const skillFolder = entries.find((e: string) => e.includes(slug.replace(/-/g, "")));
const sourcePath = path.join(tempPath, skillFolder || slug); const sourcePath = path.join(tempPath, skillFolder || slug);
// Create custom version
const customSlug = `${slug}-custom`; const customSlug = `${slug}-custom`;
const destPath = path.join(SKILLS_BASE, "horus", customSlug); const destPath = path.join(SKILLS_BASE, "horus", customSlug);
// Copy files
await execAsync(`cp -r ${sourcePath} ${destPath} 2>&1`); await execAsync(`cp -r ${sourcePath} ${destPath} 2>&1`);
// Modify SKILL.md
const skillMdPath = path.join(destPath, "SKILL.md"); const skillMdPath = path.join(destPath, "SKILL.md");
if (existsSync(skillMdPath)) { if (existsSync(skillMdPath)) {
let content = await readFile(skillMdPath, "utf-8"); let content = await readFile(skillMdPath, "utf-8");
@@ -187,12 +206,9 @@ export async function GET(req: NextRequest) {
await writeFile(skillMdPath, content); await writeFile(skillMdPath, content);
} }
// Clean up
await execAsync(`rm -rf ${tempPath} 2>/dev/null`); await execAsync(`rm -rf ${tempPath} 2>/dev/null`);
return NextResponse.json({ return NextResponse.json({ output: `Created custom skill: ${customSlug}\nPath: ${destPath}\n\nEdit SKILL.md to customize further!` });
output: `Created custom skill: ${customSlug}\nPath: ${destPath}\n\nEdit SKILL.md to customize further!`
});
} catch (e: any) { } catch (e: any) {
return NextResponse.json({ error: e.message }); return NextResponse.json({ error: e.message });
} }
@@ -218,66 +234,6 @@ export async function GET(req: NextRequest) {
return NextResponse.json({ error: "Unknown action" }, { status: 400 }); return NextResponse.json({ error: "Unknown action" }, { status: 400 });
} catch (e: any) { } catch (e: any) {
return NextResponse.json({ return NextResponse.json({ error: e.message || "Failed" }, { status: 500 });
error: e.message || "Failed",
}, { status: 500 });
}
}
export async function POST(req: NextRequest) {
try {
const body = await req.json();
const { action, slug, agents = ["horus"], name } = body;
if (action === "install") {
const results: string[] = [];
for (const agent of agents) {
const agentPath = path.join(SKILLS_BASE, agent, slug);
const agentDir = path.join(SKILLS_BASE, agent);
// Ensure agent dir exists
try {
await execAsync(`mkdir -p ${agentDir}`);
} catch {}
// Install to temp first
const tempPath = `/tmp/clawhub-install-${slug}-${Date.now()}`;
try {
await execAsync(`${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`);
// Move to agent folder
await execAsync(`mv ${tempPath} ${agentPath} 2>/dev/null || mv ${tempPath}/${slug} ${agentPath} 2>/dev/null`);
results.push(`${agent}: installed ${slug}`);
} catch (e: any) {
results.push(`${agent}: failed - ${e.message}`);
}
}
return NextResponse.json({ output: results.join("\n") });
}
if (action === "delete") {
const results: string[] = [];
for (const agent of agents) {
const agentPath = path.join(SKILLS_BASE, agent, slug);
if (existsSync(agentPath)) {
await execAsync(`rm -rf ${agentPath}`);
results.push(`${agent}: removed ${slug}`);
} else {
results.push(`- ${agent}: ${slug} not found`);
}
}
return NextResponse.json({ output: results.join("\n") });
}
return NextResponse.json({ error: "Unknown action" }, { status: 400 });
} catch (e: any) {
return NextResponse.json({
error: e.message || "Failed",
}, { status: 500 });
} }
} }
+2 -2
View File
@@ -539,8 +539,8 @@ export default function ClawHubMarketplace() {
{/* Output */} {/* Output */}
{output && ( {output && (
<div className="bg-slate-900 rounded-lg p-4 border border-slate-600"> <div className="bg-slate-900 rounded-lg p-4 border border-slate-600">
<h3 className="text-xs font-semibold text-slate-300 mb-2">Output</h3> <h3 className="text-sm font-semibold text-slate-300 mb-2">Output</h3>
<pre className="text-xs text-slate-300 whitespace-pre-wrap font-mono overflow-auto max-h-48"> <pre className="text-sm text-slate-200 whitespace-pre-wrap font-mono overflow-auto max-h-64 leading-relaxed">
{output} {output}
</pre> </pre>
</div> </div>