@tbox.cn/tboxcode-dsh-runtime 0.1.0-rc.13 → 0.1.0-rc.15
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 +22 -2
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -71,6 +71,20 @@ declare function configFilePath(configDir: string, name: string): string;
|
|
|
71
71
|
/** base 行 id 与插件名——同 id 覆盖必须 name 匹配(dsh patch 覆盖语义:name 非空时不匹配即跳过并 warn)。 */
|
|
72
72
|
declare const AGENT_DEFAULT_MODEL_ROW_ID = "agent-default-model";
|
|
73
73
|
declare const AGENT_DEFAULT_MODEL_PLUGIN = "@deepseek-ai/dsh-agent-default-model";
|
|
74
|
+
/** agent preset registry 行 id / 插件名(bundle 静态 default 与 config overlay 共用)。 */
|
|
75
|
+
declare const AGENT_PRESET_ROW_ID = "agent-preset-registry";
|
|
76
|
+
declare const AGENT_PRESET_PLUGIN = "@deepseek-ai/dsh-agent-preset-registry";
|
|
77
|
+
declare const DEFAULT_AGENT_PRESET = "standard";
|
|
78
|
+
declare const CORE_AGENT_PRESETS: readonly ["ptc", "standard"];
|
|
79
|
+
/** server/web 官方四树;当前允许自定义 id 透传,故仅作文档/未来校验常量。 */
|
|
80
|
+
declare const SERVER_AGENT_PRESETS: readonly ["standard", "ptc", "minimal", "cordis"];
|
|
81
|
+
type AgentPresetProfile = 'acp' | 'server' | 'web' | 'headless';
|
|
82
|
+
interface TranslateOptions {
|
|
83
|
+
/** profile 决定 agent_preset 支持集(acp/headless 仅 ptc/standard)。 */
|
|
84
|
+
profile?: AgentPresetProfile;
|
|
85
|
+
/** 收敛环 startup-only:false 时校验但仍不发射 registry 行。 */
|
|
86
|
+
includeAgentPreset?: boolean;
|
|
87
|
+
}
|
|
74
88
|
/** 明错类型:config 未设置 model(spawn 前置 fail fast)。 */
|
|
75
89
|
declare class ModelNotSetError extends Error {
|
|
76
90
|
readonly code = "MODEL_NOT_SET";
|
|
@@ -116,7 +130,7 @@ declare class SecretInTranslationError extends Error {
|
|
|
116
130
|
* model 缺失仍为明错(default-model-row-mapping:spawn 前置 fail fast 跨形态一致);
|
|
117
131
|
* 其余字段级问题走 warnings(warn + skip 单字段隔离)。
|
|
118
132
|
*/
|
|
119
|
-
declare function translateConfig(config: Record<string, unknown>, configDir: string, hasFile: boolean): Translation;
|
|
133
|
+
declare function translateConfig(config: Record<string, unknown>, configDir: string, hasFile: boolean, options?: TranslateOptions): Translation;
|
|
120
134
|
//#endregion
|
|
121
135
|
//#region src/patch.d.ts
|
|
122
136
|
/**
|
|
@@ -125,6 +139,12 @@ declare function translateConfig(config: Record<string, unknown>, configDir: str
|
|
|
125
139
|
* 语义。收敛环(bundle/convergence)与 overlay 序列化共用同一推导——两通道形态
|
|
126
140
|
* 必须一致。
|
|
127
141
|
*/
|
|
142
|
+
declare const LIVE_OVERLAY_ROW_IDS: ReadonlySet<string>;
|
|
143
|
+
/**
|
|
144
|
+
* 覆盖行 id 闭集(裸行交付)。agent-preset-registry 是 startup-only 覆盖行:
|
|
145
|
+
* 序列化走裸行,但收敛环不得把它当作可热替换行移除(否则 config 的
|
|
146
|
+
* agent_preset 覆盖会在首次收敛 apply 后丢失,回落到 bundle default)。
|
|
147
|
+
*/
|
|
128
148
|
declare const OVERLAY_ROW_IDS: ReadonlySet<string>;
|
|
129
149
|
/**
|
|
130
150
|
* 翻译行 → patch 元素:覆盖行裸交付(同 id 覆盖 later-wins);新增行包 insert
|
|
@@ -140,4 +160,4 @@ interface OverlayPatch {
|
|
|
140
160
|
/** 单文件 overlay,其数组全体即我方行集(识别规则免配置——config-translation-contract overlay 行规则)。 */
|
|
141
161
|
declare function writeOverlayPatch(rows: PatchRow[]): Promise<OverlayPatch>;
|
|
142
162
|
//#endregion
|
|
143
|
-
export { AGENT_DEFAULT_MODEL_PLUGIN, AGENT_DEFAULT_MODEL_ROW_ID, type ConfigWatchHandle, type LoadedConfig, ModelMalformedError, ModelNotSetError, OVERLAY_ROW_IDS, type OverlayPatch, type PatchRow, SecretInTranslationError, TOOL_PRE_EXECUTE_ROW_ID, TOOL_SKILL_ROW_ID, TOOL_WEBFETCH_ROW_ID, type Translation, type TranslationWarning, configFilePath, interpolateEnv, loadConfig, resolveConfigDir, resolveConfigPath, rowsToPatchElements, stripJsonc, translateConfig, watchConfigFiles, writeOverlayPatch };
|
|
163
|
+
export { AGENT_DEFAULT_MODEL_PLUGIN, AGENT_DEFAULT_MODEL_ROW_ID, AGENT_PRESET_PLUGIN, AGENT_PRESET_ROW_ID, type AgentPresetProfile, CORE_AGENT_PRESETS, type ConfigWatchHandle, DEFAULT_AGENT_PRESET, LIVE_OVERLAY_ROW_IDS, type LoadedConfig, ModelMalformedError, ModelNotSetError, OVERLAY_ROW_IDS, type OverlayPatch, type PatchRow, SERVER_AGENT_PRESETS, SecretInTranslationError, TOOL_PRE_EXECUTE_ROW_ID, TOOL_SKILL_ROW_ID, TOOL_WEBFETCH_ROW_ID, type TranslateOptions, type Translation, type TranslationWarning, configFilePath, interpolateEnv, loadConfig, resolveConfigDir, resolveConfigPath, rowsToPatchElements, stripJsonc, translateConfig, watchConfigFiles, writeOverlayPatch };
|
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
|
|
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`,`system_prompt`,`rules`,`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};
|