@tbox.cn/tboxcode-dsh-cli 0.1.0-rc.1 → 0.1.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{createRequire as e}from"node:module";import{spawn as t}from"node:child_process";import{existsSync as n,mkdirSync as r,readFileSync as i,readdirSync as a,rmSync as o,statSync as s}from"node:fs";import{dirname as c,join as l}from"node:path";import{homedir as u}from"node:os";import{parse as d,stringify as f}from"yaml";import{withFileLock as p,writeFileAtomic as m}from"@deepseek-ai/dsh-atomic-write";const h=e(import.meta.url);function g(){let e=h.resolve(`@deepseek-ai/dsh/package.json`),t=JSON.parse(i(e,`utf-8`)).bin?.dsh;if(t===void 0)throw Error(`@deepseek-ai/dsh 包缺 dsh bin 声明`);return l(c(e),t)}function _(e,t){return`tboxcode-dsh ${e}: dsh 非零退出(${t??`signal`})——若上方出现 ERR_MODULE_NOT_FOUND 或插件未激活,多为 profile 半装残缺,运行 tboxcode-dsh init 修复`}function v(e,t=16384){return Buffer.byteLength(e,`utf-8`)<=t?e:`…(前段截断,仅保留尾部 ${t} 字节)\n${e.slice(-t)}`}function y(e){if(process.platform===`win32`){t(`taskkill`,[`/PID`,String(e),`/T`,`/F`],{stdio:`ignore`}).on(`error`,()=>{});return}try{process.kill(-e,`SIGKILL`)}catch(e){if(e.code!==`ESRCH`)throw e}}function b(e){let n=g(),r={...process.env,DSH_HOME:e.dshHome,DSH_TELEMETRY_DISABLED:`1`};return new Promise((i,a)=>{let o=t(process.execPath,[n,...e.args],{env:r,stdio:e.capture===!1?`inherit`:[`ignore`,`pipe`,`pipe`],...e.timeoutMs===void 0?{}:{detached:!0}}),s=``,c=``;o.stdout?.on(`data`,e=>{s+=e.toString()}),o.stderr?.on(`data`,e=>{c+=e.toString()});let l;o.on(`error`,e=>{clearTimeout(l),a(e)}),o.on(`close`,e=>{clearTimeout(l),i({code:e??-1,stdout:s,stderr:c})}),e.timeoutMs!==void 0&&(l=setTimeout(()=>{o.pid!==void 0&&y(o.pid),a(Error(`dsh 进程超时(>${e.timeoutMs}ms),进程组已终止\nSTDOUT:\n${v(s)}\nSTDERR:\n${v(c)}`))},e.timeoutMs))})}const x=[`tboxcode-acp`,`tboxcode-server`,`tboxcode-web`,`tboxcode-headless`],S={"tboxcode-acp":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-cmdline`,`@tbox.cn/dsh-acp-full-app`,`@tbox.cn/dsh-acp-full`,`@deepseek-ai/dsh-tool-ask-user`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`],"tboxcode-server":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`,`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-web":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`,`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-headless":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-headless`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`]};function C(){return process.env.TBOXCODE_DSH_HOME??process.env.DSH_HOME??l(u(),`.dsh`)}function w(e,t){return l(e,`profiles`,t)}function T(e){return e.startsWith(`@tbox.cn/`)}function E(e){let t=l(e,`package.json`);return n(t)?JSON.parse(i(t,`utf-8`)):null}function D(e,t){let r=t.startsWith(`./`)?t.slice(2):t;if(n(l(e,r)))return!0;for(let t of[`.js`,`.json`,`/index.js`,`/index.json`])if(n(l(e,r+t)))return!0;return!1}function O(e){let t=l(e,`node_modules`);if(!n(t))return[];let r=[],o=(e,t)=>{for(let n of a(e,{withFileTypes:!0})){if(n.name.startsWith(`.`)||!n.isDirectory()&&!n.isSymbolicLink())continue;if(n.isDirectory()&&n.name.startsWith(`@`)){o(l(e,n.name),`${t}${n.name}/`);continue}let a=`${t}${n.name}`,s;try{s=JSON.parse(i(l(e,n.name,`package.json`),`utf-8`))}catch{r.push(a);continue}if(typeof s!=`object`||!s)continue;let c=null;if(typeof s.main==`string`&&s.main.length>0)c=s.main;else if(s.exports!==null&&typeof s.exports==`object`){let e=s.exports[`.`],t=typeof e==`string`?e:typeof e==`object`&&e?e.default??e.import??e.require:void 0;typeof t==`string`&&t.length>0&&(c=t)}c!==null&&(D(l(e,n.name),c)||r.push(a))}};return o(t,``),r.sort()}function k(e,t){let r=w(e,t),i=S[t],a=i.filter(T),o=n(r)?E(r):null;if(o===null)return{status:`missing`,profileDir:r,missingPackages:[...i],corruptPackages:[],expectedOwnOrder:a,actualOwnOrder:[],versionMismatches:[]};let s=O(r),c=o.dependencies??{},l=o.dsh?.profile?.bundles??[],u=i.filter(e=>!l.includes(e)&&(!(e in c)||F(r,e)===null)),d=l.filter(T),f=[];if(process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT!==void 0)for(let e of a){let t=P(e),n=F(r,e);t!==null&&n!==null&&t!==n&&f.push({pkg:e,expected:t,actual:n})}for(let e of i.filter(e=>!T(e))){let t=A(),n=F(r,e);t!==``&&n!==null&&t!==n&&f.push({pkg:e,expected:t,actual:n})}let p=`ok`;return u.length>0||s.length>0?p=`incomplete`:f.length>0?p=`version-drift`:(d.length!==a.length||d.some((e,t)=>e!==a[t]))&&(p=`drift`),{status:p,profileDir:r,missingPackages:u,corruptPackages:s,expectedOwnOrder:a,actualOwnOrder:d,versionMismatches:f}}function A(){let t=e(import.meta.url).resolve(`@deepseek-ai/dsh/package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function j(){let t=e(import.meta.url).resolve(`../package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function M(e){if(!T(e))return`${e}@${A()}`;let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0){let t=j();if(t===`0.0.0`)throw Error(`占位版本 0.0.0 不能用于 registry 装配——发布形态先 pnpm release bump;开发 / CI 形态设 TBOXCODE_ASSEMBLY_LOCAL_ROOT 走本地 link: 源`);return`${e}@${t}`}let n=N(t,e);if(n===null)throw Error(`装配安装源未找到包 ${e}(TBOXCODE_ASSEMBLY_LOCAL_ROOT=${t})`);return`link:${n}`}function N(e,t){for(let r of a(e)){let o=l(e,r);if(s(o).isDirectory())for(let e of a(o)){let r=l(o,e),a=l(r,`package.json`);if(!(!s(r).isDirectory()||!n(a))&&JSON.parse(i(a,`utf-8`)).name===t)return r}}return null}function P(e){let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0)return null;let n=N(t,e);return n===null?null:JSON.parse(i(l(n,`package.json`),`utf-8`)).version??null}function F(e,t){let r=l(e,`node_modules`,t,`package.json`);if(!n(r))return null;try{return JSON.parse(i(r,`utf-8`)).version??null}catch{return null}}const I={"node-pty":!0,koffi:!0,"@deepseek-ai/dsh-subprocess-local":!0,"@google/genai":!1,protobufjs:!1};async function L(e){let t=l(e,`pnpm-workspace.yaml`);await p(t,async()=>{if(!n(t)){await m(t,f({packages:[`.`],nodeLinker:`hoisted`,autoInstallPeers:!1,allowBuilds:I}),{mode:420});return}let e=d(i(t,`utf-8`))??{},r=e.allowBuilds??{},a={...I,...r};JSON.stringify(r)!==JSON.stringify(a)&&(e.allowBuilds=a,await m(t,f(e),{mode:420}))})}const R=5e3;function z(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:12e4}function B(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_ATTEMPTS);return Number.isInteger(e)&&e>0?e:2}async function V(e,t,n,r){let i=await b({dshHome:e,args:[`plugin`,`--profile`,t,`add`,n],capture:!0,timeoutMs:z()});if(i.code!==0)throw Error(`装配${r}失败(${n}):dsh plugin add 退出码 ${i.code}\nSTDOUT:\n${v(i.stdout)}\nSTDERR:\n${v(i.stderr)}`)}async function H(e,t){let r=w(e,t),i=l(r,`node_modules`),a=l(e,`profiles`,t,`node_modules`);if(!x.includes(t)||i!==a)throw Error(`装配自愈守卫拒绝:目标 ${i} 非 own profile node_modules(期望 ${a})`);return n(i)?await p(l(r,`.tboxcode-assembly-heal.lock`),async()=>O(r).length===0?!1:(o(i,{recursive:!0,force:!0}),!0)):!1}async function U(e,t,n){let r=n===`explicit`?B():1,i=[],a;for(let o=1;o<=r;o++)try{return await W(e,t,n,i)}catch(e){if(a=e,o<r){let t=String(e instanceof Error?e.message:e).split(`
2
- `)[0];i.push({kind:`retry`,detail:`第 ${o} 次尝试失败(${t}),${R/1e3}s 后重试`}),await new Promise(e=>setTimeout(e,R))}}throw a}async function W(e,t,n,i){let a=k(e,t);if(a.corruptPackages.length>0&&(await H(e,t)&&i.push({kind:`heal`,detail:`半装态自愈:node_modules 残缺 ${a.corruptPackages.length} 包(${a.corruptPackages.slice(0,3).join(`, `)}${a.corruptPackages.length>3?` …`:``})→ nuke 后全链重装`}),a=k(e,t)),a.missingPackages.length>0){r(a.profileDir,{recursive:!0}),await L(a.profileDir);for(let n of a.missingPackages){let r=M(n);await V(e,t,r,`安装`),i.push({kind:`install`,detail:`${n} ← ${r}`})}a=k(e,t)}if(a.status===`version-drift`&&n===`explicit`){for(let n of a.versionMismatches)await V(e,t,M(n.pkg),`重装`),i.push({kind:`reinstall`,detail:`${n.pkg} ${n.actual} → ${n.expected}`});a=k(e,t)}return a.status===`drift`&&(await G(e,t),i.push({kind:`correct-manifest`,detail:`自有行集校正 ${a.actualOwnOrder.join(`,`)} → ${a.expectedOwnOrder.join(`,`)}(结构行是组合契约,用户领地不动)`}),a=k(e,t)),{status:a.status,actions:i,check:a}}async function G(e,t){let n=l(w(e,t),`package.json`);await p(n,async()=>{let e=JSON.parse(i(n,`utf-8`)),r=(e.dsh?.profile?.bundles??[]).filter(e=>!T(e)),a=S[t].filter(T),o=[...r,...a];e.dsh={...e.dsh,profile:{...e.dsh?.profile,bundles:o}},await m(n,`${JSON.stringify(e,null,2)}\n`,{mode:420})})}export{U as a,_ as c,A as i,g as l,S as n,w as o,k as r,C as s,x as t,b as u};
1
+ import{createRequire as e}from"node:module";import{spawn as t}from"node:child_process";import{existsSync as n,mkdirSync as r,readFileSync as i,readdirSync as a,rmSync as o,statSync as s}from"node:fs";import{dirname as c,join as l}from"node:path";import{homedir as u}from"node:os";import{parse as d,stringify as f}from"yaml";import{withFileLock as p,writeFileAtomic as m}from"@deepseek-ai/dsh-atomic-write";const h=e(import.meta.url);function g(){let e=h.resolve(`@deepseek-ai/dsh/package.json`),t=JSON.parse(i(e,`utf-8`)).bin?.dsh;if(t===void 0)throw Error(`@deepseek-ai/dsh 包缺 dsh bin 声明`);return l(c(e),t)}function _(e,t){return`tboxcode-dsh ${e}: dsh 非零退出(${t??`signal`})——若上方出现 ERR_MODULE_NOT_FOUND 或插件未激活,多为 profile 半装残缺,运行 tboxcode-dsh init 修复`}function v(e,t=16384){return Buffer.byteLength(e,`utf-8`)<=t?e:`…(前段截断,仅保留尾部 ${t} 字节)\n${e.slice(-t)}`}function y(e){if(process.platform===`win32`){t(`taskkill`,[`/PID`,String(e),`/T`,`/F`],{stdio:`ignore`}).on(`error`,()=>{});return}try{process.kill(-e,`SIGKILL`)}catch(e){if(e.code!==`ESRCH`)throw e}}function b(e){let n=g(),r={...process.env,DSH_HOME:e.dshHome,DSH_TELEMETRY_DISABLED:`1`};return new Promise((i,a)=>{let o=t(process.execPath,[n,...e.args],{env:r,stdio:e.capture===!1?`inherit`:[`ignore`,`pipe`,`pipe`],...e.timeoutMs===void 0?{}:{detached:!0}}),s=``,c=``;o.stdout?.on(`data`,e=>{s+=e.toString()}),o.stderr?.on(`data`,e=>{c+=e.toString()});let l;o.on(`error`,e=>{clearTimeout(l),a(e)}),o.on(`close`,e=>{clearTimeout(l),i({code:e??-1,stdout:s,stderr:c})}),e.timeoutMs!==void 0&&(l=setTimeout(()=>{o.pid!==void 0&&y(o.pid),a(Error(`dsh 进程超时(>${e.timeoutMs}ms),进程组已终止\nSTDOUT:\n${v(s)}\nSTDERR:\n${v(c)}`))},e.timeoutMs))})}const x=[`tboxcode-acp`,`tboxcode-server`,`tboxcode-web`,`tboxcode-headless`],S={"tboxcode-acp":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-cmdline`,`@tbox.cn/dsh-acp-full-app`,`@tbox.cn/dsh-acp-full`,`@deepseek-ai/dsh-tool-ask-user`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`],"tboxcode-server":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`,`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-web":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`,`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-headless":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-headless`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`]};function C(){return process.env.TBOXCODE_DSH_HOME??process.env.DSH_HOME??l(u(),`.dsh`)}function w(e,t){return l(e,`profiles`,t)}function T(e){return e.startsWith(`@tbox.cn/`)}function E(e){let t=l(e,`package.json`);return n(t)?JSON.parse(i(t,`utf-8`)):null}function D(e,t){let r=t.startsWith(`./`)?t.slice(2):t;if(n(l(e,r)))return!0;for(let t of[`.js`,`.json`,`/index.js`,`/index.json`])if(n(l(e,r+t)))return!0;return!1}function O(e){let t=l(e,`node_modules`);if(!n(t))return[];let r=[],o=(e,t)=>{for(let n of a(e,{withFileTypes:!0})){if(n.name.startsWith(`.`)||!n.isDirectory()&&!n.isSymbolicLink())continue;if(n.isDirectory()&&n.name.startsWith(`@`)){o(l(e,n.name),`${t}${n.name}/`);continue}let a=`${t}${n.name}`,s;try{s=JSON.parse(i(l(e,n.name,`package.json`),`utf-8`))}catch{r.push(a);continue}if(typeof s!=`object`||!s)continue;let c=null;if(typeof s.main==`string`&&s.main.length>0)c=s.main;else if(s.exports!==null&&typeof s.exports==`object`){let e=s.exports[`.`],t=typeof e==`string`?e:typeof e==`object`&&e?e.default??e.import??e.require:void 0;typeof t==`string`&&t.length>0&&(c=t)}c!==null&&(D(l(e,n.name),c)||r.push(a))}};return o(t,``),r.sort()}function k(e,t){let r=w(e,t),i=S[t],a=i.filter(T),o=n(r)?E(r):null;if(o===null)return{status:`missing`,profileDir:r,missingPackages:[...i],corruptPackages:[],expectedOwnOrder:a,actualOwnOrder:[],versionMismatches:[]};let s=O(r),c=o.dsh?.profile?.bundles??[],l=i.filter(e=>F(r,e)===null),u=c.filter(T),d=[];if(process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT!==void 0)for(let e of a){let t=P(e),n=F(r,e);t!==null&&n!==null&&t!==n&&d.push({pkg:e,expected:t,actual:n})}for(let e of i.filter(e=>!T(e))){let t=A(),n=F(r,e);t!==``&&n!==null&&t!==n&&d.push({pkg:e,expected:t,actual:n})}let f=`ok`;return l.length>0||s.length>0?f=`incomplete`:d.length>0?f=`version-drift`:(u.length!==a.length||u.some((e,t)=>e!==a[t]))&&(f=`drift`),{status:f,profileDir:r,missingPackages:l,corruptPackages:s,expectedOwnOrder:a,actualOwnOrder:u,versionMismatches:d}}function A(){let t=e(import.meta.url).resolve(`@deepseek-ai/dsh/package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function j(){let t=e(import.meta.url).resolve(`../package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function M(e){if(!T(e))return`${e}@${A()}`;let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0){let t=j();if(t===`0.0.0`)throw Error(`占位版本 0.0.0 不能用于 registry 装配——发布形态先 pnpm release bump;开发 / CI 形态设 TBOXCODE_ASSEMBLY_LOCAL_ROOT 走本地 link: 源`);return`${e}@${t}`}let n=N(t,e);if(n===null)throw Error(`装配安装源未找到包 ${e}(TBOXCODE_ASSEMBLY_LOCAL_ROOT=${t})`);return`link:${n}`}function N(e,t){for(let r of a(e)){let o=l(e,r);if(s(o).isDirectory())for(let e of a(o)){let r=l(o,e),a=l(r,`package.json`);if(!(!s(r).isDirectory()||!n(a))&&JSON.parse(i(a,`utf-8`)).name===t)return r}}return null}function P(e){let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0)return null;let n=N(t,e);return n===null?null:JSON.parse(i(l(n,`package.json`),`utf-8`)).version??null}function F(e,t){let r=l(e,`node_modules`,t,`package.json`);if(!n(r))return null;try{return JSON.parse(i(r,`utf-8`)).version??null}catch{return null}}const I={"node-pty":!0,koffi:!0,"@deepseek-ai/dsh-subprocess-local":!0,"@google/genai":!1,protobufjs:!1};async function L(e){let t=l(e,`pnpm-workspace.yaml`);await p(t,async()=>{if(!n(t)){await m(t,f({packages:[`.`],nodeLinker:`hoisted`,autoInstallPeers:!1,allowBuilds:I}),{mode:420});return}let e=d(i(t,`utf-8`))??{},r=e.allowBuilds??{},a={...I,...r};JSON.stringify(r)!==JSON.stringify(a)&&(e.allowBuilds=a,await m(t,f(e),{mode:420}))})}const R=5e3;function z(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:12e4}function B(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_ATTEMPTS);return Number.isInteger(e)&&e>0?e:2}async function V(e,t,n,r){let i=await b({dshHome:e,args:[`plugin`,`--profile`,t,`add`,n],capture:!0,timeoutMs:z()});if(i.code!==0)throw Error(`装配${r}失败(${n}):dsh plugin add 退出码 ${i.code}\nSTDOUT:\n${v(i.stdout)}\nSTDERR:\n${v(i.stderr)}`)}async function H(e,t){let r=w(e,t),i=l(r,`node_modules`),a=l(e,`profiles`,t,`node_modules`);if(!x.includes(t)||i!==a)throw Error(`装配自愈守卫拒绝:目标 ${i} 非 own profile node_modules(期望 ${a})`);return n(i)?await p(l(r,`.tboxcode-assembly-heal.lock`),async()=>O(r).length===0?!1:(o(i,{recursive:!0,force:!0}),!0)):!1}async function U(e,t,n){let r=n===`explicit`?B():1,i=[],a;for(let o=1;o<=r;o++)try{return await W(e,t,n,i)}catch(e){if(a=e,o<r){let t=String(e instanceof Error?e.message:e).split(`
2
+ `)[0];i.push({kind:`retry`,detail:`第 ${o} 次尝试失败(${t}),${R/1e3}s 后重试`}),await new Promise(e=>setTimeout(e,R))}}throw a}async function W(e,t,n,i){let a=k(e,t);if(a.corruptPackages.length>0&&(await H(e,t)&&i.push({kind:`heal`,detail:`半装态自愈:node_modules 残缺 ${a.corruptPackages.length} 包(${a.corruptPackages.slice(0,3).join(`, `)}${a.corruptPackages.length>3?` …`:``})→ nuke 后全链重装`}),a=k(e,t)),a.missingPackages.length>0){r(a.profileDir,{recursive:!0}),await L(a.profileDir);for(let n of a.missingPackages){let r=M(n);await V(e,t,r,`安装`),i.push({kind:`install`,detail:`${n} ← ${r}`})}a=k(e,t)}if(a.status===`version-drift`&&n===`explicit`){for(let n of a.versionMismatches)await V(e,t,M(n.pkg),`重装`),i.push({kind:`reinstall`,detail:`${n.pkg} ${n.actual} → ${n.expected}`});a=k(e,t)}return a.status===`drift`&&(await G(e,t),i.push({kind:`correct-manifest`,detail:`自有行集校正 ${a.actualOwnOrder.join(`,`)} → ${a.expectedOwnOrder.join(`,`)}(结构行是组合契约,用户领地不动)`}),a=k(e,t)),{status:a.status,actions:i,check:a}}async function G(e,t){let n=l(w(e,t),`package.json`);await p(n,async()=>{let e=JSON.parse(i(n,`utf-8`)),r=(e.dsh?.profile?.bundles??[]).filter(e=>!T(e)),a=S[t].filter(T),o=[...r,...a];e.dsh={...e.dsh,profile:{...e.dsh?.profile,bundles:o}},await m(n,`${JSON.stringify(e,null,2)}\n`,{mode:420})})}export{A as a,C as c,b as d,j as i,_ as l,S as n,U as o,k as r,w as s,x as t,g as u};
package/lib/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import{a as e,c as t,i as n,l as r,o as i,r as a,s as o,t as s}from"./assembly-COH6w2mC.js";import{createRequire as c}from"node:module";import{spawn as l}from"node:child_process";import{existsSync as u,mkdirSync as d,readFileSync as f,statSync as p,writeFileSync as m}from"node:fs";import{dirname as h,join as g}from"node:path";import{loadConfig as _,resolveConfigDir as v,translateConfig as y,writeOverlayPatch as b}from"@tbox.cn/tboxcode-dsh-runtime";import{createInterface as x}from"node:readline";import{fileURLToPath as S}from"node:url";function C(e,t,n){let r=[e,`--profile`,`tboxcode-web`,`--patch`,t];n.port!==void 0&&r.push(`--port`,String(n.port)),n.host!==void 0&&r.push(`--host`,n.host),n.noOpen===!0&&r.push(`--no-open`);for(let e of n.trustedHost??[])r.push(`--trusted-host`,e);return r}async function w(n){let i=o(),a=v(),s=_(a),c=await b(y(s.config,a,s.path!==null).rows),u=await e(i,`tboxcode-web`,`startup`);if(u.status!==`ok`&&u.status!==`version-drift`)throw await c.dispose(),Error(`web 启动装配未就绪(${u.status})——运行 tboxcode-dsh init 显式装配`);let d=C(r(),c.path,{...n,dshHome:i}),f=l(process.execPath,d,{stdio:`inherit`,env:{...process.env,DSH_HOME:i,DSH_TELEMETRY_DISABLED:`1`}});for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{f.kill(e)});let p=await new Promise(e=>{f.on(`close`,e),f.on(`error`,t=>{console.error(`tboxcode-dsh web: spawn 失败(${t.message})`),e(1)})});return p!==0&&console.error(t(`web`,p)),await c.dispose(),typeof p==`number`?p:1}const T=c(import.meta.url);function E(){return g(h(T.resolve(`@tbox.cn/tboxcode-dsh-runtime/package.json`)),`assets`,`stdout-guard.cjs`)}function D(e,t,n){let r=E(),a=process.env.NODE_OPTIONS??``,o=`--require ${r}`;return{NODE_OPTIONS:a.includes(r)?a:a===``?o:`${a} ${o}`,TBOXCODE_STDIO_GUARD:n,TBOXCODE_PROFILE_DIR:i(e,t)}}function O(e,t,n){let r=[e,`--profile`,`tboxcode-headless`,`--patch`,t];return n.sessionId!==void 0&&r.push(`--session-id`,n.sessionId),n.json===!0&&r.push(`--json`),r.push(...n.task),r}async function k(n){let i=o(),a=v(),s=_(a),c=await b(y(s.config,a,s.path!==null).rows),u=await e(i,`tboxcode-headless`,`startup`);if(u.status!==`ok`&&u.status!==`version-drift`)throw await c.dispose(),Error(`headless 启动装配未就绪(${u.status})——运行 tboxcode-dsh init 显式装配`);let d=O(r(),c.path,n),f=l(process.execPath,d,{stdio:`inherit`,env:{...process.env,...D(i,`tboxcode-headless`,`quiet`),DSH_HOME:i,DSH_TELEMETRY_DISABLED:`1`}}),p=await new Promise(e=>{f.on(`close`,e),f.on(`error`,t=>{console.error(`tboxcode-dsh headless: spawn 失败(${t.message})`),e(1)})});return p!==0&&console.error(t(`headless`,p)),await c.dispose(),typeof p==`number`?p:1}function A(){return JSON.stringify({v:1,event:`standby`})}function j(e,t){return JSON.stringify({v:1,event:`ready`,port:e,token:t})}function M(e,t,n){return JSON.stringify({stage:e,kind:t,error:n})}function N(e){let t;try{t=JSON.parse(e)}catch{return{kind:`malformed`}}if(typeof t!=`object`||!t||Array.isArray(t))return{kind:`malformed`};let n=t;return n.v===1?n.cmd===`start`?{kind:`start`}:{kind:`unknown`,cmd:String(n.cmd??``)}:{kind:`version-skew`,got:typeof n.v==`number`?n.v:void 0}}function P(e){if(!e.includes(`token=`))return null;let t=/https?:\/\/\S+/.exec(e);if(t===null)return null;try{let e=new URL(t[0]);return e.searchParams.get(`token`)===null?null:e}catch{return null}}function F(e){let t=e.searchParams.get(`token`),n=e.port===``?void 0:Number(e.port);return t===null||t===``||n===void 0||!Number.isInteger(n)?null:{port:n,token:t}}var I=class extends Error{};function L(e){if(e instanceof I)return`permanent`;let t=e?.name;return t===`ModelNotSetError`||t===`ModelMalformedError`||t===`SecretInTranslationError`?`permanent`:`transient`}function R(e){return e===null?1:e===0?0:e===2||e===3?e:1}async function z(e){let{io:t}=e;return await new Promise(n=>{let r=`standby`,i=!1,a=!1,o=!1,s=!1,c,l=!1,u=(e,r,i,a)=>{o||(o=!0,r!==void 0&&i!==void 0&&a!==void 0&&t.writeStderr(`${M(r,i,a)}\n`),n(e))};t.writeStdout(`${A()}\n`),e.log(`standby(零用户态自检通过,等待 start)`),t.onSignal(t=>{if(s=!0,e.log(`收到 ${t},正常终(dsh 子进程随停)`),c===void 0){u(0);return}c.kill(t);let n=setTimeout(()=>u(0),3e3);c.onExit(()=>{clearTimeout(n),u(0)})}),t.onStdinEof(()=>{if(!a){if(a=!0,i=!0,r!==`ready`){e.log(`stdin EOF 在 ready 前到达(父进程死亡)——退出`),c?.kill(),u(1);return}e.log(`stdin EOF 在 ready 后到达——孤儿语义,继续运行`)}}),t.onStdinLine(e=>{if(e.trim()===``)return;if(r===`ready`){t.writeStderr(`${M(`protocol`,`protocol`,`start 命令在 ready 后到达(stdin 已转惰性),忽略`)}\n`);return}let n=N(e);switch(n.kind){case`version-skew`:u(3,`protocol`,`protocol`,`信封版本偏斜:期待 v1,实得 ${n.got??`缺省`}——fail-loud(部署错误最显眼信号)`);return;case`start`:if(r!==`standby`)return;r=`starting`,d();return;case`unknown`:t.writeStderr(`${M(`protocol`,`protocol`,`未知 cmd "${n.cmd}" 忽略(additive-only 版本窗口)`)}\n`);return;case`malformed`:t.writeStderr(`${M(`protocol`,`protocol`,`stdin 行非 JSON 对象,忽略`)}\n`);return}});let d=async()=>{try{let n=await e.boot();if(c=n,o){n.kill();return}n.onStdoutLine(n=>{if(l)return;let i=P(n);if(i===null)return;let a=F(i);a!==null&&(l=!0,r=`ready`,t.writeStdout(`${j(a.port,a.token)}\n`),e.log(`ready(token 已交付,stdout 永久静默;token 已弃)`))}),n.onExit(t=>{let n=s?0:R(t);r===`ready`?(e.log(`dsh 退出(码 ${t??`signal`})——server 失活,退出 ${n}`),u(n)):u(n,`boot`,n===2?`permanent`:`transient`,`dsh 在 ready 前退出(码 ${t??`signal`},stdout 零 token 行)`)}),i&&r!==`ready`&&(e.log(`stdin EOF 已在 boot 窗口到达——退出`),n.kill(),u(1))}catch(e){let t=L(e),n=e instanceof Error?e.message:String(e);u(t===`permanent`?2:1,`boot`,t,n.split(`
3
- `)[0]??n)}}})}function B(e,t,n){let r=[t,`--profile`,e===`acp`?`tboxcode-acp`:`tboxcode-server`,`--patch`,n];return e===`server`&&r.push(`--port`,`0`,`--no-open`),r}async function V(n){let i=o(),a=v(),s=_(a),c=await b(y(s.config,a,s.path!==null).rows),u=`tboxcode-acp`,d=await e(i,u,`startup`);if(d.status!==`ok`&&d.status!==`version-drift`)throw await c.dispose(),Error(`${n} 启动装配未就绪(${d.status})——运行 tboxcode-dsh init 显式装配`);let f=B(n,r(),c.path),p=l(process.execPath,f,{stdio:`inherit`,env:{...process.env,...D(i,u,`strict`),DSH_HOME:i,DSH_TELEMETRY_DISABLED:`1`}});for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{p.kill(e)});let m=await new Promise(e=>{p.on(`close`,e),p.on(`error`,t=>{console.error(`tboxcode-dsh ${n}: spawn 失败(${t.message})`),e(1)})});return m!==0&&console.error(t(n,m)),await c.dispose(),typeof m==`number`?m:1}async function H(){return V(`acp`)}function U(){let e=process.stdin,t=x({input:e,crlfDelay:1/0});return{writeStdout:e=>process.stdout.write(e),writeStderr:e=>process.stderr.write(e),onStdinLine:e=>t.on(`line`,e),onStdinEof:t=>{e.on(`end`,t),e.on(`close`,t)},onSignal:e=>{for(let t of[`SIGINT`,`SIGTERM`])process.on(t,()=>e(t))}}}async function W(t={flags:new Map,positional:[]}){if(t.flags.size>0||t.positional.length>0){let e=[...t.positional,...[...t.flags.keys()].map(e=>`--${e}`)].join(` `);return console.error(`tboxcode-dsh server: 裸命令零 flag(机器路径,Supervisor spawn 契约)——实得 "${e}",拒绝启动`),2}return await z({io:U(),log:e=>console.error(`tboxcode-dsh server: ${e}`),boot:async()=>{let t=o(),n=v(),i=_(n),a=await b(y(i.config,n,i.path!==null).rows),s=await e(t,`tboxcode-server`,`startup`);if(s.status!==`ok`&&s.status!==`version-drift`)throw await a.dispose(),new I(`profile 装配未就绪(${s.status})——运行 tboxcode-dsh init 显式装配`);let c=B(`server`,r(),a.path),u=(process.env.TBOXCODE_EXTRA_PATCHES??``).split(`:`).map(e=>e.trim()).filter(e=>e.length>0),d=[...c.slice(0,3),...u.flatMap(e=>[`--patch`,e]),...c.slice(3)],f=l(process.execPath,d,{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,DSH_HOME:t,DSH_TELEMETRY_DISABLED:`1`}});f.stderr?.on(`data`,e=>{process.stderr.write(e)}),f.on(`error`,e=>{process.stderr.write(`tboxcode-dsh server: dsh spawn 失败(${e.message})\n`),f.kill()});let p=``;f.stdout?.on(`data`,e=>{for(p+=e.toString();;){let e=p.indexOf(`
4
- `);if(e<0)break;let t=p.slice(0,e);p=p.slice(e+1),m.forEach(e=>e(t))}});let m=[],h=[];return f.on(`close`,e=>{p!==``&&m.forEach(e=>e(p)),h.forEach(t=>t(e))}),{onStdoutLine:e=>m.push(e),onExit:e=>h.push(e),kill:e=>f.kill(e??`SIGTERM`)}}})}function G(e=v()){let t=[];u(e)||(d(e,{recursive:!0}),t.push(`创建配置目录 ${e}`));let n=g(e,`config.jsonc`);u(n)||(m(n,`// tboxcode-dsh 配置(规格:.agents/designs/implemented/2026-10-01-config-translation-contract.md)
2
+ import{a as e,c as t,i as n,l as r,o as i,r as a,s as o,t as s,u as c}from"./assembly-B1Fux_L8.js";import{createRequire as l}from"node:module";import{spawn as u}from"node:child_process";import{existsSync as d,mkdirSync as f,readFileSync as p,statSync as m,writeFileSync as h}from"node:fs";import{dirname as g,join as _}from"node:path";import{loadConfig as v,resolveConfigDir as y,translateConfig as b,writeOverlayPatch as x}from"@tbox.cn/tboxcode-dsh-runtime";import{createInterface as S}from"node:readline";import{fileURLToPath as C}from"node:url";function w(e,t,n){let r=[e,`--profile`,`tboxcode-web`,`--patch`,t];n.port!==void 0&&r.push(`--port`,String(n.port)),n.host!==void 0&&r.push(`--host`,n.host),n.noOpen===!0&&r.push(`--no-open`);for(let e of n.trustedHost??[])r.push(`--trusted-host`,e);return r}async function T(e){let n=t(),a=y(),o=v(a),s=await x(b(o.config,a,o.path!==null).rows),l=await i(n,`tboxcode-web`,`startup`);if(l.status!==`ok`&&l.status!==`version-drift`)throw await s.dispose(),Error(`web 启动装配未就绪(${l.status})——运行 tboxcode-dsh init 显式装配`);let d=w(c(),s.path,{...e,dshHome:n}),f=u(process.execPath,d,{stdio:`inherit`,env:{...process.env,DSH_HOME:n,DSH_TELEMETRY_DISABLED:`1`}});for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{f.kill(e)});let p=await new Promise(e=>{f.on(`close`,e),f.on(`error`,t=>{console.error(`tboxcode-dsh web: spawn 失败(${t.message})`),e(1)})});return p!==0&&console.error(r(`web`,p)),await s.dispose(),typeof p==`number`?p:1}const E=l(import.meta.url);function D(){return _(g(E.resolve(`@tbox.cn/tboxcode-dsh-runtime/package.json`)),`assets`,`stdout-guard.cjs`)}function O(e,t,n){let r=D(),i=process.env.NODE_OPTIONS??``,a=`--require ${r}`;return{NODE_OPTIONS:i.includes(r)?i:i===``?a:`${i} ${a}`,TBOXCODE_STDIO_GUARD:n,TBOXCODE_PROFILE_DIR:o(e,t)}}function k(e,t,n){let r=[e,`--profile`,`tboxcode-headless`,`--patch`,t];return n.sessionId!==void 0&&r.push(`--session-id`,n.sessionId),n.json===!0&&r.push(`--json`),r.push(...n.task),r}async function A(e){let n=t(),a=y(),o=v(a),s=await x(b(o.config,a,o.path!==null).rows),l=await i(n,`tboxcode-headless`,`startup`);if(l.status!==`ok`&&l.status!==`version-drift`)throw await s.dispose(),Error(`headless 启动装配未就绪(${l.status})——运行 tboxcode-dsh init 显式装配`);let d=k(c(),s.path,e),f=u(process.execPath,d,{stdio:`inherit`,env:{...process.env,...O(n,`tboxcode-headless`,`quiet`),DSH_HOME:n,DSH_TELEMETRY_DISABLED:`1`}}),p=await new Promise(e=>{f.on(`close`,e),f.on(`error`,t=>{console.error(`tboxcode-dsh headless: spawn 失败(${t.message})`),e(1)})});return p!==0&&console.error(r(`headless`,p)),await s.dispose(),typeof p==`number`?p:1}function j(){return JSON.stringify({v:1,event:`standby`})}function M(e,t){return JSON.stringify({v:1,event:`ready`,port:e,token:t})}function N(e,t,n){return JSON.stringify({stage:e,kind:t,error:n})}function P(e){let t;try{t=JSON.parse(e)}catch{return{kind:`malformed`}}if(typeof t!=`object`||!t||Array.isArray(t))return{kind:`malformed`};let n=t;return n.v===1?n.cmd===`start`?{kind:`start`}:{kind:`unknown`,cmd:String(n.cmd??``)}:{kind:`version-skew`,got:typeof n.v==`number`?n.v:void 0}}function F(e){if(!e.includes(`token=`))return null;let t=/https?:\/\/\S+/.exec(e);if(t===null)return null;try{let e=new URL(t[0]);return e.searchParams.get(`token`)===null?null:e}catch{return null}}function I(e){let t=e.searchParams.get(`token`),n=e.port===``?void 0:Number(e.port);return t===null||t===``||n===void 0||!Number.isInteger(n)?null:{port:n,token:t}}var L=class extends Error{};function R(e){if(e instanceof L)return`permanent`;let t=e?.name;return t===`ModelNotSetError`||t===`ModelMalformedError`||t===`SecretInTranslationError`?`permanent`:`transient`}function z(e){return e===null?1:e===0?0:e===2||e===3?e:1}async function B(e){let{io:t}=e;return await new Promise(n=>{let r=`standby`,i=!1,a=!1,o=!1,s=!1,c,l=!1,u=(e,r,i,a)=>{o||(o=!0,r!==void 0&&i!==void 0&&a!==void 0&&t.writeStderr(`${N(r,i,a)}\n`),n(e))};t.writeStdout(`${j()}\n`),e.log(`standby(零用户态自检通过,等待 start)`),t.onSignal(t=>{if(s=!0,e.log(`收到 ${t},正常终(dsh 子进程随停)`),c===void 0){u(0);return}c.kill(t);let n=setTimeout(()=>u(0),3e3);c.onExit(()=>{clearTimeout(n),u(0)})}),t.onStdinEof(()=>{if(!a){if(a=!0,i=!0,r!==`ready`){e.log(`stdin EOF 在 ready 前到达(父进程死亡)——退出`),c?.kill(),u(1);return}e.log(`stdin EOF 在 ready 后到达——孤儿语义,继续运行`)}}),t.onStdinLine(e=>{if(e.trim()===``)return;if(r===`ready`){t.writeStderr(`${N(`protocol`,`protocol`,`start 命令在 ready 后到达(stdin 已转惰性),忽略`)}\n`);return}let n=P(e);switch(n.kind){case`version-skew`:u(3,`protocol`,`protocol`,`信封版本偏斜:期待 v1,实得 ${n.got??`缺省`}——fail-loud(部署错误最显眼信号)`);return;case`start`:if(r!==`standby`)return;r=`starting`,d();return;case`unknown`:t.writeStderr(`${N(`protocol`,`protocol`,`未知 cmd "${n.cmd}" 忽略(additive-only 版本窗口)`)}\n`);return;case`malformed`:t.writeStderr(`${N(`protocol`,`protocol`,`stdin 行非 JSON 对象,忽略`)}\n`);return}});let d=async()=>{try{let n=await e.boot();if(c=n,o){n.kill();return}n.onStdoutLine(n=>{if(l)return;let i=F(n);if(i===null)return;let a=I(i);a!==null&&(l=!0,r=`ready`,t.writeStdout(`${M(a.port,a.token)}\n`),e.log(`ready(token 已交付,stdout 永久静默;token 已弃)`))}),n.onExit(t=>{let n=s?0:z(t);r===`ready`?(e.log(`dsh 退出(码 ${t??`signal`})——server 失活,退出 ${n}`),u(n)):u(n,`boot`,n===2?`permanent`:`transient`,`dsh 在 ready 前退出(码 ${t??`signal`},stdout 零 token 行)`)}),i&&r!==`ready`&&(e.log(`stdin EOF 已在 boot 窗口到达——退出`),n.kill(),u(1))}catch(e){let t=R(e),n=e instanceof Error?e.message:String(e);u(t===`permanent`?2:1,`boot`,t,n.split(`
3
+ `)[0]??n)}}})}function V(e,t,n){let r=[t,`--profile`,e===`acp`?`tboxcode-acp`:`tboxcode-server`,`--patch`,n];return e===`server`&&r.push(`--port`,`0`,`--no-open`),r}async function H(e){let n=t(),a=y(),o=v(a),s=await x(b(o.config,a,o.path!==null).rows),l=`tboxcode-acp`,d=await i(n,l,`startup`);if(d.status!==`ok`&&d.status!==`version-drift`)throw await s.dispose(),Error(`${e} 启动装配未就绪(${d.status})——运行 tboxcode-dsh init 显式装配`);let f=V(e,c(),s.path),p=u(process.execPath,f,{stdio:`inherit`,env:{...process.env,...O(n,l,`strict`),DSH_HOME:n,DSH_TELEMETRY_DISABLED:`1`}});for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{p.kill(e)});let m=await new Promise(t=>{p.on(`close`,t),p.on(`error`,n=>{console.error(`tboxcode-dsh ${e}: spawn 失败(${n.message})`),t(1)})});return m!==0&&console.error(r(e,m)),await s.dispose(),typeof m==`number`?m:1}async function U(){return H(`acp`)}function W(){let e=process.stdin,t=S({input:e,crlfDelay:1/0});return{writeStdout:e=>process.stdout.write(e),writeStderr:e=>process.stderr.write(e),onStdinLine:e=>t.on(`line`,e),onStdinEof:t=>{e.on(`end`,t),e.on(`close`,t)},onSignal:e=>{for(let t of[`SIGINT`,`SIGTERM`])process.on(t,()=>e(t))}}}async function G(e={flags:new Map,positional:[]}){if(e.flags.size>0||e.positional.length>0){let t=[...e.positional,...[...e.flags.keys()].map(e=>`--${e}`)].join(` `);return console.error(`tboxcode-dsh server: 裸命令零 flag(机器路径,Supervisor spawn 契约)——实得 "${t}",拒绝启动`),2}return await B({io:W(),log:e=>console.error(`tboxcode-dsh server: ${e}`),boot:async()=>{let e=t(),n=y(),r=v(n),a=await x(b(r.config,n,r.path!==null).rows),o=await i(e,`tboxcode-server`,`startup`);if(o.status!==`ok`&&o.status!==`version-drift`)throw await a.dispose(),new L(`profile 装配未就绪(${o.status})——运行 tboxcode-dsh init 显式装配`);let s=V(`server`,c(),a.path),l=(process.env.TBOXCODE_EXTRA_PATCHES??``).split(`:`).map(e=>e.trim()).filter(e=>e.length>0),d=[...s.slice(0,3),...l.flatMap(e=>[`--patch`,e]),...s.slice(3)],f=u(process.execPath,d,{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,DSH_HOME:e,DSH_TELEMETRY_DISABLED:`1`}});f.stderr?.on(`data`,e=>{process.stderr.write(e)}),f.on(`error`,e=>{process.stderr.write(`tboxcode-dsh server: dsh spawn 失败(${e.message})\n`),f.kill()});let p=``;f.stdout?.on(`data`,e=>{for(p+=e.toString();;){let e=p.indexOf(`
4
+ `);if(e<0)break;let t=p.slice(0,e);p=p.slice(e+1),m.forEach(e=>e(t))}});let m=[],h=[];return f.on(`close`,e=>{p!==``&&m.forEach(e=>e(p)),h.forEach(t=>t(e))}),{onStdoutLine:e=>m.push(e),onExit:e=>h.push(e),kill:e=>f.kill(e??`SIGTERM`)}}})}function K(e=y()){let t=[];d(e)||(f(e,{recursive:!0}),t.push(`创建配置目录 ${e}`));let n=_(e,`config.jsonc`);d(n)||(h(n,`// tboxcode-dsh 配置(规格:.agents/designs/implemented/2026-10-01-config-translation-contract.md)
5
5
  // 全部字段支持行注释与块注释;热载经 config watcher(LLM 域请求级生效)
6
6
  {
7
7
  // 默认模型,"<provider>/<model>"——未设置时 cli spawn 前置明错(不静默回落)
@@ -19,8 +19,8 @@ import{a as e,c as t,i as n,l as r,o as i,r as a,s as o,t as s}from"./assembly-C
19
19
  // 凭据优先序:本目录 auth.jsonc > provider.options.apiKey;\${VAR} 环境引用值内内插,零 env 注入
20
20
  }
21
21
 
22
- `,`utf-8`),t.push(`写入 config.jsonc 模板(已存在则不覆盖)`));let r=g(e,`auth.jsonc`);return u(r)||(m(r,`{}
23
- `,{encoding:`utf-8`,mode:384}),t.push(`写入 auth.jsonc(0600 空)`)),t}async function K(t){let n=o(),r=t.profile===void 0?s:[t.profile],i=!1;for(let t of r)try{let r=await e(n,t,`explicit`),i=r.actions.length>0?`(${r.actions.map(e=>e.detail).join(`;`)})`:`(已装配且无漂移,零动作)`;console.log(`tboxcode-dsh init ${t}: ${r.status} ${i}`),r.status===`version-drift`&&console.warn(`tboxcode-dsh init ${t}: 版本偏差放行(显式模式应已重装;残留偏差请核对安装源)`)}catch(e){i=!0,console.error(`tboxcode-dsh init ${t} 失败:${e instanceof Error?e.message:String(e)}`)}if(t.config===!0)for(let e of G())console.log(`tboxcode-dsh init --config: ${e}`);return i?1:0}function q(){return JSON.parse(f(new URL(`../../package.json`,import.meta.url),`utf-8`)).version??`unknown`}const J=[{id:`profiles`,run:()=>{let e=o(),t=[],n=0;for(let r of s){let i=a(e,r),o=i.corruptPackages.length>0?`,残缺 ${i.corruptPackages.length} 包(${i.corruptPackages.slice(0,3).join(`, `)}${i.corruptPackages.length>3?` …`:``})`:``,s=i.missingPackages.length>0?`,缺 ${i.missingPackages.length} 包`:``;t.push(`${r}: ${i.status}${o}${s}`),i.status===`missing`||i.status===`incomplete`||i.status===`drift`?n+=1:i.status===`version-drift`&&t.push(` ${r}: 版本偏差 ${i.versionMismatches.map(e=>`${e.pkg} ${e.actual}→${e.expected}`).join(`, `)}(启动放行)`)}let r=`${t.join(`;`)}${n>0?`——运行 tboxcode-dsh init 修复`:``}`;return{ok:n===0,detail:r}}},{id:`config`,run:()=>{let e=v();try{let t=_(e);if(t.path===null)return{ok:!0,detail:`config 缺席(${e},零配置合法态——spawn 前置会因未设 model 明错)`};let n=t.config.model;return typeof n!=`string`||n.length===0?{ok:!1,detail:`${t.path} 缺 model 字段——spawn 前置将明错(未设 model 不静默回落)`}:{ok:!0,detail:`${t.path} model = ${n}`}}catch(e){return{ok:!1,detail:`config 解析失败:${e instanceof Error?e.message:String(e)}`}}}},{id:`auth`,run:()=>{let e=g(v(),`auth.jsonc`);if(!u(e))return{ok:!0,detail:"auth.jsonc 缺席(合法——凭据可走 provider.options 或 ${VAR} 引用)"};let t=p(e).mode&511;return t===384?{ok:!0,detail:`auth.jsonc 权限 600`}:{ok:!0,detail:`auth.jsonc 权限 ${t.toString(8)} → 建议 chmod 600(密钥铁律;llm 插件运行时会弱权限警告)`}}},{id:`versions`,run:()=>{let e=q(),t=n();return e===`0.0.0`?{ok:!0,detail:`cli ${e}(开发占位——未发布;dsh 锁版本 ${t})`}:{ok:!0,detail:`cli ${e};dsh 锁版本 ${t}`}}}];function Y(){console.log(`tboxcode-dsh doctor(诊断不修复——修复走 tboxcode-dsh init)`);let e=0;for(let t of J){let n;try{n=t.run()}catch(e){n={ok:!1,detail:e instanceof Error?e.message:String(e)}}n.ok||(e+=1);let r=n.ok?`✓`:`✗`;console.log(` ${r} [${t.id}] ${n.detail}`)}return console.log(e>0?`结果: ${e} 项红(退出码 1)`:`结果: 全绿(退出码 0)`),e>0?1:0}function X(e){let t=new Map,n=[],r=0;for(;r<e.length;){let i=e[r]??``;if(i.startsWith(`--`)){let n=i.slice(2),a=e[r+1];if(a!==void 0&&!a.startsWith(`--`)){let e=t.get(n);e===void 0?t.set(n,a):typeof e==`string`?t.set(n,[e,a]):Array.isArray(e)&&t.set(n,[...e,a]),r+=2;continue}t.set(n,!0),r+=1;continue}n.push(i),r+=1}return{flags:t,positional:n}}function Z(e){let t={},n=e.flags.get(`port`);typeof n==`string`&&(t.port=Number(n));let r=e.flags.get(`host`);typeof r==`string`&&(t.host=r),e.flags.get(`no-open`)===!0&&(t.noOpen=!0);let i=e.flags.get(`trusted-host`);return i!==void 0&&(t.trustedHost=(Array.isArray(i)?i:[i]).filter(e=>typeof e==`string`)),t}function Q(e){let t={};e.flags.get(`config`)===!0&&(t.config=!0);let n=e.flags.get(`profile`);if(typeof n==`string`&&s.includes(n))t.profile=n;else if(typeof n==`string`)throw Error(`init --profile 仅接受四 profile 名(${s.join(` / `)}),实得 ${n}`);return t}function $(e){let t={task:e.positional},n=e.flags.get(`session-id`);return typeof n==`string`&&(t.sessionId=n),e.flags.get(`json`)===!0&&(t.json=!0),t}async function ee(){let e=process.argv.slice(2);if(e.includes(`--version`)||e.includes(`-v`)){let e=JSON.parse(f(S(new URL(`../package.json`,import.meta.url)),`utf-8`));return console.log(`tboxcode-dsh ${e.version??`unknown`}`),0}let t=e[0],n=X(e.slice(1));switch(t){case`web`:return w(Z(n));case`headless`:return k($(n));case`acp`:return H();case`server`:return W({flags:n.flags,positional:n.positional});case`init`:return K(Q(n));case`doctor`:return Y();default:return console.error(`tboxcode-dsh <command> [flags]
22
+ `,`utf-8`),t.push(`写入 config.jsonc 模板(已存在则不覆盖)`));let r=_(e,`auth.jsonc`);return d(r)||(h(r,`{}
23
+ `,{encoding:`utf-8`,mode:384}),t.push(`写入 auth.jsonc(0600 空)`)),t}async function q(e){let n=t(),r=e.profile===void 0?s:[e.profile],a=!1;for(let e of r)try{let t=await i(n,e,`explicit`),r=t.actions.length>0?`(${t.actions.map(e=>e.detail).join(`;`)})`:`(已装配且无漂移,零动作)`;console.log(`tboxcode-dsh init ${e}: ${t.status} ${r}`),t.status===`version-drift`&&console.warn(`tboxcode-dsh init ${e}: 版本偏差放行(显式模式应已重装;残留偏差请核对安装源)`)}catch(t){a=!0,console.error(`tboxcode-dsh init ${e} 失败:${t instanceof Error?t.message:String(t)}`)}if(e.config===!0)for(let e of K())console.log(`tboxcode-dsh init --config: ${e}`);return a?1:0}const J=[{id:`profiles`,run:()=>{let e=t(),n=[],r=0;for(let t of s){let i=a(e,t),o=i.corruptPackages.length>0?`,残缺 ${i.corruptPackages.length} 包(${i.corruptPackages.slice(0,3).join(`, `)}${i.corruptPackages.length>3?` …`:``})`:``,s=i.missingPackages.length>0?`,缺 ${i.missingPackages.length} 包`:``;n.push(`${t}: ${i.status}${o}${s}`),i.status===`missing`||i.status===`incomplete`||i.status===`drift`?r+=1:i.status===`version-drift`&&n.push(` ${t}: 版本偏差 ${i.versionMismatches.map(e=>`${e.pkg} ${e.actual}→${e.expected}`).join(`, `)}(启动放行)`)}let i=`${n.join(`;`)}${r>0?`——运行 tboxcode-dsh init 修复`:``}`;return{ok:r===0,detail:i}}},{id:`config`,run:()=>{let e=y();try{let t=v(e);if(t.path===null)return{ok:!0,detail:`config 缺席(${e},零配置合法态——spawn 前置会因未设 model 明错)`};let n=t.config.model;return typeof n!=`string`||n.length===0?{ok:!1,detail:`${t.path} 缺 model 字段——spawn 前置将明错(未设 model 不静默回落)`}:{ok:!0,detail:`${t.path} model = ${n}`}}catch(e){return{ok:!1,detail:`config 解析失败:${e instanceof Error?e.message:String(e)}`}}}},{id:`auth`,run:()=>{let e=_(y(),`auth.jsonc`);if(!d(e))return{ok:!0,detail:"auth.jsonc 缺席(合法——凭据可走 provider.options 或 ${VAR} 引用)"};let t=m(e).mode&511;return t===384?{ok:!0,detail:`auth.jsonc 权限 600`}:{ok:!0,detail:`auth.jsonc 权限 ${t.toString(8)} → 建议 chmod 600(密钥铁律;llm 插件运行时会弱权限警告)`}}},{id:`versions`,run:()=>{let t=n(),r=e();return t===`0.0.0`?{ok:!0,detail:`cli ${t}(开发占位——未发布;dsh 锁版本 ${r})`}:{ok:!0,detail:`cli ${t};dsh 锁版本 ${r}`}}}];function Y(){console.log(`tboxcode-dsh doctor(诊断不修复——修复走 tboxcode-dsh init)`);let e=0;for(let t of J){let n;try{n=t.run()}catch(e){n={ok:!1,detail:e instanceof Error?e.message:String(e)}}n.ok||(e+=1);let r=n.ok?`✓`:`✗`;console.log(` ${r} [${t.id}] ${n.detail}`)}return console.log(e>0?`结果: ${e} 项红(退出码 1)`:`结果: 全绿(退出码 0)`),e>0?1:0}function X(e){let t=new Map,n=[],r=0;for(;r<e.length;){let i=e[r]??``;if(i.startsWith(`--`)){let n=i.slice(2),a=e[r+1];if(a!==void 0&&!a.startsWith(`--`)){let e=t.get(n);e===void 0?t.set(n,a):typeof e==`string`?t.set(n,[e,a]):Array.isArray(e)&&t.set(n,[...e,a]),r+=2;continue}t.set(n,!0),r+=1;continue}n.push(i),r+=1}return{flags:t,positional:n}}function Z(e){let t={},n=e.flags.get(`port`);typeof n==`string`&&(t.port=Number(n));let r=e.flags.get(`host`);typeof r==`string`&&(t.host=r),e.flags.get(`no-open`)===!0&&(t.noOpen=!0);let i=e.flags.get(`trusted-host`);return i!==void 0&&(t.trustedHost=(Array.isArray(i)?i:[i]).filter(e=>typeof e==`string`)),t}function Q(e){let t={};e.flags.get(`config`)===!0&&(t.config=!0);let n=e.flags.get(`profile`);if(typeof n==`string`&&s.includes(n))t.profile=n;else if(typeof n==`string`)throw Error(`init --profile 仅接受四 profile 名(${s.join(` / `)}),实得 ${n}`);return t}function $(e){let t={task:e.positional},n=e.flags.get(`session-id`);return typeof n==`string`&&(t.sessionId=n),e.flags.get(`json`)===!0&&(t.json=!0),t}async function ee(){let e=process.argv.slice(2);if(e.includes(`--version`)||e.includes(`-v`)){let e=JSON.parse(p(C(new URL(`../package.json`,import.meta.url)),`utf-8`));return console.log(`tboxcode-dsh ${e.version??`unknown`}`),0}let t=e[0],n=X(e.slice(1));switch(t){case`web`:return T(Z(n));case`headless`:return A($(n));case`acp`:return U();case`server`:return G({flags:n.flags,positional:n.positional});case`init`:return q(Q(n));case`doctor`:return Y();default:return console.error(`tboxcode-dsh <command> [flags]
24
24
 
25
25
  命令:
26
26
  web 浏览器直连 dsh 原生 web UI(零 ACP,人工姿态)
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,l as t,n,o as r,r as i,s as a,t as o,u as s}from"./assembly-COH6w2mC.js";const c=`@tbox.cn/tboxcode-dsh-cli`;export{o as OWN_PROFILES,c as PACKAGE_NAME,n as PROFILE_CHAINS,i as checkAssembly,e as ensureAssembly,r as profileDir,t as resolveDshEntry,a as resolveDshHome,s as runDsh};
1
+ import{c as e,d as t,n,o as r,r as i,s as a,t as o,u as s}from"./assembly-B1Fux_L8.js";const c=`@tbox.cn/tboxcode-dsh-cli`;export{o as OWN_PROFILES,c as PACKAGE_NAME,n as PROFILE_CHAINS,i as checkAssembly,r as ensureAssembly,a as profileDir,s as resolveDshEntry,e as resolveDshHome,t as runDsh};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/tboxcode-dsh-cli",
3
- "version": "0.1.0-rc.1",
3
+ "version": "0.1.0-rc.3",
4
4
  "type": "module",
5
5
  "description": "bin tboxcode-dsh:acp / server / web / headless / init / doctor——薄封装,spawn dsh --profile <name> --patch <generated>;装配模块住本包",
6
6
  "main": "lib/index.js",
@@ -21,7 +21,7 @@
21
21
  "@deepseek-ai/dsh": "0.2.1-rc.2",
22
22
  "@deepseek-ai/dsh-atomic-write": "0.2.1-rc.2",
23
23
  "yaml": "^2.8.0",
24
- "@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.1"
24
+ "@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.3"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@deepseek-ai/dsh-llm-mock-server": "0.2.1-rc.2"