From 163c8e5096c29c7191bf30ba2b714010405185d9 Mon Sep 17 00:00:00 2001 From: Horus AI Date: Tue, 24 Mar 2026 18:31:28 +0100 Subject: [PATCH] fix: ClawHub API syntax error --- app/api/clawhub/route.ts | 56 +++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/app/api/clawhub/route.ts b/app/api/clawhub/route.ts index 0704db6..73907bb 100644 --- a/app/api/clawhub/route.ts +++ b/app/api/clawhub/route.ts @@ -1,7 +1,6 @@ import { NextRequest, NextResponse } from "next/server"; import { exec } from "child_process"; import { promisify } from "util"; -import { readFile, writeFile, mkdir, rm, readdir } from "fs/promises"; import { existsSync } from "fs"; import path from "path"; @@ -52,25 +51,22 @@ export async function GET(req: NextRequest) { } if (action === "list") { - // List installed skills per agent - const agents = ["horus", "amun", "cleo"]; - const installed: Record = {}; - // Sync Horus repo first try { await execAsync(`cd ${SKILLS_BASE} && git pull origin main 2>&1`); - } catch {} - - for (const agent of agents) { + } catch (e) { + // Ignore sync errors + } + + const agents = ["horus", "amun", "cleo"]; + const installed: Record = {}; for (const agent of agents) { const agentPath = path.join(SKILLS_BASE, agent); if (existsSync(agentPath)) { try { - const entries = await readdir(agentPath, { withFileTypes: true }); - installed[agent] = entries - .filter((d) => d.isDirectory()) - .map((d) => d.name); + const { stdout } = await execAsync(`ls -1 ${agentPath} 2>/dev/null`); + installed[agent] = stdout.trim().split("\n").filter(Boolean); } catch { installed[agent] = []; } @@ -105,11 +101,9 @@ export async function GET(req: NextRequest) { } return NextResponse.json({ error: "Unknown action" }, { status: 400 }); - } catch (e: unknown) { - const error = e as Error & { stdout?: string; message?: string }; + } catch (e: any) { return NextResponse.json({ - error: error.message || "Failed", - details: error.stdout || "", + error: e.message || "Failed", }, { status: 500 }); } } @@ -127,20 +121,20 @@ export async function POST(req: NextRequest) { const agentDir = path.join(SKILLS_BASE, agent); // Ensure agent dir exists - if (!existsSync(agentDir)) { - await mkdir(agentDir, { recursive: true }); - } + try { + await execAsync(`mkdir -p ${agentDir}`); + } catch {} // Install to temp first - const tempPath = `/tmp/clawhub-install-${slug}`; - await execAsync(`rm -rf ${tempPath} 2>/dev/null; ${CLAWHUB_BIN} install ${slug} --dir ${tempPath} 2>&1`); - - // Move to agent folder - if (existsSync(tempPath)) { - await execAsync(`mv ${tempPath} ${agentPath}`); + 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}`); - } else { - results.push(`✗ ${agent}: failed to install ${slug}`); + } catch (e: any) { + results.push(`✗ ${agent}: failed - ${e.message}`); } } @@ -154,7 +148,7 @@ export async function POST(req: NextRequest) { const agentPath = path.join(SKILLS_BASE, agent, slug); if (existsSync(agentPath)) { - await rm(agentPath, { recursive: true }); + await execAsync(`rm -rf ${agentPath}`); results.push(`✓ ${agent}: removed ${slug}`); } else { results.push(`- ${agent}: ${slug} not found`); @@ -165,11 +159,9 @@ export async function POST(req: NextRequest) { } return NextResponse.json({ error: "Unknown action" }, { status: 400 }); - } catch (e: unknown) { - const error = e as Error & { stdout?: string; stderr?: string; message?: string }; + } catch (e: any) { return NextResponse.json({ - error: error.message || "Failed", - details: error.stdout || error.stderr || "", + error: e.message || "Failed", }, { status: 500 }); } }