dsh-context 0.72.0 → 0.73.0
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 +4 -0
- package/lib/client.js +11 -11
- package/lib/index.js +4 -4
- package/package.json +5 -4
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-context v0.
|
|
2
|
+
* dsh-context v0.73.0
|
|
3
3
|
* A DeepSeek Harness plugin for context insight and management, with context dashboard and context command, for understanding how the context is made of, and how it evolves.
|
|
4
4
|
* @author bowenliang123
|
|
5
5
|
* @license Apache-2.0
|
|
6
6
|
* @homepage https://github.com/bowenliang123/dsh-context
|
|
7
|
-
* @built 2026-10-
|
|
8
|
-
* @commit
|
|
9
|
-
* @commit-date 2026-10-
|
|
7
|
+
* @built 2026-10-17T01:50:26+00:00
|
|
8
|
+
* @commit 0103b07747c4
|
|
9
|
+
* @commit-date 2026-10-17T09:48:22+08:00
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import{createRequire as e}from"node:module";import{z as t}from"zod";import{deriveEventMessage as n,interruptedTurnClosers as r}from"@deepseek-ai/dsh-session";import i from"@deepseek-ai/schemastery";import{copyFile as a,link as o,mkdir as s}from"node:fs/promises";import{basename as c,dirname as l,isAbsolute as u,join as d,normalize as f,relative as p}from"node:path";import{getHeapStatistics as m}from"node:v8";import{existsSync as h,readFileSync as ee}from"node:fs";import{fileURLToPath as g}from"node:url";import{performance as te}from"node:perf_hooks";import{randomUUID as ne}from"node:crypto";function re(e){return typeof e!=`string`||e.length===0?0:Math.ceil(e.length/4)+4}function ie(e){return Math.ceil(e.length/4)+4}function ae(e){if(!Array.isArray(e)||e.length===0)return 0;let t=0;for(let n of e){let e=typeof n==`object`&&n&&n.type===`text`?n.text:void 0;if(typeof e==`string`){t+=e.length;continue}try{let e=JSON.stringify(n);typeof e==`string`&&(t+=e.length)}catch{}}return Math.ceil(t/4)+4}const oe=147456,_=(e,t)=>Math.floor(e/t),v=(e,t)=>Math.floor((e+t-1)/t);function se(e,t){let n=e*(t+1)+2;return e%2==1&&(n+=t+1),n+=v(e,2)*(t+1)%2*2,n}function ce(e,t,n){let r=e/t,i=Math.sqrt((n-2)/r+.25)-.5,a=i*r,o,s;if(i<1){let e=_(n-2,2);e%2==1&&--e,s=42,o=e*42}else if(a<2){let e=_(n-2,2)-1;if(e<=1)throw Error(`image tokens: budget too small to solve`);o=84,s=e*42}else{let n=Math.trunc(i),r=Math.trunc(a);r%2==1&&--r;let c=Math.min(n*42/t,r*42/e);s=Math.trunc(t*c/14)*14,o=Math.trunc(e*c/14)*14}let c=v(_(o,14),3),l=v(_(s,14),3);return{nLlmH:c,nLlmW:l,bestHeight:o,bestWidth:s,numTokens:se(c,l)}}function le(e,t,n,r){let i=v(_(n,14),3),a=v(_(r,14),3),o={nLlmH:i,nLlmW:a,bestHeight:n,bestWidth:r,numTokens:se(i,a)};if(o.numTokens>381){o=ce(e,t,381);let n=381;for(;o.numTokens>381;)--n,o=ce(e,t,n)}return o.numTokens+=3,o}function ue(e,t){let n=e,r=t;n>r*8&&(n=r*8);let i=n*r;if(i<oe&&i>0){let e=Math.sqrt(oe/i);n=Math.trunc(n*e),r=Math.trunc(r*e)}let a=v(n,14)*14,o=v(r,14)*14;return le(r,n,o,a)}function de(e,t){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return null;try{let n=ue(e,t);for(let e=1;e<10;e++){let e=ue(n.bestWidth,n.bestHeight);if(e.nLlmH===n.nLlmH&&e.nLlmW===n.nLlmW&&e.bestHeight===n.bestHeight&&e.bestWidth===n.bestWidth&&e.numTokens===n.numTokens)return n.numTokens;n=e}return null}catch{return null}}function fe(e){return e.length>0?Math.ceil(JSON.stringify(e).length/4)+4:0}function pe(e){let t=0;if(!Array.isArray(e))return 0;for(let n of e){if(typeof n!=`object`||!n){t+=4;continue}let e=n;switch(e.type){case`text`:case`reasoning`:t+=ie(e.text||``);break;case`tool-call`:t+=Math.ceil((e.name||``).length/4)+Math.ceil((e.arguments||``).length/4)+4;break;case`image`:{let n=e.attachment,r=typeof n==`object`&&n&&typeof n.width==`number`&&typeof n.height==`number`?de(n.width,n.height):null;t+=(r??Math.ceil(JSON.stringify(e).length/4))+4;break}default:t+=4+Math.ceil(JSON.stringify(e).length/4)}}return t}function me(e,t=!1){return t&&(e==null||!Array.isArray(e.content)||e.content.length===0)?0:pe(e?.content)+4}function he(e){return Math.ceil(JSON.stringify(e).length/4)+4}function ge(e){let t=0;if(!Array.isArray(e))return 0;for(let n of e){if(typeof n!=`object`||!n)continue;let e=n;e.type===`image`?t++:Array.isArray(e.content)&&(t+=ge(e.content))}return t}function y(e){if(!Array.isArray(e))return``;for(let t of e){if(typeof t!=`object`||!t)continue;let e=t;if(e.type===`text`&&typeof e.text==`string`&&e.text.trim()!==``)return e.text.replace(/\s+/g,` `).trim().slice(0,80)}return``}function _e(e){let t=[];if(!Array.isArray(e))return t;for(let n of e){if(typeof n!=`object`||!n)continue;let e=n;e.type===`tool-call`&&typeof e.name==`string`&&t.push(e.name)}return t}function ve(e){if(e?.kind===`agent-instructions`&&Array.isArray(e.changes)){let t=[];for(let n of e.changes){let e=n?.path;typeof e==`string`&&e!==``&&!t.includes(e)&&t.push(e)}if(t.length>0)return t.join(`, `)}let t=e?.plugin;if(typeof t==`string`&&t!==``)return t;let n=e?.kind;return typeof n==`string`&&n!==``?n:``}function ye(e){return e!=null&&(typeof e.kind==`string`&&e.kind!==``&&e.kind!==`user`||typeof e.form==`string`)}function be(e){if(typeof e!=`object`||!e)return!1;let t=e;switch(t.type){case`text-delta`:case`reasoning-delta`:return typeof t.text==`string`&&t.text!==``;case`tool-call-delta`:return typeof t.argumentsDelta==`string`&&t.argumentsDelta!==``||t.name!==void 0;default:return!1}}function xe(e){if(e===`reasoning`)return`reasoning`;if(e===`text`)return`text`;if(e===`tool-call`)return`toolarg`}function Se(e,t){let n={spans:{reasoning:0,text:0,toolarg:0},blocks:{reasoning:0,text:0,toolarg:0}};if(!Array.isArray(e)||!Number.isFinite(t))return n;let r,i=0;for(let t of e){if(typeof t!=`object`||!t)continue;let e=t;if(e.type!==`chunk`||e.chunk===null||typeof e.chunk!=`object`)continue;let a=e.chunk;if(a.type!==`block-start`)continue;let o=e.time;typeof o==`number`&&Number.isFinite(o)&&(r!==void 0&&(n.spans[r]+=Math.max(0,o-i)),r=xe(a.blockType),r!==void 0&&(n.blocks[r]+=1),i=o)}return r!==void 0&&(n.spans[r]+=Math.max(0,t-i)),n}function Ce(e,t){let n=[];if(!Array.isArray(e)||!Number.isFinite(t))return n;let r,i=0,a=e=>{r!==void 0&&e>i&&n.push({kind:r,start:i,end:e})};for(let t of e){if(typeof t!=`object`||!t)continue;let e=t;if(e.type!==`chunk`||e.chunk===null||typeof e.chunk!=`object`)continue;let n=e.chunk;if(n.type!==`block-start`)continue;let o=e.time;typeof o==`number`&&Number.isFinite(o)&&(a(o),r=xe(n.blockType),i=o)}return a(t),n}function we(e){let t=e.time0;if(typeof t!=`number`||!Number.isFinite(t))return;if(e.type===`tool-call-chunks`&&e.name!==void 0)return t;let n=e.type===`tool-call-chunks`?e.args:e.texts;if(!Array.isArray(n))return;let r=Array.isArray(e.dt)?e.dt:[],i=t;for(let[e,t]of n.entries()){if(e>0){let t=r[e-1];if(typeof t!=`number`||!Number.isFinite(t))return;i+=t}if(typeof t==`string`&&t!==``)return i}}function Te(e){if(Array.isArray(e))for(let t of e){if(typeof t!=`object`||!t)continue;let e=t;if(e.type===`chunk`){let t=e.time;if(typeof t==`number`&&Number.isFinite(t)&&be(e.chunk))return t;continue}let n=we(e);if(n!==void 0)return n}}function Ee(e){if(typeof e!=`object`||!e)return null;let t=e;if(t.op!==`replace`)return null;let{startSeq:n,endSeq:r}=t;return typeof n!=`number`||!Number.isFinite(n)||typeof r!=`number`||!Number.isFinite(r)?null:{start:n,end:r}}function De(e){if(typeof e!=`string`||e===``)return null;try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:null}catch{return null}}const Oe={read:`read`,read_image:`read`,write:`write`,edit:`write`,grep:`search`,glob:`search`};function ke(e){return e===void 0?null:Oe[e]??null}function Ae(e,t){return e===`str_replace_editor`?t!==null&&t.command===`view`?`read`:`write`:ke(e)}function b(e){return e===`str_replace_editor`||ke(e)!==null}function je(e){return b(e)||e===`run_code`}function Me(e,t){if(t===null)return null;if(e===`grep`||e===`glob`){let e=t.path;if(typeof e==`string`&&e!==``)return e;let n=t.pattern;return typeof n==`string`&&n!==``?n:null}for(let e of[`file_path`,`filePath`,`path`]){let n=t[e];if(typeof n==`string`&&n!==``)return n}return null}function Ne(e){if(e===``)return 0;let t=0;for(let n=0;n<e.length;n++)e[n]===`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.73.0",
|
|
4
4
|
"description": "A DeepSeek Harness plugin for context insight and management, with context dashboard and context command, for understanding how the context is made of, and how it evolves.",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"author": "bowenliang123",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"type": "module",
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": "^22.19.0 || >=24.0.0"
|
|
17
|
+
"node": "^22.19.0 || >=24.0.0",
|
|
18
|
+
"dsh": ">=0.1.7-rc.2 || >=0.2.0-rc.2"
|
|
18
19
|
},
|
|
19
20
|
"main": "lib/index.js",
|
|
20
21
|
"types": "lib/index.d.ts",
|
|
@@ -123,7 +124,7 @@
|
|
|
123
124
|
"@types/node": "^26.6.3",
|
|
124
125
|
"@types/react": "^18.3.31",
|
|
125
126
|
"@types/react-dom": "^18.3.7",
|
|
126
|
-
"@vitest/coverage-v8": "^
|
|
127
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
127
128
|
"anser": "^2.3.5",
|
|
128
129
|
"clsx": "^2.0.0",
|
|
129
130
|
"diff": "^9.0.0",
|
|
@@ -152,7 +153,7 @@
|
|
|
152
153
|
"simple-icons": "16.32.0",
|
|
153
154
|
"tsdown": "^0.23.0",
|
|
154
155
|
"typescript": "^7.0.2",
|
|
155
|
-
"vitest": "^
|
|
156
|
+
"vitest": "^5.0.5",
|
|
156
157
|
"zustand": "~4.4.7"
|
|
157
158
|
}
|
|
158
159
|
}
|