From 0f56b26894d87bdf12c4f8d4e7346f0ba60ec212 Mon Sep 17 00:00:00 2001 From: roberttwang Date: Fri, 27 Nov 2026 13:50:51 +0000 Subject: [PATCH 1/8] fix(web): keep AI schedule names and replies intact in English and translate the #1440 copy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In English mode i18n.js rewrites Chinese fragments of every text node it sees. The AI schedule list, editor and run history rendered job names, AI replies and server errors as plain text, so they were partly machine- translated ("巡检-README摘要" became "巡检-READMESummary", "当前项目共有 1 条需求" became "Current project1 requirements"), while the copy added in #1440 (latest-run bar, run-now options, session links) stayed Chinese. - Mark job names, AI replies, errors, issue titles and job filter options as data-i18n-data so only exact dictionary hits apply. - Build accessible names that embed a job name with lfT, so the name is not translated. - Add English entries for the AI schedule list, editor and run-history session actions. Co-Authored-By: Claude Code --- web/app/schedule-executions.js | 19 ++-- web/app/sync-schedule.js | 28 +++-- web/i18n-en.js | 56 ++++++++++ webtest/tests/i18n-schedules.test.mjs | 147 ++++++++++++++++++++++++++ 4 files changed, 231 insertions(+), 19 deletions(-) create mode 100644 webtest/tests/i18n-schedules.test.mjs diff --git a/web/app/schedule-executions.js b/web/app/schedule-executions.js index 14322d52f..5298c855d 100644 --- a/web/app/schedule-executions.js +++ b/web/app/schedule-executions.js @@ -149,10 +149,11 @@ function scheduleExecConversationURL(e){ } function scheduleExecSummaryLine(e){ const error=String(e.error||'').trim(); - if(error)return `

${escapeHTML(error)}

`; - if(e.jobKind==='assistant')return e.assistantMessage?`

${escapeHTML(e.assistantMessage)}

`:''; + // Errors and AI replies are data: data-i18n-data stops fragment translation. + if(error)return `

${escapeHTML(error)}

`; + if(e.jobKind==='assistant')return e.assistantMessage?`

${escapeHTML(e.assistantMessage)}

`:''; const runs=(e.runs||[]).filter(r=>r.runId).map(r=>r.issueTitle||r.issueId||r.runId); - return `

候选 ${Number(e.pulled)||0} · 启动 ${Number(e.dispatched)||0}${runs.length?` · ${escapeHTML(runs.join('、'))}`:''}

`; + return `

候选 ${Number(e.pulled)||0} · 启动 ${Number(e.dispatched)||0}${runs.length?` · ${escapeHTML(runs.join('、'))}`:''}

