feat: add source-verified project skills

This commit is contained in:
Agent Workbench Dev
2026-10-30 18:58:55 +08:00
parent b25b7ef974
commit 601f13c4f8
21 changed files with 753 additions and 12 deletions
+4
View File
@@ -11,6 +11,7 @@ import { ResearchPanel } from './ResearchPanel';
import { EnginePanel } from './EnginePanel';
import { ModelCenter } from './ModelCenter';
import { ProjectMemoryPanel } from './ProjectMemoryPanel';
import { SkillCenter } from './SkillCenter';
const activeStates = ['running', 'awaiting_approval', 'stopping'];
const defaultConfig: Config = { mode: 'demo', baseUrl: 'http://127.0.0.1:11434/v1', model: '', contextLimit: 16000, maxSteps: 12, maxOutputTokens: 2048, hasKey: false, maxRunDurationMs: 600000, maxRunTokens: 200000, maxTaskTokens: 1000000 };
@@ -68,6 +69,7 @@ export default function App() {
const [engineOpen, setEngineOpen] = useState(false);
const [modelCenterOpen, setModelCenterOpen] = useState(false);
const [memoryOpen, setMemoryOpen] = useState(false);
const [skillsOpen, setSkillsOpen] = useState(false);
const [researchDocs, setResearchDocs] = useState<ResearchDoc[]>([]);
const [report, setReport] = useState<{ title: string; content: string } | null>(null);
const chatEnd = useRef<HTMLDivElement>(null);
@@ -510,6 +512,7 @@ export default function App() {
</header>
<div className="task-toolbar"><span className="task-local"><GitBranch size={13} />本地项目</span>{session ? <Status value={session.status} /> : <span className="subtle">等待新任务</span>}<div className="toolbar-actions">
<IconButton label="运行诊断" onClick={() => openDiagnostics()}><Activity size={15} /></IconButton>
<IconButton label="项目技能" onClick={() => setSkillsOpen(true)} disabled={!selectedProject}><BookOpenText size={15} /></IconButton>
<IconButton label="查看任务记录" onClick={() => showInspector('task')}><ClipboardCheck size={15} /></IconButton>
<IconButton label="本地代理引擎" onClick={() => setEngineOpen(true)} disabled={!session}><Link2 size={15} /></IconButton>
<IconButton label="REA 工件研究" onClick={() => void openRea()} disabled={!selectedProject || creatingSession}><BookOpenText size={15} /></IconButton>
@@ -555,6 +558,7 @@ export default function App() {
{researchOpen && <Modal title="机制研究与独立设计" description="从分发客户端的静态证据提炼产品机制。运行时与远端服务的未知部分在报告中说明。" wide onClose={() => setResearchOpen(false)}><div className="research-layout"><nav>{researchDocs.map(document => <button className={report?.title === document.title ? 'selected' : ''} key={document.id} onClick={() => loadReport(document.id)}><BookOpenText size={15} /><span><strong>{document.title}</strong><small>{document.description}</small></span></button>)}</nav><article className="research-document">{report && <ResearchContent content={report.content} />}</article></div></Modal>}
{modelCenterOpen && <Modal title="模型中心" description="连接、模型池与执行健康统一管理。" wide onClose={() => setModelCenterOpen(false)}><ModelCenter busy={anyRunning} onConfig={setConfig} onLegacy={() => { setModelCenterOpen(false); openSettings(); }} /></Modal>}
{memoryOpen && selectedProject && <Modal title="项目记忆" description="项目事实与决策绑定源码指纹,变化后自动要求重新核对。" wide onClose={() => setMemoryOpen(false)}><ProjectMemoryPanel key={selectedProject.id + ':' + (session?.id ?? '')} project={selectedProject} session={session?.projectId === selectedProject.id ? session : null} /></Modal>}
{skillsOpen && selectedProject && <Modal title="项目技能" description="管理当前项目的技能来源、版本与启用状态。" wide onClose={() => setSkillsOpen(false)}><SkillCenter key={selectedProject.id} projectId={selectedProject.id} busy={isRunning} /></Modal>}
{toast && <div className="toast" role="status"><span>{toast}</span><IconButton label="关闭提示" onClick={() => setToast('')}><X size={14} /></IconButton></div>}
</div>
);
+2
View File
@@ -40,6 +40,7 @@ export function RequestContextPanel({ session, runId, openArtifact, onError }: {
<dt>历史记录</dt><dd>保留 {plan.retainedMessages} 条 · 保存 {plan.archivedGroups} 组原记录</dd>
{!!plan.workingSetEntries && <><dt>当前任务依据</dt><dd>{plan.workingSetEntries} 项代码与执行结果</dd></>}
{!!plan.projectMemoryEntries && <><dt>项目记忆</dt><dd>{plan.projectMemoryEntries} 条来源已核对的记录</dd></>}
{!!plan.skillCatalogEntries && <><dt>技能目录</dt><dd>{plan.skillCatalogEntries} 项本次目录记录</dd></>}
<dt>发送内容</dt><dd>{number(plan.requestBytes)} B<code className="context-sha" title={plan.requestSha256}>{plan.requestSha256.slice(0, 16)}</code></dd>
</dl>
<p className="record-footnote">估算包含系统提示、工具定义和历史。任务要求完整保留;省略的原记录可从本机工件检索。实际用量以模型服务为准。</p>
@@ -49,6 +50,7 @@ export function RequestContextPanel({ session, runId, openArtifact, onError }: {
{plan.workingSetArtifactId && <button type="button" className="text-button" onClick={() => openArtifact(plan.workingSetArtifactId!)}><BrainCircuit size={13} />查看工作依据</button>}
{plan.latestToolsArtifactId && <button type="button" className="text-button" onClick={() => openArtifact(plan.latestToolsArtifactId!)}><FileText size={13} />查看最近工具反馈</button>}
{plan.projectMemoryArtifactId && <button type="button" className="text-button" onClick={() => openArtifact(plan.projectMemoryArtifactId!)}><BrainCircuit size={13} />查看本次项目记忆</button>}
{plan.skillCatalogArtifactId && <button type="button" className="text-button" onClick={() => openArtifact(plan.skillCatalogArtifactId!)}><FileText size={13} />查看本次技能目录</button>}
{!!plan.archivedGroups && <button type="button" className="text-button" onClick={() => setHistoryId(plan.id)}><Archive size={13} />检索完整历史</button>}</div>
{historyId && <HistoryModal key={session.id + ':' + historyId} sessionId={session.id} planId={historyId} onError={onError}
onClose={() => setHistoryId('')} openArtifact={id => { setHistoryId(''); openArtifact(id); }} />}
+70
View File
@@ -0,0 +1,70 @@
.skill-center { color: #27394b; --skill-line: #c8d2dc; --skill-surface: #f3f6f9; }
.skill-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.skill-kicker { display: flex; align-items: center; gap: 7px; color: #516d85; font-size: 11px; font-weight: 700; letter-spacing: .07em; }
.skill-heading h3 { margin: 9px 0; font: 700 23px/1.4 'Microsoft YaHei UI', 'Segoe UI', sans-serif; color: #16324c; }
.skill-heading p { max-width: 590px; margin: 0; color: #62758a; font-size: 13px; line-height: 1.7; }
.skill-heading > button { flex-shrink: 0; }
.skill-status-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 22px; border-block: 1px solid var(--skill-line); padding: 13px 2px; margin-bottom: 18px; font-size: 12px; color: #486077; }
.skill-status-bar > span { display: inline-flex; align-items: center; gap: 7px; }
.skill-light { width: 7px; height: 7px; background: #307f72; border-radius: 50%; }
.skill-list { display: grid; gap: 14px; }
.skill-row { border: 1px solid var(--skill-line); border-left: 4px solid #647f99; background: #fff; padding: 18px; border-radius: 6px; }
.skill-row.skill-changed, .skill-row.skill-unavailable { border-left-color: #ab712c; }
.skill-row-title { display: flex; align-items: start; gap: 11px; }
.skill-row-title > svg { margin-top: 3px; color: #4f708e; flex-shrink: 0; }
.skill-row-title > div { flex: 1; min-width: 0; }
.skill-row h4 { margin: 0 0 6px; font-size: 15px; color: #213f59; overflow-wrap: anywhere; }
.skill-row h4 span { margin-left: 9px; font: 500 11px/1.4 Consolas, monospace; color: #697e91; }
.skill-row-title p { margin: 0; font-size: 12px; color: #63788b; line-height: 1.6; overflow-wrap: anywhere; }
.skill-switch-state { border: 1px solid #d2dce5; color: #6b7d8b; padding: 4px 7px; font-size: 11px; white-space: nowrap; border-radius: 4px; }
.skill-switch-state.on { color: #266b5d; background: #edf6f2; border-color: #b7d4c9; }
.skill-source { margin: 15px 0; display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; font-size: 11px; color: #698096; }
.skill-source code, .skill-revision-list code, .skill-snapshot > code { font: 11px/1.6 Consolas, 'Cascadia Code', monospace; overflow-wrap: anywhere; }
.skill-source-state { color: #35746a; font-weight: 600; }
.skill-source-state.changed, .skill-source-state.unavailable { color: #986324; }
.skill-path { flex: 0 0 100%; color: #5f7489; }
.skill-controls { display: flex; gap: 9px; }
.skill-revisions { border-top: 1px solid #e1e7ed; margin-top: 15px; padding-top: 12px; }
.skill-revisions summary { color: #5d7287; font-size: 12px; cursor: pointer; min-height: 25px; }
.skill-revision-list { display: grid; gap: 8px; margin: 10px 0; }
.skill-revision-list > div { display: flex; align-items: center; gap: 12px; font-size: 12px; flex-wrap: wrap; }
.skill-refresh { display: flex; align-items: end; gap: 10px; margin-top: 14px; }
.skill-refresh label { display: grid; gap: 5px; font-size: 11px; }
.skill-refresh input { max-width: 160px; }
.skill-alert, .skill-notice { display: flex; gap: 8px; align-items: start; padding: 12px; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; border: 1px solid #d7c3ba; color: #95513c; background: #fff6f1; border-radius: 4px; }
.skill-notice { color: #34695d; background: #eff7f3; border-color: #bfd8cb; }
.skill-alert svg, .skill-notice svg { flex-shrink: 0; margin-top: 2px; }
.skill-warning { color: #916126; font-size: 12px; line-height: 1.6; overflow-wrap: anywhere; }
.skill-empty { display: grid; gap: 10px; justify-items: center; text-align: center; padding: 30px 14px; color: #688098; border: 1px dashed #cad7e1; border-radius: 6px; margin: 14px 0; }
.skill-empty strong { color: #36566f; font-size: 14px; }
.skill-empty p { font-size: 12px; margin: 0; line-height: 1.7; }
.skill-register { border: 1px solid var(--skill-line); border-radius: 6px; padding: 18px; margin-top: 20px; background: var(--skill-surface); }
.skill-register-heading { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.skill-register-heading h4 { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 14px; }
.skill-register-heading > span { font-size: 11px; color: #6f8193; }
.skill-form-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .4fr); gap: 12px; }
.skill-form-grid label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; }
.skill-center input, .skill-center textarea { width: 100%; min-width: 0; background: #fff; border: 1px solid #c8d4df; border-radius: 4px; padding: 9px 10px; font: 13px/1.5 'Segoe UI', 'Microsoft YaHei UI', sans-serif; color: #263d52; }
.skill-center input:focus-visible, .skill-center textarea:focus-visible, .skill-center summary:focus-visible, .skill-snapshot pre:focus-visible { outline: 2px solid #4f7b9e; outline-offset: 2px; }
.skill-full { grid-column: 1 / -1; }
.skill-register footer { margin-top: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 11px; color: #6c8297; }
.skill-snapshot { margin-top: 18px; border: 1px solid #aac0d1; border-radius: 6px; overflow: hidden; }
.skill-snapshot header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: #e8f0f6; font-size: 12px; gap: 8px; }
.skill-snapshot p { margin: 12px 14px; color: #63788b; font-size: 12px; line-height: 1.6; }
.skill-snapshot > code { display: block; margin: 0 14px; color: #55718b; }
.skill-snapshot pre { padding: 14px; margin: 10px 0 0; max-height: 330px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.8 Consolas, 'Microsoft YaHei UI', monospace; background: #f4f7fa; }
@media (max-width: 620px) {
.skill-heading { flex-direction: column; gap: 13px; }
.skill-heading h3 { font-size: 21px; }
.skill-row, .skill-register { padding: 13px; }
.skill-row-title { gap: 8px; }
.skill-row-title > svg { display: none; }
.skill-row h4 span { display: block; margin: 5px 0 0; }
.skill-status-bar { gap: 10px 16px; }
.skill-controls > button { flex: 1; }
.skill-center button, .skill-center summary { min-height: 44px; }
.skill-form-grid { grid-template-columns: minmax(0, 1fr); }
.skill-register footer { flex-direction: column; align-items: stretch; }
.skill-register footer > button { justify-content: center; }
.skill-revision-list { gap: 4px; }
}
+63
View File
@@ -0,0 +1,63 @@
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<string, string> = { current: '来源一致', changed: '来源已变化', unavailable: '来源不可用' };
export function SkillCenter({ projectId, busy }: { projectId: string; busy: boolean }) {
const [view, setView] = useState<SkillView | null>(null), [working, setWorking] = useState(false);
const [error, setError] = useState(''), [notice, setNotice] = useState('');
const [snapshot, setSnapshot] = useState<Snapshot | null>(null), [versions, setVersions] = useState<Record<string, string>>({});
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<SkillView>(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<unknown>, 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<Snapshot>(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 <section className="skill-center" aria-label="项目技能管理" aria-busy={working}>
<header className="skill-heading"><div><span className="skill-kicker"><BookOpenText size={15} />项目能力 / SKILLS</span><h3>让工作流程有据可查</h3><p>登记本地技能,在本项目任务中按需读取。启用前先审查内容,来源改变后需要重新确认。</p></div><button type="button" className="button secondary" disabled={working} onClick={() => void perform(() => load(), '来源状态已重新核对。')}><RefreshCw size={14} className={working ? 'spin' : ''} />核对来源</button></header>
<div className="skill-status-bar"><span><i className="skill-light" />{active} 项可用</span><span>{skills.length} 项已登记</span><span><ShieldCheck size={14} />沿用项目权限与审查</span></div>
{error && <p className="skill-alert" role="alert"><CircleAlert size={16} />{error}</p>}
{notice && <p className="skill-notice" role="status"><Check size={16} />{notice}</p>}
{busy && <p className="skill-warning">项目正在执行,停止任务后可以修改技能配置。</p>}
<div className="skill-list">{skills.map(skill => <article className={'skill-row skill-' + skill.status} key={skill.id}>
<div className="skill-row-title"><BookOpenText size={19} /><div><h4>{skill.name}<span>v{skill.version}</span></h4><p>{skill.description}</p></div><span className={'skill-switch-state ' + (skill.enabled ? 'on' : '')}>{skill.enabled ? '已启用' : '已停用'}</span></div>
<div className="skill-source"><span className={'skill-source-state ' + skill.status}>{statusNames[skill.status]}</span><span>修订 {skill.revision}</span><code title={skill.source.sha256}>SHA256 {skill.source.sha256.slice(0, 16)}</code><span>{skill.source.bytes.toLocaleString()} B</span><code className="skill-path">{skill.source.path}</code></div>
{skill.reason && <p className="skill-warning">{skill.reason}</p>}
<div className="skill-controls"><button type="button" className="button secondary" disabled={working} onClick={() => read(skill, skill.revision)}><FileText size={14} />审查原文</button><button type="button" className={'button ' + (skill.enabled ? 'secondary' : 'primary')} disabled={locked || !skill.enabled && skill.status !== 'current'} onClick={() => void perform(() => api(url + '/toggle', { id: skill.id, revision: skill.revision, configurationRevision: skill.configurationRevision, enabled: !skill.enabled }), skill.enabled ? '技能已停用。' : '技能已启用,后续任务可以按需读取。')}><Power size={14} />{skill.enabled ? '停用技能' : '启用技能'}</button></div>
<details className="skill-revisions"><summary>版本与来源记录 · {skill.revisions.length} 个修订</summary><div className="skill-revision-list">{skill.revisions.map(version => <div key={version.revision}><span>r{version.revision} · {version.version}</span><code>{version.source.sha256.slice(0, 16)}</code><button type="button" className="text-button" disabled={working} onClick={() => read(skill, version.revision)}>查看该修订</button></div>)}</div><form onSubmit={event => { 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"><label>新修订版本<input aria-label={'新修订版本 ' + skill.name} value={versions[skill.id] ?? skill.version} onChange={event => setVersions({ ...versions, [skill.id]: event.target.value })} maxLength={80} /></label><button type="submit" className="button secondary" disabled={locked}><RefreshCw size={14} />登记新修订</button></form></details>
</article>)}</div>
{!view && !error && <p className="skill-empty"><LoaderCircle size={20} className="spin" />正在核对已登记技能</p>}
{view && !skills.length && <div className="skill-empty"><BookOpenText size={27} /><strong>为项目接入第一项技能</strong><p>选择你已审查的 SKILL.md,填写名称与用途。登记后默认停用。</p></div>}
{snapshot && <section className="skill-snapshot" aria-label="技能原文"><header><strong>原文审查 · {snapshot.version} / r{snapshot.revision}</strong><button type="button" className="text-button" onClick={() => setSnapshot(null)}>关闭原文</button></header><p>这是保存的技能参考流程,执行仍需遵循项目权限。附带脚本和文件不会自动运行。</p><code>快照 SHA256 {snapshot.snapshotSha256}</code><pre tabIndex={0}>{snapshot.content}</pre></section>}
<form className="skill-register" onSubmit={register}><div className="skill-register-heading"><h4><Plus size={17} />登记本地技能</h4><span>UTF-8 · SKILL.md · 最大 64KB</span></div><div className="skill-form-grid"><label>技能名称<input required value={draft.name} onChange={event => setDraft({ ...draft, name: event.target.value })} maxLength={100} placeholder="例如:工程交付检查" /></label><label>版本<input required value={draft.version} onChange={event => setDraft({ ...draft, version: event.target.value })} maxLength={80} /></label><label className="skill-full">技能文件路径<input required value={draft.path} onChange={event => setDraft({ ...draft, path: event.target.value })} placeholder="D:\skills\project-delivery\SKILL.md" /></label><label className="skill-full">用途说明<textarea required rows={2} maxLength={500} value={draft.description} onChange={event => setDraft({ ...draft, description: event.target.value })} placeholder="说明何时使用这项技能,便于任务选择。" /></label></div><footer><span>登记与核对来源不会请求模型。</span><button type="submit" className="button primary" disabled={locked || !draft.name.trim() || !draft.path.trim() || !draft.description.trim()}>{working ? <LoaderCircle size={14} className="spin" /> : <Plus size={14} />}登记技能</button></footer></form>
</section>;
}
+1
View File
@@ -98,6 +98,7 @@ export interface ContextPlan {
workingSetViewVersion?: number; workingRetentionTokens?: number;
latestToolsArtifactId?: string | null; latestToolsSha256?: string | null; latestToolsEntries?: number;
projectMemoryArtifactId?: string | null; projectMemorySha256?: string | null; projectMemoryEntries?: number;
skillCatalogArtifactId?: string | null; skillCatalogSha256?: string | null; skillCatalogEntries?: number;
actualUsage: { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number } | null; requestAttempts: number; error?: string;
budget: { contextLimit: number; outputReservation: number; safetyTokens: number; inputBudget: number; targetInputTokens: number; runRemainingTokens: number | null; taskRemainingTokens: number | null };
}