merge-main-ui-host-compatibility
Core regression / Python core and release configuration (push) Successful in 16s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 16s
Core regression / JavaScript syntax (pull_request) Successful in 3s
Core regression / Python core and release configuration (push) Successful in 16s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python core and release configuration (pull_request) Successful in 16s
Core regression / JavaScript syntax (pull_request) Successful in 3s
This commit is contained in:
commit
56588a9203
14 files changed
+621
-21
No files matched your search
+156
-8
@@ -1,7 +1,9 @@
|
||||
/** Application-owned composition around the unmodified official Harness web UI. */
|
||||
import {createRequire} from 'node:module';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {mkdir, writeFile, readFile, cp} from 'node:fs/promises';
|
||||
import {mkdir, writeFile, readFile, cp, rename} from 'node:fs/promises';
|
||||
import {createHash,randomUUID} from 'node:crypto';
|
||||
import {isDeepStrictEqual} from 'node:util';
|
||||
import path from 'node:path';
|
||||
import {createInterface} from 'node:readline';
|
||||
|
||||
@@ -28,12 +30,14 @@ export const DISABLED = [
|
||||
// This embedded tool uses its application-owned API configuration, without
|
||||
// upstream accounts, billing, credential onboarding or product feedback.
|
||||
'ui-settings-account','account-controller','deepseek-account','llm-deepseek-account',
|
||||
'ui-settings-models','ui-message-feedback','message-feedback','command-feedback',
|
||||
'ui-message-feedback','message-feedback','command-feedback',
|
||||
];
|
||||
|
||||
export function overlay() {
|
||||
const rows = DISABLED.map(id => ({id, disabled:true}));
|
||||
rows.push({id:'agent-preset-registry',config:{default:'dx-task'}});
|
||||
rows.push({id:'ui-settings-general',config:{welcomeNoticeVersion:'2026-09-28.1'}});
|
||||
rows.push({id:'ui-settings-models',config:{credentialOnboarding:false}});
|
||||
rows.push({id:'web-runtime',config:{openBrowser:false,printUrl:false,surfaceContext:false}});
|
||||
rows.push({id:'sandbox-policy',config:{mode:'read-only',workspaceRoot:process.env.DX_DSH_WORKSPACE}});
|
||||
rows.push({id:'permission',config:{presets:{'read-only':{sandbox:'read-only',approval:'ask'}}}});
|
||||
@@ -55,6 +59,144 @@ export function overlay() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function replaceJson(filename,value) {
|
||||
const temporary=filename+'.'+randomUUID()+'.tmp';
|
||||
const {unlink}=await import('node:fs/promises');
|
||||
try{await writeFile(temporary,JSON.stringify(value,null,2));await rename(temporary,filename);}
|
||||
finally{await unlink(temporary).catch(error=>{if(error.code!=='ENOENT')throw error;});}
|
||||
}
|
||||
|
||||
async function readOptionalModelMetadata(filename) {
|
||||
let text;
|
||||
try{text=await readFile(filename,'utf8');}catch(error){if(error.code==='ENOENT')return;throw error;}
|
||||
try{return require('js-yaml').load(text);}catch{
|
||||
// YAML parser errors can quote the line containing a credential.
|
||||
throw Error('Cannot parse stored model metadata: '+path.basename(filename));
|
||||
}
|
||||
}
|
||||
|
||||
function modelEntry(rows,id) {
|
||||
const entries=rows.filter(row=>row.id===id);
|
||||
if(entries.length>1)throw Error('Duplicate '+id+' prevents verifying model binding; startup refused.');
|
||||
return entries[0];
|
||||
}
|
||||
|
||||
function refreshApplicationModels(rows,application,{legacy=false,storedHostKey=false,previousApplication=[],boundDx}={}) {
|
||||
const current=application.find(row=>row.id==='llm-pi-ai')?.config.providers.dx;
|
||||
let userLlm=rows.filter(row=>row.id==='llm-pi-ai'&&row.config).at(-1);
|
||||
if(current&&storedHostKey&&!boundDx){
|
||||
// A generated policy alone cannot prove which endpoint a saved key belongs
|
||||
// to. Never attach an unbound local credential to today's host endpoint.
|
||||
throw Error('Stored DSH_API_KEY has no provider binding; configure a native provider with its own credential reference before starting DSH.');
|
||||
}
|
||||
if(!userLlm&¤t){
|
||||
userLlm={id:'llm-pi-ai',config:{providers:{dx:current}}};
|
||||
rows=[...rows,userLlm];
|
||||
}
|
||||
const prior=boundDx;
|
||||
if(storedHostKey&&prior?.apiKeyEnv==='DSH_API_KEY'&&!rows.some(row=>row.id==='agent-default-model')){
|
||||
const saved=previousApplication.find(row=>row.id==='agent-default-model')?.config;
|
||||
const config=saved?.provider==='dx'&&prior.models?.some(model=>model.id===saved.model)
|
||||
?saved:{provider:'dx',model:prior.models[0].id};
|
||||
rows=[...rows,{id:'agent-default-model',config}];
|
||||
}
|
||||
// A native provider with its own credential reference (or deliberately no
|
||||
// credential) owns its complete route. Only an environment-sourced
|
||||
// DSH_API_KEY belongs to the host; a saved native key owns its user route.
|
||||
const managed=prior===undefined||(prior.apiKeyEnv==='DSH_API_KEY'&&!storedHostKey);
|
||||
return rows.flatMap(row=>{
|
||||
if(row.id==='agent-default-model'&&row.config?.provider==='dx'&&managed
|
||||
&&(legacy||!current?.models.some(model=>model.id===row.config.model)))return [];
|
||||
if(row.id!=='llm-pi-ai'||!row.config)return [row];
|
||||
const providers={...row.config.providers};
|
||||
if(providers.dx===undefined||(providers.dx.apiKeyEnv==='DSH_API_KEY'&&!storedHostKey)){
|
||||
if(current)providers.dx=current;else delete providers.dx;
|
||||
}
|
||||
// Harness replaces an entire plugin config, rather than deep-merging it.
|
||||
// Keep the host route beside custom routes in any overriding user row.
|
||||
return [{...row,config:{...row.config,providers}}];
|
||||
});
|
||||
}
|
||||
|
||||
export async function prepareProfileDirectory(dir) {
|
||||
// The official settings page writes the user patch. Application defaults
|
||||
// belong to a bundle below it. Only host-owned model routes are refreshed;
|
||||
// independent native providers and their credential references remain intact.
|
||||
await mkdir(dir,{recursive:true});
|
||||
const application=overlay();
|
||||
const userPatch=path.join(dir,'cordis.patch.yml');
|
||||
const previousApplication=await readOptionalModelMetadata(path.join(dir,'node_modules/@dx/dsh-policy/cordis.patch.yml'))??[];
|
||||
const policyDir=path.join(dir,'node_modules','@dx','dsh-policy');
|
||||
await mkdir(policyDir,{recursive:true});
|
||||
await cp(path.join(root,'task-plugin'),path.join(dir,'node_modules','@dx','dsh-task'),{recursive:true});
|
||||
await replaceJson(path.join(policyDir,'package.json'),{name:'@dx/dsh-policy',version:VERSION,
|
||||
private:true,dsh:{bundle:{patch:'./cordis.patch.yml'}}});
|
||||
await replaceJson(path.join(policyDir,'cordis.patch.yml'),application);
|
||||
await replaceJson(path.join(dir,'package.json'),{private:true,type:'module',
|
||||
dependencies:{'@dx/dsh-task':'file:'+path.join(root,'task-plugin'),'@dx/dsh-policy':'file:'+policyDir},
|
||||
dsh:{profile:{bundles:['@deepseek-ai/dsh-base','@deepseek-ai/dsh-web-app','@dx/dsh-policy']}}});
|
||||
const {loadProfileDirectory,composeEntries}=await import('@deepseek-ai/dsh-app-boot');
|
||||
const profile=loadProfileDirectory('dx-dsh',dir,require.resolve('@deepseek-ai/dsh/package.json'),{userLayer:false});
|
||||
const layers=profile.layers.map(layer=>layer.patches);
|
||||
// Remove only the generated host route when testing whether a user binding
|
||||
// actually applies. Use Harness semantics, including name assertions/inserts.
|
||||
const withoutHost=profile.layers.map(layer=>layer.packageName==='@dx/dsh-policy'
|
||||
?layer.patches.filter(row=>row.id!=='llm-pi-ai'):layer.patches);
|
||||
let hostCredentialBinding;
|
||||
const refresh=async(rows,legacy=false)=>{
|
||||
const effective=composeEntries([...layers,rows]);
|
||||
const credentials=modelEntry(effective,'credentials');
|
||||
modelEntry(effective,'llm-pi-ai');modelEntry(effective,'agent-default-model');
|
||||
let storedHostKey=false,savedKey;
|
||||
if(credentials?.disabled!==true){
|
||||
if(credentials?.name!=='@deepseek-ai/dsh-credentials-local')
|
||||
throw Error('Cannot verify the configured model credential provider; startup refused.');
|
||||
const {resolveDshHome}=await import('@deepseek-ai/dsh-home-paths');
|
||||
const config=credentials.config??{};
|
||||
const home=resolveDshHome(config.dshHome,{DSH_HOME:path.resolve(dir,'../..')});
|
||||
const stored=await readOptionalModelMetadata(path.resolve(config.path??path.join(home,'.credentials.yaml')));
|
||||
savedKey=stored?.version===undefined?stored?.DSH_API_KEY:stored?.refs?.DSH_API_KEY;
|
||||
storedHostKey=typeof savedKey==='string'&&savedKey.length>0;
|
||||
}
|
||||
const boundDx=modelEntry(composeEntries([...withoutHost,rows]),'llm-pi-ai')?.config?.providers?.dx;
|
||||
const next=refreshApplicationModels(rows,application,{legacy,storedHostKey,previousApplication,boundDx});
|
||||
const actual=modelEntry(composeEntries([...layers,next]),'llm-pi-ai')?.config?.providers?.dx;
|
||||
if(storedHostKey&&actual?.apiKeyEnv==='DSH_API_KEY'
|
||||
&&(!boundDx||!isDeepStrictEqual(actual,boundDx)))
|
||||
throw Error('Stored DSH_API_KEY has no provider binding after Harness composition; startup refused.');
|
||||
if(!storedHostKey&&actual?.apiKeyEnv==='DSH_API_KEY'
|
||||
&&!isDeepStrictEqual(actual,application.find(row=>row.id==='llm-pi-ai')?.config.providers.dx))
|
||||
throw Error('Application model route did not match the current provider; startup refused.');
|
||||
if(actual?.apiKeyEnv==='DSH_API_KEY')hostCredentialBinding={source:storedHostKey?'file':'env',
|
||||
digest:createHash('sha256').update((storedHostKey?savedKey:process.env.DSH_API_KEY)??'').digest('hex')};
|
||||
return next;
|
||||
};
|
||||
let prior;
|
||||
try{prior=await readFile(userPatch,'utf8');}catch(error){if(error.code!=='ENOENT')throw error;}
|
||||
if(prior!==undefined){
|
||||
const {load}=require('js-yaml');
|
||||
const rows=load(prior);
|
||||
const legacy=Array.isArray(rows)&&rows.some(row=>Array.isArray(row?.insert)
|
||||
&&row.insert.some(entry=>entry.id==='dx-task'&&entry.name==='@dx/dsh-task')
|
||||
&&row.insert.some(entry=>entry.id==='preset-dx-task'));
|
||||
const editable=new Set(['llm-pi-ai','llm-deepseek','agent-default-model']);
|
||||
const userRows=legacy?rows.filter(row=>editable.has(row?.id)&&row.config):rows;
|
||||
const next=Array.isArray(userRows)?await refresh(userRows,legacy):userRows;
|
||||
if(legacy||JSON.stringify(next)!==JSON.stringify(rows)){
|
||||
const digest=createHash('sha256').update(prior).digest('hex');
|
||||
const backup=userPatch+(legacy?'.legacy-':'.models-')+digest+'.bak';
|
||||
try{await writeFile(backup,prior,{flag:'wx'});}catch(error){
|
||||
if(error.code!=='EEXIST'||await readFile(backup,'utf8')!==prior)throw error;
|
||||
}
|
||||
await replaceJson(userPatch,next);
|
||||
}
|
||||
}else if(application.some(row=>row.id==='llm-pi-ai')){
|
||||
const next=await refresh([]);
|
||||
await replaceJson(userPatch,next);
|
||||
}
|
||||
return {hostCredentialBinding};
|
||||
}
|
||||
|
||||
export async function bootRuntime({announce=true} = {}) {
|
||||
const installed = require('@deepseek-ai/dsh/package.json');
|
||||
if (installed.version !== VERSION) throw Error('Unsupported Harness version: ' + installed.version);
|
||||
@@ -73,12 +215,7 @@ export async function bootRuntime({announce=true} = {}) {
|
||||
process.env.DX_DSH_WORKSPACE = path.join(process.env.DX_DSH_HOME,'workspace');
|
||||
await mkdir(process.env.DX_DSH_WORKSPACE,{recursive:true});
|
||||
const dir = path.join(process.env.DX_DSH_HOME,'profiles','dx-task');
|
||||
await mkdir(path.join(dir,'node_modules','@dx'),{recursive:true});
|
||||
await cp(path.join(root,'task-plugin'),path.join(dir,'node_modules','@dx','dsh-task'),{recursive:true});
|
||||
await writeFile(path.join(dir,'package.json'), JSON.stringify({private:true,type:'module',
|
||||
dependencies:{'@dx/dsh-task':'file:'+path.join(root,'task-plugin')},
|
||||
dsh:{profile:{bundles:['@deepseek-ai/dsh-base','@deepseek-ai/dsh-web-app']}}}));
|
||||
await writeFile(path.join(dir,'cordis.patch.yml'),JSON.stringify(overlay(),null,2));
|
||||
const modelBinding=await prepareProfileDirectory(dir);
|
||||
const {runProfile, INSTALL_ANCHOR} = await import('@deepseek-ai/dsh/profile-boot');
|
||||
const {loadProfileDirectory,composeEntries} = await import('@deepseek-ai/dsh-app-boot');
|
||||
const {createLaunchEnvironmentSnapshot} = await import('@deepseek-ai/dsh-launch-environment');
|
||||
@@ -93,6 +230,17 @@ export async function bootRuntime({announce=true} = {}) {
|
||||
patchFiles:[],args:['--no-open','--host','127.0.0.1','--port','0'],
|
||||
environment:createLaunchEnvironmentSnapshot([{source:'process',values:process.env}])});
|
||||
await ctx.loader.await();
|
||||
// Check the mounted service as well as its composition: an unexpected
|
||||
// credential source must fail before exposing the runtime to the desktop.
|
||||
if(modelBinding.hostCredentialBinding){
|
||||
const actual=ctx.get('credentials')?await ctx.credentials.resolve('DSH_API_KEY')
|
||||
:{source:'env',value:process.env.DSH_API_KEY};
|
||||
if(actual?.source!==modelBinding.hostCredentialBinding.source||typeof actual?.value!=='string'
|
||||
||createHash('sha256').update(actual.value).digest('hex')!==modelBinding.hostCredentialBinding.digest){
|
||||
await shutdown.shutdown(1);
|
||||
throw Error('Host model credential source changed during startup; startup refused.');
|
||||
}
|
||||
}
|
||||
const names=ctx.tools.schemas().map(tool=>tool.name);
|
||||
if(names.length!==7 || !['dx_task_snapshot','dx_task_create','dx_task_catalog','dx_task_preflight','dx_task_manage','dx_task_execute','dx_task_operations'].every(name=>names.includes(name))) {
|
||||
await shutdown.shutdown(1);
|
||||
|
||||
@@ -13,7 +13,7 @@ window.__ModuleLoader__.load({id:'@dx/dsh-task',factory:require=>{
|
||||
h('h3',null,'任务能力'),
|
||||
h('ul',null,...['在对话中创建和修改任务;具体工程与执行范围由原生窗口确认','实时监管当前执行、阶段、耗时与保存/失败/未命中计数','保存执行回执,重启后核对原队列并手动确认恢复','预览精确位号影响;仅有料号映射时明确标记未知匹配数量','检索历史异常经验,仅将持久化核验通过的记录标为已验证','只读同步已有 Git 工单状态与评论,查看本地证据','查看会话 Token、耗时与超时状态,配置响应时限并停止模型生成','设置任务优先级、执行时间与依赖,通过原生窗口确认排期'].map(text=>h('li',{key:text},text))),
|
||||
h('h3',null,'模型与数据'),
|
||||
h('p',null,'使用主工具配置的模型,在输入框下方选择。会话保存在本机任务中心数据目录。'),
|
||||
h('p',null,'在“模型”设置页添加模型提供商或自定义模型 API,填写地址后可获取可用模型,也可手动填写模型 ID。保存后在输入框下方选择,模型设置和会话在重启后保留。'),
|
||||
h('h3',null,'异常工单'),
|
||||
h('p',null,'随工具预置专用工单上报身份,无需安装 Git 或登录。未解决的异常自动提交项目工单,并上传脱敏诊断证据。'),
|
||||
h('p',null,'工程修改与执行核验由任务中心完成。模型不直接访问工程文件或执行命令。'));
|
||||
|
||||
Reference in new issue
Block a user