`; } function scheduleExecRowMenuHTML(e){ const id=escapeHTML(e.id),job=(state.data.scheduleJobs||[]).find(j=>j.id===e.jobId); @@ -163,14 +164,14 @@ function scheduleExecRowMenuHTML(e){ job?item('data-exec-edit-job',e.jobId,'编辑任务','edit'):'' ].join(''); if(!items)return ''; - return ``; + return ``; } function scheduleExecDetailHTML(e,detailId){ const assistant=e.jobKind==='assistant'; const field=(label,value)=>value?`
${label}
${value}
`:''; const error=String(e.error||'').trim(); const runs=(e.runs||[]).filter(r=>r.runId); - const runLinks=runs.length?`
${runs.map(r=>``).join('')}
`:''; + const runLinks=runs.length?`
${runs.map(r=>``).join('')}
`:''; const finished=knownTime(e.finishedAt); return `
${field('触发方式',escapeHTML(scheduleExecTriggerLabel(e.triggerOrigin)))}${field('开始时间',escapeHTML(scheduleExecTimeLabel(e.startedAt)))}${field('结束时间',finished?escapeHTML(scheduleExecTimeLabel(e.finishedAt)):'')}${field('耗时',e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs)))}${field('Trace ID',e.traceId?`${escapeHTML(e.traceId)}`:'')}${assistant?'':field('候选 / 启动',`${Number(e.pulled)||0} / ${Number(e.dispatched)||0}`)}${scheduleExecUsageDetailHTML(e)}
${error?`
错误
${escapeHTML(error)}
`:''}${!error&&assistant&&e.assistantMessage?`
AI 回复
${escapeHTML(e.assistantMessage)}
`:''}${runLinks?`
派发运行${runLinks}
`:''}
`; } @@ -191,7 +192,7 @@ function scheduleExecRowHTML(e){ const assistant=e.jobKind==='assistant',open=scheduleExecExpanded.has(e.id); const detailId=`sched-exec-detail-${String(e.id).replace(/[^A-Za-z0-9_-]/g,'')}`; const trace=e.traceId?``:'—'; - return `${scheduleExecBadgeHTML(e)}${assistant?'AI':'触发'}${escapeHTML(e.jobName||e.jobId)}${scheduleExecSummaryLine(e)}${escapeHTML(scheduleExecTimeLabel(e.startedAt))}${e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs))}${scheduleExecTokenCellHTML(e)}${trace}
${scheduleExecPrimaryActionHTML(e)}${scheduleExecRowMenuHTML(e)||''}
${scheduleExecDetailHTML(e,detailId)}`; + return `${scheduleExecBadgeHTML(e)}${assistant?'AI':'触发'}${escapeHTML(e.jobName||e.jobId)}${scheduleExecSummaryLine(e)}${escapeHTML(scheduleExecTimeLabel(e.startedAt))}${e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs))}${scheduleExecTokenCellHTML(e)}${trace}
${scheduleExecPrimaryActionHTML(e)}${scheduleExecRowMenuHTML(e)||''}
${scheduleExecDetailHTML(e,detailId)}`; } function scheduleExecTableHTML(rows){ return `${rows.map(scheduleExecRowHTML).join('')}
状态任务名称触发时间耗时${scheduleExecIcon('info',12)}Token${scheduleExecIcon('info',12)}Trace ID操作
`; @@ -224,7 +225,7 @@ function renderScheduleExecutionCount(){ count.textContent=records?String(records):''; count.hidden=!records; count.classList.toggle('is-danger',failed>0); - count.title=records?`共 ${records} 条执行记录${failed?`,最近 7 天失败 ${failed} 次`:''}`:''; + count.title=!records?'':lfT(`共 ${records} 条执行记录${failed?`,最近 7 天失败 ${failed} 次`:''}`,`${records} ${records===1?'run':'runs'} in total${failed?`, ${failed} failed in the last 7 days`:''}`); } function scheduleExecFiltersActive(){return !!(scheduleExecStatusFilter||scheduleExecJobFilter||scheduleExecRangeFilter||scheduleExecQuery.trim())} function renderScheduleExecutions(){ @@ -235,7 +236,7 @@ function renderScheduleExecutions(){ const jobSelect=$('#scheduleExecJob'),statusSelect=$('#scheduleExecStatus'),rangeSelect=$('#scheduleExecRange'),search=$('#scheduleExecSearch'); const options=scheduleExecJobOptions(); if(jobSelect){ - jobSelect.replaceChildren(new Option('全部任务',''),...options.map(([id,name])=>new Option(name,id))); + jobSelect.replaceChildren(new Option('全部任务',''),...options.map(([id,name])=>{const o=new Option(name,id);o.dataset.i18nData='';return o})); jobSelect.value=scheduleExecJobFilter; } if(statusSelect)statusSelect.value=scheduleExecStatusFilter; @@ -244,7 +245,7 @@ function renderScheduleExecutions(){ const reset=$('#scheduleExecReset');if(reset)reset.disabled=!scheduleExecFiltersActive(); // The overview follows the job filter only: it always covers the last 7 days. const jobName=scheduleExecJobFilter?options.find(([id])=>id===scheduleExecJobFilter)?.[1]:''; - const scope=$('#scheduleExecOverviewScope');if(scope)scope.textContent=jobName?`(最近 7 天 · ${jobName})`:'(最近 7 天)'; + const scope=$('#scheduleExecOverviewScope');if(scope)scope.innerHTML=jobName?`${lfT('(最近 7 天 · ','(Last 7 days · ')}${escapeHTML(jobName)}${lfT(')',')')}`:'(最近 7 天)'; $('#scheduleExecMetrics').innerHTML=scheduleExecMetricsHTML(scheduleExecOverview); const list=$('#scheduleExecList'); const focused=document.activeElement; diff --git a/web/app/sync-schedule.js b/web/app/sync-schedule.js index fe57516b5..31898a3ba 100644 --- a/web/app/sync-schedule.js +++ b/web/app/sync-schedule.js @@ -129,7 +129,7 @@ function renderScheduleLatestExecBar(job){ ?`` :''; const runBtn=``; - host.innerHTML=`
最近一次执行${badge}${escapeHTML(when)}
${runBtn}${jumpBtn}
${summary?`

${escapeHTML(String(summary).slice(0,220))}

`:''}`; + host.innerHTML=`
最近一次执行${badge}${escapeHTML(when)}
${runBtn}${jumpBtn}
${summary?`

${escapeHTML(String(summary).slice(0,220))}

`:''}`; window.AgentFlowHarnessIcons?.hydrate(host); const runEl=host.querySelector('[data-modal-run-schedule]'); if(runEl)runEl.onclick=()=>{ @@ -149,6 +149,15 @@ function scheduleJobStatusText(job){ if(job?.lastStatus==='failed')return `失败:${job.lastError||''}`; return ''; } +// Names, errors and AI replies are user/server data: data-i18n-data keeps the +// English page from rewriting fragments of them (i18n.js only swaps exact hits). +function scheduleUserTextHTML(text){return `${escapeHTML(text)}`} +function scheduleJobStatusHTML(job){ + if(scheduleJobRunning(job))return escapeHTML(scheduleJobStatusText(job)); + if(job?.lastStatus==='waiting')return `${lfT('待对齐基线:','Waiting for baseline alignment: ')}${scheduleUserTextHTML(job.lastError||'')}`; + if(job?.lastStatus==='failed')return `${lfT('失败:','Failed: ')}${scheduleUserTextHTML(job.lastError||'')}`; + return ''; +} function scheduleJobsInView(jobs, projectId){ return (jobs||[]).filter(j=>!projectId||j.projectId===projectId); } @@ -594,7 +603,7 @@ function renderScheduleJobs(){ const triggerHint=$('#aiScheduleTriggerHint');if(triggerHint)triggerHint.textContent=canRun?'按计划扫描本项目选定状态、尚未跑过 LOOP 的需求,通过基线门禁后派发 LOOP。每个项目使用一份触发配置。':disabled; $('#aiScheduleRuntimeHint').textContent=!state.projectFilter?'请先在顶栏选择项目,再管理 AI 定时任务。':canRun?'任务以最后保存人的身份和完全权限执行。关闭页面后,任务会继续运行。':disabled; $('#aiScheduleProjectName').textContent=currentProject()?.name||'当前项目'; - $('#aiScheduleCount').textContent=`${assistant.length} 个任务`; + $('#aiScheduleCount').textContent=lfT(`${assistant.length} 个任务`,`${assistant.length} ${assistant.length===1?'task':'tasks'}`); $('#newAISchedule').disabled=!state.projectFilter; const editTrigger=$('#editScheduleTrigger');if(editTrigger){editTrigger.disabled=!state.projectFilter;editTrigger.lastChild.textContent=dispatch.length?'编辑触发配置':'配置触发'} const triggerList=$('#aiScheduleTriggerList'); @@ -614,7 +623,7 @@ function renderScheduleJobs(){ // The schedule is started and stopped on the row, not in the editor. function scheduleEnabledSwitchHTML(j){ const on=!!j.enabled,label=on?'已启用':'已停用'; - return ``; + return ``; } async function toggleScheduleJobEnabled(input){ const id=input.dataset.toggleSchedule,enabled=input.checked; @@ -639,7 +648,7 @@ async function toggleScheduleJobEnabled(input){ function scheduleRowMenuHTML(j){ const id=escapeHTML(j.id); const item=(attr,label,icon,cls='')=>``; - return ``; + return ``; } function closeScheduleRowMenus({restore=false}={}){ document.querySelectorAll('.schedule-row-menu:not([hidden])').forEach(menu=>{ @@ -703,7 +712,7 @@ function scheduleJobGroupHTML(g,rowHTML){ const last=g.jobs.map(j=>knownTime(j.lastRunAt)).filter(Boolean).sort((a,b)=>b-a)[0]; const summary=[timings.slice(0,3).join('、')+(timings.length>3?` 等 ${timings.length} 种`:''),`已启用 ${enabled}/${g.jobs.length}`,running?`${running} 个运行中`:'',failed?`${failed} 个失败`:'',updates?`${updates} 个待升级`:''].filter(Boolean).join(' · '); const key=escapeHTML(g.key),id=`schedule-group-${g.jobs[0].id}`; - return `
${g.jobs.map(rowHTML).join('')}
`; + return `
${g.jobs.map(rowHTML).join('')}
`; } function renderScheduleJobList(list,jobs,kind,canRun){ if(!list)return; @@ -715,21 +724,20 @@ function renderScheduleJobList(list,jobs,kind,canRun){ const reopenId=openMenu?.dataset.menuFor||'',reopenFocus=!!openMenu?.contains(focused); if(kind==='dispatch'){ const job=jobs[0]; - list.innerHTML=job?`
${job.enabled?'已启用':'未启用'} · ${escapeHTML(scheduleJobTimingLabel(job))}${escapeHTML(scheduleSourceLabel(job))} · ${scheduleIssueStatusValues(job).map(issueStatusLabel).join('、')}${knownTime(job.lastRunAt)?`最近:${knownTime(job.lastRunAt).toLocaleString()} · 候选 ${job.lastPulled||0},启动 ${job.lastDispatched||0}`:'尚未运行'}${scheduleJobStatusText(job)?` · ${escapeHTML(scheduleJobStatusText(job))}`:''}
${scheduleJobTraceActionsHTML(job)}
${scheduleBlockerHTML(job)}`:''; + list.innerHTML=job?`
${job.enabled?'已启用':'未启用'} · ${escapeHTML(scheduleJobTimingLabel(job))}${escapeHTML(scheduleSourceLabel(job))} · ${scheduleIssueStatusValues(job).map(issueStatusLabel).join('、')}${knownTime(job.lastRunAt)?`最近:${knownTime(job.lastRunAt).toLocaleString()} · 候选 ${job.lastPulled||0},启动 ${job.lastDispatched||0}`:'尚未运行'}${scheduleJobStatusText(job)?` · ${scheduleJobStatusHTML(job)}`:''}
${scheduleJobTraceActionsHTML(job)}
${scheduleBlockerHTML(job)}`:''; }else{ const rowHTML=j=>{ const assistant=!!j.skipDispatch; const kind=assistant?'AI':'触发'; const running=scheduleJobRunning(j); - const extra=running?'':assistant?(j.lastAssistantMessage?`,${escapeHTML(String(j.lastAssistantMessage).slice(0,80))}`:''):`,${scheduleSourceLabel(j)},${scheduleIssueStatusValues(j).map(issueStatusLabel).join('、')},候选 ${j.lastPulled||0},启动 ${j.lastDispatched||0}`; - const statusText=scheduleJobStatusText(j); - const status=statusText?`,${escapeHTML(statusText)}`:''; + const extra=running?'':assistant?(j.lastAssistantMessage?`${lfT(',',', ')}${scheduleUserTextHTML(String(j.lastAssistantMessage).slice(0,80))}`:''):`,${scheduleSourceLabel(j)},${scheduleIssueStatusValues(j).map(issueStatusLabel).join('、')},候选 ${j.lastPulled||0},启动 ${j.lastDispatched||0}`; + const status=scheduleJobStatusText(j)?`,${scheduleJobStatusHTML(j)}`:''; const runDisabled=running||!canRun; const runTitle=running?'任务正在服务端运行,关闭页面不会中断':(canRun?'':'本实例未启用 scheduler'); const session=assistant&&j.sessionMode==='fixed'?' · 同一会话':''; const latestAction=assistant?scheduleLatestExecutionAction(j):null; const latestBtn=latestAction?``:''; - return `
${sharedScheduleRowAction(j)}${latestBtn}${assistant?scheduleEnabledSwitchHTML(j):''}${scheduleRowMenuHTML(j)}
${assistant?'':scheduleBlockerHTML(j)}
`; + return `
${sharedScheduleRowAction(j)}${latestBtn}${assistant?scheduleEnabledSwitchHTML(j):''}${scheduleRowMenuHTML(j)}
${assistant?'':scheduleBlockerHTML(j)}
`; }; list.innerHTML=scheduleJobGroups(jobs).map(g=>g.jobs.length>1?scheduleJobGroupHTML(g,rowHTML):rowHTML(g.jobs[0])).join('')||'
当前项目还没有 AI 定时任务,点击右上角「新建 AI 定时任务」。
'; list.querySelectorAll('[data-schedule-group]').forEach(b=>b.onclick=()=>{ diff --git a/web/i18n-en.js b/web/i18n-en.js index bcbb89c8d..c9d58d5bd 100644 --- a/web/i18n-en.js +++ b/web/i18n-en.js @@ -1095,3 +1095,59 @@ Object.assign(window.LF_I18N_EN, { "在对话里澄清和改代码": "Clarify and change code in chat", "这条需求不使用 LOOP,在对话里澄清需求、直接改代码;定时任务不会自动认领它。": "This requirement uses no LOOP: clarify and change code in chat; scheduled jobs won't pick it up.", }); +Object.assign(window.LF_I18N_EN, { + "共享任务市场": "Shared task market", + "发布共享": "Publish as shared", + "执行记录": "Run history", + "全部任务": "All tasks", + "任务以最后保存人的身份和完全权限执行。关闭页面后,任务会继续运行。": "Tasks run as the last person who saved them, with full permissions. They keep running after you close the page.", + "点击停用:不再按计划执行,正在运行的这次不受影响": "Click to disable: stops running on schedule; a run in progress is not affected", + "点击启用:按计划执行": "Click to enable: runs on schedule", + "同一会话": "Same conversation", + "AI 定时任务": "AI scheduled task", + "新建 AI 定时任务": "New AI scheduled task", + "编辑 AI 定时任务": "Edit AI scheduled task", + "AI 定时任务已保存": "AI scheduled task saved", + "按计划以保存人的身份和完全权限执行提示词,可调用 LOOP、平台工具、工作区及浏览器。": "Runs the prompt on schedule as the person who saved it, with full permissions; it can use LOOPs, platform tools, workspaces and the browser.", + "最近一次执行": "Latest run", + "立即执行一次": "Run once now", + "查看实时执行 ↗": "View live run ↗", + "查看最近执行 ↗": "View latest run ↗", + "查看失败会话 ↗": "View failed conversation ↗", + "查看执行记录": "View run history", + "执行记录(会话已清理)": "Run history (session cleaned up)", + "正在服务端执行,会话就绪后可直接点击跳转实时观看。": "Running on the server. Once the conversation is ready, click to watch it live.", + "创建后可点击底部「保存并立即执行」马上试跑一次": "After creating it, click “Save and run now” below to try it right away", + "执行器与模型": "CLI and model", + "每次新开会话": "New conversation each run", + "始终在同一个会话里继续": "Always continue in the same conversation", + "每次执行各开一个会话,可在执行记录里打开。": "Each run opens its own conversation; open it from the run history.", + "每次执行都接着同一个会话,带上之前的上下文。": "Every run continues the same conversation with the earlier context.", + "每次执行都接着同一个会话,带上之前的上下文。首次执行时创建这个会话;会话被删除后会重新创建。": "Every run continues the same conversation with the earlier context. The first run creates it; it is recreated if deleted.", + "打开当前会话 ↗": "Open current conversation ↗", + "保留会话数": "Conversations to keep", + "最近 10 个": "Latest 10", + "最近 50 个": "Latest 50", + "最近 100 个": "Latest 100", + "不限": "Unlimited", + "超过后每次执行结束时自动删除最早的会话,执行记录仍保留,但打不开已删除的会话。": "Beyond this, the oldest conversation is deleted after each run. Run history is kept, but deleted conversations can't be opened.", + "到点以与主页 AI 对话相同的完全权限执行提示词,可按需读写平台、启动 LOOP、操作工作区及浏览器。": "When due, the prompt runs with the same full permissions as the home AI chat: it can read and write the platform, start LOOPs, and use workspaces and the browser.", + "Bot 通知": "Bot notifications", + "可把执行结果、AI 摘要或自定义消息发送到项目 Bot。": "Send the run result, an AI summary or a custom message to a project Bot.", + "执行成功或失败后,通知 Bot 已绑定的聊天": "After a run succeeds or fails, notify the chats bound to the Bot", + "+ 添加 Bot 通知": "+ Add Bot notification", + "立即执行后直接打开会话": "Open the conversation after running", + "仅保存": "Save only", + "保存并立即执行": "Save and run now", + "保存并启动中…": "Saving and starting…", + "已启动执行,可点击上方「查看实时执行 ↗」跳转": "Run started. Click “View live run ↗” above to follow it", + "已启动执行,会话就绪后将自动打开…": "Run started. The conversation will open when it's ready…", + "打开会话": "Open conversation", + "会话已清理": "Session cleaned up", + "这次执行的会话已被清理(超出任务的保留会话数或保留期限,或被手动删除),无法再打开;AI 回复仍可在详情里查看": "This run's conversation was cleaned up (beyond the task's kept conversations or retention period, or deleted by hand) and can't be opened; the AI reply is still in the details", + "在新标签页打开本次执行的对话": "Open this run's conversation in a new tab", + "准备中": "Preparing", + "无会话": "No conversation", + "会话创建后即可打开": "Can be opened once the conversation is created", + "这次执行在创建会话之前就结束了(例如缺少 Key),没有对话可打开": "This run ended before a conversation was created (for example, a missing key), so there is nothing to open", +}); diff --git a/webtest/tests/i18n-schedules.test.mjs b/webtest/tests/i18n-schedules.test.mjs new file mode 100644 index 000000000..eda90d097 --- /dev/null +++ b/webtest/tests/i18n-schedules.test.mjs @@ -0,0 +1,147 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import path from 'node:path'; +import vm from 'node:vm'; +import { JSDOM } from 'jsdom'; +import { loadApp, settle, WEB_ROOT } from '../lib/load-app.mjs'; + +const HAN = /[㐀-鿿]/; +const ATTRS = ['placeholder', 'title', 'aria-label', 'data-tip', 'data-tooltip']; + +async function englishPage() { + const dom = new JSDOM('', { runScripts: 'outside-only', url: 'http://127.0.0.1/' }); + for (const file of ['i18n-en.js', 'i18n.js']) { + new vm.Script(await readFile(path.join(WEB_ROOT, file), 'utf8'), { filename: file }).runInContext(dom.getInternalVMContext()); + } + return dom.window; +} + +// Chinese left in product copy; user data (data-i18n-data) may stay Chinese. +function leftoverChinese(root, { skipHidden = false } = {}) { + const left = []; + const skip = `[data-i18n-data],[data-i18n-skip],code${skipHidden ? ',[hidden]' : ''}`; + for (const el of [root, ...root.querySelectorAll('*')]) { + if (el.closest(skip)) continue; + for (const node of el.childNodes) if (node.nodeType === 3 && HAN.test(node.nodeValue)) left.push(node.nodeValue.trim()); + for (const name of ATTRS) { + const value = el.getAttribute(name); + if (value && HAN.test(value)) left.push(`${name}="${value}"`); + } + } + return left; +} + +const NAME = '巡检-README摘要'; +const REPLY = '当前项目共有 1 条需求。'; +const ERROR = 'CLI 异常退出,未完成本轮回复'; +const JOBS = [ + { id: 'job-ok', projectId: 'project-1', name: NAME, skipDispatch: true, assistantPrompt: 'x', enabled: true, intervalSec: 3600, lastStatus: 'success', lastRunAt: '2026-11-27T05:27:21Z', lastSessionId: 'ses-gone', lastSessionGone: true, lastAssistantMessage: REPLY }, + { id: 'job-failed', projectId: 'project-1', name: '巡检-Cursor', skipDispatch: true, assistantPrompt: 'y', enabled: false, intervalSec: 3600, lastStatus: 'failed', lastRunAt: '2026-11-27T05:32:17Z', lastSessionId: 'ses-failed', lastError: ERROR }, + { id: 'job-live', projectId: 'project-1', name: '巡检-Pi', skipDispatch: true, assistantPrompt: 'z', enabled: true, sessionMode: 'fixed', intervalSec: 3600, lastStatus: 'running', lastRunAt: '2026-11-27T05:32:09Z', lastSessionId: 'ses-live' }, +]; +const EXECUTIONS = [ + { id: 'sjx-1', jobId: 'job-ok', jobName: NAME, jobKind: 'assistant', projectId: 'project-1', traceId: '0123456789abcdef0123456789abcdef', triggerOrigin: 'manual_run', status: 'success', assistantMessage: REPLY, sessionId: 'ses-gone', sessionGone: true, startedAt: '2026-11-27T05:27:21Z', finishedAt: '2026-11-27T05:28:24Z', durationMs: 63000 }, + { id: 'sjx-2', jobId: 'job-failed', jobName: '巡检-Cursor', jobKind: 'assistant', projectId: 'project-1', traceId: 'fedcba9876543210fedcba9876543210', triggerOrigin: 'manual_run', status: 'failed', error: ERROR, sessionId: 'ses-failed', startedAt: '2026-11-27T05:32:17Z', finishedAt: '2026-11-27T05:32:17Z', durationMs: 400 }, +]; +const ROUTES = [ + { method: 'GET', path: '/api/assistant/models', body: { default: 'glm-test', models: [{ id: 'glm-test', name: 'GLM Test', family: 'glm' }], engines: [{ id: 'codebuddy', name: 'CodeBuddy', configured: true }] } }, + { method: 'GET', path: /^\/api\/schedule-job-executions\/dashboard\?/, body: { items: EXECUTIONS, total: 2, records: 2, recentFailed: 1, overview: { current: { total: 2, finished: 2, success: 1, failed: 1, running: 0, avgMs: 31700 }, previous: { total: 0 } } } }, +]; + +async function englishCopy(t, app, selectors) { + const en = await englishPage(); + t.after(() => en.close()); + const root = en.document.createElement('div'); + root.innerHTML = selectors.map((s) => app.document.querySelector(s).outerHTML).join(''); + en.document.body.append(root); + await new Promise((resolve) => en.setTimeout(resolve, 0)); + return root; +} + +async function scheduleApp(t) { + const app = await loadApp({ routes: ROUTES }); + t.after(app.close); + // The app page runs i18n.js in Chinese; lfT answers in English like a page loaded with data-lang="en". + app.evaluate("window.lfT = (zh, en) => en; toast = () => {};"); + app.router.get('/api/schedule-jobs', () => app.evaluate('state.data.scheduleJobs')); + app.evaluate(`state.projectFilter='project-1';state.data.schedulerEnabled=true;state.data.scheduleJobs=${JSON.stringify(JOBS)};switchView('aiSchedules');renderScheduleJobs()`); + await settle(6); + return app; +} + +test('English AI schedule list keeps job names and AI replies as written and leaves no Chinese copy', async (t) => { + const app = await scheduleApp(t); + const root = await englishCopy(t, app, ['#aiSchedulesView .tabs, #aiSchedulesView [role=tablist]', '#aiScheduleProjectPanel']); + assert.deepEqual(leftoverChinese(root), []); + const names = [...root.querySelectorAll('.schedule-job-main b [data-i18n-data]')].map((el) => el.textContent); + assert.deepEqual(names.sort(), [NAME, '巡检-Cursor', '巡检-Pi'].sort()); + const text = root.textContent.replace(/\s+/g, ' '); + assert.ok(text.includes(REPLY), 'the AI reply is not fragment-translated'); + assert.match(root.querySelector('[data-edit-schedule="job-ok"] small').textContent, new RegExp(`AM, ${REPLY}$`), 'the reply keeps its separator'); + assert.ok(text.includes(ERROR), 'the server error is not fragment-translated'); + assert.doesNotMatch(text, /READMESummary|Current project/); + assert.match(text, /3 tasks/); + assert.match(text, /Failed: CLI 异常退出/); + assert.match(text, /Hourly · Same conversation · Running/); + assert.deepEqual([...root.querySelectorAll('.schedule-latest-btn')].map((el) => el.textContent), ['Run history (session cleaned up)', 'View failed conversation ↗', 'View live run ↗']); + // Accessible names: the product words are English, the job name is kept as written. + assert.equal(root.querySelector('[data-toggle-schedule="job-ok"]').getAttribute('aria-label'), `Enable ${NAME}`); + assert.equal(root.querySelector('[data-schedule-menu="job-ok"]').getAttribute('aria-label'), `More actions: ${NAME}`); +}); + +test('English AI schedule editor shows the latest-run bar and run options in English', async (t) => { + const app = await scheduleApp(t); + await app.evaluate(`openScheduleJobModal('assistant',state.data.scheduleJobs.find(j=>j.id==='job-failed'))`); + await settle(6); + const root = await englishCopy(t, app, ['#scheduleModal']); + assert.deepEqual(leftoverChinese(root, { skipHidden: true }), []); + const bar = root.querySelector('#scheduleLatestExecBar'); + assert.match(bar.textContent, /Latest run/); + assert.equal(bar.querySelector('[data-modal-run-schedule]').textContent, 'Run once now'); + assert.equal(bar.querySelector('[data-modal-jump-latest]').textContent, 'View failed conversation ↗'); + assert.equal(bar.querySelector('.schedule-latest-exec-summary').textContent, ERROR, 'the error is shown as written'); + assert.equal(root.querySelector('#scheduleSaveAndRun').textContent, 'Save and run now'); + assert.equal(root.querySelector('[type=submit]').textContent, 'Save only'); + assert.match(root.querySelector('.schedule-open-after-run').textContent, /Open the conversation after running/); +}); + +test('English AI schedule editor keeps the live-run hint translated while a run is in progress', async (t) => { + const app = await scheduleApp(t); + await app.evaluate(`openScheduleJobModal('assistant',state.data.scheduleJobs.find(j=>j.id==='job-live'))`); + await settle(6); + const root = await englishCopy(t, app, ['#scheduleLatestExecBar']); + assert.deepEqual(leftoverChinese(root), []); + assert.match(root.textContent, /Running on the server\. Once the conversation is ready, click to watch it live\./); + assert.equal(root.querySelector('[data-modal-jump-latest]').textContent, 'View live run ↗'); +}); + +test('English run history keeps job names, AI replies and errors as written', async (t) => { + const app = await scheduleApp(t); + app.document.querySelector('[data-ai-schedule-tab="executions"]').click(); + await settle(8); + const root = await englishCopy(t, app, ['#scheduleExecList']); + const names = [...root.querySelectorAll('.sched-exec-name')].map((el) => el.textContent); + assert.deepEqual(names, [NAME, '巡检-Cursor']); + const lines = [...root.querySelectorAll('.sched-exec-main p')].map((el) => el.textContent); + assert.deepEqual(lines, [REPLY, ERROR]); + assert.deepEqual([...root.querySelectorAll('.sched-exec-action > span')].map((el) => el.textContent), ['Session cleaned up', 'Open conversation']); + assert.equal(root.querySelector('[data-schedule-menu="sjx-1"]').getAttribute('aria-label').startsWith(`More actions: ${NAME} `), true); + const options = [...app.document.querySelectorAll('#scheduleExecJob option')].slice(1); + assert.ok(options.length && options.every((o) => o.hasAttribute('data-i18n-data')), 'job names in the filter are data'); +}); + +test('English run-history filter keeps the chosen job name in the overview scope', async (t) => { + const app = await scheduleApp(t); + app.document.querySelector('[data-ai-schedule-tab="executions"]').click(); + await settle(8); + const job = app.document.querySelector('#scheduleExecJob'); + job.value = 'job-ok'; + job.dispatchEvent(new app.window.Event('change')); + await settle(8); + const root = await englishCopy(t, app, ['#scheduleExecOverviewScope', '#scheduleExecJob']); + assert.equal(root.querySelector('#scheduleExecOverviewScope').textContent, `(Last 7 days · ${NAME})`); + const [all, ...names] = [...root.querySelectorAll('option')].map((o) => o.textContent); + assert.equal(all, 'All tasks'); + assert.deepEqual(names.sort(), ['巡检-Cursor', '巡检-Pi', NAME].sort()); +}); From 874445d2b0f8846141dc179adaced2de6d3c7210 Mon Sep 17 00:00:00 2001 From: roberttwang Date: Fri, 27 Nov 2026 15:55:11 +0000 Subject: [PATCH 2/8] fix(web): never translate AI schedule names, replies or dispatched titles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit data-i18n-data only stops fragment rewrites; an exact dictionary hit still translated. A task named 执行记录 became "Run history" in English (one of the keys this change adds), and 代码审查 became "Code review" as on main. User data now uses data-i18n-skip; server errors keep data-i18n-data. Co-Authored-By: Claude Code --- web/app/schedule-executions.js | 15 ++++++++------- web/app/sync-schedule.js | 17 ++++++++++------- webtest/tests/i18n-schedules.test.mjs | 22 +++++++++++++++++++--- 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/web/app/schedule-executions.js b/web/app/schedule-executions.js index 5298c855d..d6d3e2f6a 100644 --- a/web/app/schedule-executions.js +++ b/web/app/schedule-executions.js @@ -149,11 +149,12 @@ function scheduleExecConversationURL(e){ } function scheduleExecSummaryLine(e){ const error=String(e.error||'').trim(); - // Errors and AI replies are data: data-i18n-data stops fragment translation. + // Errors are server copy (whole-string hits only); AI replies are user data + // and are never translated. if(error)return `

