feat: verify existing file results and preserve honest task delivery

This commit is contained in:
Agent Workbench Dev
2026-11-02 14:30:38 +08:00
parent 0dc0325346
commit d5d9df8275
44 changed files with 1011 additions and 81 deletions
+2 -1
View File
@@ -29,6 +29,7 @@ export function DeliveryPanel({ session, busy, onSession, onError, openArtifact
const unresolved = jobs.some(job => job.requiresVerification);
const pending = session.changes.some(change => ['pending', 'conflict'].includes(change.status));
const hasApplied = session.changes.some(change => change.taskId === task?.id && change.status === 'applied');
const existingOnly = !hasApplied && !!session.execution?.fileResults?.length;
const reports = session.execution?.artifacts.filter(artifact => artifact.kind === 'delivery-report-markdown') ?? [];
const latestReport = reports.at(-1);
const waitingPlan = (session.execution?.deliveryPlans ?? []).filter(plan => plan.taskId === task?.id
@@ -105,7 +106,7 @@ export function DeliveryPanel({ session, busy, onSession, onError, openArtifact
<label className="form-field delivery-message">提交说明<textarea aria-label="提交说明" rows={2} value={message} maxLength={1600} disabled={busy || running} onChange={event => setMessage(event.target.value)} /></label>
<details className="delivery-author"><summary>Git署名</summary><p>默认采用项目Git署名;尚未配置时使用 Agent Workbench 本地身份。预览会展示实际署名。</p><label className="form-field">提交者姓名<input value={authorName} disabled={busy || running} onChange={event => setAuthorName(event.target.value)} placeholder="采用默认署名" autoComplete="off" /></label><label className="form-field">提交者邮箱<input type="email" value={authorEmail} disabled={busy || running} onChange={event => setAuthorEmail(event.target.value)} placeholder="采用默认邮箱" autoComplete="off" /></label></details>
<button type="button" className="button primary" aria-label="预览Git提交" disabled={!task || !hasApplied || pending || busy || running || unresolved || planning || !message.trim()} onClick={prepare}>{planning ? <LoaderCircle size={14} className="spin" /> : <GitCommitHorizontal size={14} />}预览Git提交</button>
{(!hasApplied || pending) && <p className="record-footnote">应用本任务的文件提案后,可以准备Git提交。</p>}
{existingOnly ? <p className="record-footnote">本任务沿用已有成果,无新增修改,不创建空提交。可生成报告核对成果与原检查。</p> : (!hasApplied || pending) && <p className="record-footnote">应用本任务的文件提案后,可以准备Git提交。</p>}
{jobs.slice().reverse().map(job => <div key={job.id} className={'delivery-job ' + (job.requiresVerification ? 'delivery-attention' : '')}>
<div className="record-heading"><Status value={job.status} /><code>{job.id.slice(0, 8)}</code>{active.includes(job.status) && <button type="button" className="text-button" onClick={() => api<Session>('/sessions/' + session.id + '/delivery-jobs/' + job.id + '/stop', {}).then(onSession).catch(onError)}>停止提交</button>}</div>
<time>{date(job.startedAt)} · {job.branch}</time>
+15
View File
@@ -0,0 +1,15 @@
.file-results .record-heading { flex-wrap: wrap; }
.file-result-row { border-top: 1px solid var(--line); padding: 13px 0; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.file-result-row > div:first-child { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.file-result-row small { color: var(--muted); font-size: 11px; }
.file-result-row > p { margin: 8px 0; }
.file-result-sha { display: block; font: 11px/1.65 "Cascadia Code", Consolas, monospace; overflow-wrap: anywhere; color: var(--muted); }
.file-result-error, .file-result-notice { padding: 9px 11px; background: #faf4e8; color: #684b19; border-left: 2px solid #b18c48; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.file-result-form { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }
.file-result-form summary { cursor: pointer; font-weight: 600; font-size: 12px; padding: 5px 0; }
.file-result-form label { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; font-size: 12px; }
.file-result-form select, .file-result-form textarea { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 5px; padding: 9px; background: var(--panel, #fff); font: inherit; color: inherit; }
.file-result-form pre { max-height: 230px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: #f3f6f4; border: 1px solid var(--line); padding: 10px; font: 11px/1.7 Consolas, monospace; }
.file-result-finish { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 9px; }
.file-result-outcome { padding: 10px; background: #edf7ef; color: #256148; font-size: 12px; line-height: 1.7; }
@media (max-width: 600px) { .file-results button, .file-result-form select { min-height: 42px; } .file-result-form textarea { font-size: 16px; } }
+83
View File
@@ -0,0 +1,83 @@
import { useEffect, useRef, useState } from 'react';
import { FileCheck2, FileText, LoaderCircle, RefreshCw } from 'lucide-react';
import { api } from './api';
import type { Session, FileResultView } from './types';
import './FileResultsPanel.css';
type View = { taskId: string; results: FileResultView[]; sources: { id: string; taskId: string; runId: string; reason: string; files: { path: string; sha256: string }[] }[] };
type File = { path: string; content: string; sha256: string; bytes: number };
export function FileResultsPanel({ session, busy, onSession, openArtifact }: {
session: Session; busy: boolean; onSession: (value: Session) => void; openArtifact: (id: string) => void;
}) {
const task = session.execution?.task;
const [view, setView] = useState<View | null>(null), [files, setFiles] = useState<string[]>([]);
const [path, setPath] = useState(''), [file, setFile] = useState<File | null>(null), [source, setSource] = useState('');
const [reason, setReason] = useState(''), [notice, setNotice] = useState('');
const [loading, setLoading] = useState(false), [acting, setActing] = useState(false);
const scope = useRef(0), readRequest = useRef(0), viewRequest = useRef(0), flight = useRef(false);
const known = view?.sources.filter(row => row.files.some(file => file.path === path)) ?? [];
const current = view?.results.some(row => row.verification === 'current');
async function load() {
const id = scope.current, request = ++viewRequest.current; setLoading(true);
try {
const [result, inventory] = await Promise.all([api<View>('/sessions/' + session.id + '/file-results' + (path ? '?path=' + encodeURIComponent(path) : '')), api<{ files: { path: string; kind: string; bytes: number }[] }>('/projects/' + session.projectId + '/files')]);
if (scope.current !== id || viewRequest.current !== request) return;
setView(result); setFiles(inventory.files.filter(item => item.kind === 'file' && item.bytes <= 1024 * 1024).map(item => item.path));
} catch (error) { if (scope.current === id && viewRequest.current === request) setNotice(error instanceof Error ? error.message : String(error)); }
finally { if (scope.current === id && viewRequest.current === request) setLoading(false); }
}
useEffect(() => {
scope.current++; readRequest.current++; flight.current = false; setActing(false); setView(null); setPath(''); setFile(null); setSource(''); setReason(''); setNotice(''); void load();
return () => { scope.current++; readRequest.current++; };
}, [session.id, task?.id]);
useEffect(() => { void load(); }, [session.execution?.fileResults?.at(-1)?.id, session.execution?.run?.id, session.status]);
async function choose(value: string) {
setPath(value); setFile(null); setSource(''); setNotice('');
const id = scope.current, request = ++readRequest.current, viewId = ++viewRequest.current;
setLoading(false);
if (!value) return;
try { const [result, currentView] = await Promise.all([api<File>('/projects/' + session.projectId + '/file?path=' + encodeURIComponent(value)), api<View>('/sessions/' + session.id + '/file-results?path=' + encodeURIComponent(value))]);
if (scope.current === id && readRequest.current === request) { setFile(result); if (viewRequest.current === viewId) setView(currentView); }
} catch (error) { if (scope.current === id && readRequest.current === request) setNotice(error instanceof Error ? error.message : String(error)); }
}
async function save(complete = false) {
if (!task || !session.execution?.run || flight.current) return;
if (!complete && (!file || file.path !== path || !reason.trim())) return;
const id = scope.current; viewRequest.current++; setLoading(false); flight.current = true; setActing(true); setNotice('');
try {
const result = await api<View & { session: Session }>('/sessions/' + session.id + '/file-results' + (complete ? '/complete' : ''), {
taskId: task.id, runId: session.execution.run.id,
...(!complete && file ? { files: [{ path: file.path, sha256: file.sha256, ...(source ? { source_result_id: source } : {}) }], reason } : {}),
});
if (scope.current !== id) return;
setView(result); onSession(result.session); setNotice(complete ? '任务已按当前成果结束,原运行和检查记录保留。' : '当前文件已核对并登记;未新增文件改动、测试或Git提交。');
} catch (error) { if (scope.current === id) setNotice(error instanceof Error ? error.message : String(error)); }
finally { if (scope.current === id) { flight.current = false; setActing(false); } }
}
return <section className="task-record-section file-results" aria-label="当前文件成果" aria-busy={loading || acting}>
<div className="record-heading"><FileCheck2 size={15} /><h3>当前文件成果</h3><span>{view?.results.length ?? 0} 份凭据</span></div>
<p className="record-footnote">已有文件可以核对后沿用。成果、实际修改、检查与提交分别保留。</p>
<button type="button" className="text-button" disabled={loading || acting} onClick={() => void load()}>{loading ? <LoaderCircle size={13} className="spin" /> : <RefreshCw size={13} />}刷新成果状态</button>
{view?.results.map(row => <article className="file-result-row" key={row.id}>
<div><strong>{row.verification === 'current' ? '当前文件已核对' : row.verification === 'stale' ? '需要重新核对' : '原凭据需核查'}</strong><small>Task {row.taskId.slice(0, 8)} · Run {row.runId.slice(0, 8)}</small></div>
{row.files.map(item => <div key={item.path}><code>{item.path}</code><small className="file-result-sha">SHA-256 {item.sha256}</small>{item.origin && <p className="record-footnote">采用自 Task {item.origin.taskId.slice(0, 8)} · Run {item.origin.runId.slice(0, 8)}<br />原文件 SHA-256 {item.origin.sha256}</p>}
{row.verification !== 'current' && <button type="button" className="text-button" disabled={busy || acting} onClick={() => { void choose(item.path); setReason(row.reason); }}>重新打开此文件核对</button>}
</div>)}
<p>{row.reason}</p>{row.error && <p className="file-result-error">{row.error}</p>}
<button type="button" className="text-button" onClick={() => openArtifact(row.contractArtifactId)}><FileText size={13} />查看原成果凭据</button>
</article>)}
<details className="file-result-form">
<summary>核对已有文件</summary>
<label>选择项目内文件<select aria-label="成果文件" value={path} disabled={busy || acting || loading} onChange={event => void choose(event.target.value)}><option value="">选择一个文件</option>{files.map(value => <option key={value} value={value}>{value}</option>)}</select></label>
{path && <button type="button" className="text-button" disabled={busy || acting} onClick={() => void choose(path)}><RefreshCw size={13} />重新读取当前文件</button>}
{file && <><p className="record-footnote">{file.bytes.toLocaleString('zh-CN')} 字节 · 当前读取 SHA-256</p><code className="file-result-sha">{file.sha256}</code><pre aria-label="成果文件内容">{file.content.length > 12000 ? file.content.slice(0, 12000) + '\n…界面仅展开前12000字符;核对保存完整文件快照。' : file.content}</pre></>}
{!!known.length && <label>采用来源<select aria-label="成果来源" value={source} disabled={busy || acting} onChange={event => setSource(event.target.value)}><option value="">选择原任务成果</option>{known.map(row => <option key={row.id} value={row.id}>Task {row.taskId.slice(0, 8)} · {row.reason.slice(0, 60)}</option>)}</select></label>}
<label>采用原因<textarea aria-label="成果采用原因" rows={3} maxLength={600} placeholder="说明这个文件满足了当前任务的哪些要求" value={reason} disabled={busy || acting} onChange={event => setReason(event.target.value)} /></label>
<button type="button" className="button secondary" disabled={busy || acting || !file || !reason.trim() || !!known.length && !source} onClick={() => void save()}>{acting ? <LoaderCircle size={14} className="spin" /> : <FileCheck2 size={14} />}核对并采用此文件</button>
</details>
{current && task?.status !== 'completed' && <div className="file-result-finish"><p className="record-footnote">当前要求已满足时可结束。修改要求、原检查和执行计划仍需通过核对。</p><button type="button" className="button secondary" disabled={busy || acting} onClick={() => void save(true)}>按当前成果结束任务</button></div>}
{task?.delivery?.status === 'existing_verified' && <p className="file-result-outcome">结束时采用已有成果 · 无新增修改。当前有效性见逐项核对,检查与Git另列。</p>}
{notice && <p className="file-result-notice" role="status">{notice}</p>}
</section>;
}
+3 -1
View File
@@ -13,6 +13,7 @@ import { McpJobHistory } from './McpJobHistory';
import './TaskPanel.css';
import { EnvironmentPanel } from './EnvironmentPanel';
import { PreviewPanel } from './PreviewPanel';
import { FileResultsPanel } from './FileResultsPanel';
const stopReasons: Record<string, string> = { no_progress: '重复读取未推进任务,请核对后继续', context_limit: '完整任务要求超过请求上下文预算', time_limit: '到达运行时间预算', token_limit: '到达本次 token 预算', task_token_limit: '到达任务累计预算', step_limit: '到达工具轮次上限', cancelled: '用户停止', model_error: '模型请求失败', interrupted: '进程中断' };
const number = (value: number | undefined) => (value ?? 0).toLocaleString('zh-CN');
@@ -21,7 +22,7 @@ stopReasons.git_review_declined = 'Git预览已撤回,文件和检查记录保
stopReasons.task_plan_incomplete = '执行计划仍有未核验或失效步骤,请核对后继续';
stopReasons.diagnostic_answered = '诊断答复已完成;原任务的目标与交付状态保持';
stopReasons.verification_incomplete = '答复已收到,当前任务的工程检查尚未通过';
stopReasons.delivery_incomplete = '答复已收到,要求的文件尚无已应用记录';
stopReasons.delivery_incomplete = '答复已收到,当前文件成果或要求的修改仍需核对';
const time = (value: string | null | undefined) => value ? new Date(value).toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }) : '执行中';
export function TaskPanel({ project, session, onSession, onError, busy, onWorkspaceRefresh, onWorkspaceNavigate, onOpenPreview }: { project: Project; session: Session; onSession: (value: Session) => void; onError: (error: unknown) => void; busy: boolean; onOpenPreview?:()=>void; onWorkspaceRefresh: (projectId: string, sessionId: string, isCurrent?: () => boolean) => Promise<void>; onWorkspaceNavigate: (projectId: string, sessionId: string, isCurrent?: () => boolean) => Promise<void> }) {
@@ -94,6 +95,7 @@ export function TaskPanel({ project, session, onSession, onError, busy, onWorksp
{!!task.instructions.length && <details className="task-instructions"><summary>追加要求 · {task.instructions.length}</summary>{task.instructions.map(instruction => <p key={instruction.id}><small>{instruction.source && instruction.source !== 'user' ? '系统操作 · ' + instruction.source : '用户要求'}</small><br />{instruction.content}</p>)}</details>}
</> : <p className="record-empty">发送任务后,这里保存目标、每次运行和实际结果。</p>}
</section>
{task && <FileResultsPanel session={session} busy={busy} onSession={onSession} openArtifact={openArtifact} />}
{task && <TaskPlanPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
{task && <TaskCheckpointPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
{execution?.progress.requiresVerification.length ? <section className="verification-note" role="status"><ShieldQuestion size={17} /><div><strong>{execution.progress.requiresVerification.length} 项结果需要核对</strong><p>这些调用已进入执行,但缺少可靠结果。继续任务会保留记录。</p>{execution.progress.requiresVerification.map(tool => <code key={tool.id}>{tool.tool} · {tool.id.slice(0, 8)}</code>)}</div></section> : null}
+5 -5
View File
@@ -5,16 +5,16 @@ import { Modal, Status } from './components';
import type { Session, TaskPlanReply, TaskPlanStep, TaskPlanView } from './types';
import './TaskPlanPanel.css';
const kinds: Record<TaskPlanStep['kind'], string> = { analysis: '读取工程', changes: '源码改动', checks: '工程检查', browser: '页面验收' };
const kinds: Record<TaskPlanStep['kind'], string> = { analysis: '读取工程', changes: '源码改动', results: '当前文件成果', checks: '工程检查', browser: '页面验收' };
const readTools = { inspect_project: '识别工程', read_file: '读取文件', list_files: '文件清单', search_files: '搜索文件', index_project: '工程索引', query_code: '定位符号', read_research_evidence: 'REA原结果', inspect_engine_checks: '引擎核验', read_browser_result: '原页面记录' };
const browserActions = { fill: '填写', select: '选择', click: '点击', assert_text: '文本断言', assert_count: '数量断言', assert_visible: '可见断言' };
const cleanStep = (step: TaskPlanStep): TaskPlanStep => ({ key: step.key, title: step.title, criterion: step.criterion, kind: step.kind, depends_on: [...step.depends_on],
...(step.kind === 'analysis' ? { tools: [...(step.tools ?? [])] } : step.kind === 'changes' ? { paths: (step.paths ?? []).map(value => value.trim()).filter(Boolean) }
...(step.kind === 'analysis' ? { tools: [...(step.tools ?? [])] } : ['changes', 'results'].includes(step.kind) ? { paths: (step.paths ?? []).map(value => value.trim()).filter(Boolean) }
: step.kind === 'checks' ? { checks: (step.checks ?? []).map(value => value.trim()).filter(Boolean) } : { viewport_width: step.viewport_width, actions: [...(step.actions ?? [])] }) });
const freshStep = (kind: TaskPlanStep['kind'] = 'analysis'): TaskPlanStep => ({ key: 'step_' + crypto.randomUUID().slice(0, 8), title: kinds[kind], criterion: '', kind, depends_on: [],
...(kind === 'analysis' ? { tools: ['inspect_project'] } : kind === 'changes' ? { paths: [] } : kind === 'checks' ? { checks: ['test', 'build'] } : { viewport_width: 1280, actions: ['assert_visible'] }) });
...(kind === 'analysis' ? { tools: ['inspect_project'] } : ['changes', 'results'].includes(kind) ? { paths: [] } : kind === 'checks' ? { checks: ['test', 'build'] } : { viewport_width: 1280, actions: ['assert_visible'] }) });
const scopeText = (step: TaskPlanStep) => step.kind === 'analysis' ? (step.tools ?? []).map(tool => readTools[tool as keyof typeof readTools] ?? tool).join(' / ')
: step.kind === 'changes' ? step.paths?.join('、') : step.kind === 'checks' ? step.checks?.join(' / ')
: ['changes', 'results'].includes(step.kind) ? step.paths?.join('、') : step.kind === 'checks' ? step.checks?.join(' / ')
: `${step.viewport_width}px · ${(step.actions ?? []).map(action => browserActions[action as keyof typeof browserActions]).join(' / ')}`;
export function TaskPlanPanel({ session, busy, onSession, onError, openArtifact }: {
@@ -116,7 +116,7 @@ export function TaskPlanPanel({ session, busy, onSession, onError, openArtifact
const next = freshStep(event.target.value as TaskPlanStep['kind']); setDraft(steps => steps.map((value, at) => at === index ? { ...next, key: value.key, title: value.title, criterion: value.criterion, depends_on: value.depends_on } : value));
}}>{Object.entries(kinds).map(([key, label]) => <option key={key} value={key}>{label}</option>)}</select></label>
{step.kind === 'analysis' && <div className="plan-option-list"><span>可核验的读取结果(任一)</span>{Object.entries(readTools).map(([key, label]) => <label key={key}><input type="checkbox" checked={step.tools?.includes(key) ?? false} onChange={event => update(index, { tools: event.target.checked ? [...(step.tools ?? []), key] : step.tools?.filter(tool => tool !== key) })} />{label}</label>)}</div>}
{step.kind === 'changes' && <label>改动文件(每行一项)<textarea aria-label={`步骤${index + 1}文件范围`} rows={3} value={step.paths?.join('\n') ?? ''} placeholder="src/main.tsx" onChange={event => update(index, { paths: event.target.value.split('\n') })} /></label>}
{['changes', 'results'].includes(step.kind) && <label>{step.kind === 'results' ? '成果文件' : '改动文件'}(每行一项)<textarea aria-label={`步骤${index + 1}文件范围`} rows={3} value={step.paths?.join('\n') ?? ''} placeholder="src/main.tsx" onChange={event => update(index, { paths: event.target.value.split('\n') })} /></label>}
{step.kind === 'checks' && <label>检查名称(逗号分隔)<input aria-label={`步骤${index + 1}检查范围`} value={step.checks?.join(',') ?? ''} placeholder="test,build 或 python:test,python:compile" onChange={event => update(index, { checks: event.target.value.split(',') })} /></label>}
{step.kind === 'browser' && <><label>页面宽度<select aria-label={`步骤${index + 1}页面宽度`} value={step.viewport_width} onChange={event => update(index, { viewport_width: Number(event.target.value) })}><option value={1280}>桌面 · 1280px</option><option value={390}>手机 · 390px</option>{![1280, 390].includes(step.viewport_width ?? 0) && <option value={step.viewport_width}>{step.viewport_width}px</option>}</select></label>
<div className="plan-option-list"><span>必须实际完成的操作</span>{Object.entries(browserActions).map(([key, label]) => <label key={key}><input type="checkbox" checked={step.actions?.includes(key) ?? false} onChange={event => update(index, { actions: event.target.checked ? [...(step.actions ?? []), key] : step.actions?.filter(action => action !== key) })} />{label}</label>)}</div></>}
+2 -1
View File
@@ -12,7 +12,8 @@ export interface MobileTask extends MobileBrief {
browserObservations?:{id:string;tabId:string;url:string;title:string;createdAt:string;revision:string;scope:{complete:boolean};screenshotSha256:string}[];
inputAttachments?: import('./types').InputAttachment[];
budgetPause?: import('./types').BudgetPause|null;
task: { id: string; goal: string; status: string; usage: MobileUsage; budget: { maxTokens: number }; verification: { status: string } } | null;
task: { id: string; goal: string; status: string; usage: MobileUsage; budget: { maxTokens: number }; verification: { status: string }; delivery?: { status: string; paths: string[]; checks: string } } | null;
fileResults?: { id: string; taskId: string; runId: string; verification: string; reason: string; contractSha256: string; files: { path: string; sha256: string; bytes: number; origin: { taskId: string; runId: string; sha256: string } | null }[] }[];
run: { id: string; status: string; steps: number; toolCalls: number; stopReason: string | null; usage: MobileUsage } | null;
progress: { total: number; completed: number; unknown: { id: string; tool: string; state: string; runId: string }[] };
events: { id: string; label: string; phase: string; output: string; taskId?: string; runId?: string; createdAt: string; exitCode?: number;
+2
View File
@@ -5,6 +5,7 @@ import { ArrowLeft, ChevronRight, ClipboardCheck, FileDiff, Folder, Link2, Refre
import type { CompanionDevice, MobileBrief, MobileTask } from '../companion-types';
import { mobileApi, MobileError, verifiedText, verifyDigest } from './api';
import { MobileInputImage } from './MobileInputImage';
import './file-results.css';
const stateLabel = (state: string) => ({ idle: '未开始', waiting: '等待审批', validating: '校验中', queued: '排队中', executing: '执行中', error: '错误', running: '执行中', awaiting_approval: '等待审批', stopping: '正在停止', completed: '已完成', needs_review: '待审查', failed: '失败', interrupted: '已中断', cancelled: '已停止', paused: '已暂停', unknown: '需核对', completed_with_changes: '待审查', passed: '通过', pending: '待处理', applied: '已应用', denied: '已拒绝', approved: '已批准', conflict: '有冲突', unverified: '需核对', stale: '已变化' } as Record<string, string>)[state] ?? state;
const time = (value: string) => new Date(value).toLocaleString('zh-CN', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' });
@@ -124,6 +125,7 @@ export function MobileApp({ initialToken }: { initialToken: string }) {
{!!selectedTask.progress.unknown.length && <div className="mobile-unknown"><strong>{selectedTask.progress.unknown.length} 项工具结果需要核对</strong><p>请在电脑核对原输入和实际结果。刷新、重连和手机审批均不会自动重新执行。</p>{selectedTask.progress.unknown.map(item => <code key={item.id}>{item.tool} · {stateLabel(item.state)}</code>)}</div>}
{selectedTask.browserObservations?.slice(-1).map(observation=><MobileBrowserObservation key={observation.id} sessionId={selectedTask.id} observation={observation} onError={cause=>{if(cause instanceof MobileError&&[401,403].includes(cause.status))revoke(cause.message);else setError(cause instanceof Error?cause.message:'原网页截图读取失败。');}}/>)}
{!!selectedTask.approvals.length && <section className="mobile-approvals"><h2><ShieldCheck size={18} />等待你的确认</h2>{selectedTask.approvals.map(approval => <article key={approval.id}><span>{approval.shell}</span><pre>{approval.command}</pre><p>{approval.reason}</p>{!me.device.permissions.approve ? <p className="mobile-muted">此设备仅可观察,请在电脑审批。</p> : !approval.actionable ? <p className="mobile-muted">原审批已失效,请在电脑核对。</p> : <div className="mobile-action-pair"><button disabled={!fresh || !!busy} onClick={() => setDecision({ requestId: crypto.randomUUID(), kind: 'approve', task: selectedTask, approval, allow: false })}>拒绝</button><button className="mobile-primary" disabled={!fresh || !!busy} onClick={() => setDecision({ requestId: crypto.randomUUID(), kind: 'approve', task: selectedTask, approval, allow: true })}>核对并批准</button></div>}</article>)}</section>}
{!!selectedTask.fileResults?.length && <section className="mobile-file-results" aria-label="当前文件成果"><h2>当前文件成果</h2>{selectedTask.fileResults.map(result => <article key={result.id}><strong>{result.verification === 'current' ? '当前文件已核对' : '文件或要求已变化,请在电脑重新核对'}</strong><p>Task {result.taskId.slice(0, 8)} · Run {result.runId.slice(0, 8)}</p>{result.files.map(file => <p key={file.path}><strong>{file.path}</strong><br /><code>SHA-256 {file.sha256}</code>{file.origin && <><br />来源 Task {file.origin.taskId.slice(0, 8)} · Run {file.origin.runId.slice(0, 8)}<br /><code>原 SHA-256 {file.origin.sha256}</code></>}</p>)}<p>{result.reason}</p><details><summary>原成果凭据 SHA-256</summary><code>{result.contractSha256}</code></details></article>)}<p className="mobile-muted">已有成果与新增修改分开记录;测试、差异和Git结果见各自原记录。</p></section>}
<nav className="mobile-tabs" aria-label="任务内容">{[['progress', '执行进展'], ['changes', '文件差异'], ['checks', '检查与报告']].map(([key, label]) => <button key={key} aria-current={tab === key ? 'page' : undefined} onClick={() => { setTab(key); setDocument(null); }}>{label}{key === 'changes' && !!selectedTask.changes.length && <span>{selectedTask.changes.length}</span>}</button>)}</nav>
{tab === 'progress' && <section className="mobile-progress"><div className="mobile-section-heading"><h2>原执行记录</h2><span>{selectedTask.progress.completed} / {selectedTask.progress.total} 工具完成</span></div><ol>{selectedTask.events.map(item => <li key={item.id}><div><strong>{item.label || '执行事件'}</strong><span className={'mobile-state state-' + item.phase}>{stateLabel(item.phase)}</span></div>{item.stream && item.stream.status !== "completed" && <div className="mobile-stream"><strong>{item.stream.status === "receiving" ? "正在接收模型输出" : "模型输出未完成"}</strong><span>{item.stream.textCharacters ?? 0} 字符 · 片段不执行工具</span>{item.stream.textPreview && <pre>{item.stream.textPreview}</pre>}</div>}{item.output && <details><summary>查看原输出片段{item.exitCode !== undefined ? ' · 退出码 ' + item.exitCode : ''}</summary><pre>{item.output}</pre></details>}</li>)}</ol>{!selectedTask.events.length && <p className="mobile-muted">尚无工具执行记录。</p>}{selectedTask.messages.map(message => <article className="mobile-message" key={message.id}><span>{message.role === 'assistant' ? '代理回复' : '系统记录'} · {time(message.createdAt)}</span><p>{message.content}</p></article>)}<p className="mobile-muted">手机显示最近60条执行记录和8条回复;完整记录保留在电脑原会话。</p></section>}
{tab === 'changes' && <section className="mobile-changes"><div className="mobile-section-heading"><h2>当前任务的改动</h2><span>{selectedTask.changes.length} 个文件</span></div>{!selectedTask.changes.length && <p className="mobile-muted">尚未提出文件改动。</p>}{selectedTask.changes.map(change => <button key={change.id} className="mobile-file-row" disabled={!!busy || !fresh} onClick={() => void openDiff(change)}><FileDiff size={19} /><div><strong>{change.path}</strong><span>{stateLabel(change.status)} · <b>+{change.additions}</b> / −{change.deletions}</span></div><ChevronRight size={17} /></button>)}<p className="mobile-muted">手机可查看原差异;应用、恢复和 Git 提交在电脑审查。</p></section>}
+6
View File
@@ -0,0 +1,6 @@
.mobile-file-results { padding: 18px; border-block: 1px solid #d8e2dc; background: #f5f8f6; }
.mobile-file-results h2 { font-size: 16px; margin: 0 0 12px; }
.mobile-file-results article { padding: 12px 0; border-bottom: 1px solid #d8e2dc; font-size: 13px; line-height: 1.65; }
.mobile-file-results p { margin: 8px 0; }
.mobile-file-results code { font-size: 11px; overflow-wrap: anywhere; word-break: break-word; }
.mobile-file-results details summary { min-height: 42px; display: flex; align-items: center; cursor: pointer; }
+6 -1
View File
@@ -165,6 +165,11 @@ export interface ContextHistoryGroup {
export interface ContextHistory { planId: string; groups: ContextHistoryGroup[]; offset: number; totalGroups: number; truncated: boolean }
export interface Task { id: string; goal: string; status: string; instructions: { id: string; content: string; createdAt: string; source?: string }[]; usage: Usage; budget: { maxTokens: number }; verification: { status: string; checkJobId: string | null }; origin: string; workspaceIdentity?: WorkspaceIdentity }
export interface Task { contract?: { schemaVersion: number; goal: string; checks: string; inheritedFromTaskId?: string }; delivery?: { status: string; paths: string[]; at: string; checks: string } }
export interface FileResultView {
id: string; taskId: string; runId: string; source: string; reason: string; createdAt: string; verification: 'current' | 'stale' | 'invalid'; error: string | null;
contractArtifactId: string; contractSha256: string; files: { path: string; sha256: string; bytes: number; origin: { taskId: string; runId: string; resultId: string; sha256: string } | null }[];
}
export interface ExecutionSnapshot { fileResults?: Omit<FileResultView, 'verification' | 'error'>[] }
export interface Artifact { id: string; taskId: string | null; runId: string | null; kind: string; mediaType: string; sha256: string; bytes: number; createdAt: string; status: string }
export interface ArtifactPreview extends Artifact { content: string; offset: number; totalCharacters: number; truncated: boolean }
export interface ProjectMemorySource { kind: 'project' | 'file' | 'artifact' | 'session' | 'task' | 'run'; id?: string; path?: string; sha256?: string; sourceFingerprint: string; label?: string; artifactKind?: string }
@@ -200,7 +205,7 @@ export interface ChangeSet {
observations?: { path: string; state: string; exists: boolean | null; actualSha256: string | null; problem?: string }[];
}
export interface TaskPlanStep {
key: string; title: string; criterion: string; kind: 'analysis' | 'changes' | 'checks' | 'browser'; depends_on: string[];
key: string; title: string; criterion: string; kind: 'analysis' | 'changes' | 'results' | 'checks' | 'browser'; depends_on: string[];
tools?: string[]; paths?: string[]; checks?: string[]; viewport_width?: number; actions?: string[];
}
export interface TaskPlanRecord { id: string; taskId: string; runId: string; revision: number; parentPlanId: string | null; steps: TaskPlanStep[]; contractArtifactId: string; contractSha256: string }