@tbox.cn/tboxcode-dsh-cli 0.1.0-rc.12 → 0.1.0-rc.14
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 +12 -3
- package/lib/assembly-CxMZLSKV.js +2 -0
- package/lib/bin.js +13 -6
- package/lib/index.d.ts +38 -6
- package/lib/index.js +1 -1
- package/package.json +8 -5
- package/lib/assembly-ZFOXMi7d.js +0 -2
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
npm i -g @tbox.cn/tboxcode-dsh-cli
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
要求 Node >=
|
|
11
|
+
要求 Node >= 24.9.0。安装后 `tboxcode-dsh --version` 验证;首次使用建议 `tboxcode-dsh doctor` 诊断环境。
|
|
12
12
|
|
|
13
13
|
## 本地开发
|
|
14
14
|
|
|
@@ -27,7 +27,7 @@ pnpm release rehearse # L2 发版前彩排(verdaccio registry 全保真
|
|
|
27
27
|
| `tboxcode-dsh acp` | 人工 | ACP stdio 载体(Zed 等客户端直连);stdout 为 ACP 协议通道(strict 净化守卫) |
|
|
28
28
|
| `tboxcode-dsh server` | 机器 | 长驻服务(Supervisor spawn 目标);裸命令零 flag——stdio 信封协议 v2.2 |
|
|
29
29
|
| `tboxcode-dsh headless <task>` | 机器 | 一次性任务(task → stdout → 退出);`--session-id` / `--json` |
|
|
30
|
-
| `tboxcode-dsh init` | 维护 | profile 装配(ensure 显式模式);`--config` 生成配置骨架;`--profile <name>` 指定单 profile |
|
|
30
|
+
| `tboxcode-dsh init` | 维护 | profile 装配(ensure 显式模式);`--config` 生成配置骨架;`--profile <name>` 指定单 profile;`--dry-run` 只读预览;`--repair-all` 显式允许 foreign corrupt 全量修复 |
|
|
31
31
|
| `tboxcode-dsh doctor` | 维护 | 诊断不修复(装配态 / config / 凭据权限 / 版本链——修复走 init) |
|
|
32
32
|
|
|
33
33
|
通用:`--version`。
|
|
@@ -45,7 +45,16 @@ tboxcode-dsh init --config # 生成注释化 config.jsonc 模板 + 0600 空 au
|
|
|
45
45
|
|
|
46
46
|
## profile 与 home
|
|
47
47
|
|
|
48
|
-
四 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 行 / 用户 `@tbox.cn/*` bundle 行)神圣不动。手动 pin 的版本会被 `init` 对齐回当前 CLI 版本(家族单版本纪律)。
|
|
49
|
+
|
|
50
|
+
`init` 所有权边界:
|
|
51
|
+
|
|
52
|
+
- 当前 profile 的官方基座行与本仓链行 → 装配器维护
|
|
53
|
+
- `PROFILE_CLEANUP_ROWS` 登记的已退役 / 非 bundle 自有行 → 删除
|
|
54
|
+
- 用户自装插件、用户 `@tbox.cn/*` bundle 行、patch 行 → 保留
|
|
55
|
+
- 其他 profile 的官方基座行 → 删除(避免错误基座)
|
|
56
|
+
- 本仓链损坏 → 默认自愈;用户插件 / 传递依赖损坏 → 默认只告警,`--repair-all` 才重建 `node_modules`(用户自装插件需自行重装)
|
|
57
|
+
- `--dry-run` 输出状态、missing / forbidden、managed / foreign corrupt 与结构 diff,不写文件、不跑 `dsh plugin`
|
|
49
58
|
|
|
50
59
|
## 相关包
|
|
51
60
|
|
|
@@ -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-presets`,`@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-presets`,`@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([`@deepseek-ai/dsh-base`,`@deepseek-ai/dsh-web-app`,`@deepseek-ai/dsh-headless`]),O={"tboxcode-acp":[`@tbox.cn/dsh-acp-full`],"tboxcode-server":[`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-web":[`@tbox.cn/tboxcode-dsh-presets`],"tboxcode-headless":[]};function k(e){let t=E[e],n=new Set([...O[e],...[...D].filter(e=>!t.includes(e))]),r=T[e].filter(e=>P(e)&&!n.has(e));return{officialRows:t,managedOwnRows:r,managedRows:new Set([...t,...r]),cleanupRows:n}}function A(e,t){return e.managedRows.has(t)||e.cleanupRows.has(t)}function j(e){let t=k(e);return[...t.officialRows,...t.managedOwnRows]}function M(){return process.env.TBOXCODE_DSH_HOME??process.env.DSH_HOME??l(u(),`.dsh`)}function N(e,t){return l(e,`profiles`,t)}function P(e){return e.startsWith(`@tbox.cn/`)}function F(e){let t=l(e,`package.json`);return n(t)?JSON.parse(i(t,`utf-8`)):null}function I(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 L(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&&(I(l(e,n.name),c)||r.push(a))}};return o(t,``),r.sort()}function R(e,t){let r=N(e,t),i=T[t],a=k(t),o=j(t),s=n(r)?F(r):null;if(s===null)return{status:`missing`,profileDir:r,missingPackages:[...i],managedCorruptPackages:[],foreignCorruptPackages:[],forbiddenPackages:[],expectedStructureOrder:o,actualStructureOrder:[],versionMismatches:[]};let c=L(r),l=new Set(i),u=c.filter(e=>l.has(e)),d=c.filter(e=>!l.has(e)),f=s.dsh?.profile?.bundles??[],p=Object.keys(s.dependencies??{}).filter(e=>D.has(e)),m=i.filter(e=>G(r,e)===null),h=f.filter(e=>A(a,e)),g=[],_=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT===void 0?`registry`:`local`,v=_===`registry`?B():``;for(let e of i.filter(P)){let t=W(_,_===`local`?U(e):null,v),n=G(r,e);t!==null&&n!==null&&t!==n&&g.push({pkg:e,expected:t,actual:n})}for(let e of i.filter(e=>!P(e))){let t=z(),n=G(r,e);t!==``&&n!==null&&t!==n&&g.push({pkg:e,expected:t,actual:n})}let y=`ok`;return m.length>0||u.length>0||p.length>0?y=`incomplete`:g.length>0?y=`version-drift`:(h.length!==o.length||h.some((e,t)=>e!==o[t]))&&(y=`drift`),{status:y,profileDir:r,missingPackages:m,managedCorruptPackages:u,foreignCorruptPackages:d,forbiddenPackages:p,expectedStructureOrder:o,actualStructureOrder:h,versionMismatches:g}}function z(){let t=e(import.meta.url).resolve(`@deepseek-ai/dsh/package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function B(){let t=e(import.meta.url).resolve(`../package.json`);return JSON.parse(i(t,`utf-8`)).version??``}function V(e){if(!P(e))return`${e}@${z()}`;let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0){let t=B();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=H(t,e);if(n===null)throw Error(`装配安装源未找到包 ${e}(TBOXCODE_ASSEMBLY_LOCAL_ROOT=${t})`);return`link:${n}`}function H(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 U(e){let t=process.env.TBOXCODE_ASSEMBLY_LOCAL_ROOT;if(t===void 0)return null;let n=H(t,e);return n===null?null:JSON.parse(i(l(n,`package.json`),`utf-8`)).version??null}function W(e,t,n){return e===`local`?t===``?null:t:n===``||n===`0.0.0`?null:n}function G(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 K={"node-pty":!0,koffi:!0,"@deepseek-ai/dsh-subprocess-local":!0,"@google/genai":!1,protobufjs:!1};async function q(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:K}),{mode:420});return}let e=d(i(t,`utf-8`))??{},r=e.allowBuilds??{},a={...K,...r};JSON.stringify(r)!==JSON.stringify(a)&&(e.allowBuilds=a,await m(t,f(e),{mode:420}))})}const J=5e3;function Y(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:12e4}function X(){let e=Number(process.env.TBOXCODE_ASSEMBLY_INSTALL_ATTEMPTS);return Number.isInteger(e)&&e>0?e:2}async function Z(e,t,n,r){let i=await C({dshHome:e,args:[`plugin`,`--profile`,t,`add`,n],capture:!0,timeoutMs:Y()});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 Q(e,t,n){let r=await C({dshHome:e,args:[`plugin`,`--profile`,t,`remove`,...n],capture:!0,timeoutMs:Y()});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 ee(e,t,r={}){let i=N(e,t),a=l(i,`node_modules`),s=l(e,`profiles`,t,`node_modules`);if(!w.includes(t)||a!==s)throw Error(`装配自愈守卫拒绝:目标 ${a} 非 own profile node_modules(期望 ${s})`);return n(a)?await p(l(i,`.tboxcode-assembly-heal.lock`),async()=>{let e=L(i),n=new Set(T[t]);return!e.some(e=>n.has(e))&&r.includeForeign!==!0?!1:(o(a,{recursive:!0,force:!0}),!0)}):!1}async function te(e,t,n,r={}){let i=n===`explicit`?X():1,a=[],o;for(let s=1;s<=i;s++)try{return await ne(e,t,n,a,r)}catch(e){if(o=e,s<i){let t=String(e instanceof Error?e.message:e).split(`
|
|
2
|
+
`)[0];a.push({kind:`retry`,detail:`第 ${s} 次尝试失败(${t}),${J/1e3}s 后重试`}),await new Promise(e=>setTimeout(e,J))}}throw o}async function ne(e,t,n,i,a){let o=R(e,t);o.forbiddenPackages.length>0&&(await Q(e,t,o.forbiddenPackages),i.push({kind:`decontaminate`,detail:`官方元包去污染:dsh plugin remove ${o.forbiddenPackages.join(` `)}(元包实体破坏 dsh 单实例——settings 持久化写与热重载全灭;官方基座行转 installation 解析)`}),o=R(e,t));let s=a.repairForeignCorruption===!0&&o.foreignCorruptPackages.length>0;if(o.managedCorruptPackages.length>0||s){let n=[...new Set([...o.managedCorruptPackages,...o.foreignCorruptPackages])];await ee(e,t,{includeForeign:s})&&i.push({kind:`heal`,detail:`半装态自愈${s?`(含 foreign;用户自装插件需自行重装)`:``}:node_modules 残缺 ${n.length} 包(${n.slice(0,3).join(`, `)}${n.length>3?` …`:``})→ nuke 后全链重装`}),o=R(e,t)}else o.foreignCorruptPackages.length>0&&i.push({kind:`warn-foreign-corrupt`,detail:`非受管包残缺(用户插件或传递依赖):${o.foreignCorruptPackages.slice(0,3).join(`, `)}${o.foreignCorruptPackages.length>3?` …`:``}——默认不重建 node_modules;确认需要全量修复时运行 tboxcode-dsh init --profile ${t} --repair-all(会重建 node_modules,用户自装插件需自行重装)`});if(o.missingPackages.length>0){r(o.profileDir,{recursive:!0}),await q(o.profileDir);for(let n of o.missingPackages){let r=V(n);await Z(e,t,r,`安装`),i.push({kind:`install`,detail:`${n} ← ${r}`})}o=R(e,t)}if(o.status===`version-drift`&&n===`explicit`){for(let n of o.versionMismatches)await Z(e,t,V(n.pkg),`重装`),i.push({kind:`reinstall`,detail:`${n.pkg} ${n.actual} → ${n.expected}`});o=R(e,t)}return o.status!==`missing`&&(o.actualStructureOrder.length!==o.expectedStructureOrder.length||o.actualStructureOrder.some((e,t)=>e!==o.expectedStructureOrder[t]))&&(await ie(e,t),i.push({kind:`correct-manifest`,detail:`结构行集校正 [${o.actualStructureOrder.join(`,`)}] → [${o.expectedStructureOrder.join(`,`)}](结构行是组合契约,用户领地不动)`}),o=R(e,t)),{status:o.status,actions:i,check:o}}function $(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}function re(e,t,n={}){let r=[];if(e.check.foreignCorruptPackages.length>0){let n=e.check.foreignCorruptPackages;r.push(`${t} 非受管包残缺(用户插件或传递依赖):${n.slice(0,3).join(`, `)}${n.length>3?` …`:``}——默认不重建 node_modules;确认需要全量修复时运行 tboxcode-dsh init --profile ${t} --repair-all(会重建 node_modules,用户自装插件需自行重装)`)}if(n.includeVersionDrift!==!1){let n=$(e,t);n!==null&&r.push(n)}return e.check.forbiddenPackages.length>0&&r.push(`${t} 官方元包污染(${e.check.forbiddenPackages.join(`, `)})——运行 tboxcode-dsh init --profile ${t} 去污染`),r}async function ie(e,t){let n=l(N(e,t),`package.json`);await p(n,async()=>{let e=JSON.parse(i(n,`utf-8`)),r=e.dsh?.profile?.bundles??[],a=k(t),o=[...new Set(r.filter(e=>!A(a,e)))],s=[...a.officialRows,...o,...a.managedOwnRows];e.dsh={...e.dsh,profile:{...e.dsh?.profile,bundles:s}},await m(n,`${JSON.stringify(e,null,2)}\n`,{mode:420})})}export{g as _,re as a,z as c,M as d,$ as f,h as g,C as h,E as i,te as l,y as m,T as n,R as o,b as p,O as r,B as s,w as t,N as u,_ as v};
|
package/lib/bin.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
3
|
-
`)[0]??n)}}})}function
|
|
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
|
|
2
|
+
import{_ as e,a as t,c as n,d as r,l as i,m as a,o,p as s,s as c,t as l,u,v as d}from"./assembly-CxMZLSKV.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){for(let t of e)console.error(`tboxcode: ${t.field}: ${t.reason}`)}function O(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 k(n){let o=r(),c=S(),l=x(c),u=C(l.config,c,l.path!==null,{profile:`web`});D(u.warnings);let f=await w(u.rows),m=await i(o,`tboxcode-web`,`startup`);if(m.status!==`ok`&&m.status!==`version-drift`)throw await f.dispose(),Error(`web 启动装配未就绪(${m.status})——运行 tboxcode-dsh init 显式装配`);for(let e of t(m,`tboxcode-web`))console.error(`tboxcode-dsh web: ${e}`);let h=O(a(),f.path,{...n,dshHome:o}),g=p(process.execPath,d(e.web,h),{stdio:`inherit`,env:{...process.env,DSH_HOME:o,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(s(`web`,_)),await f.dispose(),typeof _==`number`?_:1}const A=f(import.meta.url);function j(){return b(y(A.resolve(`@tbox.cn/tboxcode-dsh-runtime/package.json`)),`assets`,`stdout-guard.cjs`)}function M(e,t,n){let r=j(),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:u(e,t)}}function N(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 P(n){let o=r(),c=S(),l=x(c),u=C(l.config,c,l.path!==null,{profile:`headless`});D(u.warnings);let f=await w(u.rows),m=await i(o,`tboxcode-headless`,`startup`);if(m.status!==`ok`&&m.status!==`version-drift`)throw await f.dispose(),Error(`headless 启动装配未就绪(${m.status})——运行 tboxcode-dsh init 显式装配`);for(let e of t(m,`tboxcode-headless`))console.error(`tboxcode-dsh headless: ${e}`);let h=N(a(),f.path,n),g=p(process.execPath,d(e.headless,h),{stdio:`inherit`,env:{...process.env,...M(o,`tboxcode-headless`,`quiet`),DSH_HOME:o,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(s(`headless`,_)),await f.dispose(),typeof _==`number`?_:1}function F(){return JSON.stringify({v:1,event:`standby`})}function I(e,t){return JSON.stringify({v:1,event:`ready`,port:e,token:t})}function L(e,t,n){return JSON.stringify({stage:e,kind:t,error:n})}function R(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 z(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 B(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 V=class extends Error{};function H(e){if(e instanceof V)return`permanent`;let t=e?.name;return t===`ModelNotSetError`||t===`ModelMalformedError`||t===`SecretInTranslationError`?`permanent`:`transient`}function U(e){return e===null?1:e===0?0:e===2||e===3?e:1}async function W(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(`${L(r,i,a)}\n`),n(e))};t.writeStdout(`${F()}\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(`${L(`protocol`,`protocol`,`start 命令在 ready 后到达(stdin 已转惰性),忽略`)}\n`);return}let n=R(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(`${L(`protocol`,`protocol`,`未知 cmd "${n.cmd}" 忽略(additive-only 版本窗口)`)}\n`);return;case`malformed`:t.writeStderr(`${L(`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=z(n);if(i===null)return;let a=B(i);a!==null&&(l=!0,r=`ready`,t.writeStdout(`${I(a.port,a.token)}\n`),e.log(`ready(token 已交付,stdout 永久静默;token 已弃)`))}),n.onExit(t=>{let n=s?0:U(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=H(e),n=e instanceof Error?e.message:String(e);u(t===`permanent`?2:1,`boot`,t,n.split(`
|
|
3
|
+
`)[0]??n)}}})}function G(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 K(n){let o=r(),c=S(),l=x(c),u=C(l.config,c,l.path!==null,{profile:`acp`});D(u.warnings);let f=await w(u.rows),m=`tboxcode-acp`,h=await i(o,m,`startup`);if(h.status!==`ok`&&h.status!==`version-drift`)throw await f.dispose(),Error(`${n} 启动装配未就绪(${h.status})——运行 tboxcode-dsh init 显式装配`);for(let e of t(h,m))console.error(`tboxcode-dsh ${n}: ${e}`);let g=G(n,a(),f.path),_=p(process.execPath,d(e[n],g),{stdio:`inherit`,env:{...process.env,...M(o,m,`strict`),DSH_HOME:o,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(e=>{_.on(`close`,t=>{v!==void 0&&clearTimeout(v),e(t??1)}),_.on(`error`,t=>{console.error(`tboxcode-dsh ${n}: spawn 失败(${t.message})`),e(1)})});return y!==0&&console.error(s(n,y)),await f.dispose(),typeof y==`number`?y:1}async function q(){return K(`acp`)}function J(){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 Y(n={flags:new Map,positional:[]}){if(n.flags.size>0||n.positional.length>0){let e=[...n.positional,...[...n.flags.keys()].map(e=>`--${e}`)].join(` `);return console.error(`tboxcode-dsh server: 裸命令零 flag(机器路径,Supervisor spawn 契约)——实得 "${e}",拒绝启动`),2}return await W({io:J(),log:e=>console.error(`tboxcode-dsh server: ${e}`),boot:async()=>{let n=r(),o=S(),s=x(o),c=C(s.config,o,s.path!==null,{profile:`server`});D(c.warnings);let l=await w(c.rows),u=await i(n,`tboxcode-server`,`startup`);if(u.status!==`ok`&&u.status!==`version-drift`)throw await l.dispose(),new V(`profile 装配未就绪(${u.status})——运行 tboxcode-dsh init 显式装配`);for(let e of t(u,`tboxcode-server`))console.error(`tboxcode-dsh server: ${e}`);let f=G(`server`,a(),l.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,d(e.server,h),{stdio:[`ignore`,`pipe`,`pipe`],env:{...process.env,DSH_HOME:n,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 X(e=S(),t=!1){let n=[];m(e)||(t?n.push(`将创建配置目录 ${e}`):(h(e,{recursive:!0}),n.push(`创建配置目录 ${e}`)));let r=b(e,`config.jsonc`);m(r)||(t?n.push(`将写入 config.jsonc 模板(已存在则不覆盖)`):(v(r,`// 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 前置明错(不静默回落)
|
|
8
8
|
"model": "deepseek-official/deepseek-flash",
|
|
9
9
|
|
|
10
|
+
// 默认 agent preset——缺省 standard;acp/headless 仅支持 ptc / standard,
|
|
11
|
+
// server/web 另支持 minimal / cordis。修改后需重启进程(startup-only)。
|
|
12
|
+
// "agent_preset": "ptc",
|
|
13
|
+
|
|
10
14
|
// provider 定义(LlmAdapter:anthropic / openai / openai-compatible;全量接入归 llm-stack)
|
|
11
15
|
// "provider": {
|
|
12
16
|
// "<id>": {
|
|
@@ -25,8 +29,8 @@ 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 a
|
|
|
25
29
|
// 凭据优先序:本目录 auth.jsonc > provider.options.apiKey;\${VAR} 环境引用值内内插,零 env 注入
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
`,`utf-8`),
|
|
29
|
-
`,{encoding:`utf-8`,mode:384}),
|
|
32
|
+
`,`utf-8`),n.push(`写入 config.jsonc 模板(已存在则不覆盖)`)));let i=b(e,`auth.jsonc`);return m(i)||(t?n.push(`将写入 auth.jsonc(0600 空)`):(v(i,`{}
|
|
33
|
+
`,{encoding:`utf-8`,mode:384}),n.push(`写入 auth.jsonc(0600 空)`))),n}function Z(e,n,r){let i=n.actualStructureOrder.length!==n.expectedStructureOrder.length||n.actualStructureOrder.some((e,t)=>e!==n.expectedStructureOrder[t]);console.log(`tboxcode-dsh init ${e}: dry-run ${n.status}`),n.missingPackages.length>0&&console.log(` missing: ${n.missingPackages.join(`, `)}`),n.forbiddenPackages.length>0&&console.log(` forbidden: ${n.forbiddenPackages.join(`, `)}`),n.managedCorruptPackages.length>0&&console.log(` managed corrupt: ${n.managedCorruptPackages.join(`, `)}(init 将 nuke 重建)`),n.foreignCorruptPackages.length>0&&console.log(` foreign corrupt: ${n.foreignCorruptPackages.join(`, `)}(默认不重建;--repair-all 才重建)`),i?(console.log(` structure expected: [${n.expectedStructureOrder.join(`, `)}]`),console.log(` structure actual: [${n.actualStructureOrder.join(`, `)}]`)):console.log(` structure: 无漂移`);let a=r&&(n.managedCorruptPackages.length>0||n.foreignCorruptPackages.length>0);console.log(` repair-all: ${r?a?`是(将执行全量 nuke;用户自装插件需自行重装)`:`是(当前无残缺包,不会触发 nuke)`:`否`}`);for(let r of t({status:n.status,actions:[],check:n},e))console.warn(r)}async function Q(e){let n=r(),a=e.profile===void 0?l:[e.profile],s=!1;for(let r of a)try{if(e.dryRun===!0){Z(r,o(n,r),e.repairAll===!0);continue}let a=await i(n,r,`explicit`,{repairForeignCorruption:e.repairAll===!0}),s=a.actions.filter(e=>e.kind!==`warn-foreign-corrupt`),c=s.length>0?`(${s.map(e=>e.detail).join(`;`)})`:a.actions.length>0?`(装配无写入,另有诊断提示)`:`(已装配且无漂移,零动作)`;console.log(`tboxcode-dsh init ${r}: ${a.status} ${c}`),a.status===`version-drift`&&console.warn(`tboxcode-dsh init ${r}: 版本偏差放行(显式模式应已重装;残留偏差请核对安装源)`);for(let e of t(a,r,{includeVersionDrift:!1}))console.warn(e)}catch(e){s=!0,console.error(`tboxcode-dsh init ${r} 失败:${e instanceof Error?e.message:String(e)}`)}if(e.config===!0){let t=X(void 0,e.dryRun===!0);for(let e of t)console.log(`tboxcode-dsh init --config: ${e}`)}return s?1:0}const $=[{id:`profiles`,run:()=>{let e=r(),t=[],n=0;for(let r of l){let i=o(e,r),a=i.managedCorruptPackages.length>0?`,本仓链残缺 ${i.managedCorruptPackages.length} 包(${i.managedCorruptPackages.slice(0,3).join(`, `)}${i.managedCorruptPackages.length>3?` …`:``}——运行 tboxcode-dsh init 自愈)`:``,s=i.foreignCorruptPackages.length>0?`,非受管残缺 ${i.foreignCorruptPackages.length} 包(${i.foreignCorruptPackages.slice(0,3).join(`, `)}${i.foreignCorruptPackages.length>3?` …`:``}——默认不重建 node_modules;确认需要全量修复时运行 tboxcode-dsh init --repair-all;会重建 node_modules,用户自装插件需自行重装)`:``,c=i.missingPackages.length>0?`,缺 ${i.missingPackages.length} 包`:``,l=i.forbiddenPackages.length>0?`,官方元包污染 ${i.forbiddenPackages.length} 包(${i.forbiddenPackages.join(`, `)}——破坏 dsh 单实例,运行 tboxcode-dsh init 去污染)`:``,u=i.status!==`missing`&&(i.actualStructureOrder.length!==i.expectedStructureOrder.length||i.actualStructureOrder.some((e,t)=>e!==i.expectedStructureOrder[t]))?`,结构漂移 expected=[${i.expectedStructureOrder.join(`, `)}] actual=[${i.actualStructureOrder.join(`, `)}](运行 tboxcode-dsh init 校正)`:``;t.push(`${r}: ${i.status}${a}${s}${c}${l}${u}`),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 i=`${t.join(`;`)}${n>0?`——运行 tboxcode-dsh init 修复`:``}`;return{ok:n===0,detail:i}}},{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;if(typeof n!=`string`||n.length===0)return{ok:!1,detail:`${t.path} 缺 model 字段——spawn 前置将明错(未设 model 不静默回落)`};let r=t.config.agent_preset,i=typeof r==`string`&&r.length>0?`;agent_preset = ${r}`:`;agent_preset 未设置(bundle default standard)`;return{ok:!0,detail:`${t.path} model = ${n}${i}`}}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 e=c(),t=n();return e===`0.0.0`?{ok:!0,detail:`cli ${e}(开发占位——未发布;dsh 锁版本 ${t})`}:{ok:!0,detail:`cli ${e};dsh 锁版本 ${t}`}}}];function ee(){console.log(`tboxcode-dsh doctor(诊断不修复——修复走 tboxcode-dsh init)`);let e=0;for(let t of $){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}const te=new Set([`json`,`no-open`,`dry-run`,`repair-all`,`config`]);function ne(e){let t=new Map,n=[],r=0;for(;r<e.length;){let i=e[r]??``;if(i.startsWith(`--`)){let n=i.slice(2);if(te.has(n)){t.set(n,!0),r+=1;continue}let 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 re(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 ie(e){let t={};e.flags.get(`config`)===!0&&(t.config=!0),e.flags.get(`dry-run`)===!0&&(t.dryRun=!0),e.flags.get(`repair-all`)===!0&&(t.repairAll=!0);let n=e.flags.get(`profile`);if(typeof n==`string`&&l.includes(n))t.profile=n;else if(typeof n==`string`)throw Error(`init --profile 仅接受四 profile 名(${l.join(` / `)}),实得 ${n}`);return t}function ae(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 oe(){process.title=e.cli;let t=process.argv.slice(2);if(t.includes(`--version`)||t.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 n=t[0],r=ne(t.slice(1));switch(n){case`web`:return k(re(r));case`headless`:return P(ae(r));case`acp`:return q();case`server`:return Y({flags:r.flags,positional:r.positional});case`init`:return Q(ie(r));case`doctor`:return ee();default:return console.error(`tboxcode-dsh <command> [flags]
|
|
30
34
|
|
|
31
35
|
命令:
|
|
32
36
|
web 浏览器直连 dsh 原生 web UI(零 ACP,人工姿态)
|
|
@@ -34,6 +38,9 @@ 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 a
|
|
|
34
38
|
server 长驻服务(agtcodingbox spawn)
|
|
35
39
|
headless 一次性任务(task → stdout → 退出)
|
|
36
40
|
init profile 装配(--config 生成配置骨架)
|
|
41
|
+
--profile <name> 指定单 profile
|
|
42
|
+
--dry-run 只读预览,不写文件、不跑 dsh plugin
|
|
43
|
+
--repair-all 显式允许 foreign corrupt 也重建 node_modules(用户自装插件需自行重装)
|
|
37
44
|
doctor 诊断不修复
|
|
38
45
|
|
|
39
|
-
通用:--version`),2}}
|
|
46
|
+
通用:--version`),2}}oe().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
|
@@ -18,6 +18,19 @@ declare const PROFILE_CHAINS: Record<ProfileName, readonly string[]>;
|
|
|
18
18
|
/** 官方基座 bundles 行(结构行,不安装——installation 解析生效;patch 层叠基座,
|
|
19
19
|
* 官方模板同款组合)。 */
|
|
20
20
|
declare const PROFILE_OFFICIAL_ROWS: Record<ProfileName, readonly string[]>;
|
|
21
|
+
/**
|
|
22
|
+
* 每 profile 的 cleanup registry:已退役 / 已知非 bundle 的自有行。
|
|
23
|
+
* 链内 own 行若登记于此,会从 managedOwn 排除(如 acp-full 仍安装但不写结构行);
|
|
24
|
+
* 退链行(如 presets)登记后随校正清除;其他 `@tbox.cn/*` → 用户行,保留。
|
|
25
|
+
* 其他 profile 的官方基座行由 FORBIDDEN_OFFICIAL_METAPACKAGES 过滤自动进入 cleanup。
|
|
26
|
+
*/
|
|
27
|
+
declare const PROFILE_CLEANUP_ROWS: Record<ProfileName, readonly string[]>;
|
|
28
|
+
interface ProfileRules {
|
|
29
|
+
officialRows: readonly string[];
|
|
30
|
+
managedOwnRows: readonly string[];
|
|
31
|
+
managedRows: ReadonlySet<string>;
|
|
32
|
+
cleanupRows: ReadonlySet<string>;
|
|
33
|
+
}
|
|
21
34
|
/** dsh home 解析(对齐 dsh configured > $DSH_HOME > ~/.dsh;configured 通道为本仓 env 覆盖)。 */
|
|
22
35
|
declare function resolveDshHome(): string;
|
|
23
36
|
declare function profileDir(dshHome: string, profile: ProfileName): string;
|
|
@@ -27,11 +40,14 @@ interface AssemblyCheck {
|
|
|
27
40
|
profileDir: string;
|
|
28
41
|
/** 缺失待安装的本仓包与 acp 叶子官方包(chain 序)。 */
|
|
29
42
|
missingPackages: string[];
|
|
30
|
-
/**
|
|
31
|
-
* manifest
|
|
43
|
+
/** 本仓直接链损坏(node_modules 逐包扫描:包目录 + package.json 在场但入口缺席 /
|
|
44
|
+
* manifest 损坏)——init 负责自愈。pnpm 状态自洽下 install/--force 均不
|
|
32
45
|
* 重写("Already up to date"),唯 nuke + 全链重装可愈(2026-10-26 三 e2e home
|
|
33
46
|
* 四链 120-140 包残缺实证)。归 incomplete 状态(状态机零扩展)。 */
|
|
34
|
-
|
|
47
|
+
managedCorruptPackages: string[];
|
|
48
|
+
/** 非受管包损坏(用户插件或传递依赖)——默认只告警,不重建 node_modules;
|
|
49
|
+
* `--repair-all` 显式允许其触发 nuke。不参与 status。 */
|
|
50
|
+
foreignCorruptPackages: string[];
|
|
35
51
|
/** dependencies 中的官方元包(deny-list 命中)——去污染前置步的执行面
|
|
36
52
|
* (2026-10-27 官方元包进 profile 破坏 dsh 单实例实证;归 incomplete 状态)。 */
|
|
37
53
|
forbiddenPackages: string[];
|
|
@@ -51,7 +67,7 @@ interface AssemblyCheck {
|
|
|
51
67
|
* 在场性检查防"已声明但 node_modules 缺失"的半途态被误报 ok(超时杀进程后重试的构造性兜底)。 */
|
|
52
68
|
declare function checkAssembly(dshHome: string, profile: ProfileName): AssemblyCheck;
|
|
53
69
|
interface AssemblyAction {
|
|
54
|
-
kind: 'install' | 'correct-manifest' | 'reinstall' | 'retry' | 'heal' | 'decontaminate';
|
|
70
|
+
kind: 'install' | 'correct-manifest' | 'reinstall' | 'retry' | 'heal' | 'decontaminate' | 'warn-foreign-corrupt';
|
|
55
71
|
detail: string;
|
|
56
72
|
}
|
|
57
73
|
interface AssemblyOutcome {
|
|
@@ -59,13 +75,29 @@ interface AssemblyOutcome {
|
|
|
59
75
|
actions: AssemblyAction[];
|
|
60
76
|
check: AssemblyCheck;
|
|
61
77
|
}
|
|
78
|
+
interface HealOptions {
|
|
79
|
+
/** 默认 false:只处理本仓直接链损坏。true = 任意 corrupt(含用户插件 / 传递依赖)都 nuke。 */
|
|
80
|
+
includeForeign?: boolean;
|
|
81
|
+
}
|
|
82
|
+
interface EnsureOptions {
|
|
83
|
+
/** `init --repair-all` 显式同意 foreign corrupt 也触发 nuke;默认 false。 */
|
|
84
|
+
repairForeignCorruption?: boolean;
|
|
85
|
+
}
|
|
62
86
|
/**
|
|
63
87
|
* 执行装配(幂等;已装配且无漂移时纯读零写入)。
|
|
64
88
|
* 重试仅 explicit 模式(启动模式守"永不意外慢");链级重试 + 幂等 = 包级断点续传,
|
|
65
89
|
* 不分类瞬态/确定性错误(后者秒败,重试代价可忽略)。
|
|
66
90
|
* @param mode startup = 启动检查(版本偏差 warn 放行,永不意外慢);explicit = init 显式模式(版本偏差重装)
|
|
67
91
|
*/
|
|
68
|
-
declare function ensureAssembly(dshHome: string, profile: ProfileName, mode: 'startup' | 'explicit'): Promise<AssemblyOutcome>;
|
|
92
|
+
declare function ensureAssembly(dshHome: string, profile: ProfileName, mode: 'startup' | 'explicit', options?: EnsureOptions): Promise<AssemblyOutcome>;
|
|
93
|
+
/** startup 版本偏差提示(展示层纯函数):不重装,只引导用户显式 init 对齐。 */
|
|
94
|
+
declare function versionDriftHint(outcome: AssemblyOutcome, profile: ProfileName): string | null;
|
|
95
|
+
interface AssemblyHintOptions {
|
|
96
|
+
/** init 已执行显式重装时置 false,避免继续提示“运行 init 升级”。 */
|
|
97
|
+
includeVersionDrift?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** 统一装配提示(init / 四启动命令共用;doctor 用自身明细;展示层纯函数,零写入)。 */
|
|
100
|
+
declare function assemblyHint(outcome: AssemblyOutcome, profile: ProfileName, options?: AssemblyHintOptions): string[];
|
|
69
101
|
//#endregion
|
|
70
102
|
//#region src/dsh.d.ts
|
|
71
103
|
/** dsh bin 入口(lib/bin.js)绝对路径。 */
|
|
@@ -95,4 +127,4 @@ interface DshRunResult {
|
|
|
95
127
|
/** spawn dsh;env 映射 TBOXCODE_DSH_HOME → DSH_HOME 并关遥测(CI / 测试确定性)。 */
|
|
96
128
|
declare function runDsh(options: DshRunOptions): Promise<DshRunResult>;
|
|
97
129
|
//#endregion
|
|
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 };
|
|
130
|
+
export { type AssemblyAction, type AssemblyCheck, type AssemblyHintOptions, type AssemblyOutcome, type AssemblyStatus, type DshRunOptions, type DshRunResult, type EnsureOptions, type HealOptions, OWN_PROFILES, PACKAGE_NAME, PROFILE_CHAINS, PROFILE_CLEANUP_ROWS, PROFILE_OFFICIAL_ROWS, type ProfileName, type ProfileRules, assemblyHint, checkAssembly, ensureAssembly, profileDir, resolveDshEntry, resolveDshHome, runDsh, versionDriftHint };
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as e,d as t,f as n,g as r,h as i,i as a,l as o,m as s,n as c,o as l,r as u,t as d,u as f}from"./assembly-CxMZLSKV.js";export{d as OWN_PROFILES,r as PACKAGE_NAME,c as PROFILE_CHAINS,u as PROFILE_CLEANUP_ROWS,a as PROFILE_OFFICIAL_ROWS,e as assemblyHint,l as checkAssembly,o as ensureAssembly,f as profileDir,s as resolveDshEntry,t as resolveDshHome,i as runDsh,n as versionDriftHint};
|
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.14",
|
|
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",
|
|
@@ -17,14 +17,17 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"lib"
|
|
19
19
|
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=24.9.0"
|
|
22
|
+
},
|
|
20
23
|
"dependencies": {
|
|
21
|
-
"@deepseek-ai/dsh": "0.2.
|
|
22
|
-
"@deepseek-ai/dsh-atomic-write": "0.2.
|
|
24
|
+
"@deepseek-ai/dsh": "0.2.2-rc.1",
|
|
25
|
+
"@deepseek-ai/dsh-atomic-write": "0.2.2-rc.1",
|
|
23
26
|
"yaml": "^2.8.0",
|
|
24
|
-
"@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.
|
|
27
|
+
"@tbox.cn/tboxcode-dsh-runtime": "0.1.0-rc.14"
|
|
25
28
|
},
|
|
26
29
|
"devDependencies": {
|
|
27
|
-
"@deepseek-ai/dsh-llm-mock-server": "0.2.
|
|
30
|
+
"@deepseek-ai/dsh-llm-mock-server": "0.2.2-rc.1"
|
|
28
31
|
},
|
|
29
32
|
"scripts": {
|
|
30
33
|
"build": "tsdown",
|
package/lib/assembly-ZFOXMi7d.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=`@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};
|