feat: embed native Harness assistant and verify live task model

This commit is contained in:
阿白叔 committed 2026-10-30 11:32:16 +08:00
1 parent 9c508333bb
commit 96227eed2e
29 files changed
+11110 -582

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
const React=require('react'),h=React.createElement;
const names={observe:'待命',draft:'待配置',configuring:'待配置',running:'执行中',paused:'已暂停',completed:'已完成',blocked:'已阻断',uncertain:'待核验',failed:'失败'};
function TaskPanel(){
const[data,setData]=React.useState(null),[notice,setNotice]=React.useState('');
React.useEffect(()=>{
let live=true;
const read=()=>fetch('/dx/context').then(r=>{if(!r.ok)throw Error();return r.json();}).then(v=>{if(live)setData(v);}).catch(()=>{if(live)setNotice('任务上下文暂不可用');});
read();const timer=setInterval(read,1500);return()=>{live=false;clearInterval(timer);};
},[]);
async function request(action){
setNotice('等待任务中心确认…');
try{
const response=await fetch('/dx/action',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({action,task_id:data.task_id,revision:data.revision})});
setNotice(response.ok?'请求已交给任务中心,请在工具中确认。':'任务状态已改变,请刷新后重试。');
}catch{setNotice('任务服务暂不可用,请稍后重试。');}
}
const section=(title,text)=>h('section',{style:{marginBottom:24}},h('h3',{style:{fontSize:14,fontWeight:500,marginBottom:10}},title),
h('div',{style:{whiteSpace:'pre-wrap',color:'var(--dsw-alias-label-secondary)',lineHeight:1.8}},text));
return h('div',{'data-testid':'dx-task-panel',style:{padding:20,overflow:'auto',height:'100%',boxSizing:'border-box'}},
section('当前任务',data?(data.task_name||data.task_id||'尚未选择任务'):'读取中…'),
section('执行状态',data?(names[data.status]||data.status)+(data.issue_code?'\n'+data.issue_code:''):'—'),
section('异常与依据',data?.issue||'暂无异常证据'),
section('规则与进度',data?`${data.rules_count} 条规则\n已完成 ${data.progress.completed||0} / ${data.progress.total||0} 步`:'—'),
h('h3',{style:{fontSize:14,fontWeight:500}},'任务操作'),
...[['refresh_snapshot','刷新任务上下文'],['retry_failed','准备失败项重试'],['pause_task','安全暂停']].map(([action,title])=>
h('button',{key:action,disabled:!data?.task_id,onClick:()=>request(action),style:{display:'block',width:'100%',textAlign:'left',marginTop:8,padding:'10px 12px',
border:'1px solid var(--dsw-alias-border-l2)',background:'var(--dsw-alias-bg-base)',color:'var(--dsw-alias-label-primary)',borderRadius:12,cursor:'pointer'}},title)),
h('p',{role:'status',style:{fontSize:12,color:'var(--dsw-alias-label-secondary)'}},data?.action_result||notice),
section('能力边界','模型只可读取当前任务脱敏快照。\n工程修改、重试执行和不确定状态恢复继续使用任务中心的确认与核验。'),
section('监管记录',(data?.events||[]).join('\n')||'等待任务事件'));
}
return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession'],apply(ctx){
ctx.sidebarRightTabs.register({id:'@dx/dsh-task',kind:'dx-task',priority:'extension',title:()=>'任务监管',guide:[{id:'dx-task',order:0,title:()=>'任务监管',description:()=>'当前任务与受控操作'}]});
ctx.slots.inject('sidebar.right.pane.tab',()=>ctx.slots.register({name:'sidebar.right.pane.tab',key:'@dx/dsh-task'},TaskPanel));
ctx.slots.inject('sidebar.brand.name',()=>ctx.slots.register({name:'sidebar.brand.name',priority:-10},()=>h('span',null,'DSH助手')));
const current=ctx.sidebarRight.mounted;
ctx.effect(()=>{
let frame=0,attempts=0;
const open=()=>{
if(current.getSnapshot())try{ctx.sidebarRight.openTab('dx-task');if(ctx.sidebarRight.isExpanded())return;}catch{}
if(++attempts<120)frame=requestAnimationFrame(open);
};
const queue=()=>{cancelAnimationFrame(frame);attempts=0;frame=requestAnimationFrame(()=>{frame=requestAnimationFrame(open);});};
const stop=current.subscribe(queue);queue();return()=>{stop();cancelAnimationFrame(frame);};
},'dx-task: active session');
}};
}});