@tbox.cn/tboxcode-dsh-cli 0.1.0-rc.2 → 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(`
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
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,5 +1,5 @@
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,u as c}from"./assembly-B38Z-Al8.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(`
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
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
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 域请求级生效)
package/lib/index.js CHANGED
@@ -1 +1 @@
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-B38Z-Al8.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};
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.2",
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.2"
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"