/** Compare the embedded assistant with the installed official Standard preset. */ import assert from 'node:assert/strict'; import {mkdir,mkdtemp,writeFile,readFile} from 'node:fs/promises'; import path from 'node:path'; import os from 'node:os'; import {createRequire} from 'node:module'; import {pathToFileURL} from 'node:url'; import {bootRuntime} from '../integration/dsh/start.mjs'; const output=path.resolve('build/dsh-native-capabilities'); await mkdir(output,{recursive:true}); const root=await mkdtemp(path.join(os.tmpdir(),'dsh-native-capabilities-')); for(const key of ['DSH_API_KEY','DSH_API_BASE','DSH_MODEL','DX_DSH_MODELS'])delete process.env[key]; process.env.DX_DSH_HOME=path.join(root,'home'); process.env.DX_DSH_CONTEXT_FILE=path.join(root,'context.json'); await writeFile(process.env.DX_DSH_CONTEXT_FILE,JSON.stringify({task_id:'capabilities',revision:'native'})); const {ctx,shutdown}=await bootRuntime({announce:false}); try{ const presets=await ctx.agentPresets.list(); const standard=presets.find(p=>p.id==='standard'); assert.ok(standard&&!standard.broken,'Official Standard must be available: '+JSON.stringify(presets)); const workspace=await ctx.workspaceRegistry.create(process.env.DX_DSH_WORKSPACE,'Native capabilities'); const create=async agentPreset=>{ const {sessionId}=await ctx.sessionController.create({workspaceId:workspace.id,agentPreset}); return ctx.agents.get(sessionId); }; const native=await create('standard'),embedded=await create('dx-task'); const names=agent=>ctx.tools.schemas(agent).map(t=>t.name).sort(); assert.deepEqual(names(embedded),names(native),'Existing dx-task sessions must retain the full native tool catalog'); for(const tool of ['read','write','edit','pwsh','get_goal','create_goal','update_goal','todo_write','subagent']) assert.ok(names(embedded).includes(tool),'Missing native capability: '+tool); const call=(name,args)=>ctx.tools.execute({name,arguments:args,callId:crypto.randomUUID(),agent:embedded,signal:AbortSignal.timeout(20000)}); const filename=path.join(process.env.DX_DSH_WORKSPACE,'native-write.txt'); const written=await call('write',{file_path:filename,content:'native file operations'}); assert.equal(written.isError,false,JSON.stringify(written)); assert.equal(await readFile(filename,'utf8'),'native file operations'); const shell=await call('pwsh',{description:'Verify the native PowerShell execution path',command:"'NATIVE_HARNESS_SHELL_OK'"}); assert.equal(shell.isError,false,JSON.stringify(shell)); assert.match(JSON.stringify(shell),/NATIVE_HARNESS_SHELL_OK/); assert.ok(ctx.get('goals'),'Native goal service must be mounted'); assert.ok(ctx.agentPresets.serviceFor(embedded,'compaction'),'Native automatic compaction must be mounted'); const require=createRequire(new URL('../integration/dsh/start.mjs',import.meta.url)); const {LlmAdapter}=await import(pathToFileURL(require.resolve('@deepseek-ai/dsh-llm')).href); let responses=0; class GoalFixture extends LlmAdapter{ providerInfo(provider){return {id:provider,name:'Native goal verification'};} async listModels(provider){return [{provider,id:'fixture',name:'Fixture',reasoning:{efforts:[{id:'high',name:'High'}]}}];} async resolveModel(provider,id){return {provider,id,name:'Fixture',reasoning:{efforts:[{id:'high',name:'High'}]}};} async *stream(options){ responses++; assert.equal(options.reasoningEffort,'high','Native selected reasoning must reach the adapter'); const goal=ctx.goals.get(embedded); const tool=responses===1?{name:'create_goal',arguments:{objective:'Complete a controlled multi-round task',max_goal_rounds:3}} :goal?.roundsStarted>0&&goal.phase==='active'?{name:'update_goal',arguments:{goal_id:goal.id,revision:goal.revision,action:'complete'}}:null; if(tool){ const block={type:'tool-call',id:crypto.randomUUID(),name:tool.name,arguments:JSON.stringify(tool.arguments)}; yield {type:'block-start',index:0,blockType:'tool-call'}; yield {type:'block-end',index:0,block}; }else{ yield {type:'block-start',index:0,blockType:'text'}; yield {type:'block-end',index:0,block:{type:'text',text:'Controlled round completed.'}}; } yield {type:'usage',usage:{inputTokens:12,outputTokens:4,totalTokens:16}}; yield {type:'finish',reason:{kind:tool?'tool-calls':'stop'}}; } } const release=ctx.llm.registerAdapter(['native-goal-fixture'],new GoalFixture()); await ctx.sessionController.selectModel({sessionId:embedded.id,provider:'native-goal-fixture',model:'fixture',reasoningEffort:'high'}); await ctx.sessionController.commands.prompt({sessionId:embedded.id,requestId:crypto.randomUUID(),mode:'queue', content:[{type:'text',text:'Create a goal and continue autonomously until the controlled task completes.'}]},{kind:'user',rpcId:crypto.randomUUID()}); const deadline=Date.now()+120000; while(ctx.goals.get(embedded)?.phase!=='complete'&&Date.now()setTimeout(resolve,20)); await embedded.whenIdle(); const goal=ctx.goals.get(embedded); assert.equal(goal?.phase,'complete',JSON.stringify({goal,responses,events:embedded.session.snapshotEvents().slice(-8)})); assert.ok(goal.roundsStarted>0,'A goal must continue without a second human prompt'); release(); const report={status:'passed',presets:presets.map(p=>p.id),tools:names(embedded),nativeParity:true,fileWrite:true,shell:true, goalCompleted:true,autonomousRounds:goal.roundsStarted,reasoningEffort:'high',responses}; await writeFile(path.join(root,'report.json'),JSON.stringify(report,null,2)); await writeFile(path.join(output,'report.json'),JSON.stringify(report,null,2)); console.log(JSON.stringify(report)); }finally{await shutdown.shutdown(0);}