${escapeHTML(error)}

`; - if(e.jobKind==='assistant')return e.assistantMessage?`

${escapeHTML(e.assistantMessage)}

`:''; + if(e.jobKind==='assistant')return e.assistantMessage?`

${escapeHTML(e.assistantMessage)}

`:''; const runs=(e.runs||[]).filter(r=>r.runId).map(r=>r.issueTitle||r.issueId||r.runId); - return `

候选 ${Number(e.pulled)||0} · 启动 ${Number(e.dispatched)||0}${runs.length?` · ${escapeHTML(runs.join('、'))}`:''}

`; + return `

候选 ${Number(e.pulled)||0} · 启动 ${Number(e.dispatched)||0}${runs.length?` · ${escapeHTML(runs.join('、'))}`:''}

`; } function scheduleExecRowMenuHTML(e){ const id=escapeHTML(e.id),job=(state.data.scheduleJobs||[]).find(j=>j.id===e.jobId); @@ -171,7 +172,7 @@ function scheduleExecDetailHTML(e,detailId){ const field=(label,value)=>value?`
${label}
${value}
`:''; const error=String(e.error||'').trim(); const runs=(e.runs||[]).filter(r=>r.runId); - const runLinks=runs.length?`
${runs.map(r=>``).join('')}
`:''; + const runLinks=runs.length?`
${runs.map(r=>``).join('')}
`:''; const finished=knownTime(e.finishedAt); return `
${field('触发方式',escapeHTML(scheduleExecTriggerLabel(e.triggerOrigin)))}${field('开始时间',escapeHTML(scheduleExecTimeLabel(e.startedAt)))}${field('结束时间',finished?escapeHTML(scheduleExecTimeLabel(e.finishedAt)):'')}${field('耗时',e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs)))}${field('Trace ID',e.traceId?`${escapeHTML(e.traceId)}`:'')}${assistant?'':field('候选 / 启动',`${Number(e.pulled)||0} / ${Number(e.dispatched)||0}`)}${scheduleExecUsageDetailHTML(e)}
${error?`
错误
${escapeHTML(error)}
`:''}${!error&&assistant&&e.assistantMessage?`
AI 回复
${escapeHTML(e.assistantMessage)}
`:''}${runLinks?`
派发运行${runLinks}
`:''}
`; } @@ -192,7 +193,7 @@ function scheduleExecRowHTML(e){ const assistant=e.jobKind==='assistant',open=scheduleExecExpanded.has(e.id); const detailId=`sched-exec-detail-${String(e.id).replace(/[^A-Za-z0-9_-]/g,'')}`; const trace=e.traceId?``:'—'; - return `${scheduleExecBadgeHTML(e)}${assistant?'AI':'触发'}${escapeHTML(e.jobName||e.jobId)}${scheduleExecSummaryLine(e)}${escapeHTML(scheduleExecTimeLabel(e.startedAt))}${e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs))}${scheduleExecTokenCellHTML(e)}${trace}
${scheduleExecPrimaryActionHTML(e)}${scheduleExecRowMenuHTML(e)||''}
${scheduleExecDetailHTML(e,detailId)}`; + return `${scheduleExecBadgeHTML(e)}${assistant?'AI':'触发'}${escapeHTML(e.jobName||e.jobId)}${scheduleExecSummaryLine(e)}${escapeHTML(scheduleExecTimeLabel(e.startedAt))}${e.status==='running'?'进行中':escapeHTML(scheduleExecDurationLabel(e.durationMs))}${scheduleExecTokenCellHTML(e)}${trace}
${scheduleExecPrimaryActionHTML(e)}${scheduleExecRowMenuHTML(e)||''}
${scheduleExecDetailHTML(e,detailId)}`; } function scheduleExecTableHTML(rows){ return `${rows.map(scheduleExecRowHTML).join('')}
状态任务名称触发时间耗时${scheduleExecIcon('info',12)}Token${scheduleExecIcon('info',12)}Trace ID操作
`; @@ -236,7 +237,7 @@ function renderScheduleExecutions(){ const jobSelect=$('#scheduleExecJob'),statusSelect=$('#scheduleExecStatus'),rangeSelect=$('#scheduleExecRange'),search=$('#scheduleExecSearch'); const options=scheduleExecJobOptions(); if(jobSelect){ - jobSelect.replaceChildren(new Option('全部任务',''),...options.map(([id,name])=>{const o=new Option(name,id);o.dataset.i18nData='';return o})); + jobSelect.replaceChildren(new Option('全部任务',''),...options.map(([id,name])=>{const o=new Option(name,id);o.dataset.i18nSkip='';return o})); jobSelect.value=scheduleExecJobFilter; } if(statusSelect)statusSelect.value=scheduleExecStatusFilter; @@ -245,7 +246,7 @@ function renderScheduleExecutions(){ const reset=$('#scheduleExecReset');if(reset)reset.disabled=!scheduleExecFiltersActive(); // The overview follows the job filter only: it always covers the last 7 days. const jobName=scheduleExecJobFilter?options.find(([id])=>id===scheduleExecJobFilter)?.[1]:''; - const scope=$('#scheduleExecOverviewScope');if(scope)scope.innerHTML=jobName?`${lfT('(最近 7 天 · ','(Last 7 days · ')}${escapeHTML(jobName)}${lfT(')',')')}`:'(最近 7 天)'; + const scope=$('#scheduleExecOverviewScope');if(scope)scope.innerHTML=jobName?`${lfT('(最近 7 天 · ','(Last 7 days · ')}${escapeHTML(jobName)}${lfT(')',')')}`:'(最近 7 天)'; $('#scheduleExecMetrics').innerHTML=scheduleExecMetricsHTML(scheduleExecOverview); const list=$('#scheduleExecList'); const focused=document.activeElement; diff --git a/web/app/sync-schedule.js b/web/app/sync-schedule.js index 31898a3ba..c8e04a691 100644 --- a/web/app/sync-schedule.js +++ b/web/app/sync-schedule.js @@ -129,7 +129,7 @@ function renderScheduleLatestExecBar(job){ ?`` :''; const runBtn=``; - host.innerHTML=`
最近一次执行${badge}${escapeHTML(when)}
${runBtn}${jumpBtn}
${summary?`

${escapeHTML(String(summary).slice(0,220))}

`:''}`; + host.innerHTML=`
最近一次执行${badge}${escapeHTML(when)}
${runBtn}${jumpBtn}
${summary?`

${escapeHTML(String(summary).slice(0,220))}

`:''}`; window.AgentFlowHarnessIcons?.hydrate(host); const runEl=host.querySelector('[data-modal-run-schedule]'); if(runEl)runEl.onclick=()=>{ @@ -149,13 +149,16 @@ function scheduleJobStatusText(job){ if(job?.lastStatus==='failed')return `失败:${job.lastError||''}`; return ''; } -// Names, errors and AI replies are user/server data: data-i18n-data keeps the -// English page from rewriting fragments of them (i18n.js only swaps exact hits). -function scheduleUserTextHTML(text){return `${escapeHTML(text)}`} +// A task name is pure user data: data-i18n-skip never translates it, so a name +// that happens to equal product copy ("执行记录") keeps showing as typed. +function scheduleUserTextHTML(text){return `${escapeHTML(text)}`} +// Errors come from the server and are product copy: data-i18n-data lets i18n.js +// swap a whole-string dictionary hit but never rewrites fragments of it. +function scheduleErrorTextHTML(text){return `${escapeHTML(text)}`} function scheduleJobStatusHTML(job){ if(scheduleJobRunning(job))return escapeHTML(scheduleJobStatusText(job)); - if(job?.lastStatus==='waiting')return `${lfT('待对齐基线:','Waiting for baseline alignment: ')}${scheduleUserTextHTML(job.lastError||'')}`; - if(job?.lastStatus==='failed')return `${lfT('失败:','Failed: ')}${scheduleUserTextHTML(job.lastError||'')}`; + if(job?.lastStatus==='waiting')return `${lfT('待对齐基线:','Waiting for baseline alignment: ')}${scheduleErrorTextHTML(job.lastError||'')}`; + if(job?.lastStatus==='failed')return `${lfT('失败:','Failed: ')}${scheduleErrorTextHTML(job.lastError||'')}`; return ''; } function scheduleJobsInView(jobs, projectId){ @@ -712,7 +715,7 @@ function scheduleJobGroupHTML(g,rowHTML){ const last=g.jobs.map(j=>knownTime(j.lastRunAt)).filter(Boolean).sort((a,b)=>b-a)[0]; const summary=[timings.slice(0,3).join('、')+(timings.length>3?` 等 ${timings.length} 种`:''),`已启用 ${enabled}/${g.jobs.length}`,running?`${running} 个运行中`:'',failed?`${failed} 个失败`:'',updates?`${updates} 个待升级`:''].filter(Boolean).join(' · '); const key=escapeHTML(g.key),id=`schedule-group-${g.jobs[0].id}`; - return `
${g.jobs.map(rowHTML).join('')}
`; + return `
${g.jobs.map(rowHTML).join('')}
`; } function renderScheduleJobList(list,jobs,kind,canRun){ if(!list)return; diff --git a/webtest/tests/i18n-schedules.test.mjs b/webtest/tests/i18n-schedules.test.mjs index eda90d097..2e5fd1588 100644 --- a/webtest/tests/i18n-schedules.test.mjs +++ b/webtest/tests/i18n-schedules.test.mjs @@ -17,7 +17,7 @@ async function englishPage() { return dom.window; } -// Chinese left in product copy; user data (data-i18n-data) may stay Chinese. +// Chinese left in product copy; user data (data-i18n-skip, data-i18n-data) may stay Chinese. function leftoverChinese(root, { skipHidden = false } = {}) { const left = []; const skip = `[data-i18n-data],[data-i18n-skip],code${skipHidden ? ',[hidden]' : ''}`; @@ -74,7 +74,7 @@ test('English AI schedule list keeps job names and AI replies as written and lea const app = await scheduleApp(t); const root = await englishCopy(t, app, ['#aiSchedulesView .tabs, #aiSchedulesView [role=tablist]', '#aiScheduleProjectPanel']); assert.deepEqual(leftoverChinese(root), []); - const names = [...root.querySelectorAll('.schedule-job-main b [data-i18n-data]')].map((el) => el.textContent); + const names = [...root.querySelectorAll('.schedule-job-main b [data-i18n-skip]')].map((el) => el.textContent); assert.deepEqual(names.sort(), [NAME, '巡检-Cursor', '巡检-Pi'].sort()); const text = root.textContent.replace(/\s+/g, ' '); assert.ok(text.includes(REPLY), 'the AI reply is not fragment-translated'); @@ -128,7 +128,7 @@ test('English run history keeps job names, AI replies and errors as written', as assert.deepEqual([...root.querySelectorAll('.sched-exec-action > span')].map((el) => el.textContent), ['Session cleaned up', 'Open conversation']); assert.equal(root.querySelector('[data-schedule-menu="sjx-1"]').getAttribute('aria-label').startsWith(`More actions: ${NAME} `), true); const options = [...app.document.querySelectorAll('#scheduleExecJob option')].slice(1); - assert.ok(options.length && options.every((o) => o.hasAttribute('data-i18n-data')), 'job names in the filter are data'); + assert.ok(options.length && options.every((o) => o.hasAttribute('data-i18n-skip')), 'job names in the filter are never translated'); }); test('English run-history filter keeps the chosen job name in the overview scope', async (t) => { @@ -145,3 +145,19 @@ test('English run-history filter keeps the chosen job name in the overview scope assert.equal(all, 'All tasks'); assert.deepEqual(names.sort(), ['巡检-Cursor', '巡检-Pi', NAME].sort()); }); + +test('a job name that equals product copy is shown as typed in English', async (t) => { + const app = await scheduleApp(t); + // "执行记录" is product copy that this PR translates to "Run history"; a task + // named after it is user data and must stay Chinese. + app.evaluate(`state.data.scheduleJobs=[{id:'job-copy',projectId:'project-1',name:'执行记录',skipDispatch:true,assistantPrompt:'x',enabled:true,intervalSec:3600,lastStatus:'success',lastRunAt:'2026-11-27T05:27:21Z',lastAssistantMessage:'代码审查'}]; renderScheduleJobs()`); + await settle(4); + const root = await englishCopy(t, app, ['#aiSchedulesView .tabs, #aiSchedulesView [role=tablist]', '#aiScheduleProjectPanel']); + const row = root.querySelector('[data-edit-schedule="job-copy"]'); + assert.ok(row); + assert.ok(row.textContent.includes('执行记录'), 'the task name is kept'); + assert.ok(row.textContent.includes('代码审查'), 'an AI reply that equals product copy is kept'); + assert.ok(!row.textContent.includes('Run history'), 'the task name is not translated to product copy'); + assert.equal(root.querySelector('[data-schedule-menu="job-copy"]').getAttribute('aria-label'), 'More actions: 执行记录'); + assert.equal(root.querySelector('[data-toggle-schedule="job-copy"]').getAttribute('aria-label'), 'Enable 执行记录'); +}); From c52a403da9315b0a8b43284a59e0afe561cc6d97 Mon Sep 17 00:00:00 2001 From: roberttwang Date: Fri, 27 Nov 2026 17:10:07 +0000 Subject: [PATCH 3/8] fix(web): keep user-data options as written in the Harness select panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The run-history job filter marks each job name with data-i18n-skip, but hui-select rebuilds the options in its own panel (and the trigger in trigger mode) from option.text, so i18n.js still fragment-translated the names there: a job named 执行记录 showed as "Run history" once the dropdown was opened. Copy data-i18n-skip / data-i18n-data from the option onto the panel label and the trigger value. Also translate the run-detail labels (start/end time, token fields, AI reply, candidates / started, dispatched runs) that were still Chinese in the English UI. Co-Authored-By: Claude Code --- web/app/hui-select.js | 15 ++++- web/i18n-en.js | 12 ++++ webtest/tests/i18n-schedules.test.mjs | 80 +++++++++++++++++++++++++-- 3 files changed, 100 insertions(+), 7 deletions(-) diff --git a/web/app/hui-select.js b/web/app/hui-select.js index e37203b68..7bc526429 100644 --- a/web/app/hui-select.js +++ b/web/app/hui-select.js @@ -100,6 +100,16 @@ function optionSearch(option) { return option.getAttribute?.('data-search') || option.dataset?.search || ''; } + // i18n.js decides per element whether text is product copy: user data on an + //