@tbox.cn/tboxcode-dsh-cli 0.1.0-rc.1 → 0.1.0-rc.11
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.
- package/README.md +10 -1
- package/lib/assembly-ZFOXMi7d.js +2 -0
- package/lib/bin.js +13 -7
- package/lib/index.d.ts +22 -10
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/lib/assembly-COH6w2mC.js +0 -2
package/README.md
CHANGED
|
@@ -10,6 +10,15 @@ npm i -g @tbox.cn/tboxcode-dsh-cli
|
|
|
10
10
|
|
|
11
11
|
要求 Node >= 22.19。安装后 `tboxcode-dsh --version` 验证;首次使用建议 `tboxcode-dsh doctor` 诊断环境。
|
|
12
12
|
|
|
13
|
+
## 本地开发
|
|
14
|
+
|
|
15
|
+
仓库内免安装调试与发版前彩排(三层矩阵 + 食谱详见 [docs/development.md](../../../docs/development.md)):
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm dev <cmd> # L0 日常调试(link: 装配 → 专属 dev home,零全局零发版)
|
|
19
|
+
pnpm release rehearse # L2 发版前彩排(verdaccio registry 全保真 → 写 stamp)
|
|
20
|
+
```
|
|
21
|
+
|
|
13
22
|
## 命令矩阵
|
|
14
23
|
|
|
15
24
|
| 命令 | 形态 | 说明 |
|
|
@@ -36,7 +45,7 @@ tboxcode-dsh init --config # 生成注释化 config.jsonc 模板 + 0600 空 au
|
|
|
36
45
|
|
|
37
46
|
## profile 与 home
|
|
38
47
|
|
|
39
|
-
四 profile(`tboxcode-web` / `tboxcode-acp` / `tboxcode-server` / `tboxcode-headless`)装配于 dsh home(缺省 `~/.dsh`,`TBOXCODE_DSH_HOME` 覆盖)。装配幂等:启动时自动检查(缺包安装 / 残缺自愈 /
|
|
48
|
+
四 profile(`tboxcode-web` / `tboxcode-acp` / `tboxcode-server` / `tboxcode-headless`)装配于 dsh home(缺省 `~/.dsh`,`TBOXCODE_DSH_HOME` 覆盖)。装配幂等:启动时自动检查(缺包安装 / 残缺自愈 / 行漂移校正 / 版本偏差提示),`init` 显式模式按当前 CLI 版本重装自有包与官方包。用户领地(自装插件 / patch 行)神圣不动。手动 pin 的版本会被 `init` 对齐回当前 CLI 版本(家族单版本纪律)。
|
|
40
49
|
|
|
41
50
|
## 相关包
|
|
42
51
|
|
|
@@ -0,0 +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=`@tbox.cn/tboxcode-dsh-cli`,g={cli:`tboxcode-dsh`,acp:`tboxcode-dsh-acp`,server:`tboxcode-dsh-server`,web:`tboxcode-dsh-web`,headless:`tboxcode-dsh-headless`};function _(e,t){return[`--title=${e}`,...t]}const v=e(import.meta.url);function y(){let e=v.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 b(e,t){return`tboxcode-dsh ${e}: dsh 非零退出(${t??`signal`})——若上方出现 ERR_MODULE_NOT_FOUND 或插件未激活,多为 profile 半装残缺,运行 tboxcode-dsh init 修复`}function x(e,t=16384){return Buffer.byteLength(e,`utf-8`)<=t?e:`…(前段截断,仅保留尾部 ${t} 字节)\n${e.slice(-t)}`}function S(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 C(e){let n=y(),r={...process.env,DSH_HOME:e.dshHome,DSH_TELEMETRY_DISABLED:`1`};return new Promise((i,a)=>{let o=t(process.execPath,_(g.cli,[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&&S(o.pid),a(Error(`dsh 进程超时(>${e.timeoutMs}ms),进程组已终止\nSTDOUT:\n${x(s)}\nSTDERR:\n${x(c)}`))},e.timeoutMs))})}const w=[`tboxcode-acp`,`tboxcode-server`,`tboxcode-web`,`tboxcode-headless`],T={"tboxcode-acp":[`@deepseek-ai/dsh-cmdline`,`@deepseek-ai/dsh-tool-ask-user`,`@tbox.cn/dsh-acp-full-app`,`@tbox.cn/dsh-acp-full`,`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`],"tboxcode-server":[`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`],"tboxcode-web":[`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`],"tboxcode-headless":[`@tbox.cn/tboxcode-dsh-llm`,`@tbox.cn/tboxcode-dsh-tools`,`@tbox.cn/tboxcode-dsh-bundle`]},E={"tboxcode-acp":[`@deepseek-ai/dsh-base`],"tboxcode-server":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`],"tboxcode-web":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`],"tboxcode-headless":[`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-headless`]},D=new Set([`@tbox.cn/dsh-acp-full`]);function O(e){return[...E[e],...T[e].filter(e=>M(e)&&!D.has(e))]}const k=new Set([`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@deepseek-ai/dsh-headless`]);function A(){return process.env.TBOXCODE_DSH_HOME??process.env.DSH_HOME??l(u(),`.dsh`)}function j(e,t){return l(e,`profiles`,t)}function M(e){return e.startsWith(`@tbox.cn/`)}function N(e){let t=l(e,`package.json`);return n(t)?JSON.parse(i(t,`utf-8`)):null}function P(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 F(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&&(P(l(e,n.name),c)||r.push(a))}};return o(t,``),r.sort()}function I(e,t){let r=j(e,t),i=T[t],a=E[t],o=O(t),s=e=>M(e)||a.includes(e),c=n(r)?N(r):null;if(c===null)return{status:`missing`,profileDir:r,missingPackages:[...i],corruptPackages:[],forbiddenPackages:[],expectedStructureOrder:o,actualStructureOrder:[],versionMismatches:[]};let l=F(r),u=c.dsh?.profile?.bundles??[],d=Object.keys(c.dependencies??{}).filter(e=>k.has(e)),f=i.filter(e=>U(r,e)===null),p=u.filter(s),m=[],h=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT===void 0?`registry`:`local`,g=h===`registry`?R():``;for(let e of i.filter(M)){let t=H(h,h===`local`?V(e):null,g),n=U(r,e);t!==null&&n!==null&&t!==n&&m.push({pkg:e,expected:t,actual:n})}for(let e of i.filter(e=>!M(e))){let t=L(),n=U(r,e);t!==``&&n!==null&&t!==n&&m.push({pkg:e,expected:t,actual:n})}let _=`ok`;return f.length>0||l.length>0||d.length>0?_=`incomplete`:m.length>0?_=`version-drift`:(p.length!==o.length||p.some((e,t)=>e!==o[t]))&&(_=`drift`),{status:_,profileDir:r,missingPackages:f,corruptPackages:l,forbiddenPackages:d,expectedStructureOrder:o,actualStructureOrder:p,versionMismatches:m}}function L(){let t=e(import.meta.url).resolve(`@deepseek-ai/dsh/package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function R(){let t=e(import.meta.url).resolve(`../package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function z(e){if(!M(e))return`${e}@${L()}`;let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0){let t=R();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=B(t,e);if(n===null)throw Error(`装配安装源未找到包 ${e}(TBOXCODE_ASSEMBLY_LOCAL_ROOT=${t})`);return`link:${n}`}function B(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 V(e){let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0)return null;let n=B(t,e);return n===null?null:JSON.parse(i(l(n,`package.json`),`utf-8`)).version??null}function H(e,t,n){return e===`local`?t===``?null:t:n===``||n===`0.0.0`?null:n}function U(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 W={"node-pty":!0,koffi:!0,"@deepseek-ai/dsh-subprocess-local":!0,"@google/genai":!1,protobufjs:!1};async function G(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:W}),{mode:420});return}let e=d(i(t,`utf-8`))??{},r=e.allowBuilds??{},a={...W,...r};JSON.stringify(r)!==JSON.stringify(a)&&(e.allowBuilds=a,await m(t,f(e),{mode:420}))})}const K=5e3;function q(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:12e4}function J(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_ATTEMPTS);return Number.isInteger(e)&&e>0?e:2}async function Y(e,t,n,r){let i=await C({dshHome:e,args:[`plugin`,`--profile`,t,`add`,n],capture:!0,timeoutMs:q()});if(i.code!==0)throw Error(`装配${r}失败(${n}):dsh plugin add 退出码 ${i.code}\nSTDOUT:\n${x(i.stdout)}\nSTDERR:\n${x(i.stderr)}`)}async function X(e,t,n){let r=await C({dshHome:e,args:[`plugin`,`--profile`,t,`remove`,...n],capture:!0,timeoutMs:q()});if(r.code!==0)throw Error(`官方元包去污染失败(dsh plugin remove ${n.join(` `)}):退出码 ${r.code}\nSTDOUT:\n${x(r.stdout)}\nSTDERR:\n${x(r.stderr)}`)}async function Z(e,t){let r=j(e,t),i=l(r,`node_modules`),a=l(e,`profiles`,t,`node_modules`);if(!w.includes(t)||i!==a)throw Error(`装配自愈守卫拒绝:目标 ${i} 非 own profile node_modules(期望 ${a})`);return n(i)?await p(l(r,`.tboxcode-assembly-heal.lock`),async()=>F(r).length===0?!1:(o(i,{recursive:!0,force:!0}),!0)):!1}async function Q(e,t,n){let r=n===`explicit`?J():1,i=[],a;for(let o=1;o<=r;o++)try{return await $(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}),${K/1e3}s 后重试`}),await new Promise(e=>setTimeout(e,K))}}throw a}async function $(e,t,n,i){let a=I(e,t);if(a.forbiddenPackages.length>0&&(await X(e,t,a.forbiddenPackages),i.push({kind:`decontaminate`,detail:`官方元包去污染:dsh plugin remove ${a.forbiddenPackages.join(` `)}(元包实体破坏 dsh 单实例——settings 持久化写与热重载全灭;官方基座行转 installation 解析)`}),a=I(e,t)),a.corruptPackages.length>0&&(await Z(e,t)&&i.push({kind:`heal`,detail:`半装态自愈:node_modules 残缺 ${a.corruptPackages.length} 包(${a.corruptPackages.slice(0,3).join(`, `)}${a.corruptPackages.length>3?` …`:``})→ nuke 后全链重装`}),a=I(e,t)),a.missingPackages.length>0){r(a.profileDir,{recursive:!0}),await G(a.profileDir);for(let n of a.missingPackages){let r=z(n);await Y(e,t,r,`安装`),i.push({kind:`install`,detail:`${n} ← ${r}`})}a=I(e,t)}if(a.status===`version-drift`&&n===`explicit`){for(let n of a.versionMismatches)await Y(e,t,z(n.pkg),`重装`),i.push({kind:`reinstall`,detail:`${n.pkg} ${n.actual} → ${n.expected}`});a=I(e,t)}return a.status!==`missing`&&(a.actualStructureOrder.length!==a.expectedStructureOrder.length||a.actualStructureOrder.some((e,t)=>e!==a.expectedStructureOrder[t]))&&(await te(e,t),i.push({kind:`correct-manifest`,detail:`结构行集校正 [${a.actualStructureOrder.join(`,`)}] → [${a.expectedStructureOrder.join(`,`)}](结构行是组合契约,用户领地不动)`}),a=I(e,t)),{status:a.status,actions:i,check:a}}function ee(e,t){return e.status===`version-drift`?`${t} 版本偏差(${e.check.versionMismatches.map(e=>`${e.pkg} ${e.actual}→${e.expected}`).join(`, `)})——运行 tboxcode-dsh init --profile ${t} 升级`:null}async function te(e,t){let n=l(j(e,t),`package.json`);await p(n,async()=>{let e=JSON.parse(i(n,`utf-8`)),r=e.dsh?.profile?.bundles??[],a=E[t],o=e=>M(e)||a.includes(e),s=r.filter(e=>!o(e)),c=T[t].filter(e=>M(e)&&!D.has(e)),l=[...a,...s,...c];e.dsh={...e.dsh,profile:{...e.dsh?.profile,bundles:l}},await m(n,`${JSON.stringify(e,null,2)}\n`,{mode:420})})}export{R as a,j as c,b as d,y as f,_ as g,g as h,I as i,A as l,h as m,T as n,L as o,C as p,E as r,Q as s,w as t,ee 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,
|
|
3
|
-
`)[0]??n)}}})}function
|
|
4
|
-
`);if(e<0)break;let t=
|
|
2
|
+
import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,l as s,o as c,s as l,t as u,u as d}from"./assembly-ZFOXMi7d.js";import{createRequire as f}from"node:module";import{spawn as p}from"node:child_process";import{existsSync as m,mkdirSync as h,readFileSync as g,statSync as _,writeFileSync as v}from"node:fs";import{dirname as y,join as b}from"node:path";import{loadConfig as x,resolveConfigDir as S,translateConfig as C,writeOverlayPatch as w}from"@tbox.cn/tboxcode-dsh-runtime";import{createInterface as T}from"node:readline";import{fileURLToPath as E}from"node:url";function D(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 O(e){let t=s(),o=S(),c=x(o),u=await w(C(c.config,o,c.path!==null).rows),f=await l(t,`tboxcode-web`,`startup`);if(f.status!==`ok`&&f.status!==`version-drift`)throw await u.dispose(),Error(`web 启动装配未就绪(${f.status})——运行 tboxcode-dsh init 显式装配`);let m=d(f,`tboxcode-web`);m!==null&&console.error(`tboxcode-dsh web: ${m}`);let h=D(r(),u.path,{...e,dshHome:t}),g=p(process.execPath,i(a.web,h),{stdio:`inherit`,env:{...process.env,DSH_HOME:t,DSH_TELEMETRY_DISABLED:`1`}});for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{g.kill(e)});let _=await new Promise(e=>{g.on(`close`,e),g.on(`error`,t=>{console.error(`tboxcode-dsh web: spawn 失败(${t.message})`),e(1)})});return _!==0&&console.error(n(`web`,_)),await u.dispose(),typeof _==`number`?_:1}const k=f(import.meta.url);function A(){return b(y(k.resolve(`@tbox.cn/tboxcode-dsh-runtime/package.json`)),`assets`,`stdout-guard.cjs`)}function j(e,n,r){let i=A(),a=process.env.NODE_OPTIONS??``,o=`--require ${i}`;return{NODE_OPTIONS:a.includes(i)?a:a===``?o:`${a} ${o}`,TBOXCODE_STDIO_GUARD:r,TBOXCODE_PROFILE_DIR:t(e,n)}}function M(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 N(e){let t=s(),o=S(),c=x(o),u=await w(C(c.config,o,c.path!==null).rows),f=await l(t,`tboxcode-headless`,`startup`);if(f.status!==`ok`&&f.status!==`version-drift`)throw await u.dispose(),Error(`headless 启动装配未就绪(${f.status})——运行 tboxcode-dsh init 显式装配`);let m=d(f,`tboxcode-headless`);m!==null&&console.error(`tboxcode-dsh headless: ${m}`);let h=M(r(),u.path,e),g=p(process.execPath,i(a.headless,h),{stdio:`inherit`,env:{...process.env,...j(t,`tboxcode-headless`,`quiet`),DSH_HOME:t,DSH_TELEMETRY_DISABLED:`1`}}),_=await new Promise(e=>{g.on(`close`,e),g.on(`error`,t=>{console.error(`tboxcode-dsh headless: spawn 失败(${t.message})`),e(1)})});return _!==0&&console.error(n(`headless`,_)),await u.dispose(),typeof _==`number`?_:1}function P(){return JSON.stringify({v:1,event:`standby`})}function F(e,t){return JSON.stringify({v:1,event:`ready`,port:e,token:t})}function I(e,t,n){return JSON.stringify({stage:e,kind:t,error:n})}function L(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 R(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 z(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 B=class extends Error{};function V(e){if(e instanceof B)return`permanent`;let t=e?.name;return t===`ModelNotSetError`||t===`ModelMalformedError`||t===`SecretInTranslationError`?`permanent`:`transient`}function H(e){return e===null?1:e===0?0:e===2||e===3?e:1}async function U(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(`${I(r,i,a)}\n`),n(e))};t.writeStdout(`${P()}\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(`${I(`protocol`,`protocol`,`start 命令在 ready 后到达(stdin 已转惰性),忽略`)}\n`);return}let n=L(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(`${I(`protocol`,`protocol`,`未知 cmd "${n.cmd}" 忽略(additive-only 版本窗口)`)}\n`);return;case`malformed`:t.writeStderr(`${I(`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=R(n);if(i===null)return;let a=z(i);a!==null&&(l=!0,r=`ready`,t.writeStdout(`${F(a.port,a.token)}\n`),e.log(`ready(token 已交付,stdout 永久静默;token 已弃)`))}),n.onExit(t=>{let n=s?0:H(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=V(e),n=e instanceof Error?e.message:String(e);u(t===`permanent`?2:1,`boot`,t,n.split(`
|
|
3
|
+
`)[0]??n)}}})}function W(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 G(e){let t=s(),o=S(),c=x(o),u=await w(C(c.config,o,c.path!==null).rows),f=`tboxcode-acp`,m=await l(t,f,`startup`);if(m.status!==`ok`&&m.status!==`version-drift`)throw await u.dispose(),Error(`${e} 启动装配未就绪(${m.status})——运行 tboxcode-dsh init 显式装配`);let h=d(m,f);h!==null&&console.error(`tboxcode-dsh ${e}: ${h}`);let g=W(e,r(),u.path),_=p(process.execPath,i(a[e],g),{stdio:`inherit`,env:{...process.env,...j(t,f,`strict`),DSH_HOME:t,DSH_TELEMETRY_DISABLED:`1`}}),v;for(let e of[`SIGINT`,`SIGTERM`])process.on(e,()=>{_.kill(e),v===void 0&&(v=setTimeout(()=>{try{_.kill(`SIGKILL`)}catch{}},8e3),v.unref?.())});process.on(`exit`,()=>{try{_.kill(`SIGKILL`)}catch{}});let y=await new Promise(t=>{_.on(`close`,e=>{v!==void 0&&clearTimeout(v),t(e??1)}),_.on(`error`,n=>{console.error(`tboxcode-dsh ${e}: spawn 失败(${n.message})`),t(1)})});return y!==0&&console.error(n(e,y)),await u.dispose(),typeof y==`number`?y:1}async function K(){return G(`acp`)}function q(){let e=process.stdin,t=T({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 J(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 U({io:q(),log:e=>console.error(`tboxcode-dsh server: ${e}`),boot:async()=>{let e=s(),t=S(),n=x(t),o=await w(C(n.config,t,n.path!==null).rows),c=await l(e,`tboxcode-server`,`startup`);if(c.status!==`ok`&&c.status!==`version-drift`)throw await o.dispose(),new B(`profile 装配未就绪(${c.status})——运行 tboxcode-dsh init 显式装配`);let u=d(c,`tboxcode-server`);u!==null&&console.error(`tboxcode-dsh server: ${u}`);let f=W(`server`,r(),o.path),m=(process.env.TBOXCODE_EXTRA_PATCHES??``).split(`:`).map(e=>e.trim()).filter(e=>e.length>0),h=[...f.slice(0,3),...m.flatMap(e=>[`--patch`,e]),...f.slice(3)],g=p(process.execPath,i(a.server,h),{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,DSH_HOME:e,DSH_TELEMETRY_DISABLED:`1`}});g.stderr?.on(`data`,e=>{process.stderr.write(e)}),g.on(`error`,e=>{process.stderr.write(`tboxcode-dsh server: dsh spawn 失败(${e.message})\n`),g.kill()});let _=``;g.stdout?.on(`data`,e=>{for(_+=e.toString();;){let e=_.indexOf(`
|
|
4
|
+
`);if(e<0)break;let t=_.slice(0,e);_=_.slice(e+1),v.forEach(e=>e(t))}});let v=[],y=[];return g.on(`close`,e=>{_!==``&&v.forEach(e=>e(_)),y.forEach(t=>t(e))}),{onStdoutLine:e=>v.push(e),onExit:e=>y.push(e),kill:e=>g.kill(e??`SIGTERM`)}}})}function Y(e=S()){let t=[];m(e)||(h(e,{recursive:!0}),t.push(`创建配置目录 ${e}`));let n=b(e,`config.jsonc`);m(n)||(v(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 前置明错(不静默回落)
|
|
@@ -12,15 +12,21 @@ 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
|
|
|
12
12
|
// "<id>": {
|
|
13
13
|
// "protocol": "openai-compatible",
|
|
14
14
|
// "options": { "baseURL": "https://...", "apiKey": "\${MY_ENV_KEY}" },
|
|
15
|
-
// "models": { "<model-id>": {} }
|
|
15
|
+
// "models": { "<model-id>": { "limit": { "context": 128000, "output": 8192 } } }
|
|
16
16
|
// }
|
|
17
17
|
// },
|
|
18
|
+
// 官方 DeepSeek API 直连示例(deepseek-official 官方 adapter 行已禁,id 可自由取用):
|
|
19
|
+
// "deepseek-official": {
|
|
20
|
+
// "protocol": "openai-compatible",
|
|
21
|
+
// "options": { "baseURL": "https://api.deepseek.com" },
|
|
22
|
+
// "models": { "deepseek-flash": { "limit": { "context": 128000, "output": 8192 } } }
|
|
23
|
+
// },
|
|
18
24
|
|
|
19
25
|
// 凭据优先序:本目录 auth.jsonc > provider.options.apiKey;\${VAR} 环境引用值内内插,零 env 注入
|
|
20
26
|
}
|
|
21
27
|
|
|
22
|
-
`,`utf-8`),t.push(`写入 config.jsonc 模板(已存在则不覆盖)`));let r=
|
|
23
|
-
`,{encoding:`utf-8`,mode:384}),t.push(`写入 auth.jsonc(0600 空)`)),t}async function
|
|
28
|
+
`,`utf-8`),t.push(`写入 config.jsonc 模板(已存在则不覆盖)`));let r=b(e,`auth.jsonc`);return m(r)||(v(r,`{}
|
|
29
|
+
`,{encoding:`utf-8`,mode:384}),t.push(`写入 auth.jsonc(0600 空)`)),t}async function X(e){let t=s(),n=e.profile===void 0?u:[e.profile],r=!1;for(let e of n)try{let n=await l(t,e,`explicit`),r=n.actions.length>0?`(${n.actions.map(e=>e.detail).join(`;`)})`:`(已装配且无漂移,零动作)`;console.log(`tboxcode-dsh init ${e}: ${n.status} ${r}`),n.status===`version-drift`&&console.warn(`tboxcode-dsh init ${e}: 版本偏差放行(显式模式应已重装;残留偏差请核对安装源)`)}catch(t){r=!0,console.error(`tboxcode-dsh init ${e} 失败:${t instanceof Error?t.message:String(t)}`)}if(e.config===!0)for(let e of Y())console.log(`tboxcode-dsh init --config: ${e}`);return r?1:0}const Z=[{id:`profiles`,run:()=>{let e=s(),t=[],n=0;for(let r of u){let i=o(e,r),a=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} 包`:``,c=i.forbiddenPackages.length>0?`,官方元包污染 ${i.forbiddenPackages.length} 包(${i.forbiddenPackages.join(`, `)}——破坏 dsh 单实例,运行 tboxcode-dsh init 去污染)`:``;t.push(`${r}: ${i.status}${a}${s}${c}`),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(`, `)}(运行 tboxcode-dsh init --profile ${r} 升级)`)}let r=`${t.join(`;`)}${n>0?`——运行 tboxcode-dsh init 修复`:``}`;return{ok:n===0,detail:r}}},{id:`config`,run:()=>{let e=S();try{let t=x(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=b(S(),`auth.jsonc`);if(!m(e))return{ok:!0,detail:"auth.jsonc 缺席(合法——凭据可走 provider.options 或 ${VAR} 引用)"};let t=_(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=e(),n=c();return t===`0.0.0`?{ok:!0,detail:`cli ${t}(开发占位——未发布;dsh 锁版本 ${n})`}:{ok:!0,detail:`cli ${t};dsh 锁版本 ${n}`}}}];function Q(){console.log(`tboxcode-dsh doctor(诊断不修复——修复走 tboxcode-dsh init)`);let e=0;for(let t of Z){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 $(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 ee(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 te(e){let t={};e.flags.get(`config`)===!0&&(t.config=!0);let n=e.flags.get(`profile`);if(typeof n==`string`&&u.includes(n))t.profile=n;else if(typeof n==`string`)throw Error(`init --profile 仅接受四 profile 名(${u.join(` / `)}),实得 ${n}`);return t}function ne(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 re(){process.title=a.cli;let e=process.argv.slice(2);if(e.includes(`--version`)||e.includes(`-v`)){let e=JSON.parse(g(E(new URL(`../package.json`,import.meta.url)),`utf-8`));return console.log(`tboxcode-dsh ${e.version??`unknown`}`),0}let t=e[0],n=$(e.slice(1));switch(t){case`web`:return O(ee(n));case`headless`:return N(ne(n));case`acp`:return K();case`server`:return J({flags:n.flags,positional:n.positional});case`init`:return X(te(n));case`doctor`:return Q();default:return console.error(`tboxcode-dsh <command> [flags]
|
|
24
30
|
|
|
25
31
|
命令:
|
|
26
32
|
web 浏览器直连 dsh 原生 web UI(零 ACP,人工姿态)
|
|
@@ -30,4 +36,4 @@ 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
|
|
|
30
36
|
init profile 装配(--config 生成配置骨架)
|
|
31
37
|
doctor 诊断不修复
|
|
32
38
|
|
|
33
|
-
通用:--version`),2}}
|
|
39
|
+
通用:--version`),2}}re().then(e=>{process.exit(e)}).catch(e=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});export{};
|
package/lib/index.d.ts
CHANGED
|
@@ -6,11 +6,18 @@ declare const PACKAGE_NAME = "@tbox.cn/tboxcode-dsh-cli";
|
|
|
6
6
|
declare const OWN_PROFILES: readonly ["tboxcode-acp", "tboxcode-server", "tboxcode-web", "tboxcode-headless"];
|
|
7
7
|
type ProfileName = (typeof OWN_PROFILES)[number];
|
|
8
8
|
/** 四 profile 组合链(overview profile 模板清单;装配管辖边界 = 四 profile 名)。
|
|
9
|
+
* 官方元包(dsh-base / dsh-web-app / dsh-headless)不在安装链——它们是 bundle 元包,装进
|
|
10
|
+
* profile 会拖全套官方插件实体破坏 dsh 单实例(决策:official-metapackage-profile-
|
|
11
|
+
* decontamination);基座 bundles 行由 PROFILE_OFFICIAL_ROWS 写入(installation 解析生效)。
|
|
9
12
|
* acp 链补注:@tbox.cn/dsh-acp-full(own 互依不进 full-app dependencies——profile 树
|
|
10
13
|
* pnpm 不解析 link 包的 workspace:* spec,链安装保证树内物理)与
|
|
11
|
-
* @deepseek-ai/dsh-tool-ask-user + @deepseek-ai/dsh-cmdline
|
|
12
|
-
* 行挂载与 startup 插件 import 前提;plugin add link 包不装 dependencies
|
|
14
|
+
* @deepseek-ai/dsh-tool-ask-user + @deepseek-ai/dsh-cmdline(官方叶子包 registry pin——
|
|
15
|
+
* 行挂载与 startup 插件 import 前提;plugin add link 包不装 dependencies——真机装配实证;
|
|
16
|
+
* 叶子包不带全家,不伤单实例链)。 */
|
|
13
17
|
declare const PROFILE_CHAINS: Record<ProfileName, readonly string[]>;
|
|
18
|
+
/** 官方基座 bundles 行(结构行,不安装——installation 解析生效;patch 层叠基座,
|
|
19
|
+
* 官方模板同款组合)。 */
|
|
20
|
+
declare const PROFILE_OFFICIAL_ROWS: Record<ProfileName, readonly string[]>;
|
|
14
21
|
/** dsh home 解析(对齐 dsh configured > $DSH_HOME > ~/.dsh;configured 通道为本仓 env 覆盖)。 */
|
|
15
22
|
declare function resolveDshHome(): string;
|
|
16
23
|
declare function profileDir(dshHome: string, profile: ProfileName): string;
|
|
@@ -18,28 +25,33 @@ type AssemblyStatus = 'missing' | 'incomplete' | 'drift' | 'version-drift' | 'ok
|
|
|
18
25
|
interface AssemblyCheck {
|
|
19
26
|
status: AssemblyStatus;
|
|
20
27
|
profileDir: string;
|
|
21
|
-
/**
|
|
28
|
+
/** 缺失待安装的本仓包与 acp 叶子官方包(chain 序)。 */
|
|
22
29
|
missingPackages: string[];
|
|
23
30
|
/** 端态残缺包(node_modules 逐包扫描:包目录 + package.json 在场但入口缺席 /
|
|
24
31
|
* manifest 损坏)——装配打断的端态证据。pnpm 状态自洽下 install/--force 均不
|
|
25
32
|
* 重写("Already up to date"),唯 nuke + 全链重装可愈(2026-10-26 三 e2e home
|
|
26
33
|
* 四链 120-140 包残缺实证)。归 incomplete 状态(状态机零扩展)。 */
|
|
27
34
|
corruptPackages: string[];
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/**
|
|
35
|
+
/** dependencies 中的官方元包(deny-list 命中)——去污染前置步的执行面
|
|
36
|
+
* (2026-10-27 官方元包进 profile 破坏 dsh 单实例实证;归 incomplete 状态)。 */
|
|
37
|
+
forbiddenPackages: string[];
|
|
38
|
+
/** 结构行集漂移:期望序(官方基座 + 自有)vs 实际序(bundles 结构行)。 */
|
|
39
|
+
expectedStructureOrder: string[];
|
|
40
|
+
actualStructureOrder: string[];
|
|
41
|
+
/** 版本偏差:自有包 local 源比 workspace 版本、registry 源比 CLI manifest 版本
|
|
42
|
+
* (家族单版本纪律);官方包比 dsh 锁版本。 */
|
|
32
43
|
versionMismatches: {
|
|
33
44
|
pkg: string;
|
|
34
45
|
expected: string;
|
|
35
46
|
actual: string;
|
|
36
47
|
}[];
|
|
37
48
|
}
|
|
38
|
-
/** 装配检查(只读,零写入——已装配且无漂移时纯读)。缺失判定 =
|
|
49
|
+
/** 装配检查(只读,零写入——已装配且无漂移时纯读)。缺失判定 = 未装入(安装链对象——
|
|
50
|
+
* 官方元包不安装,其 dependencies 在场归 forbiddenPackages 而非 missing);
|
|
39
51
|
* 在场性检查防"已声明但 node_modules 缺失"的半途态被误报 ok(超时杀进程后重试的构造性兜底)。 */
|
|
40
52
|
declare function checkAssembly(dshHome: string, profile: ProfileName): AssemblyCheck;
|
|
41
53
|
interface AssemblyAction {
|
|
42
|
-
kind: 'install' | 'correct-manifest' | 'reinstall' | 'retry' | 'heal';
|
|
54
|
+
kind: 'install' | 'correct-manifest' | 'reinstall' | 'retry' | 'heal' | 'decontaminate';
|
|
43
55
|
detail: string;
|
|
44
56
|
}
|
|
45
57
|
interface AssemblyOutcome {
|
|
@@ -83,4 +95,4 @@ interface DshRunResult {
|
|
|
83
95
|
/** spawn dsh;env 映射 TBOXCODE_DSH_HOME → DSH_HOME 并关遥测(CI / 测试确定性)。 */
|
|
84
96
|
declare function runDsh(options: DshRunOptions): Promise<DshRunResult>;
|
|
85
97
|
//#endregion
|
|
86
|
-
export { type AssemblyAction, type AssemblyCheck, type AssemblyOutcome, type AssemblyStatus, type DshRunOptions, type DshRunResult, OWN_PROFILES, PACKAGE_NAME, PROFILE_CHAINS, type ProfileName, checkAssembly, ensureAssembly, profileDir, resolveDshEntry, resolveDshHome, runDsh };
|
|
98
|
+
export { type AssemblyAction, type AssemblyCheck, type AssemblyOutcome, type AssemblyStatus, type DshRunOptions, type DshRunResult, OWN_PROFILES, PACKAGE_NAME, PROFILE_CHAINS, PROFILE_OFFICIAL_ROWS, type ProfileName, checkAssembly, ensureAssembly, profileDir, resolveDshEntry, resolveDshHome, runDsh };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{c as e,f as t,i as n,l as r,m as i,n as a,p as o,r as s,s as c,t as l}from"./assembly-ZFOXMi7d.js";export{l as OWN_PROFILES,i as PACKAGE_NAME,a as PROFILE_CHAINS,s as PROFILE_OFFICIAL_ROWS,n as checkAssembly,c as ensureAssembly,e as profileDir,t as resolveDshEntry,r as resolveDshHome,o 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.
|
|
3
|
+
"version": "0.1.0-rc.11",
|
|
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.
|
|
24
|
+
"@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.11"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@deepseek-ai/dsh-llm-mock-server": "0.2.1-rc.2"
|
package/lib/assembly-COH6w2mC.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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};
|