import { useEffect, useRef, useState } from 'react'; import { ArrowRight, ArrowUpRight, Download, FileText, Fingerprint, LoaderCircle, ShieldCheck, Square } from 'lucide-react'; import { api, downloadEngineRunReport } from './api'; import { Modal } from './components'; import type { Session, EngineRunView, ArtifactPreview } from './types'; import './EngineRunPanel.css'; const active = ['queued', 'starting', 'initializing', 'running', 'waiting_tool', 'closing', 'stopping']; const labels: Record = { queued: '待启动', starting: '启动中', initializing: '核对启动', running: '执行中', waiting_tool: '等待宿主工具', closing: '核对停止', stopping: '停止中', completed: '运行已核验', failed: '执行未通过', cancelled: '已停止', unknown: '结果待核对', resolved_external: '已保留原未知结果' }; type Preview = { job: EngineRunView; kind: 'input' | 'report'; page: ArtifactPreview }; export function EngineRunPanel({ session, onSession, onError, onNavigate }: { session: Session; onSession: (session: Session) => void; onError: (error: unknown) => void; onNavigate?: (projectId: string, sessionId: string) => Promise; }) { const jobs = (session.execution?.engineRuns ?? []).slice().reverse(), worker = session.execution?.workers?.[0]; const [preview, setPreview] = useState(null), [pending, setPending] = useState(false); const scope = useRef(0), request = useRef(0); useEffect(() => { scope.current++; request.current++; setPreview(null); setPending(false); return () => { scope.current++; request.current++; }; }, [session.id]); async function read(job: EngineRunView, kind: 'input' | 'report', offset = 0) { const generation = scope.current, current = ++request.current; setPending(true); try { const page = await api('/sessions/' + session.id + '/engine-runs/' + job.id + '/' + kind + '?offset=' + offset + '&limit=4000'); if (generation === scope.current && current === request.current) setPreview({ job, kind, page }); } catch (error) { if (generation === scope.current && current === request.current) onError(error); } finally { if (generation === scope.current && current === request.current) setPending(false); } } async function stop() { const generation = scope.current; setPending(true); try { const value = await api('/sessions/' + session.id + '/stop', {}); if (generation === scope.current) onSession(value); } catch (error) { if (generation === scope.current) onError(error); } finally { if (generation === scope.current) setPending(false); } } async function download(job: EngineRunView) { const generation = scope.current; try { await downloadEngineRunReport(session.id, job.id); } catch (error) { if (generation === scope.current) onError(error); } } if (!jobs.length && !worker?.engine) return null; return
所属独立工程 / 原执行依据

受控引擎运行

{jobs.some(job => active.includes(job.status)) && }
{worker &&
{worker.label}

允许修改:{worker.paths.join('、')}。提案、检查和父工程交付沿用原审查。

{onNavigate && }
} {!jobs.length &&

安装与范围已经封存。请从父目标开始引擎任务。

} {jobs.map(job =>
DeepSeek Harness {job.installation.version}{new Date(job.startedAt).toLocaleString('zh-CN')}
{active.includes(job.status) && }{labels[job.status] ?? job.status}
固定安装{job.installation.controlledSha256?.slice(0, 12)}
所属进程{job.nativeSummary.pid ? 'PID ' + job.nativeSummary.pid : '尚未封存'}
实际模型请求{job.modelRequests}
实际工具请求{job.toolRequests}
进程树关闭{job.nativeSummary.treeConfirmed ? '已核对' : job.finishedAt ? '待核对' : '运行中'}
{job.error &&

{job.error}

} {job.status === 'completed' &&

原引擎运行与调用账本已核验。工程完成仍以提案应用、当前检查和父工程交付为准。

} {job.requiresVerification &&

请返回父目标核对原输入与现场。原未知结果保留,继续会创建新的运行。

} {job.installation.strategy &&
Purge {job.installation.strategy.kind==='purge-original-restricted-v1'?'原版受限模式':'提示实验'} · {job.installation.strategy.source.version}

{job.installation.strategy.kind==='purge-original-restricted-v1'?'本 Run 加载固定原版入口,自动重试和继续关闭;工作台审批与预算继续生效。':'本 Run 使用已封存工程提示,原审批与预算继续生效。'}

查看本次实验策略
策略 SHA256
{job.installation.strategy.sha256}
来源 SHA256
{job.installation.strategy.source.sourceSha256}
文本 SHA256
{job.installation.strategy.promptSha256}
来源目录
{job.installation.strategy.source.root}
{job.installation.strategy.kind==='purge-original-restricted-v1'&&<>
固定运行依赖 SHA256
{job.installation.strategy.runtime.sha256}
加载范围
{job.installation.strategy.runtime.inputs.length} 份固定输入 / {job.installation.strategy.runtime.nativeAddons.length} 个固定原生模块
}
{job.installation.strategy.prompt}
} {job.review &&

人工核对记录:{job.review.evidenceSha256.slice(0, 16)}。原未知输出未改写为完成。

}
任务身份与来源
Task
{job.taskId}
Run
{job.runId}
SDK 会话
{job.sdkSessionId}
安装目录
{job.installation.root}
输入 SHA256
{job.inputSha256}
报告 SHA256
{job.reportSha256 ?? '尚未封存'}
原事件
{job.nativeSummary.notifications} 项
)} {preview && { request.current++; setPreview(null); setPending(false); }}>
{preview.page.sha256}
{preview.page.content}
{preview.page.offset.toLocaleString()}–{(preview.page.offset + preview.page.content.length).toLocaleString()} / {preview.page.totalCharacters.toLocaleString()} 字符
}
; }