136 lines
29 KiB
TypeScript
136 lines
29 KiB
TypeScript
import { useCallback, useEffect, useRef, useState } from 'react';
|
||
import { ArrowUpRight, Check, GitBranch, LoaderCircle, Play, RefreshCw, ShieldCheck, Square } from 'lucide-react';
|
||
import { api, downloadBlob } from './api';
|
||
import { Modal } from './components';
|
||
import { PurgeStrategyControl, emptyPurgeDraft, purgeDraftReady, purgeStrategyInput } from './PurgeStrategyControl';
|
||
import type { CollaborationGroup, Config, Session, WorkerView, ControlledEngineAvailability } from './types';
|
||
import './WorkerPanel.css';
|
||
|
||
const active = ['preparing', 'starting', 'running', 'stopping', 'collecting', 'merge_preparing', 'reconciling'];
|
||
const labels: Record<string, string> = { planned: '计划已封存', unprepared: '待创建', partially_prepared: '部分工作区已创建', ready: '就绪', preparing: '创建工作区', starting: '启动中', running: '执行中', stopping: '停止中', collecting: '核对成果', merge_preparing: '准备合并审查', reconciling: '核对现场', completed: '完成', ready_to_collect: '待核对成果', collected: '成果可审查', conflict: '需要处理冲突', merge_prepared: '等待合并审查', failed: '需要处理', paused: '已暂停', awaiting_review: '等待改动审查', needs_review: '等待改动审查', unknown: '结果待核对', stale: '来源已变化', discarded: '计划已撤销', resolved_external: '已保留现场' };
|
||
const number = (value?: number) => (value ?? 0).toLocaleString('zh-CN');
|
||
const statusLabel = (value: string, open = false, merged = false) => merged ? '已合并到父工程' : open && value === 'collected' ? '成果可合并' : open && value === 'merge_preparing' ? '正在合并到父工程' : value === 'awaiting_approval' ? '等待检查审批' : labels[value] ?? value;
|
||
type ModelRoutes = { connections: { id: string; name: string; model: string; enabled: boolean; revision: number }[]; pools: { id: string; name: string; revision: number }[] };
|
||
const newDraft = (label = '独立模块') => ({ label, goal: '', paths: '', role: '工程实现', requirements: '', model: 'default' });
|
||
const splitPaths = (value: string) => value.split(/[\n,,]/).map(path => path.trim()).filter(Boolean);
|
||
|
||
export function WorkerPanel({ session, config, busy, onSession, onNavigate, onReview }: {
|
||
session: Session; config: Config; busy: boolean; onSession: (value: Session) => void;
|
||
onNavigate: (projectId: string, sessionId: string, view?: 'task' | 'changes' | 'approval') => Promise<void>; onReview: () => void;
|
||
}) {
|
||
const [view, setView] = useState<WorkerView | null>(null), [selectedId, setSelectedId] = useState('');
|
||
const [error, setError] = useState(''), [action, setAction] = useState(''), [loading, setLoading] = useState(false);
|
||
const [goal, setGoal] = useState(''), [creating, setCreating] = useState(false);
|
||
const [engineMode, setEngineMode] = useState<'workbench' | 'deepseek'>('workbench'), [engineRoot, setEngineRoot] = useState('');
|
||
const [engineInstallation, setEngineInstallation] = useState<ControlledEngineAvailability | null>(null), [detectingEngine, setDetectingEngine] = useState(false);
|
||
const detection = useRef(0);
|
||
const [purge, setPurge] = useState(emptyPurgeDraft);
|
||
const [drafts, setDrafts] = useState([newDraft('核心实现'), newDraft()]);
|
||
const [routes, setRoutes] = useState<ModelRoutes | null>(null);
|
||
const openMode = config.executionMode === 'unrestricted';
|
||
const [tokens, setTokens] = useState(config.maxRunTokens), [steps, setSteps] = useState(Math.min(200, config.maxSteps * 2));
|
||
const [duration, setDuration] = useState(Math.floor(config.maxRunDurationMs / 60000)), [toolCalls, setToolCalls] = useState(96);
|
||
const [confirmation, setConfirmation] = useState<{ group: CollaborationGroup; operation: string; workerId?: string; retain?: boolean } | null>(null);
|
||
const [preview, setPreview] = useState<{ title: string; content: string; groupId: string } | null>(null), [readEvidenceSha, setReadEvidenceSha] = useState('');
|
||
const scope = useRef(0), requestId = useRef(0), fetchPending = useRef<number | null>(null), selectedGroup = useRef('');
|
||
const load = useCallback(async (quiet = false) => {
|
||
if (fetchPending.current !== null) return;
|
||
const generation = scope.current, request = ++requestId.current; fetchPending.current = request;
|
||
if (!quiet) setLoading(true);
|
||
try { const [result, models] = await Promise.all([api<WorkerView>('/sessions/' + session.id + '/collaborations'), api<ModelRoutes>('/model-center')]); if (generation === scope.current && request === requestId.current) { setView(result); setRoutes(models); } }
|
||
catch (failure) { if (generation === scope.current) setError(failure instanceof Error ? failure.message : String(failure)); }
|
||
finally { if (fetchPending.current === request) fetchPending.current = null; if (generation === scope.current) setLoading(false); }
|
||
}, [session.id]);
|
||
useEffect(() => { scope.current++; fetchPending.current = null; setView(null); setRoutes(null); setDrafts([newDraft('核心实现'), newDraft()]); setGoal(''); setSelectedId(''); setCreating(false); setEngineInstallation(null); setEngineMode('workbench'); setDetectingEngine(false); setPurge(emptyPurgeDraft()); void load(); return () => { scope.current++; requestId.current++; detection.current++; }; }, [load]);
|
||
useEffect(() => { void load(true); }, [session.revision, load]);
|
||
const group = view?.groups.find(value => value.id === selectedId) ?? view?.groups.at(-1), running = !!group && active.includes(group.status);
|
||
const openGroup = group?.model.executionMode === 'unrestricted';
|
||
selectedGroup.current = group?.id ?? '';
|
||
useEffect(() => { setError(''); setAction(''); setConfirmation(null); setPreview(null); setReadEvidenceSha(''); }, [session.id, group?.id, group?.evidence?.sha256]);
|
||
useEffect(() => { if (!running) return; const timer = setInterval(() => void load(true), 1500); return () => clearInterval(timer); }, [running, load]);
|
||
async function execute(group: CollaborationGroup, operation: string, extra: Record<string, unknown> = {}) {
|
||
if (selectedGroup.current !== group.id) return;
|
||
const generation = scope.current; setAction(operation); setError(''); setConfirmation(null);
|
||
try {
|
||
const result = await api<{ session: Session }>('/sessions/' + session.id + '/collaborations/' + group.id + '/' + operation, { fingerprint: group.fingerprint, ...extra });
|
||
if (generation !== scope.current || selectedGroup.current !== group.id) return;
|
||
onSession(result.session); await load(true);
|
||
} catch (failure) { if (generation === scope.current && selectedGroup.current === group.id) setError(failure instanceof Error ? failure.message : String(failure)); }
|
||
finally { if (generation === scope.current && selectedGroup.current === group.id) setAction(''); }
|
||
}
|
||
async function create() {
|
||
const generation = scope.current; setAction('plan'); setError('');
|
||
try {
|
||
const result = await api<{ group: CollaborationGroup; session: Session }>('/sessions/' + session.id + '/collaborations', {
|
||
goal, children: (engineMode === 'deepseek' ? drafts.slice(0, 1) : drafts).map(child => ({ label: child.label, goal: child.goal, paths: splitPaths(child.paths), role: child.role, requirements: child.requirements.split('\n').map(value => value.trim()).filter(Boolean), ...(child.model === 'default' ? {} : { modelSelection: { type: child.model.split(':')[0], id: child.model.slice(child.model.indexOf(':') + 1) } }) })),
|
||
...(engineMode === 'deepseek' ? { engine: { id: 'deepseek-harness', root: engineInstallation?.root, controlledSha256: engineInstallation?.controlledSha256,
|
||
...(purge.enabled ? { strategy: purgeStrategyInput(purge) } : {}) } } : {}),
|
||
budget: { maxTokens: tokens, maxSteps: steps, maxToolCalls: toolCalls, maxDurationMs: duration * 60000 },
|
||
});
|
||
if (generation !== scope.current) return;
|
||
setSelectedId(result.group.id); setCreating(false); onSession(result.session); await load(true);
|
||
} catch (failure) { if (generation === scope.current) setError(failure instanceof Error ? failure.message : String(failure)); }
|
||
finally { if (generation === scope.current) setAction(''); }
|
||
}
|
||
async function detectEngine() {
|
||
const generation = scope.current, request = ++detection.current; setDetectingEngine(true); setError('');
|
||
try {
|
||
const result = await api<ControlledEngineAvailability>('/engines/deepseek/controlled-availability' + (engineRoot.trim() ? '?root=' + encodeURIComponent(engineRoot.trim()) : ''));
|
||
if (generation !== scope.current || request !== detection.current) return;
|
||
setEngineInstallation(result); if (result.root) setEngineRoot(result.root);
|
||
} catch (failure) { if (generation === scope.current && request === detection.current) setError(failure instanceof Error ? failure.message : String(failure)); }
|
||
finally { if (generation === scope.current && request === detection.current) setDetectingEngine(false); }
|
||
}
|
||
async function showRecord(group: CollaborationGroup, kind: 'collection' | 'evidence') {
|
||
const generation = scope.current; setAction('record'); setError('');
|
||
try { const result = await api<unknown>('/sessions/' + session.id + '/collaborations/' + group.id + '/' + kind); if (generation === scope.current && selectedGroup.current === group.id) { setPreview({ title: kind === 'collection' ? '原成果核对记录' : '原输入与现场核对', content: JSON.stringify(result, null, 2), groupId: group.id }); if (kind === 'evidence') setReadEvidenceSha(group.evidence?.sha256 ?? ''); } }
|
||
catch (failure) { if (generation === scope.current && selectedGroup.current === group.id) setError(failure instanceof Error ? failure.message : String(failure)); }
|
||
finally { if (generation === scope.current && selectedGroup.current === group.id) setAction(''); }
|
||
}
|
||
const canPlan = !!view && !view.worker && !busy && !action && view.groups.every(value => ['completed', 'discarded', 'resolved_external'].includes(value.status));
|
||
const engineReady = engineInstallation?.controlledStatus === 'available' && !!engineInstallation.controlledSha256;
|
||
const promptReady = purgeDraftReady(purge);
|
||
const visibleDrafts = engineMode === 'deepseek' ? drafts.slice(0, 1) : drafts;
|
||
return <div className="worker-console" aria-label="隔离协作控制台">
|
||
<div className="worker-console-heading"><div><p className="worker-eyebrow">工程执行 / 分工与引擎</p><h2>一个目标,明确分工与真实成果</h2><p>为每个子任务绑定职责与模型,核对真实改动、检查和用量后归集到父工程。</p></div><button className="button secondary" disabled={loading || !!action} onClick={() => void load()}><RefreshCw size={14} />刷新</button></div>
|
||
{error && <div className="worker-error" role="alert">{error}</div>}
|
||
{loading && !view && <p role="status"><LoaderCircle className="spin" size={16} />正在读取当前任务记录</p>}
|
||
{view?.worker ? <div className="worker-origin"><ShieldCheck size={22} /><div><h3>当前是受限子任务:{view.worker.label}</h3><p>固定范围:{view.worker.paths.join('、')}。开始、停止全部与成果合并在父目标中处理。</p><button className="button secondary" onClick={() => void onNavigate(view.worker!.parentProjectId, view.worker!.parentSessionId)}>返回父目标<ArrowUpRight size={14} /></button></div></div> : <>
|
||
{!!view?.groups.length && <label className="worker-history">协作记录<select value={group?.id ?? ''} onChange={event => { setSelectedId(event.target.value); setCreating(false); }} aria-label="选择协作记录">{view.groups.map(value => <option key={value.id} value={value.id}>{statusLabel(value.status, value.model.executionMode === 'unrestricted', value.merge?.status === 'applied')} · {value.goal.slice(0, 40)}</option>)}</select></label>}
|
||
{(!group || creating) && <div className="worker-plan-form">
|
||
<label>执行方式<select aria-label="执行方式" value={engineMode} onChange={event => setEngineMode(event.target.value as 'workbench' | 'deepseek')}><option value="workbench">工作台 · 独立子任务</option><option value="deepseek">DeepSeek Harness · 一个受控工程</option></select></label>
|
||
{engineMode === 'deepseek' && <section className="worker-engine-install" aria-label="受控引擎安装"><label>Harness 安装目录<input value={engineRoot} placeholder="留空检测已知本地安装" onChange={event => { detection.current++; setEngineRoot(event.target.value); setEngineInstallation(null); setDetectingEngine(false); }} /></label><button className="button secondary" disabled={detectingEngine || !!action} onClick={() => void detectEngine()}>{detectingEngine ? <LoaderCircle size={14} className="spin" /> : <ShieldCheck size={14} />}检测受控安装</button>{engineInstallation && <div role="status"><strong>{engineReady ? '受控安装可用' : '安装尚不可用'}</strong><p>{engineInstallation.message}</p>{engineReady && <code>Harness {engineInstallation.version} · {engineInstallation.controlledSha256?.slice(0, 16)}</code>}</div>}<p className="worker-note">模型连接由工作台使用;引擎提交范围内的提案与检查请求,按所选访问权限执行。</p></section>}
|
||
{engineMode === 'deepseek' && <PurgeStrategyControl value={purge} onChange={value => { setPurge(value); setError(''); }} busy={!!action} harnessRoot={engineInstallation?.root} />}
|
||
<label>父目标<textarea value={goal} onChange={event => setGoal(event.target.value)} placeholder="描述需要交付的结果与验收要求" maxLength={20000} rows={3} /></label>
|
||
<div className={'worker-lanes' + (engineMode === 'deepseek' ? ' single' : '')}>{visibleDrafts.map((child, index) => <fieldset key={index}><legend>{engineMode === 'deepseek' ? '引擎工程' : '子任务 ' + (index + 1)}</legend><label>任务名称<input value={child.label} maxLength={64} onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, label: event.target.value } : value))} /></label><label>职责<input value={child.role} placeholder="例如工程实现、测试完善、文档维护" onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, role: event.target.value } : value))} /></label>
|
||
<label>执行模型<select aria-label="执行模型" value={child.model} onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, model: event.target.value } : value))}><option value="default">规划时绑定当前默认模型</option>{routes?.connections.filter(value => value.enabled && value.model).map(value => <option key={value.id} value={'connection:' + value.id}>{value.name} · {value.model}</option>)}{routes?.pools.map(value => <option key={value.id} value={'pool:' + value.id}>模型池 · {value.name}</option>)}{child.model !== 'default' && ![...(routes?.connections.filter(value => value.enabled && value.model).map(value => 'connection:' + value.id) ?? []), ...(routes?.pools.map(value => 'pool:' + value.id) ?? [])].includes(child.model) && <option value={child.model}>原选择已不可用,请重新选择</option>}</select></label><label>独立子目标<textarea value={child.goal} maxLength={8000} rows={3} onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, goal: event.target.value } : value))} /></label><label>允许修改的文件或目录<textarea value={child.paths} rows={2} placeholder="例如 src/parser.mjs,每行一个相对路径" onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, paths: event.target.value } : value))} /></label><label>交付要求(每行一项)<textarea aria-label="交付要求(每行一项)" value={child.requirements} rows={2} placeholder="列出需要核对的结果;模型自述不作为通过证据" onChange={event => setDrafts(values => values.map((value, i) => i === index ? { ...value, requirements: event.target.value } : value))} /></label>{openMode && engineMode === 'workbench' && drafts.length > 1 && <button className="text-button" onClick={() => setDrafts(values => values.filter((_, i) => i !== index))}>移除此子任务</button>}</fieldset>)}</div>
|
||
{openMode && engineMode === 'workbench' && <button className="text-button" onClick={() => setDrafts(values => [...values, newDraft()])}>添加子任务</button>}
|
||
{!openMode && <div className="worker-budget-form"><label>总 token 预算<input type="number" min={0} value={tokens} onChange={event => setTokens(Number(event.target.value))} /></label><label>总请求轮次<input type="number" min={0} value={steps} onChange={event => setSteps(Number(event.target.value))} /></label><label>总工具次数<input type="number" min={0} value={toolCalls} onChange={event => setToolCalls(Number(event.target.value))} /></label><label>总时限(分钟)<input type="number" min={1} value={duration} onChange={event => setDuration(Number(event.target.value))} /></label></div>}
|
||
<p className="worker-note">{openMode ? '本地额度不限;模型和原生参数在规划时固定,切换新任务默认模型不会改变本计划。' : <>{engineMode === 'deepseek' ? '这个引擎工程使用整份预算。' : '两份预算各分一半。'}续接沿用累计用量与原时限,实际模型尝试也计入轮次限制。来源只检出已提交 HEAD。</>}</p>
|
||
<div className="worker-actions"><button className="button" disabled={!canPlan || !goal.trim() || visibleDrafts.some(child => !child.role.trim() || !child.goal.trim() || !splitPaths(child.paths).length) || engineMode === 'deepseek' && (!engineReady || detectingEngine || !promptReady)} onClick={() => void create()}><ShieldCheck size={15} />封存分工计划</button>{creating && <button className="button secondary" onClick={() => setCreating(false)}>返回原协作</button>}</div>
|
||
</div>}
|
||
{group && !creating && <>
|
||
{group.children[0]?.engine?.strategy && <p className="worker-engine-badge">本计划的 Purge {group.children[0].engine.strategy.kind==='purge-original-restricted-v1'?'原版受限模式':'提示实验'} · {group.children[0].engine.strategy.source.version} · {group.children[0].engine.strategy.sha256.slice(0, 16)}</p>}
|
||
{group.evaluation && <p className="worker-note">本协作属于固定工程评测。执行与采纳请使用「工程评测」;这里保留原任务导航和中断现场核对。</p>}<section className="worker-parent"><div className="worker-parent-top"><span className={'worker-status ' + (group.requiresVerification || group.status === 'conflict' ? 'attention' : '')}>{statusLabel(group.status, openGroup, group.merge?.status === 'applied')}</span><code>{group.source.identity.branch} · {group.source.identity.head.slice(0, 12)}</code></div><h3>{group.goal}</h3><p>{group.summary}</p><dl><div><dt>模型</dt><dd>{group.children.some(child => child.assignment) ? '按子任务分别绑定,见下方' : group.model.mode === 'demo' ? '历史演示配置' : group.model.model}</dd></div><div><dt>执行方式</dt><dd>{group.children[0].engine ? "DeepSeek Harness " + group.children[0].engine.version : "工作台受限子任务"}</dd></div><div><dt>总预算</dt><dd>{openGroup ? '不限' : <>{number(group.budget.maxTokens)} tokens / {group.budget.maxSteps} 轮 / {group.budget.maxToolCalls} 次工具</>}</dd></div><div><dt>累计用量</dt><dd>{number(group.usage?.totalTokens ?? group.usage?.accountedTokens)} 已报告 tokens{group.usage?.unknownRequests ? <> + {group.usage.unknownRequests} 次用量未知(估算 {number(group.usage.estimatedUnknownTokens)})</> : null} / {group.usage?.steps ?? 0} 轮 / {group.usage?.toolCalls ?? 0} 次工具 / {group.usage?.requests ?? 0} 次模型请求</dd></div><div><dt>原修改</dt><dd>{group.source.changedPaths.length ? group.source.changedPaths.map(value => value.path).join('、') : '无未提交修改'}</dd></div></dl></section>
|
||
<div className={"worker-lanes" + (group.children.length === 1 ? " single" : "")}>{(group.workers ?? []).map((child, index) => <section className="worker-lane" key={child.id}><div className="worker-lane-title"><span>通道 {index + 1}</span><span className={'worker-status ' + (child.requiresVerification ? 'attention' : '')}>{statusLabel(child.sessionStatus === 'awaiting_approval' ? 'awaiting_approval' : child.status)}</span></div><h3>{child.label}</h3>{child.engine && <p className="worker-engine-badge">DeepSeek Harness {child.engine.version} · 固定安装 {child.engine.controlledSha256?.slice(0, 12)}</p>}{child.assignment && <p className="worker-assignment"><strong>{child.assignment.role}</strong><span>{child.assignment.model.model} · {child.assignment.selection?.type === 'pool' ? '模型池' : '固定连接'}</span><span>{child.assignment.selectionSource === 'explicit' ? '独立选择' : '规划时的默认选择'} · 原配置已封存</span></p>}<p className="worker-goal">{child.goal}</p>{!!child.assignment?.requirements.length && <ul className="worker-requirements">{child.assignment.requirements.map((value, i) => <li key={i}>{value}</li>)}</ul>}<div className="worker-scope"><span>允许修改</span>{child.paths.map(path => <code key={path}>{path}</code>)}</div><p className="worker-meter">{number(child.usage?.totalTokens)} 已报告 tokens · {child.usage?.steps ?? 0} 轮{child.usage?.unknownRequests ? <> · {child.usage.unknownRequests} 次用量未知(估算 {number(child.usage.estimatedUnknownTokens)})</> : null}{!openGroup && <> · 预算 {number(child.budget.maxTokens)}</>}</p><p className="worker-summary">{child.summary ?? '先创建独立工作区,再开始子任务。'}</p>{child.result && <div className="worker-proof"><Check size={14} />{child.result.paths.length} 个原改动 · {child.result.checkJobId ? '当前检查已封存' : '检查未验证'}{child.result.quality && ' · 要求语义未评价'}</div>}<div className="worker-actions">{child.status !== 'unprepared' && <button className="button secondary" onClick={() => void onNavigate(child.projectId, child.sessionId, child.sessionStatus === "awaiting_approval" ? "approval" : child.sessionStatus === "needs_review" ? "changes" : "task")}>{child.sessionStatus === 'awaiting_approval' ? '查看并审批检查' : child.sessionStatus === 'needs_review' ? '审查子任务改动' : '打开子任务'}<ArrowUpRight size={13} /></button>}{!group.evaluation && ['ready', 'paused', 'failed', 'awaiting_review'].includes(child.status) && !running && child.sessionStatus !== 'needs_review' && <button className="text-button" disabled={!!action || child.assignment?.model.mode === 'demo' || !child.assignment && group.model.mode === 'demo' || group.requiresVerification} onClick={() => config.approvalMode === 'full' ? void execute(group, 'start', { workerId: child.id }) : setConfirmation({ group, operation: 'start', workerId: child.id })}><Play size={13} />继续子任务</button>}</div></section>)}</div>
|
||
<section className="worker-review"><div className="worker-review-title"><GitBranch size={18} /><h3>{openGroup ? '父工程成果' : '父工程成果审查'}</h3></div>{group.collection ? <><p>{group.collection.paths.length} 个路径已核对,原记录 <code>{group.collection.sha256.slice(0, 16)}</code></p>{group.collection.conflicts.length > 0 && <ul className="worker-conflicts">{group.collection.conflicts.map((conflict, i) => <li key={i}><code>{conflict.path}</code><span>{conflict.reason}</span></li>)}</ul>}<button className="text-button" disabled={!!action} onClick={() => void showRecord(group, 'collection')}>查看原成果记录</button></> : <p>等待 {group.children.length} 个子任务形成实际成果。重叠路径、来源变化或原证据失效会阻止合并。</p>}{group.merge?.changeSetId && <button className="button secondary" onClick={onReview}>{openGroup ? '查看父工程改动' : '打开父工程变更集审查'}<ArrowUpRight size={14} /></button>}</section>
|
||
<div className="worker-actions worker-primary-actions">
|
||
{!group.evaluation && ['planned', 'partially_prepared'].includes(group.status) && <button className="button" disabled={!!action || busy} onClick={() => config.approvalMode === 'full' ? void execute(group, 'prepare') : setConfirmation({ group, operation: 'prepare' })}><GitBranch size={15} />{group.children.length === 2 ? '创建两个工作区' : group.children[0]?.engine ? '创建引擎工作区' : '创建独立工作区'}</button>}
|
||
{!group.evaluation && ['ready', 'paused', 'awaiting_review'].includes(group.status) && <button className="button" disabled={!!action || running || group.children.some(child => (child.assignment?.model ?? group.model).mode === 'demo') || group.requiresVerification || group.workers?.some(child => child.sessionStatus === 'needs_review')} onClick={() => config.approvalMode === 'full' ? void execute(group, 'start') : setConfirmation({ group, operation: 'start' })}><Play size={15} />{group.status === 'ready' ? group.children.length === 2 ? '开始两个子任务' : group.children[0]?.engine ? '开始引擎任务' : '开始子任务' : '继续未完成子任务'}</button>}
|
||
{running && <button className="button worker-stop" disabled={action === 'stop'} onClick={() => void execute(group, 'stop')}><Square size={14} />停止全部</button>}
|
||
{!group.evaluation && ['ready_to_collect', 'collected', 'conflict'].includes(group.status) && <button className="button secondary" disabled={!!action || running} onClick={() => void execute(group, 'collect')}><ShieldCheck size={15} />核对成果</button>}
|
||
{!group.evaluation && group.status === 'collected' && <button className="button" disabled={!!action} onClick={() => void execute(group, 'merge')}><GitBranch size={15} />{openGroup ? '合并到父工程' : '准备合并审查'}</button>}
|
||
{!group.evaluation && group.merge?.changeSetId && <button className="button secondary" disabled={!!action || busy} onClick={() => void execute(group, 'finalize')}>核对检查与 Git 交付</button>}
|
||
{group.requiresVerification && <><button className="button secondary" disabled={!!action || running} onClick={() => void execute(group, 'reconcile')}>核对原输入与现场</button>{group.evidence && <><button className="text-button" disabled={!!action} onClick={() => void showRecord(group, 'evidence')}>查看核对记录</button><button className="button secondary" disabled={!!action || readEvidenceSha !== group.evidence.sha256} onClick={() => setConfirmation({ group, operation: 'acknowledge' })}>确认核对并继续</button><button className="text-button" disabled={!!action || readEvidenceSha !== group.evidence.sha256} onClick={() => setConfirmation({ group, operation: 'acknowledge', retain: true })}>确认核对并保留现场结束</button></>}</>}
|
||
{!running && !group.requiresVerification && !['completed', 'discarded', 'resolved_external'].includes(group.status) && <button className="text-button" disabled={!!action} onClick={() => setConfirmation({ group, operation: 'discard' })}>结束协作并保留现场</button>}
|
||
{canPlan && <button className="button secondary" onClick={() => { setPurge(emptyPurgeDraft()); setCreating(true); }}>创建下一父目标</button>}
|
||
</div>
|
||
{group.children.some(child => (child.assignment?.model ?? group.model).mode === 'demo') && ['ready', 'paused'].includes(group.status) && <p className="worker-note">当前为离线演示。请先配置可用模型,再新建使用该模型快照的协作计划。</p>}
|
||
</>}
|
||
</>}
|
||
<p className="worker-boundary"><ShieldCheck size={14} />独立工作区与受限工具用于约束任务;审批的工程程序仍以本机账户执行。</p>
|
||
{confirmation && <Modal title={confirmation.operation === 'start' ? '确认受限子执行' : confirmation.operation === 'prepare' ? '确认创建隔离工作区' : confirmation.operation === 'acknowledge' && !confirmation.retain ? '确认原结果核对' : '确认保留现场'} onClose={() => setConfirmation(null)}><div className="worker-confirm"><p>{confirmation.operation === 'start' ? '将请求已封存模型并使用剩余累计预算。每项工程检查仍在对应子任务中审批;旧工具不会重放。' : confirmation.operation === 'prepare' ? '按已封存 HEAD 创建 ' + confirmation.group.children.length + ' 个独立 Git 工作区。原暂存与未提交修改保持在来源工程。' : confirmation.operation === 'acknowledge' && !confirmation.retain ? '按已阅读的原输入与现场记录解除核对门控。原未知结果保留,继续需要新检查和审批。' : '保留实际工作区、原任务、改动与报告,撤销未执行计划并结束本次协作;本次不记为交付完成。'}<strong>{confirmation.group.goal}</strong></p><button className="button" disabled={!!action || confirmation.operation === 'acknowledge' && readEvidenceSha !== confirmation.group.evidence?.sha256} onClick={() => void execute(confirmation.group, confirmation.operation, { ...(confirmation.workerId ? { workerId: confirmation.workerId } : {}), ...(confirmation.operation === 'acknowledge' ? { evidenceSha256: readEvidenceSha, retain: !!confirmation.retain } : {}) })}>确认{confirmation.operation === 'start' ? '开始' : confirmation.operation === 'prepare' ? '创建' : confirmation.operation === 'acknowledge' && !confirmation.retain ? '核对并继续' : '保留现场结束'}</button></div></Modal>}
|
||
{preview && <Modal title={preview.title} wide onClose={() => setPreview(null)}><div className="worker-record"><button className="button secondary" onClick={() => downloadBlob(new Blob([preview.content], { type: 'application/json' }), 'agent-workbench-collaboration-' + preview.groupId + '.json')}>导出原记录</button><pre>{preview.content}</pre></div></Modal>}
|
||
</div>;
|
||
}
|