// Render the backend's boot-scoped projection. No browser-side phase reducer. (() => { const $ = id => document.getElementById(id); const esc = value => String(value ?? '').replace(/[&<>"']/g, c => ({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c])); const states = {running:'执行中',waiting_input:'等待输入',observed:'已观测',completed:'已观察到结束',skipped:'已跳过',failed:'失败 / 被阻断',interrupted:'已中断',unknown:'结束未确认'}; const planStates = {idle:'尚未启动计划',running:'计划自动运行',waiting_boot:'等待真实新启动',waiting_user:'等待人工操作',paused:'计划已暂停',completed:'计划已完成',blocked:'计划被阻断',failed:'计划执行失败',stopped:'自动执行已停止',amt_preparing:'正在准备 AMT',amt_running:'AMT 执行中'}; const terminalStates = new Set(['completed','skipped','failed','interrupted']); const closeReasons = {console_offline:'控制台离线,当前执行状态未知',later_stage_observed_without_end:'已观察到后续阶段,未收到此步骤的结束回显'}; let api, currentScope = '', rowLimit = 80; const list = value => Array.isArray(value) ? value : []; const count = value => Number.isFinite(Number(value)) ? Math.max(0, Number(value)) : 0; const time = value => Number(value) > 0 ? api.time(value) : '—'; const duration = value => typeof value === 'number' && Number.isFinite(value) ? value.toLocaleString() + ' ms' : '未报告'; const cpuName = value => value !== null && value !== undefined && value !== '' ? 'CPU' + value : '全局'; const stateName = (row, live) => { if (row.state === 'unknown' && row.closed_reason === 'console_offline') return '离线 · 最后' + (states[row.last_observed_state] || '状态未知'); const name = states[row.state] || '已观测'; return !live && !terminalStates.has(row.state) ? '最后观测:' + name : name; }; function stateBadge(row, live) { const state = Object.hasOwn(states, row.state) ? row.state : 'observed'; return `${esc(stateName(row, live))}`; } function mainLabel(progress) { return progress.main?.label || '等待阶段数据'; } function renderSummary(control, progress, firmware, station, live) { const main = progress.main || {}, stages = list(progress.stages), prompt = firmware.console_prompt || {}; $('boot-title').textContent = live || !main.id || main.id === 'unknown' ? '本轮启动主进度' : '启动主进度 · 最后观测'; $('boot-identity').textContent = firmware.boot_pending ? '已请求复位,等待真实新启动证据' : progress.boot_id ? `第 ${count(progress.boot_sequence)} 次已确认启动 · ${progress.boot_id}` : progress.main?.id && progress.main.id !== 'unknown' ? '当前会话未捕获启动边界;已记录实际观察到的阶段' : '等待真实启动边界;重新连接不会创建一次启动'; $('boot-current').textContent = main.id && main.id !== 'unknown' ? `${live ? '本轮已推进到' : '最后推进到'}:${mainLabel(progress)}` : '等待当前启动的阶段证据'; const container = $('boot-stages'); Object.assign(container.dataset, {source:station.run_id ? 'run' : 'diagnostic',runId:station.run_id || '',context:live ? 'current' : 'historical_session',bootId:progress.boot_id || '',mainPhase:main.id || 'unknown'}); const stageErrors = firmware.stage_errors || {}; container.innerHTML = stages.map(row => { const observed = row.state !== 'unobserved', current = row.state === 'current'; const status = current ? live ? '已到此阶段' : '最后到达' : observed ? '已观测' : '未观测'; const details = count(row.step_count) ? `${count(row.step_count)} 个步骤 · 结束 ${count(row.completed_count)}` : '尚无步骤记录'; const errRecords = list(stageErrors[row.id]).length; const issues = (count(row.failed_count) || errRecords) ? ` · 异常 ${Math.max(count(row.failed_count), errRecords)}` : ''; return `
等待后端阶段数据。
'; const plan = control.boot_execution || {}; const oldPlan = plan.boot_id && progress.boot_id && plan.boot_id !== progress.boot_id; $('stage-plan-state').textContent = (oldPlan ? '上次计划:' : plan.boot_id && !progress.boot_id ? '计划记录:' : '') + (planStates[plan.state] || (plan.state ? plan.state : '尚未启动计划')); $('stage-plan-state').classList.toggle('is-attention', ['waiting_user','paused','blocked','failed'].includes(plan.state)); $('stage-plan-state').title = [plan.boot_id && !progress.boot_id ? '当前会话尚未捕获启动边界,计划与本轮启动的归属未确认。' : '',plan.waiting_reason || plan.error || ''].filter(Boolean).join(' '); const input = prompt.kind === 'uip' ? `ICT${prompt.uip_stage ?? ''}` : prompt.kind === 'amt' ? 'AMT 菜单' : prompt.kind === 'uefi' ? 'UEFI Shell' : prompt.kind || ''; $('stage-input-context').textContent = prompt.ready ? `${live && prompt.live !== false ? '当前输入位置' : '最后输入位置'}:${cpuName(prompt.cpu)} · ${input}` : live ? '当前没有等待输入的菜单' : '控制台未实时在线,显示最后观测'; $('boot-evidence').textContent = api.terminalText(main.evidence || '尚无主阶段证据'); $('boot-evidence').title = main.evidence || ''; // Render 7 distinct stage completion badges const sc = control.stage_completions || firmware.stage_completions || {}; const compStrip = $('stage-completions-strip'); if (compStrip) { const compDefs = [ ['ict_stage1_complete', '1. ICT1 完成'], ['training_complete', '2. Training 完成'], ['rmt_complete', '3. RMT 完成'], ['amt_complete', '4. AMT 完成'], ['ict_stage2_complete', '5. ICT2 完成'], ['uefi_complete', '6. UEFI 到达'], ['mt_pass_complete', '7. MT PASS 完成'], ]; compStrip.innerHTML = '7 阶段独立完成判定:' + compDefs.map(([key, labelText]) => { const isMtFail = key === 'mt_pass_complete' && sc.mt_fail_complete === true && sc[key] !== true; const done = sc[key] === true; if (isMtFail) { return `✗ 7. MT FAIL`; } return `${done ? '✓ ' : '○ '}${esc(labelText)}`; }).join(''); } // Render firmware family & task_status badges const fwFam = firmware.firmware_family || 'unknown'; if ($('station-fw-family-badge')) { $('station-fw-family-badge').textContent = fwFam === 'vd012' ? '固件: 107_VD012 (24算子)' : fwFam === 'cxmt' ? '固件: CxmtDdrTest (19算子)' : '固件待识别'; } const tStatus = control.task_status || station.task_status || 'not_started'; if ($('station-task-status-badge')) { $('station-task-status-badge').textContent = `任务状态: ${tStatus}`; $('station-task-status-badge').classList.toggle('connected', tStatus === 'completed'); $('station-task-status-badge').classList.toggle('error', tStatus === 'failed'); } // Render awaiting_dimm_replacement or stage_errors banner const awaitingRep = !!(control.awaiting_dimm_replacement || station.awaiting_dimm_replacement); const hasStageErrs = Object.values(stageErrors).some(arr => Array.isArray(arr) && arr.length > 0); if ($('dimm-replacement-banner')) { $('dimm-replacement-banner').classList.toggle('hidden', !awaitingRep && !hasStageErrs); } // Render live pending StageIntents (last-write-wins) const intents = control.stage_intents || {}; if ($('stage-intent-summary')) { const parts = []; for (const [stg, obj] of Object.entries(intents)) { if (obj && typeof obj === 'object' && obj.action) { const stgName = stg === 'uip1' ? 'ICT1' : stg === 'uip2' ? 'ICT2' : stg === 'uip' ? 'ICT' : stg.toUpperCase(); parts.push(`${stgName}→${obj.action}(rev#${obj.revision || 1})`); } } $('stage-intent-summary').textContent = parts.length ? `待消费预置: ${parts.join(' · ')}` : '当前待消费预置: 无'; } } function updateOptions(id, values, allLabel) { const select = $(id), selected = select.value; const signature = JSON.stringify(values); if (select.dataset.signature === signature) return; select.dataset.signature = signature; select.innerHTML = `` + values.map(([value,label]) => ``).join(''); select.value = values.some(([value]) => String(value) === selected) ? selected : ''; } function renderCpus(progress, live) { const rows = list(progress.per_cpu); $('stage-cpu-cards').innerHTML = rows.map(row => { const current = row.current || {}, active = list(row.active_steps); const activity = active.length ? active : current.step_id || current.name ? [current] : []; return `${esc(api.terminalText(step.evidence || '没有附带原始行'))}尚无本次启动的 CPU 步骤。
'}尚未收到本次启动的 CPU 步骤;后端收到可归属 CPU 的固件输出后显示。
'; } function renderSteps(progress, live) { const steps = [...list(progress.steps)].sort((a,b) => count(a.observed_unix_ms)-count(b.observed_unix_ms) || count(a.sequence)-count(b.sequence)), stages = list(progress.stages); updateOptions('stage-filter-phase', stages.map(row => [row.id,row.label || row.id]), '全部阶段'); const cpus = new Set([...list(progress.per_cpu).map(row => row.cpu), ...steps.map(row => row.cpu)].filter(cpu => cpu !== null && cpu !== undefined && cpu !== '')); const cpuOptions = [...cpus].sort((a,b) => Number(a)-Number(b)).map(cpu => [String(cpu),cpuName(cpu)]); if (steps.some(row => row.cpu === null || row.cpu === undefined || row.cpu === '')) cpuOptions.push(['global','全局步骤']); updateOptions('stage-filter-cpu', cpuOptions, '全部 CPU / 全局'); const stage = $('stage-filter-phase').value, cpu = $('stage-filter-cpu').value; const isGlobal = row => row.cpu === null || row.cpu === undefined || row.cpu === ''; const filtered = steps.filter(row => (!stage || row.stage === stage) && (!cpu || (cpu === 'global' ? isGlobal(row) : String(row.cpu) === cpu))); const visible = filtered.slice(-rowLimit).reverse(), body = $('stage-steps-body'); $('stage-step-count').textContent = `当前启动 ${count(progress.step_count)} 个步骤 · 匹配 ${filtered.length} 个 · 显示 ${visible.length} 个`; $('stage-retention-note').textContent = (count(progress.truncated_count) ? `另有 ${count(progress.truncated_count)} 条较早记录不在当前快照中。` : '') + '按最近观测排列;完成数量只计实际结束回显,不估算百分比。'; $('btn-stage-more').hidden = visible.length >= filtered.length; const signature = JSON.stringify([progress.boot_id,live,visible]); if (body.dataset.signature === signature) return; const open = new Set([...body.querySelectorAll('details[open]')].map(node => node.dataset.stepId)); body.dataset.signature = signature; body.innerHTML = visible.map(row => { const metadata = [row.detail_label && row.detail_label !== row.name ? row.detail_label : '',row.firmware_step !== null && row.firmware_step !== undefined ? `固件步骤 ${row.firmware_step}` : '',count(row.attempt) > 1 ? `第 ${row.attempt} 次` : ''].filter(Boolean).join(' · '); const lines = [row.first_evidence && row.first_evidence !== row.evidence ? '首次:\n' + row.first_evidence : '',row.evidence || '没有附带原始行',row.closed_reason ? '记录状态说明:' + (closeReasons[row.closed_reason] || row.closed_reason) : ''].filter(Boolean).join('\n\n'); return `${esc(api.terminalText(lines))}${esc(api.terminalText(row.evidence || ''))}${esc(row.evidence || row.boot_id || '')}