chore: ARTEX 初始化
ARTEX — AI 自主渗透测试系统(Go 后端 + Next.js 前端,单二进制内嵌)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
0ef8561411
287 files changed
+70178
No files matched your search
@@ -0,0 +1,764 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
ChevronRightIcon,
|
||||
FolderIcon,
|
||||
FolderOpenIcon,
|
||||
FolderPlusIcon,
|
||||
FileTextIcon,
|
||||
FilePlusIcon,
|
||||
PlusIcon,
|
||||
Trash2Icon,
|
||||
UploadIcon,
|
||||
} from "lucide-react";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { ScrollArea } from "@/components/ui/scroll-area";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { api } from "@/lib/api";
|
||||
import type { Agent, SkillItem, MCPServer } from "@/lib/types";
|
||||
|
||||
// ── Tree node ──────────────────────────────────────────────────────────────
|
||||
interface TreeNode {
|
||||
name: string;
|
||||
path: string; // relative to skill root, dirs WITHOUT trailing slash
|
||||
type: "file" | "dir";
|
||||
children: TreeNode[];
|
||||
}
|
||||
|
||||
// Backend returns dirs as "scripts/" (trailing slash) and files as "scripts/a.py".
|
||||
function buildTree(entries: string[]): TreeNode[] {
|
||||
const root: TreeNode[] = [];
|
||||
const dirMap = new Map<string, TreeNode>();
|
||||
|
||||
function ensureDir(dirPath: string, parentNodes: TreeNode[]): TreeNode[] {
|
||||
if (dirMap.has(dirPath)) return dirMap.get(dirPath)!.children;
|
||||
const parts = dirPath.split("/");
|
||||
let nodes = root;
|
||||
let cur = "";
|
||||
for (const part of parts) {
|
||||
cur = cur ? `${cur}/${part}` : part;
|
||||
if (!dirMap.has(cur)) {
|
||||
const d: TreeNode = { name: part, path: cur, type: "dir", children: [] };
|
||||
nodes.push(d);
|
||||
dirMap.set(cur, d);
|
||||
}
|
||||
nodes = dirMap.get(cur)!.children;
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
for (const entry of [...entries].sort()) {
|
||||
if (entry.endsWith("/")) {
|
||||
// Explicit directory entry — ensure the node exists (may already be created)
|
||||
ensureDir(entry.slice(0, -1), root);
|
||||
} else {
|
||||
// File — ensure parent dirs exist, then push file node
|
||||
const parts = entry.split("/");
|
||||
let nodes = root;
|
||||
let cur = "";
|
||||
for (let i = 0; i < parts.length - 1; i++) {
|
||||
cur = cur ? `${cur}/${parts[i]}` : parts[i];
|
||||
if (!dirMap.has(cur)) {
|
||||
const d: TreeNode = { name: parts[i], path: cur, type: "dir", children: [] };
|
||||
nodes.push(d);
|
||||
dirMap.set(cur, d);
|
||||
}
|
||||
nodes = dirMap.get(cur)!.children;
|
||||
}
|
||||
const fname = parts[parts.length - 1];
|
||||
if (fname) nodes.push({ name: fname, path: entry, type: "file", children: [] });
|
||||
}
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
// ── State types ───────────────────────────────────────────────────────────
|
||||
type Selected =
|
||||
| { skill: string; path: null }
|
||||
| { skill: string; path: string };
|
||||
|
||||
type Creating = {
|
||||
skill: string;
|
||||
inDir: string;
|
||||
kind: "file" | "dir";
|
||||
} | null;
|
||||
|
||||
// ── Page ──────────────────────────────────────────────────────────────────
|
||||
export default function SkillsPage() {
|
||||
const [skills, setSkills] = React.useState<SkillItem[]>([]);
|
||||
const [agents, setAgents] = React.useState<Agent[]>([]);
|
||||
const [selected, setSelected] = React.useState<Selected | null>(null);
|
||||
const [visibility, setVisibility] = React.useState<Record<string, string[]>>({});
|
||||
const [expanded, setExpanded] = React.useState<Set<string>>(new Set());
|
||||
|
||||
// file editor
|
||||
const [fileContent, setFileContent] = React.useState("");
|
||||
const [fileLoading, setFileLoading] = React.useState(false);
|
||||
const [dirty, setDirty] = React.useState(false);
|
||||
const [saving, setSaving] = React.useState(false);
|
||||
|
||||
// inline create — using a ref to avoid stale closure in onBlur
|
||||
const [creating, setCreating] = React.useState<Creating>(null);
|
||||
const [newEntryName, setNewEntryName] = React.useState("");
|
||||
const inlineRef = React.useRef<HTMLInputElement>(null);
|
||||
// cancelRef prevents onBlur from committing when Escape was pressed
|
||||
const cancelRef = React.useRef(false);
|
||||
|
||||
// new skill dialog
|
||||
const [newOpen, setNewOpen] = React.useState(false);
|
||||
const [newName, setNewName] = React.useState("");
|
||||
const [newDesc, setNewDesc] = React.useState("");
|
||||
const [newLicense, setNewLicense] = React.useState("");
|
||||
const [newCompat, setNewCompat] = React.useState("");
|
||||
const [newInst, setNewInst] = React.useState("");
|
||||
const [newMcps, setNewMcps] = React.useState<string[]>([]);
|
||||
const [newVisibility, setNewVisibility] = React.useState<string[]>([]);
|
||||
const [mcpOptions, setMcpOptions] = React.useState<MCPServer[]>([]);
|
||||
const [creatingSkill, setCreatingSkill] = React.useState(false);
|
||||
const [uploading, setUploading] = React.useState(false);
|
||||
const uploadRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
// skill detail — MCP edit state (optimistic, rolls back on error)
|
||||
const [detailMcps, setDetailMcps] = React.useState<string[]>([]);
|
||||
|
||||
// ── Data ──────────────────────────────────────────────────────────────────
|
||||
const load = React.useCallback(() => {
|
||||
api.agents().then(setAgents).catch(() => {});
|
||||
api.mcpServers().then(setMcpOptions).catch(() => {});
|
||||
api.skills().then((ss) => {
|
||||
setSkills(ss);
|
||||
ss.forEach((s) =>
|
||||
api.skillVisibility(s.name)
|
||||
.then((ids) => setVisibility((v) => ({ ...v, [s.name]: ids })))
|
||||
.catch(() => {}),
|
||||
);
|
||||
}).catch(() => {});
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => { load(); }, [load]);
|
||||
|
||||
// ── Upload a .zip skill ───────────────────────────────────────────────────
|
||||
async function uploadZip(file: File, overwrite = false) {
|
||||
setUploading(true);
|
||||
try {
|
||||
const r = await api.uploadSkill(file, overwrite);
|
||||
toast.success(`已安装 Skill:${r.name}(${r.files} 个文件)`);
|
||||
load();
|
||||
} catch (e) {
|
||||
const msg = (e as Error).message;
|
||||
// offer overwrite when the skill already exists
|
||||
if (!overwrite && msg.includes("已存在")) {
|
||||
if (window.confirm(`${msg}\n\n是否覆盖同名 Skill?`)) {
|
||||
await uploadZip(file, true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
toast.error("上传失败:" + msg);
|
||||
}
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
}
|
||||
function onUploadPick(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const f = e.target.files?.[0];
|
||||
e.target.value = ""; // reset so picking the same file again re-fires
|
||||
if (f) uploadZip(f);
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (creating) {
|
||||
// Small timeout so the element is actually in the DOM before focusing
|
||||
setTimeout(() => inlineRef.current?.focus(), 20);
|
||||
}
|
||||
}, [creating]);
|
||||
|
||||
// Sync detail-panel MCP state when the selected skill changes.
|
||||
React.useEffect(() => {
|
||||
if (!selected || selected.path !== null) return;
|
||||
const sk = skills.find((s) => s.name === selected.skill);
|
||||
setDetailMcps(sk?.mcps ?? []);
|
||||
}, [selected, skills]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!selected || selected.path === null) { setFileContent(""); setDirty(false); return; }
|
||||
setFileLoading(true);
|
||||
api.readSkillFile(selected.skill, selected.path)
|
||||
.then((c) => { setFileContent(c); setDirty(false); })
|
||||
.catch(() => toast.error("读取文件失败"))
|
||||
.finally(() => setFileLoading(false));
|
||||
}, [selected]);
|
||||
|
||||
// ── Expand helpers ────────────────────────────────────────────────────────
|
||||
function toggleExpanded(key: string) {
|
||||
setExpanded((prev) => {
|
||||
const next = new Set(prev);
|
||||
if (next.has(key)) next.delete(key); else next.add(key);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
function ensureExpanded(skill: string, dirPath: string) {
|
||||
setExpanded((prev) => {
|
||||
const next = new Set(prev);
|
||||
next.add(skill);
|
||||
if (dirPath) {
|
||||
let cur = "";
|
||||
for (const part of dirPath.split("/")) {
|
||||
cur = cur ? `${cur}/${part}` : part;
|
||||
next.add(`${skill}:${cur}`);
|
||||
}
|
||||
}
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
// ── Inline create ─────────────────────────────────────────────────────────
|
||||
function startCreate(skill: string, inDir: string, kind: "file" | "dir") {
|
||||
cancelRef.current = false;
|
||||
ensureExpanded(skill, inDir);
|
||||
setCreating({ skill, inDir, kind });
|
||||
setNewEntryName("");
|
||||
}
|
||||
|
||||
// Use a ref snapshot so commitCreate reads the latest creating value
|
||||
// without depending on potentially stale closure state.
|
||||
const creatingRef = React.useRef<Creating>(null);
|
||||
React.useEffect(() => { creatingRef.current = creating; }, [creating]);
|
||||
const newEntryRef = React.useRef("");
|
||||
React.useEffect(() => { newEntryRef.current = newEntryName; }, [newEntryName]);
|
||||
|
||||
async function commitCreate() {
|
||||
if (cancelRef.current) { cancelRef.current = false; return; }
|
||||
const c = creatingRef.current;
|
||||
const name = newEntryRef.current.trim();
|
||||
setCreating(null);
|
||||
setNewEntryName("");
|
||||
if (!c || !name) return;
|
||||
|
||||
const fullPath = c.inDir ? `${c.inDir}/${name}` : name;
|
||||
try {
|
||||
if (c.kind === "dir") {
|
||||
await api.createSkillDir(c.skill, fullPath);
|
||||
toast.success(`已创建文件夹:${fullPath}`);
|
||||
ensureExpanded(c.skill, fullPath);
|
||||
} else {
|
||||
await api.writeSkillFile(c.skill, fullPath, "");
|
||||
toast.success(`已创建文件:${fullPath}`);
|
||||
setSelected({ skill: c.skill, path: fullPath });
|
||||
ensureExpanded(c.skill, c.inDir);
|
||||
}
|
||||
load();
|
||||
} catch (e) {
|
||||
toast.error("创建失败:" + (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
function cancelCreate() {
|
||||
cancelRef.current = true;
|
||||
setCreating(null);
|
||||
setNewEntryName("");
|
||||
}
|
||||
|
||||
async function deletePath(skill: string, path: string) {
|
||||
try {
|
||||
await api.deleteSkillPath(skill, path);
|
||||
toast.success(`已删除:${path}`);
|
||||
if (selected?.skill === skill && selected.path === path) setSelected(null);
|
||||
load();
|
||||
} catch (e) {
|
||||
toast.error("删除失败:" + (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteSkill(name: string) {
|
||||
try {
|
||||
await api.deleteSkill(name);
|
||||
toast.success(`已删除 Skill:${name}`);
|
||||
if (selected?.skill === name) setSelected(null);
|
||||
load();
|
||||
} catch (e) {
|
||||
toast.error("删除失败:" + (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveFile() {
|
||||
if (!selected || selected.path === null) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
await api.writeSkillFile(selected.skill, selected.path, fileContent);
|
||||
toast.success("已保存");
|
||||
setDirty(false);
|
||||
} catch (e) {
|
||||
toast.error("保存失败:" + (e as Error).message);
|
||||
} finally { setSaving(false); }
|
||||
}
|
||||
|
||||
async function toggleSkillMcp(skillName: string, mcpName: string, mcpOn: boolean) {
|
||||
const next = mcpOn
|
||||
? [...detailMcps, mcpName]
|
||||
: detailMcps.filter((n) => n !== mcpName);
|
||||
setDetailMcps(next);
|
||||
try {
|
||||
await api.updateSkillMeta(skillName, { mcps: next });
|
||||
toast.success(`${mcpOn ? "关联" : "取消关联"}「${mcpName}」`);
|
||||
load();
|
||||
} catch (e) {
|
||||
// roll back on error
|
||||
setDetailMcps(detailMcps);
|
||||
toast.error("操作失败:" + (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleVisibility(skillName: string, agentId: string, agentName: string) {
|
||||
const on = (visibility[skillName] ?? []).includes(agentId);
|
||||
try {
|
||||
await api.toggleSkillVisibility(agentId, skillName, !on);
|
||||
toast.success(`${on ? "取消" : "授予"}「${agentName}」可见`);
|
||||
const ids = await api.skillVisibility(skillName);
|
||||
setVisibility((v) => ({ ...v, [skillName]: ids }));
|
||||
} catch (e) {
|
||||
toast.error("操作失败:" + (e as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
async function createNewSkill() {
|
||||
if (!newName.trim()) { toast.error("请填写 name"); return; }
|
||||
if (!newDesc.trim()) { toast.error("description 为必填项"); return; }
|
||||
setCreatingSkill(true);
|
||||
try {
|
||||
const name = newName.trim();
|
||||
await api.createSkill({
|
||||
name, description: newDesc.trim(),
|
||||
license: newLicense.trim() || undefined,
|
||||
compatibility: newCompat.trim() || undefined,
|
||||
mcps: newMcps.length ? newMcps : undefined,
|
||||
instructions: newInst.trim() || undefined,
|
||||
});
|
||||
// apply initial visibility (fire-and-forget per agent; best-effort)
|
||||
await Promise.all(newVisibility.map((id) => api.toggleSkillVisibility(id, name, true)));
|
||||
toast.success("已创建 Skill");
|
||||
setNewOpen(false);
|
||||
setNewName(""); setNewDesc(""); setNewLicense(""); setNewCompat(""); setNewInst("");
|
||||
setNewMcps([]); setNewVisibility([]);
|
||||
load();
|
||||
} catch (e) {
|
||||
toast.error("创建失败:" + (e as Error).message);
|
||||
} finally { setCreatingSkill(false); }
|
||||
}
|
||||
|
||||
// ── Inline input JSX helper (NOT a React component — avoids remount on re-render) ──
|
||||
// Defined as a plain function returning JSX so React never sees a new component type.
|
||||
function inlineInputJSX(indent: number) {
|
||||
return (
|
||||
<div
|
||||
key="__inline_create__"
|
||||
className="flex items-center gap-1 py-0.5 pr-2"
|
||||
style={{ paddingLeft: indent }}
|
||||
>
|
||||
{creating?.kind === "dir"
|
||||
? <FolderIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
: <FileTextIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
}
|
||||
<Input
|
||||
ref={inlineRef}
|
||||
className="h-6 flex-1 px-1 py-0 font-mono text-xs"
|
||||
placeholder={creating?.kind === "dir" ? "folder-name" : "filename.py"}
|
||||
value={newEntryName}
|
||||
onChange={(e) => setNewEntryName(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") { cancelRef.current = false; void commitCreate(); }
|
||||
if (e.key === "Escape") cancelCreate();
|
||||
}}
|
||||
onBlur={() => { void commitCreate(); }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ── Recursive tree renderer ───────────────────────────────────────────────
|
||||
function renderTree(nodes: TreeNode[], skill: string, depth: number): React.ReactNode {
|
||||
const baseIndent = 8 + depth * 14;
|
||||
return nodes.map((node) => {
|
||||
if (node.type === "dir") {
|
||||
const key = `${skill}:${node.path}`;
|
||||
const open = expanded.has(key);
|
||||
return (
|
||||
<div key={node.path}>
|
||||
<div
|
||||
className="group flex cursor-pointer select-none items-center gap-1 rounded py-0.5 pr-1 text-sm hover:bg-muted"
|
||||
style={{ paddingLeft: baseIndent }}
|
||||
onClick={() => toggleExpanded(key)}
|
||||
>
|
||||
<ChevronRightIcon className={cn("size-3.5 shrink-0 transition-transform", open && "rotate-90")} />
|
||||
{open
|
||||
? <FolderOpenIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
: <FolderIcon className="size-3.5 shrink-0 text-amber-500" />
|
||||
}
|
||||
<span className="flex-1 truncate">{node.name}</span>
|
||||
<span className="ml-auto hidden shrink-0 items-center gap-0.5 group-hover:flex">
|
||||
<Button size="icon" variant="ghost" className="size-5" title="新建文件"
|
||||
onClick={(e) => { e.stopPropagation(); startCreate(skill, node.path, "file"); }}>
|
||||
<FilePlusIcon className="size-3 text-muted-foreground" />
|
||||
</Button>
|
||||
<Button size="icon" variant="ghost" className="size-5" title="新建文件夹"
|
||||
onClick={(e) => { e.stopPropagation(); startCreate(skill, node.path, "dir"); }}>
|
||||
<FolderPlusIcon className="size-3 text-muted-foreground" />
|
||||
</Button>
|
||||
<Button size="icon" variant="ghost" className="size-5" title="删除文件夹"
|
||||
onClick={(e) => { e.stopPropagation(); deletePath(skill, node.path); }}>
|
||||
<Trash2Icon className="size-3 text-destructive" />
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
{open && (
|
||||
<>
|
||||
{renderTree(node.children, skill, depth + 1)}
|
||||
{creating?.skill === skill && creating.inDir === node.path &&
|
||||
inlineInputJSX(baseIndent + 14)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// file node
|
||||
const isSelected = selected?.skill === skill && selected.path === node.path;
|
||||
return (
|
||||
<div
|
||||
key={node.path}
|
||||
className={cn(
|
||||
"group flex cursor-pointer select-none items-center gap-1 rounded py-0.5 pr-1 text-sm",
|
||||
isSelected ? "bg-accent text-accent-foreground" : "hover:bg-muted",
|
||||
)}
|
||||
style={{ paddingLeft: baseIndent + 16 }}
|
||||
onClick={() => setSelected({ skill, path: node.path })}
|
||||
>
|
||||
<FileTextIcon className="size-3.5 shrink-0 text-muted-foreground" />
|
||||
<span className="flex-1 truncate font-mono text-xs">{node.name}</span>
|
||||
<Button size="icon" variant="ghost" className="ml-auto hidden size-5 group-hover:flex"
|
||||
title="删除文件"
|
||||
onClick={(e) => { e.stopPropagation(); deletePath(skill, node.path); }}>
|
||||
<Trash2Icon className="size-3 text-destructive" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const selectedSkill = selected
|
||||
? skills.find((s) => s.name === selected.skill) ?? null
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div data-content-padding="false" className="flex flex-1 flex-col overflow-hidden">
|
||||
<div className="flex flex-col gap-0.5 border-b px-4 py-2.5 lg:px-6">
|
||||
<h1 className="text-sm font-semibold leading-tight">Skill</h1>
|
||||
<p className="text-muted-foreground text-xs">技能库 · agentskills.io 规范 · 按 Agent 授权可见</p>
|
||||
</div>
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
{/* ── 左侧文件树 ── */}
|
||||
<div className="flex w-64 shrink-0 flex-col border-r">
|
||||
<div className="flex flex-col gap-2 border-b p-2">
|
||||
<Button size="sm" variant="outline" className="w-full" onClick={() => setNewOpen(true)}>
|
||||
<PlusIcon className="size-3.5" />新建 Skill
|
||||
</Button>
|
||||
<input
|
||||
ref={uploadRef}
|
||||
type="file"
|
||||
accept=".zip,application/zip"
|
||||
className="hidden"
|
||||
onChange={onUploadPick}
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="w-full"
|
||||
disabled={uploading}
|
||||
onClick={() => uploadRef.current?.click()}
|
||||
title="上传包含 SKILL.md 的 .zip 压缩包"
|
||||
>
|
||||
<UploadIcon className="size-3.5" />
|
||||
{uploading ? "上传中…" : "上传压缩包"}
|
||||
</Button>
|
||||
</div>
|
||||
<ScrollArea className="flex-1">
|
||||
<div className="p-1">
|
||||
{skills.map((s) => {
|
||||
const isOpen = expanded.has(s.name);
|
||||
const tree = buildTree(s.files);
|
||||
const isSkillSelected = selected?.skill === s.name && selected.path === null;
|
||||
return (
|
||||
<div key={s.name}>
|
||||
{/* skill 根节点 */}
|
||||
<div
|
||||
className={cn(
|
||||
"group flex cursor-pointer select-none items-center gap-1 rounded px-2 py-1 text-sm",
|
||||
isSkillSelected ? "bg-accent text-accent-foreground" : "hover:bg-muted",
|
||||
)}
|
||||
onClick={() => {
|
||||
toggleExpanded(s.name);
|
||||
setSelected({ skill: s.name, path: null });
|
||||
}}
|
||||
>
|
||||
<ChevronRightIcon className={cn("size-3.5 shrink-0 transition-transform", isOpen && "rotate-90")} />
|
||||
{isOpen
|
||||
? <FolderOpenIcon className="size-3.5 shrink-0 text-blue-500" />
|
||||
: <FolderIcon className="size-3.5 shrink-0 text-blue-500" />
|
||||
}
|
||||
<span className="flex-1 truncate font-semibold">{s.name}</span>
|
||||
<span className="ml-auto hidden shrink-0 items-center gap-0.5 group-hover:flex">
|
||||
<Button size="icon" variant="ghost" className="size-5" title="新建文件"
|
||||
onClick={(e) => { e.stopPropagation(); startCreate(s.name, "", "file"); }}>
|
||||
<FilePlusIcon className="size-3 text-muted-foreground" />
|
||||
</Button>
|
||||
<Button size="icon" variant="ghost" className="size-5" title="新建文件夹"
|
||||
onClick={(e) => { e.stopPropagation(); startCreate(s.name, "", "dir"); }}>
|
||||
<FolderPlusIcon className="size-3 text-muted-foreground" />
|
||||
</Button>
|
||||
<Button size="icon" variant="ghost" className="size-5" title="删除 Skill"
|
||||
onClick={(e) => { e.stopPropagation(); deleteSkill(s.name); }}>
|
||||
<Trash2Icon className="size-3 text-destructive" />
|
||||
</Button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 展开:递归文件树 */}
|
||||
{isOpen && (
|
||||
<>
|
||||
{renderTree(tree, s.name, 0)}
|
||||
{creating?.skill === s.name && creating.inDir === "" &&
|
||||
inlineInputJSX(22)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{skills.length === 0 && (
|
||||
<p className="p-3 text-xs text-muted-foreground">暂无 Skill,点击「新建」开始</p>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</div>
|
||||
|
||||
{/* ── 右侧面板 ── */}
|
||||
<div className="flex flex-1 flex-col overflow-auto p-4">
|
||||
{!selected && (
|
||||
<div className="flex h-full items-center justify-center">
|
||||
<p className="text-sm text-muted-foreground">选择左侧 Skill 或文件</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selected && selected.path === null && selectedSkill && (
|
||||
<div className="max-w-xl space-y-5">
|
||||
<div>
|
||||
<h2 className="font-mono text-base font-semibold">{selectedSkill.name}</h2>
|
||||
{selectedSkill.description && (
|
||||
<p className="mt-1 text-sm text-muted-foreground">{selectedSkill.description}</p>
|
||||
)}
|
||||
<div className="mt-2 flex flex-wrap gap-2">
|
||||
{selectedSkill.license && (
|
||||
<Badge variant="outline" className="text-xs font-normal">License: {selectedSkill.license}</Badge>
|
||||
)}
|
||||
{selectedSkill.compatibility && (
|
||||
<Badge variant="secondary" className="text-xs font-normal">{selectedSkill.compatibility}</Badge>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── 关联 MCP ── */}
|
||||
<div className="space-y-2">
|
||||
<Label className="text-xs text-muted-foreground">
|
||||
关联 MCP
|
||||
<span className="ml-1 font-normal">(加载 Skill 时才披露/解锁其工具)</span>
|
||||
</Label>
|
||||
{mcpOptions.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">暂无 MCP,可在「MCP」页添加。</p>
|
||||
) : (
|
||||
<div className="flex flex-wrap gap-x-4 gap-y-2">
|
||||
{mcpOptions.map((m) => (
|
||||
<label key={m.id} className="flex cursor-pointer items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
checked={detailMcps.includes(m.name)}
|
||||
onCheckedChange={(on) => toggleSkillMcp(selectedSkill.name, m.name, !!on)}
|
||||
/>
|
||||
{m.name}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* ── 可见性 ── */}
|
||||
<div className="space-y-2">
|
||||
<Label className="text-xs text-muted-foreground">可见性(按 Agent 授权)</Label>
|
||||
<div className="space-y-2">
|
||||
{agents.map((a) => (
|
||||
<label key={a.key} className="flex cursor-pointer items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
checked={(visibility[selectedSkill.name] ?? []).includes(a.id)}
|
||||
onCheckedChange={() => toggleVisibility(selectedSkill.name, a.id, a.name)}
|
||||
/>
|
||||
{a.name}
|
||||
</label>
|
||||
))}
|
||||
{agents.length === 0 && (
|
||||
<span className="text-xs text-muted-foreground">(暂无 Agent)</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{selected && selected.path !== null && (
|
||||
<div className="flex h-full flex-col gap-2">
|
||||
<div className="flex items-center gap-2 text-xs text-muted-foreground">
|
||||
<span className="font-medium text-foreground">{selected.skill}</span>
|
||||
<span>/</span>
|
||||
<span className="font-mono">{selected.path}</span>
|
||||
<Button size="sm" className="ml-auto" onClick={saveFile} disabled={!dirty || saving}>
|
||||
{saving ? "保存中…" : "保存"}
|
||||
</Button>
|
||||
</div>
|
||||
{fileLoading ? (
|
||||
<p className="text-xs text-muted-foreground">加载中…</p>
|
||||
) : (
|
||||
<Textarea
|
||||
className="flex-1 resize-none font-mono text-xs"
|
||||
value={fileContent}
|
||||
onChange={(e) => { setFileContent(e.target.value); setDirty(true); }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ── 新建 Skill 对话框 ── */}
|
||||
<Sheet open={newOpen} onOpenChange={setNewOpen}>
|
||||
<SheetContent side="right" className="flex w-full flex-col gap-0 data-[side=right]:sm:max-w-xl">
|
||||
<SheetHeader className="px-4 pt-4">
|
||||
<SheetTitle>新建 Skill</SheetTitle>
|
||||
</SheetHeader>
|
||||
<Tabs defaultValue="basic" className="flex min-h-0 flex-1 flex-col">
|
||||
<TabsList className="mx-4 mt-3 shrink-0 justify-start">
|
||||
<TabsTrigger value="basic">基本信息</TabsTrigger>
|
||||
<TabsTrigger value="mcp">
|
||||
关联 MCP
|
||||
{newMcps.length > 0 && (
|
||||
<span className="ml-1.5 rounded-full bg-primary px-1.5 py-0.5 text-[10px] leading-none text-primary-foreground">
|
||||
{newMcps.length}
|
||||
</span>
|
||||
)}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="visibility">
|
||||
可见性
|
||||
{newVisibility.length > 0 && (
|
||||
<span className="ml-1.5 rounded-full bg-primary px-1.5 py-0.5 text-[10px] leading-none text-primary-foreground">
|
||||
{newVisibility.length}
|
||||
</span>
|
||||
)}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
|
||||
{/* 基本信息 */}
|
||||
<TabsContent value="basic" className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-4 pt-4 data-[state=inactive]:hidden">
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="sk-name">名称 <span className="text-destructive">*</span></Label>
|
||||
<Input id="sk-name" placeholder="sqli-deepdive" value={newName} onChange={(e) => setNewName(e.target.value)} />
|
||||
<p className="text-muted-foreground text-xs">小写字母 / 数字 / 连字符,1–64 字符</p>
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label htmlFor="sk-desc">描述 <span className="text-destructive">*</span></Label>
|
||||
<Textarea id="sk-desc" rows={2} className="resize-none"
|
||||
placeholder="这个 skill 做什么、何时使用。"
|
||||
value={newDesc} onChange={(e) => setNewDesc(e.target.value)} />
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-1.5">
|
||||
<Label className="text-muted-foreground text-xs">license</Label>
|
||||
<Input placeholder="MIT / Proprietary" value={newLicense} onChange={(e) => setNewLicense(e.target.value)} />
|
||||
</div>
|
||||
<div className="grid gap-1.5">
|
||||
<Label className="text-muted-foreground text-xs">compatibility</Label>
|
||||
<Input placeholder="需要 sqlmap、python3" value={newCompat} onChange={(e) => setNewCompat(e.target.value)} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex min-h-0 flex-1 flex-col gap-1.5">
|
||||
<Label htmlFor="sk-inst">正文 <span className="text-muted-foreground text-xs font-normal">(留空自动生成骨架)</span></Label>
|
||||
<Textarea id="sk-inst"
|
||||
className="min-h-40 flex-1 resize-none font-mono text-sm leading-relaxed"
|
||||
placeholder={"## 执行方法\n\n1. 先探测错误\n2. 区分盲注类型\n\n脚本放 scripts/ 目录。"}
|
||||
value={newInst} onChange={(e) => setNewInst(e.target.value)} />
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
{/* 关联 MCP */}
|
||||
<TabsContent value="mcp" className="overflow-y-auto px-4 pb-4 pt-4 data-[state=inactive]:hidden">
|
||||
<p className="mb-3 text-xs text-muted-foreground">加载 Skill 时才披露并解锁所选 MCP 的工具。</p>
|
||||
{mcpOptions.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">暂无 MCP,可在「MCP」页添加。</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{mcpOptions.map((m) => (
|
||||
<label key={m.id} className="flex cursor-pointer items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
checked={newMcps.includes(m.name)}
|
||||
onCheckedChange={(on) =>
|
||||
setNewMcps((cur) => on ? [...cur, m.name] : cur.filter((n) => n !== m.name))
|
||||
}
|
||||
/>
|
||||
{m.name}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
|
||||
{/* 可见性 */}
|
||||
<TabsContent value="visibility" className="overflow-y-auto px-4 pb-4 pt-4 data-[state=inactive]:hidden">
|
||||
<p className="mb-3 text-xs text-muted-foreground">选中的 Agent 创建后即可见此 Skill。</p>
|
||||
{agents.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">(暂无 Agent)</p>
|
||||
) : (
|
||||
<div className="flex flex-col gap-2">
|
||||
{agents.map((a) => (
|
||||
<label key={a.key} className="flex cursor-pointer items-center gap-2 text-sm">
|
||||
<Checkbox
|
||||
checked={newVisibility.includes(a.id)}
|
||||
onCheckedChange={(on) =>
|
||||
setNewVisibility((cur) => on ? [...cur, a.id] : cur.filter((id) => id !== a.id))
|
||||
}
|
||||
/>
|
||||
{a.name}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
<SheetFooter className="flex-row justify-end gap-2 border-t px-4 py-3">
|
||||
<Button variant="outline" onClick={() => setNewOpen(false)}>取消</Button>
|
||||
<Button onClick={createNewSkill} disabled={creatingSkill}>{creatingSkill ? "创建中…" : "创建"}</Button>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user