import { useEffect, useRef, useState } from 'react'; import type { FormEvent } from 'react'; import { BookOpenText, Check, CircleAlert, FileText, LoaderCircle, Plus, Power, RefreshCw, ShieldCheck } from 'lucide-react'; import { api } from './api'; import './SkillCenter.css'; type SkillVersion = { revision: number; version: string; source: { path: string; sha256: string; bytes: number }; snapshotSha256: string; createdAt: string }; type Skill = SkillVersion & { id: string; projectId: string; name: string; description: string; enabled: boolean; configurationRevision: number; updatedAt: string; status: string; reason: string; revisions: SkillVersion[] }; type SkillView = { skills: Skill[]; projectId: string; revision: number; modelRequests: number }; type Snapshot = SkillVersion & { id: string; content: string }; const statusNames: Record = { current: '来源一致', changed: '来源已变化', unavailable: '来源不可用' }; export function SkillCenter({ projectId, busy }: { projectId: string; busy: boolean }) { const [view, setView] = useState(null), [working, setWorking] = useState(false); const [error, setError] = useState(''), [notice, setNotice] = useState(''); const [snapshot, setSnapshot] = useState(null), [versions, setVersions] = useState>({}); const [draft, setDraft] = useState({ name: '', description: '', path: '', version: '1.0.0' }); const generation = useRef(0); const url = '/projects/' + projectId + '/skills'; const load = async (current = generation.current) => { const result = await api(url); if (current === generation.current) setView(result); }; useEffect(() => { const current = ++generation.current; setView(null); setSnapshot(null); setError(''); void load(current).catch(cause => { if (current === generation.current) setError(String(cause.message ?? cause)); }); return () => { generation.current++; }; }, [projectId]); const perform = async (action: () => Promise, success: string) => { const current = generation.current; setWorking(true); setError(''); setNotice(''); try { await action(); if (current === generation.current) { setNotice(success); await load(current); } } catch (cause) { if (current === generation.current) setError(cause instanceof Error ? cause.message : String(cause)); } finally { if (current === generation.current) setWorking(false); } }; const register = (event: FormEvent) => { event.preventDefault(); void perform(async () => { await api(url, draft); }, '技能已登记。审查原文后,可以为当前项目启用。'); }; const read = (skill: Skill, revision: number) => { const current = generation.current; void perform(async () => { const value = await api(url + '/content?id=' + skill.id + '&revision=' + revision); if (current === generation.current) setSnapshot(value); }, '已读取保存的原修订。'); }; const skills = view?.skills ?? [], active = skills.filter(value => value.enabled && value.status === 'current').length; const locked = busy || working; return
项目能力 / SKILLS

让工作流程有据可查

登记本地技能,在本项目任务中按需读取。启用前先审查内容,来源改变后需要重新确认。

{active} 项可用{skills.length} 项已登记沿用项目权限与审查
{error &&

{error}

} {notice &&

{notice}

} {busy &&

项目正在执行,停止任务后可以修改技能配置。

}
{skills.map(skill =>

{skill.name}v{skill.version}

{skill.description}

{skill.enabled ? '已启用' : '已停用'}
{statusNames[skill.status]}修订 {skill.revision}SHA256 {skill.source.sha256.slice(0, 16)}{skill.source.bytes.toLocaleString()} B{skill.source.path}
{skill.reason &&

{skill.reason}

}
版本与来源记录 · {skill.revisions.length} 个修订
{skill.revisions.map(version =>
r{version.revision} · {version.version}{version.source.sha256.slice(0, 16)}
)}
{ event.preventDefault(); void perform(() => api(url + '/refresh', { id: skill.id, revision: skill.revision, configurationRevision: skill.configurationRevision, version: versions[skill.id] || skill.version }), '新修订已登记,并已停用。请审查后重新启用。'); }} className="skill-refresh">
)}
{!view && !error &&

正在核对已登记技能

} {view && !skills.length &&
为项目接入第一项技能

选择你已审查的 SKILL.md,填写名称与用途。登记后默认停用。

} {snapshot &&
原文审查 · {snapshot.version} / r{snapshot.revision}

这是保存的技能参考流程,执行仍需遵循项目权限。附带脚本和文件不会自动运行。

快照 SHA256 {snapshot.snapshotSha256}
{snapshot.content}
}

登记本地技能

UTF-8 · SKILL.md · 最大 64KB