@tbox.cn/tboxcode-dsh-runtime 0.1.0-rc.16 → 0.1.0-rc.17
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/lib/index.d.ts +3 -2
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -54,8 +54,9 @@ declare function configFilePath(configDir: string, name: string): string;
|
|
|
54
54
|
* 比例制——语义异构不硬译)/ subagent.max_parallel(dsh 无 per-tool 并发
|
|
55
55
|
* 上限——契约既定)
|
|
56
56
|
* - 自读域 passthrough:翻译器零消费、插件自读(provider 域 / effort /
|
|
57
|
-
* trait_presets / llm_log / retention /
|
|
58
|
-
*
|
|
57
|
+
* trait_presets / llm_log / retention / skills / permission / title /
|
|
58
|
+
* interaction 等)——快照进 Translation 供对账;`system_prompt` / `rules`
|
|
59
|
+
* 已退役,只出 warning,不进 passthrough
|
|
59
60
|
*
|
|
60
61
|
* 密钥铁律:翻译输出永不含密钥材料——行值与 passthrough 过扫描器(模式表:
|
|
61
62
|
* sk- 前缀 / AWS AKIA / Bearer 头 / api_key 键面),命中即明错(invariant:
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import{existsSync as e,readFileSync as t,statSync as n,watch as r}from"node:fs";import{homedir as i,tmpdir as a}from"node:os";import{join as o}from"node:path";import{mkdtemp as s,rm as c,writeFile as l}from"node:fs/promises";import{stringify as u}from"yaml";function d(){return process.env.TBOXCODE_DSH_CONFIG_DIR??o(i(),`.config`,`tboxcode-dsh`)}function f(t=d()){for(let n of[`config.jsonc`,`config.json`]){let r=o(t,n);if(e(r))return r}return null}function p(e){let t=``,n=0,r=e.length,i=!1;for(;n<r;){let a=e[n];if(i){if(t+=a,a===`\\`){n+1<r&&(t+=e[n+1]),n+=2;continue}a===`"`&&(i=!1),n++;continue}if(a===`"`){i=!0,t+=a,n++;continue}if(a===`/`&&e[n+1]===`/`){for(;n<r&&e[n]!==`
|
|
2
|
-
`;)n++;continue}if(a===`/`&&e[n+1]===`*`){for(n+=2;n<r&&!(e[n]===`*`&&e[n+1]===`/`);)n++;n+=2;continue}t+=a,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function m(e,t=new WeakSet){if(typeof e==`string`)return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>{let n=process.env[t];return n===void 0?e:n});if(Array.isArray(e))return e.map(e=>m(e,t));if(typeof e==`object`&&e){let n=e;if(t.has(n))return e;t.add(n);let r={};for(let[e,i]of Object.entries(n))r[e]=m(i,t);return t.delete(n),r}return e}function h(e=d()){let n=f(e);if(n===null)return{path:null,config:{}};let r=t(n,`utf-8`);try{let e=JSON.parse(p(r));if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`config 顶层必须是对象`);return{path:n,config:m(e)}}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`config 解析失败(${n}):${t}`)}}function g(e,t,i,a=500){let s=new Set(t),c,l=!1,u=()=>{c!==void 0&&clearTimeout(c),c=setTimeout(()=>{l||i()},a)},d=()=>{let t=[];for(let r of s)try{let i=n(o(e,r));t.push(`${r}:${i.mtimeMs}:${i.size}:${i.ino}`)}catch{t.push(`${r}:-`)}return t.join(`|`)},f=d(),p=setInterval(()=>{if(l)return;let e=d();e!==f&&(f=e,u())},1e3);p.unref?.();let m;try{m=r(e,{persistent:!1},(e,t)=>{t!==null&&!s.has(t)||u()})}catch{return clearInterval(p),{dispose:()=>{l=!0,clearInterval(p)}}}return m.on(`error`,()=>{}),{dispose:()=>{l=!0,clearInterval(p),c!==void 0&&clearTimeout(c),m.close()}}}function _(e,t){return o(e,t)}const v=`agent-default-model`,y=`@deepseek-ai/dsh-agent-default-model`,b=`agent-preset-registry`,x=`@deepseek-ai/dsh-agent-preset-registry`,S=`standard`,C=[`ptc`,`standard`],w=[`standard`,`ptc`,`minimal`,`cordis`];var T=class extends Error{code=`MODEL_NOT_SET`;constructor(e,t){let n=t?e:`${e}(配置文件尚不存在)`;super(`tboxcode: config 未设置 model——spawn 拒绝(fail fast,跨形态一致)。base 默认行指向 deepseek-official 专有 provider,本栈禁用该行族,静默回落即首请求失败(决策:default-model-row-mapping 未设明错)。请在 ${n} 的 config.jsonc 设置 model: "<provider>/<model>",或运行 tboxcode-dsh init --config 生成配置骨架。`),this.name=`ModelNotSetError`}},E=class extends Error{code=`MODEL_MALFORMED`;constructor(e){super(`tboxcode: config model 形态非法(${JSON.stringify(e)})——须为 "<provider>/<model>" 两段式`),this.name=`ModelMalformedError`}};const D=`tool-skill`,O=`tboxcode-webfetch`,k=`tboxcode-pre-execute`;var A=class extends Error{code=`SECRET_IN_TRANSLATION`;constructor(e){super(`tboxcode: 翻译输出疑似密钥材料(${e})——翻译输出永不含密钥(契约密钥铁律)。凭据三来源:auth.jsonc / provider.options.apiKey 值内 \${VAR} / reload 旁路;若 \${VAR} 引用的 env 值本身是密钥,请改走 auth.jsonc(0600)。`),this.name=`SecretInTranslationError`}};const j=[/api[_-]?key/i,/secret/i,/password/i,/authorization/i,/private[_-]?key/i],M=[/\bsk-[A-Za-z0-9]{16,}/,/\bAKIA[A-Z0-9]{16}\b/,/Bearer\s+[A-Za-z0-9._-]{24,}/];function N(e,t,n=new WeakSet){if(typeof e==`string`){for(let n of M)if(n.test(e))throw new A(`${t}: 值命中密钥模式 ${n.source}`);return}if(Array.isArray(e)){for(let r of e)N(r,t,n);return}if(typeof e==`object`&&e){if(n.has(e))return;n.add(e);for(let[r,i]of Object.entries(e)){if(j.some(e=>e.test(r))&&typeof i==`string`&&i.length>0)throw new A(`${t}: 键 ${r} 携带疑似凭据面(凭据归 auth.jsonc / \${VAR} 值引用)`);N(i,`${t}.${r}`,n)}}}function P(e,t){if(typeof e!=`string`)throw new E(`${t}=${JSON.stringify(e)}`.slice(0,120));let n=e.indexOf(`/`),r=n>0?e.slice(0,n):``,i=n>0?e.slice(n+1):``;if(r.length===0||i.length===0)throw new E(`${t}=${JSON.stringify(e)}`.slice(0,120));return{provider:r,model:i}}function F(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:void 0}function I(e,t,n){if(typeof e!=`string`||e.trim()===``)return n.push({field:`agent_preset`,reason:`非字符串或空串——回退 ${S}`}),S;let r=e.trim();return(t===`acp`||t===`headless`)&&!C.includes(r)?(n.push({field:`agent_preset`,reason:`取值不受 ${t} profile 支持(支持:${C.join(` / `)})——回退 ${S}`}),S):r}function L(e,t,n,r={}){let i=e.model;if(i==null||i===``)throw new T(t,n);let a=P(i,`model`),o=[],s=[];o.push({id:v,name:y,config:{provider:a.provider,model:a.model}});let c=e.agent_preset;if(c!==void 0){let e=I(c,r.profile??`server`,s);r.includeAgentPreset!==!1&&o.push({id:b,name:x,config:{default:e}})}let l=e.tools?.output;if(l!==void 0&&typeof l==`object`){let e=F(l.max_lines),t=F(l.max_bytes);if(e===void 0&&l.max_lines!==void 0&&s.push({field:`tools.output.max_lines`,reason:`非正整数——跳过`}),t===void 0&&l.max_bytes!==void 0&&s.push({field:`tools.output.max_bytes`,reason:`非正整数——跳过`}),e!==void 0||t!==void 0){let n={};e!==void 0&&(n.maxLines=e),t!==void 0&&(n.maxBytes=t),o.push({id:O,name:`@tbox.cn/tboxcode-dsh-tools/webfetch`,config:n})}}let u=e.permission,d=e.security,f=d?.denyPaths??e.denyPaths,p=Array.isArray(f)?f.filter(e=>typeof e==`string`&&e.trim().length>0):void 0,m=d?.mcpDenyPatterns??e.mcpDenyPatterns,h=Array.isArray(m)?m.filter(e=>typeof e==`string`&&e.length>0):void 0;(u!==void 0||p!==void 0||h!==void 0)&&o.push({id:k,name:`@tbox.cn/tboxcode-dsh-tools/pre-execute`,config:{...u===void 0?{}:{permission:u},...p===void 0?{}:{denyPaths:p},...h===void 0?{}:{mcpDenyPatterns:h}}});let g=e.auto_commit;typeof g==`object`&&g&&!Array.isArray(g)&&o.push({id:`tboxcode-auto-commit`,name:`@tbox.cn/tboxcode-dsh-tools/auto-commit`,config:g}),o.push({id:D,name:`@deepseek-ai/dsh-tool-skill`,config:{catalogDescriptionMaxLength:1024}}),e.bash!==void 0&&s.push({field:`bash`,reason:`dsh tool-bash Config 无超时面(enableRunInBackground/promoteOnTimeout),shell spec timeoutMs 是调用面非行 config——无等价翻译面,跳过`}),e.watchdog!==void 0&&s.push({field:`watchdog`,reason:`dsh timeout-policy 零 Config(声明制 timeoutMs 归工具定义硬编码)——turn 级 idle 超时无对位,跳过(近似对位非同构的落点修正)`}),e.compaction!==void 0&&s.push({field:`compaction`,reason:`dsh compaction-basic 是字符阈值制(thresholdChars),基线是上下文比例制(threshold ≤1)——语义异构不硬译,跳过`}),e.subagent!==void 0&&s.push({field:`subagent.max_parallel`,reason:`dsh 无 per-tool 并发上限可翻译(契约既定 warn + skip)`}),e.small_model!==void 0&&s.push({field:`small_model`,reason:`键已退役(subagent-native-adoption——0.2.1 原生采纳,委派模型路由归 modelSelection/modelDiscovery 或 agent_preset),值被忽略`}),e.agents!==void 0&&s.push({field:`agents`,reason:`键已退役(subagent-native-adoption——0.2.1 类型面弃用,委派全链原生单实例),值被忽略`});let _={};for(let t of[`workspace`,`media_policy`,`auto_commit`,`security`,`attachments`,`provider`,`enabled_providers`,`disabled_providers`,`effort`,`effort_templates`,`trait_presets`,`llm_log`,`retention`,`
|
|
2
|
+
`;)n++;continue}if(a===`/`&&e[n+1]===`*`){for(n+=2;n<r&&!(e[n]===`*`&&e[n+1]===`/`);)n++;n+=2;continue}t+=a,n++}return t.replace(/,(\s*[}\]])/g,`$1`)}function m(e,t=new WeakSet){if(typeof e==`string`)return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,t)=>{let n=process.env[t];return n===void 0?e:n});if(Array.isArray(e))return e.map(e=>m(e,t));if(typeof e==`object`&&e){let n=e;if(t.has(n))return e;t.add(n);let r={};for(let[e,i]of Object.entries(n))r[e]=m(i,t);return t.delete(n),r}return e}function h(e=d()){let n=f(e);if(n===null)return{path:null,config:{}};let r=t(n,`utf-8`);try{let e=JSON.parse(p(r));if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`config 顶层必须是对象`);return{path:n,config:m(e)}}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`config 解析失败(${n}):${t}`)}}function g(e,t,i,a=500){let s=new Set(t),c,l=!1,u=()=>{c!==void 0&&clearTimeout(c),c=setTimeout(()=>{l||i()},a)},d=()=>{let t=[];for(let r of s)try{let i=n(o(e,r));t.push(`${r}:${i.mtimeMs}:${i.size}:${i.ino}`)}catch{t.push(`${r}:-`)}return t.join(`|`)},f=d(),p=setInterval(()=>{if(l)return;let e=d();e!==f&&(f=e,u())},1e3);p.unref?.();let m;try{m=r(e,{persistent:!1},(e,t)=>{t!==null&&!s.has(t)||u()})}catch{return clearInterval(p),{dispose:()=>{l=!0,clearInterval(p)}}}return m.on(`error`,()=>{}),{dispose:()=>{l=!0,clearInterval(p),c!==void 0&&clearTimeout(c),m.close()}}}function _(e,t){return o(e,t)}const v=`agent-default-model`,y=`@deepseek-ai/dsh-agent-default-model`,b=`agent-preset-registry`,x=`@deepseek-ai/dsh-agent-preset-registry`,S=`standard`,C=[`ptc`,`standard`],w=[`standard`,`ptc`,`minimal`,`cordis`];var T=class extends Error{code=`MODEL_NOT_SET`;constructor(e,t){let n=t?e:`${e}(配置文件尚不存在)`;super(`tboxcode: config 未设置 model——spawn 拒绝(fail fast,跨形态一致)。base 默认行指向 deepseek-official 专有 provider,本栈禁用该行族,静默回落即首请求失败(决策:default-model-row-mapping 未设明错)。请在 ${n} 的 config.jsonc 设置 model: "<provider>/<model>",或运行 tboxcode-dsh init --config 生成配置骨架。`),this.name=`ModelNotSetError`}},E=class extends Error{code=`MODEL_MALFORMED`;constructor(e){super(`tboxcode: config model 形态非法(${JSON.stringify(e)})——须为 "<provider>/<model>" 两段式`),this.name=`ModelMalformedError`}};const D=`tool-skill`,O=`tboxcode-webfetch`,k=`tboxcode-pre-execute`;var A=class extends Error{code=`SECRET_IN_TRANSLATION`;constructor(e){super(`tboxcode: 翻译输出疑似密钥材料(${e})——翻译输出永不含密钥(契约密钥铁律)。凭据三来源:auth.jsonc / provider.options.apiKey 值内 \${VAR} / reload 旁路;若 \${VAR} 引用的 env 值本身是密钥,请改走 auth.jsonc(0600)。`),this.name=`SecretInTranslationError`}};const j=[/api[_-]?key/i,/secret/i,/password/i,/authorization/i,/private[_-]?key/i],M=[/\bsk-[A-Za-z0-9]{16,}/,/\bAKIA[A-Z0-9]{16}\b/,/Bearer\s+[A-Za-z0-9._-]{24,}/];function N(e,t,n=new WeakSet){if(typeof e==`string`){for(let n of M)if(n.test(e))throw new A(`${t}: 值命中密钥模式 ${n.source}`);return}if(Array.isArray(e)){for(let r of e)N(r,t,n);return}if(typeof e==`object`&&e){if(n.has(e))return;n.add(e);for(let[r,i]of Object.entries(e)){if(j.some(e=>e.test(r))&&typeof i==`string`&&i.length>0)throw new A(`${t}: 键 ${r} 携带疑似凭据面(凭据归 auth.jsonc / \${VAR} 值引用)`);N(i,`${t}.${r}`,n)}}}function P(e,t){if(typeof e!=`string`)throw new E(`${t}=${JSON.stringify(e)}`.slice(0,120));let n=e.indexOf(`/`),r=n>0?e.slice(0,n):``,i=n>0?e.slice(n+1):``;if(r.length===0||i.length===0)throw new E(`${t}=${JSON.stringify(e)}`.slice(0,120));return{provider:r,model:i}}function F(e){return typeof e==`number`&&Number.isInteger(e)&&e>0?e:void 0}function I(e,t,n){if(typeof e!=`string`||e.trim()===``)return n.push({field:`agent_preset`,reason:`非字符串或空串——回退 ${S}`}),S;let r=e.trim();return(t===`acp`||t===`headless`)&&!C.includes(r)?(n.push({field:`agent_preset`,reason:`取值不受 ${t} profile 支持(支持:${C.join(` / `)})——回退 ${S}`}),S):r}function L(e,t,n,r={}){let i=e.model;if(i==null||i===``)throw new T(t,n);let a=P(i,`model`),o=[],s=[];o.push({id:v,name:y,config:{provider:a.provider,model:a.model}});let c=e.agent_preset;if(c!==void 0){let e=I(c,r.profile??`server`,s);r.includeAgentPreset!==!1&&o.push({id:b,name:x,config:{default:e}})}let l=e.tools?.output;if(l!==void 0&&typeof l==`object`){let e=F(l.max_lines),t=F(l.max_bytes);if(e===void 0&&l.max_lines!==void 0&&s.push({field:`tools.output.max_lines`,reason:`非正整数——跳过`}),t===void 0&&l.max_bytes!==void 0&&s.push({field:`tools.output.max_bytes`,reason:`非正整数——跳过`}),e!==void 0||t!==void 0){let n={};e!==void 0&&(n.maxLines=e),t!==void 0&&(n.maxBytes=t),o.push({id:O,name:`@tbox.cn/tboxcode-dsh-tools/webfetch`,config:n})}}let u=e.permission,d=e.security,f=d?.denyPaths??e.denyPaths,p=Array.isArray(f)?f.filter(e=>typeof e==`string`&&e.trim().length>0):void 0,m=d?.mcpDenyPatterns??e.mcpDenyPatterns,h=Array.isArray(m)?m.filter(e=>typeof e==`string`&&e.length>0):void 0;(u!==void 0||p!==void 0||h!==void 0)&&o.push({id:k,name:`@tbox.cn/tboxcode-dsh-tools/pre-execute`,config:{...u===void 0?{}:{permission:u},...p===void 0?{}:{denyPaths:p},...h===void 0?{}:{mcpDenyPatterns:h}}});let g=e.auto_commit;typeof g==`object`&&g&&!Array.isArray(g)&&o.push({id:`tboxcode-auto-commit`,name:`@tbox.cn/tboxcode-dsh-tools/auto-commit`,config:g}),o.push({id:D,name:`@deepseek-ai/dsh-tool-skill`,config:{catalogDescriptionMaxLength:1024}}),e.bash!==void 0&&s.push({field:`bash`,reason:`dsh tool-bash Config 无超时面(enableRunInBackground/promoteOnTimeout),shell spec timeoutMs 是调用面非行 config——无等价翻译面,跳过`}),e.watchdog!==void 0&&s.push({field:`watchdog`,reason:`dsh timeout-policy 零 Config(声明制 timeoutMs 归工具定义硬编码)——turn 级 idle 超时无对位,跳过(近似对位非同构的落点修正)`}),e.compaction!==void 0&&s.push({field:`compaction`,reason:`dsh compaction-basic 是字符阈值制(thresholdChars),基线是上下文比例制(threshold ≤1)——语义异构不硬译,跳过`}),e.subagent!==void 0&&s.push({field:`subagent.max_parallel`,reason:`dsh 无 per-tool 并发上限可翻译(契约既定 warn + skip)`}),e.small_model!==void 0&&s.push({field:`small_model`,reason:`键已退役(subagent-native-adoption——0.2.1 原生采纳,委派模型路由归 modelSelection/modelDiscovery 或 agent_preset),值被忽略`}),e.agents!==void 0&&s.push({field:`agents`,reason:`键已退役(subagent-native-adoption——0.2.1 类型面弃用,委派全链原生单实例),值被忽略`}),e.system_prompt!==void 0&&s.push({field:`system_prompt`,reason:`键已退役(native-prompt-reset——config.jsonc 路径此前未接入插件,值未生效);改用 preset persona 或 identity.persona`}),e.rules!==void 0&&s.push({field:`rules`,reason:`键已退役(native-prompt-reset)——迁移到 $DSH_HOME/AGENTS.md 或项目 AGENTS.md`});let _={};for(let t of[`workspace`,`media_policy`,`auto_commit`,`security`,`attachments`,`provider`,`enabled_providers`,`disabled_providers`,`effort`,`effort_templates`,`trait_presets`,`llm_log`,`retention`,`skills`,`permission`,`title`,`interaction`,`env`])e[t]!==void 0&&(_[t]=e[t]);return N(o,`rows`),{rows:o,passthrough:_,warnings:s}}const R=new Set([`agent-default-model`,`tool-skill`,`tboxcode-webfetch`]),z=new Set([...R,`agent-preset-registry`]);function B(e){let t=e.filter(e=>z.has(e.id)),n=e.filter(e=>!z.has(e.id)),r=t.map(e=>({...e}));return n.length>0&&r.push({insert:n.map(e=>({...e}))}),r}async function V(e){let t=await s(o(a(),`tboxcode-overlay-`)),n=o(t,`tboxcode-overlay.yml`);return await l(n,u(B(e),{lineWidth:0}),`utf-8`),{path:n,dispose:async()=>{await c(t,{recursive:!0,force:!0})}}}export{y as AGENT_DEFAULT_MODEL_PLUGIN,v as AGENT_DEFAULT_MODEL_ROW_ID,x as AGENT_PRESET_PLUGIN,b as AGENT_PRESET_ROW_ID,C as CORE_AGENT_PRESETS,S as DEFAULT_AGENT_PRESET,R as LIVE_OVERLAY_ROW_IDS,E as ModelMalformedError,T as ModelNotSetError,z as OVERLAY_ROW_IDS,w as SERVER_AGENT_PRESETS,A as SecretInTranslationError,k as TOOL_PRE_EXECUTE_ROW_ID,D as TOOL_SKILL_ROW_ID,O as TOOL_WEBFETCH_ROW_ID,_ as configFilePath,m as interpolateEnv,h as loadConfig,d as resolveConfigDir,f as resolveConfigPath,B as rowsToPatchElements,p as stripJsonc,L as translateConfig,g as watchConfigFiles,V as writeOverlayPatch};
|