feat(tasks): bind diagnostics to original failures and explain delivery gaps
This commit is contained in:
@@ -5,10 +5,8 @@ import { Modal } from './components';
|
||||
import type { RequirementDraft, RequirementItem, RequirementView, Session, TaskPlanStep } from './types';
|
||||
import { RequirementDraftEditor, RequirementScopeFields, requirementInput as clean, requirementRoles } from './RequirementDraftEditor';
|
||||
import './RequirementPanel.css';
|
||||
import { requirementStates as states } from '../shared/contracts/task-follow-up.mjs';
|
||||
|
||||
const states: Record<string, string> = { pending: '待复核', failed: '复核未通过', stale: '依据已失效', unverified: '原记录待核对',
|
||||
evidence_verified: '所选证据已核对', user_confirmed: '用户已确认', not_requested: '按约定未执行',
|
||||
scope_unknown: '范围待澄清', reference_recorded: '参考已记录', boundary_recorded: '边界已记录' };
|
||||
const kinds: Record<TaskPlanStep['kind'], string> = { analysis: '研究与读取', changes: '已应用改动', results: '当前文件', checks: '工程检查', browser: '页面断言' };
|
||||
const scope = (kind: TaskPlanStep['kind']) => kind === 'analysis' ? { tools: ['read_file'] } : ['changes', 'results'].includes(kind)
|
||||
? { paths: [] } : kind === 'checks' ? { checks: ['test', 'build'] } : { viewport_width: 1280, actions: ['assert_visible'] };
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { api } from './api';
|
||||
import type { DeliveryStatus, Session } from './types';
|
||||
|
||||
export function TaskFollowUp({ session, openArtifact }: { session: Session; openArtifact: (id: string) => void }) {
|
||||
const task = session.execution?.task, run = session.execution?.run;
|
||||
const [value, setValue] = useState<DeliveryStatus | null>(null), [error, setError] = useState(''), [refresh, setRefresh] = useState(0), [loading, setLoading] = useState(false);
|
||||
const identity = session.id + '/' + task?.id + '/' + run?.id;
|
||||
const [loadedIdentity, setLoadedIdentity] = useState('');
|
||||
const active = ['running', 'awaiting_approval', 'stopping'].includes(session.status);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setError('');
|
||||
if (!task || !run || active) { setLoading(false); return; }
|
||||
const timer = setTimeout(() => {
|
||||
setLoading(true); setError('');
|
||||
api<DeliveryStatus>(`/sessions/${session.id}/delivery-status?taskId=${task.id}&runId=${run.id}`)
|
||||
.then(result => { if (alive) { setValue(result); setLoadedIdentity(identity); } })
|
||||
.catch(reason => { if (alive) { setError(reason instanceof Error ? reason.message : String(reason)); setValue(null); } })
|
||||
.finally(() => { if (alive) setLoading(false); });
|
||||
}, 160);
|
||||
return () => { alive = false; clearTimeout(timer); };
|
||||
}, [identity, session.revision, session.status, refresh]);
|
||||
const current = loadedIdentity === identity ? value : null, diagnostic = current?.diagnostics.at(-1), context = diagnostic?.context;
|
||||
return <section className="task-record-section task-follow-up" aria-label="当前缺口与下一步">
|
||||
<div className="record-heading"><h3>当前缺口与下一步</h3><button className="text-button" disabled={active || loading} onClick={() => setRefresh(n => n + 1)}>{loading ? '正在核对' : '刷新当前结果'}</button></div>
|
||||
{active ? <p className="record-footnote">等待所属运行、检查或审批结束,再核对当前结果。</p> : error ? <p role="alert" className="plan-problem">{error} 请刷新当前结果;原记录保留。</p> : current ? <>
|
||||
<p><strong>{current.followUp.statusLabel}</strong></p>
|
||||
<p className="follow-up-next">下一步:{current.followUp.nextStep}</p>
|
||||
{!!current.followUp.gaps.length && <details><summary>待处理事项 · {current.followUp.gaps.length}</summary><ul>{current.followUp.gaps.map((gap, i) => <li key={gap.kind + gap.id + i}><strong>{gap.label}</strong><p>{gap.nextStep}</p></li>)}</ul></details>}
|
||||
{diagnostic && context && <div className="diagnostic-origin" aria-label="诊断原执行">
|
||||
<strong>最近只读诊断 · {diagnostic.status === 'completed' ? '答复已完成' : diagnostic.status === 'failed' ? '诊断失败' : '尚未完成'}</strong>
|
||||
<p>{diagnostic.question}</p>
|
||||
{diagnostic.failure && <p>本次诊断错误:{diagnostic.failure.message}</p>}
|
||||
{context.evidenceVerified ? <><p>原执行:{context.originalRunId?.slice(0, 8) ?? '未记录'}</p><p>原错误:{context.failure?.value.message ?? '未记录具体错误;原因保持未知。'}</p>
|
||||
{context.check && <p>原检查:{context.check.id.slice(0, 8)} · {context.check.status}</p>}</> : <p>{context.error ?? context.note}</p>}
|
||||
{context.artifactId && <button className="text-button" onClick={() => openArtifact(context.artifactId!)}>查看诊断原绑定</button>}
|
||||
</div>}
|
||||
<p className="record-footnote">{current.followUp.note}</p>
|
||||
</> : <p className="record-footnote">正在核对当前目标、要求和原结果。</p>}
|
||||
</section>;
|
||||
}
|
||||
@@ -5,6 +5,15 @@
|
||||
.record-heading > span:not(.status) { margin-left: auto; font-size: 11px; color: var(--muted); }
|
||||
.record-heading > code { margin-left: auto; font-size: 11px; color: var(--muted); }
|
||||
.task-goal { line-height: 1.85; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
|
||||
.task-follow-up { font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
|
||||
.follow-up-next { margin: 10px 0; }
|
||||
.task-follow-up summary { cursor: pointer; color: var(--teal); }
|
||||
.task-follow-up ul { padding-left: 18px; }
|
||||
.task-follow-up li { margin-top: 12px; }
|
||||
.task-follow-up li p { margin-top: 3px; }
|
||||
.diagnostic-origin { margin-top: 14px; padding-left: 10px; border-left: 2px solid #bd9654; }
|
||||
.diagnostic-origin p { margin: 6px 0; white-space: pre-wrap; }
|
||||
@media (max-width: 600px) { .task-follow-up .text-button { min-height: 44px; } }
|
||||
.record-id { display: inline-block; font-size: 10px; color: var(--muted); margin-top: 9px; }
|
||||
.task-instructions { margin-top: 14px; font-size: 11px; }
|
||||
.task-instructions summary { cursor: pointer; color: var(--teal); }
|
||||
|
||||
@@ -17,6 +17,7 @@ import './TaskPanel.css';
|
||||
import { EnvironmentPanel } from './EnvironmentPanel';
|
||||
import { PreviewPanel } from './PreviewPanel';
|
||||
import { FileResultsPanel } from './FileResultsPanel';
|
||||
import { TaskFollowUp } from './TaskFollowUp';
|
||||
|
||||
const stopReasons: Record<string, string> = { model_identity: '模型返回型号需要核对', 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');
|
||||
@@ -100,6 +101,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 && <TaskFollowUp session={session} openArtifact={openArtifact} />}
|
||||
{task && <FileResultsPanel session={session} busy={busy} onSession={onSession} openArtifact={openArtifact} />}
|
||||
{task && <TaskPlanPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
|
||||
{task && <RequirementPanel session={session} busy={busy} onSession={onSession} onError={onError} openArtifact={openArtifact} />}
|
||||
@@ -112,6 +114,7 @@ export function TaskPanel({ project, session, onSession, onError, busy, onWorksp
|
||||
{run ? <><div className="run-status"><Status value={run.status} /><code title={run.id}>{run.id.slice(0, 8)}</code></div>
|
||||
{run.status === 'needs_review' && task.delivery?.status === 'files_applied' && <p className="record-footnote">这次运行在文件审查前结束;文件此后已应用,当前交付状态见上方任务目标。</p>}
|
||||
{run.purpose === 'diagnostic' && <p className="record-footnote">本次为只读诊断,运行结束仅表示答复完成;原任务状态另行保留。</p>}
|
||||
{run.purpose === 'diagnostic' && run.diagnosticContext && <p className="record-footnote">原执行 {run.diagnosticContext.originalRunId?.slice(0, 8) ?? '未记录'}<button className="text-button" onClick={() => openArtifact(run.diagnosticContext!.artifactId)}>查看原绑定</button></p>}
|
||||
<dl className="record-fields"><ActualModelFields run={run} session={session} />{run.workspaceIdentity && <><dt>执行目录</dt><dd className="record-endpoint">{run.workspaceIdentity.root}</dd>{run.workspaceIdentity.branch && <><dt>独立分支</dt><dd className="record-endpoint">{run.workspaceIdentity.branch}</dd></>}</>}<dt>开始 / 结束</dt><dd>{time(run.startedAt)}<br />{time(run.finishedAt)}</dd><dt>模型轮次 / 工具</dt><dd>{run.steps} / {run.toolCalls}</dd><dt>已报告用量</dt><dd>{number(run.usage?.totalTokens)} tokens<br /><small>输入 {number(run.usage?.inputTokens)} · 输出 {number(run.usage?.outputTokens)}</small></dd>
|
||||
{!!run.usage?.unknownRequests && <><dt>未报告用量</dt><dd>{run.usage.unknownRequests} 次请求 · 估算 {number(run.usage.estimatedUnknownTokens)} tokens</dd></>}
|
||||
<dt>本次预算</dt><dd>{number(run.budget?.maxTokens)} tokens · {Math.round((run.budget?.maxDurationMs ?? 0) / 60000)} 分钟 · {run.budget?.maxSteps} 轮</dd><dt>任务累计</dt><dd>{number(execution?.accountedTaskTokens)} / {number(task.budget.maxTokens)} tokens</dd>
|
||||
|
||||
@@ -149,6 +149,18 @@ export interface TurnObservation {
|
||||
}
|
||||
export interface Run { progressShadow?: { mode: 'shadow'; observations: number; truncated: boolean; turns: TurnObservation[] }; progressShadowArtifactIds?: string[]; progressShadowError?: { kind: string; phase: string } }
|
||||
export interface RunBrief { purpose?: 'execution' | 'diagnostic'; source?: string; taskStatusBefore?: string; consumption?: ModelConsumption[] }
|
||||
export interface Run { question?: string; diagnosticContext?: { artifactId: string; sha256: string; originalRunId: string | null } }
|
||||
export interface DiagnosticContext {
|
||||
artifactId?: string; originalRunId?: string | null; evidenceVerified: boolean; historical?: boolean; note?: string; error?: string;
|
||||
failure?: { id: string; eventId: string; runId: string; sha256: string; value: RuntimeFailure } | null;
|
||||
check?: { id: string; runId: string; status: string } | null;
|
||||
}
|
||||
export interface DeliveryStatus {
|
||||
requirementsRevision: number;
|
||||
followUp: { taskId: string; runId: string; goal: string; taskStatus: string; status: string; statusLabel: string; nextStep: string; note: string;
|
||||
gaps: { kind: string; id: string; label: string; nextStep: string }[] };
|
||||
diagnostics: { runId: string; status: string; stopReason: string | null; question: string; failure?: RuntimeFailure | null; context: DiagnosticContext }[];
|
||||
}
|
||||
export interface TaskCheckpoint {
|
||||
id: string; sessionId: string; projectId: string; taskId: string; runId: string; createdAt: string;
|
||||
status: string; artifactId: string; sha256: string; sourceFingerprint: string; requirementsSha256: string;
|
||||
|
||||
Reference in New Issue
Block a user