feat: add confirmed DSH task management and execution control
This commit is contained in:
1 parent
be382a117d
commit
f861a3d386
25 files changed
+1190
-25
No files matched your search
@@ -11,7 +11,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
h('h3',null,'工作方式'),
|
||||
h('p',null,'在顶部切换任务中心和 DSH助手。会话、任务选择和未发送草稿会保留。'),
|
||||
h('h3',null,'任务能力'),
|
||||
h('ul',null,...['在对话中描述任务名和替换规则,由原生窗口确认工程后创建真实任务','异常后自动创建诊断会话,收集证据','已授权执行遇到明确失败时,按规则最多重试一次并核验','无法解决时复盘,保存诊断和完整证据链,尝试提交 Git 工单','手动刷新任务上下文、准备重试或安全暂停'].map(text=>h('li',{key:text},text))),
|
||||
h('ul',null,...['在对话中创建任务、查找和切换任务、复制配置到新工程','修改名称、备注、Value 策略与已有规则,预览同批影响后确认;归档保留证据','执行前预检所选任务,显示阻断原因;确认工程范围后启动或继续现有队列','对话请求安全暂停,返回实际保存、失败与未命中计数','异常后自动创建诊断会话,收集证据','已授权执行遇到明确失败时,按规则最多重试一次并核验','无法解决时复盘,保存诊断和完整证据链,尝试提交 Git 工单'].map(text=>h('li',{key:text},text))),
|
||||
h('h3',null,'模型与数据'),
|
||||
h('p',null,'使用主工具配置的模型,在输入框下方选择。会话保存在本机任务中心数据目录。'),
|
||||
h('h3',null,'异常工单'),
|
||||
@@ -42,6 +42,17 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
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||'尚未选择任务'):'读取中…'),
|
||||
data?.lifecycle?.request_id&&h('section',{'data-testid':'dx-task-lifecycle',style:{marginBottom:24}},
|
||||
h('h3',{style:{fontSize:14,fontWeight:500}},data.lifecycle.title||'对话任务操作'),
|
||||
h('p',{'data-testid':'dx-lifecycle-status'},({checking:'正在核对真实任务',awaiting_confirmation:'请核对原生确认窗口',
|
||||
applying:'正在保存配置',executing:'正在执行,等待实际结果',updated:'配置已更新',archived:'已移入回收站',
|
||||
selected:'已切换任务',created:'已复制到新工程',preflight:'预检已完成',blocked:'执行已阻断',read:'任务记录已读取',
|
||||
completed:'执行流程已结束,请核对各项计数',paused:'已安全暂停',cancelled:'已取消',rejected:'当前状态不允许操作',failed:'操作未完成'}[data.lifecycle.status]||data.lifecycle.status)),
|
||||
data.lifecycle.preview&&h('p',{style:{whiteSpace:'pre-wrap',maxHeight:220,overflow:'auto',fontSize:12}},data.lifecycle.preview),
|
||||
data.lifecycle.result?.tasks?.map(t=>h('p',{key:t.task_id,style:{whiteSpace:'pre-wrap',fontSize:12}},
|
||||
(t.name||t.task_id)+'\n'+(t.blockers?.length?t.blockers.join('\n'):t.saved_items!==undefined?
|
||||
`已保存 ${t.saved_items} · 失败 ${t.failed_items} · 未命中 ${t.no_match_items}`:''))),
|
||||
data.lifecycle.result?.message&&h('p',{style:{fontSize:12}},data.lifecycle.result.message)),
|
||||
data?.creation?.request_id&&h('section',{'data-testid':'dx-task-creation',style:{marginBottom:24}},
|
||||
h('h3',{style:{fontSize:14,fontWeight:500}},'对话创建任务'),
|
||||
h('p',null,data.creation.name),
|
||||
@@ -68,7 +79,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
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('能力边界','任务修改与执行展示具体范围后由原生窗口确认;预检核对保存的配置,不代表 CAD 已连通。\n自动诊断只读事件快照,处理沿用既有执行规则;不确定状态保留现场,转人工与工单。'),
|
||||
section('监管记录',(data?.events||[]).join('\n')||'等待任务事件'));
|
||||
}
|
||||
return{inject:['slots','sidebarRightTabs','sidebarRight','uiSession','uiWorkspace'],apply(ctx){
|
||||
|
||||
@@ -2,6 +2,7 @@ import {readFile,appendFile} from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import {randomUUID,createHash} from 'node:crypto';
|
||||
import {defineTool} from '@deepseek-ai/dsh-tools';
|
||||
import {registerLifecycle,lifecycleNames} from './lifecycle.mjs';
|
||||
|
||||
export const inject=['webServer','connection','tools','workspaceRegistry','sessionController','agents'];
|
||||
const actions=new Set(['retry_failed','pause_task','refresh_snapshot','retry_issue','open_evidence']);
|
||||
@@ -16,10 +17,10 @@ export async function apply(ctx){
|
||||
const creations=new Map();
|
||||
let auditTail=Promise.resolve();
|
||||
ctx.on('tools/result',(exec,result)=>{
|
||||
if(!['dx_task_snapshot','dx_task_create'].includes(exec.name))return;
|
||||
if(!['dx_task_snapshot','dx_task_create',...lifecycleNames].includes(exec.name))return;
|
||||
const row={at:new Date().toISOString(),name:exec.name,call_id:exec.callId,is_error:result.isError,
|
||||
task_id:result.value?.task_id||'',revision:result.value?.revision||'',
|
||||
...exec.name==='dx_task_create'?{status:result.value?.status,task_ids:result.value?.task_ids||[]}: {}};
|
||||
status:result.value?.status,task_ids:result.value?.task_ids||result.value?.tasks?.map(t=>t.task_id)||[]};
|
||||
auditTail=auditTail.then(()=>appendFile(path.join(process.env.DX_DSH_HOME,'task-tool-audit.jsonl'),JSON.stringify(row)+'\n'))
|
||||
.catch(()=>{console.error('dx-task: could not persist tool audit');});
|
||||
});
|
||||
@@ -92,7 +93,8 @@ export async function apply(ctx){
|
||||
return await promise;
|
||||
}finally{clearTimeout(timer);exec.signal.removeEventListener('abort',cancel);creations.delete(request_id);}
|
||||
}}));
|
||||
ctx.tools.guard(exec=>exec.name==='dx_task_snapshot'||(exec.name==='dx_task_create'&&!incidentSnapshots.has(exec.agent?.id))?
|
||||
registerLifecycle(ctx);
|
||||
ctx.tools.guard(exec=>exec.name==='dx_task_snapshot'||(['dx_task_create',...lifecycleNames].includes(exec.name)&&!incidentSnapshots.has(exec.agent?.id))?
|
||||
undefined:'This tool is not enabled for this session. Automatic incident sessions may only read their snapshot.');
|
||||
const workspace=await ctx.workspaceRegistry.create(process.env.DX_DSH_WORKSPACE,'DxDesigner 任务中心');
|
||||
ctx.on('dx/diagnose-request',request=>{
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import {createHash} from 'node:crypto';
|
||||
import {defineTool} from '@deepseek-ai/dsh-tools';
|
||||
|
||||
export const lifecycleNames=['dx_task_catalog','dx_task_preflight','dx_task_manage','dx_task_execute'];
|
||||
|
||||
export function registerLifecycle(ctx){
|
||||
const pending=new Map();
|
||||
ctx.on('dx/task-lifecycle-result',value=>pending.get(value.request_id)?.resolve(value));
|
||||
ctx.effect(()=>()=>{for(const request of pending.values())request.reject(Error('Task center disconnected'));},'dx-task: lifecycle requests');
|
||||
async function request(capability,spec,exec){
|
||||
if(process.env.DX_DSH_PARENT_PIPE!=='1')throw Error('This capability requires the task-center desktop.');
|
||||
if(!spec||typeof spec!=='object'||JSON.stringify(spec).length>16000)throw Error('Invalid task request');
|
||||
const request_id=createHash('sha256').update((exec.agent?.id||'')+':'+exec.callId).digest('hex').slice(0,32);
|
||||
if(pending.has(request_id))return pending.get(request_id).promise;
|
||||
let resolve,reject,timer;
|
||||
const promise=new Promise((yes,no)=>{resolve=yes;reject=no;});
|
||||
const cancel=()=>{
|
||||
process.stdout.write('DX_DSH_LIFECYCLE_CANCEL '+JSON.stringify({request_id})+'\n');
|
||||
reject(Error('Conversation wait cancelled. Confirmed configuration writes may still finish. If execution started, a safe pause was requested; inspect actual task receipts.'));
|
||||
};
|
||||
pending.set(request_id,{promise,resolve,reject});
|
||||
try{
|
||||
exec.signal.throwIfAborted();exec.signal.addEventListener('abort',cancel,{once:true});
|
||||
timer=setTimeout(cancel,capability==='execute'&&spec.operation==='start'?86400000:300000);
|
||||
process.stdout.write('DX_DSH_LIFECYCLE_REQUEST '+JSON.stringify({request_id,capability,spec})+'\n');
|
||||
return await promise;
|
||||
}finally{clearTimeout(timer);exec.signal.removeEventListener('abort',cancel);pending.delete(request_id);}
|
||||
}
|
||||
const output={schema:{type:'object',additionalProperties:true},render:(_args,value)=>[{type:'text',text:JSON.stringify(value)}]};
|
||||
const ids={type:'array',required:true,items:{type:'string'},description:'1 to 20 distinct real task IDs obtained from current records, in execution order. Never infer IDs.'};
|
||||
const definitions=[
|
||||
{name:'dx_task_catalog',capability:'catalog',parameters:{task_id:{type:'string',description:'Optional real task ID to also read its saved rule mappings, Value policy and execution phase.'}},
|
||||
description:'List real tasks and their IDs, names, groups, statuses and notes. Optionally read one task in detail, including existing rule mappings. Use to resolve natural-language task references before changing, copying or executing a task. Reads saved records only. Interactive conversations only.'},
|
||||
{name:'dx_task_preflight',capability:'preflight',parameters:{task_ids:ids},
|
||||
description:'Check the selected saved tasks before execution. Reports project availability, enabled rules/targets, existing execution evidence, unresolved failures and resource blockers. No CAD connection or engineering writes. Returns concrete blockers; does not guarantee a successful CAD run. Interactive conversations only.'},
|
||||
{name:'dx_task_manage',capability:'manage',parameters:{
|
||||
operation:{type:'string',required:true,enum:['select','copy','update','archive']},task_id:{type:'string',required:true},
|
||||
patch:{type:'object',additionalProperties:false,description:'Only for update. Omit fields the user did not request. Rule edits propagate to the existing task batch and are shown in the native preview.',properties:{
|
||||
name:{type:'string'},note:{type:'string'},copy_part_number_to_value:{type:'boolean'},
|
||||
rules:{type:'array',items:{type:'object',additionalProperties:false,properties:{old_part_number:{type:'string',required:true},
|
||||
new_part_number:{type:'string'},target_cell:{type:'string'},custom_value:{type:'string'},custom_value_enabled:{type:'boolean'},sync_nc:{type:'boolean'},enabled:{type:'boolean'}}}}}}},
|
||||
description:'Manage an existing real task. select changes the task-center selection. update previews explicit metadata and existing rule changes, then waits for native user confirmation. archive moves only that task to the recycle bin, preserving evidence. copy copies mapping configuration and opens the native selector for NEW engineering scope; never duplicates execution evidence or executes CAD. Returns committed IDs/results or cancellation. Native user confirmation cannot be supplied by model arguments. Interactive conversations only.'},
|
||||
{name:'dx_task_execute',capability:'execute',parameters:{operation:{type:'string',required:true,enum:['start','pause']},task_ids:ids},
|
||||
description:'Start or continue the existing serial execution queue for an explicit ordered list of real task IDs. Prechecks and native confirmation are required; actual execution can replace and save engineering files using existing backup, interruption and verification gates. Waits for real results including saved, failed and no-match counts. For pause, provide exactly the active run scope; requests safe stopping after the current item and returns pause_requested, not a claim that stopping has completed. No force-stop, no new CAD scripting or hidden retry. Interactive conversations only.'},
|
||||
];
|
||||
for(const {capability,...definition} of definitions){
|
||||
ctx.tools.register(defineTool({...definition,output,execute:(spec,exec)=>request(capability,spec,exec)}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user