@hermenics/deepseek-code 0.2.1 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/cli.mjs +1 -1
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -1017,7 +1017,7 @@ ${f}`,w++}else Fe0(B,C,y)?O=B.slice(B.charCodeAt(C+6)===AX?C+7:C+6,I)||void 0:V(
1017
1017
  `,C),v=-1;if(I!==-1&&y!==-1?v=I<y?I:y:I!==-1?I===B.length-1?v=-1:v=I:y!==-1&&(v=y),v===-1)break;V(B,C,v),C=v+1,B.charCodeAt(C-1)===PW1&&B.charCodeAt(C)===Te0&&C++}return B.slice(C)}function V(B,C,I){if(C===I){_();return}let y=B.charCodeAt(C);if(_e0(B,C,y)){let K0=B.charCodeAt(C+5)===AX?C+6:C+5,c=B.slice(K0,I);H=w===0?c:`${H}
1018
1018
  ${c}`,w++;return}if(Fe0(B,C,y)){O=B.slice(B.charCodeAt(C+6)===AX?C+7:C+6,I)||void 0;return}if(y===105&&B.charCodeAt(C+1)===100&&B.charCodeAt(C+2)===58){let K0=B.slice(B.charCodeAt(C+3)===AX?C+4:C+3,I);W=K0.includes("\x00")?void 0:K0;return}if(y===58){if(J){let K0=B.slice(C,I);J(K0.slice(B.charCodeAt(C+1)===AX?2:1))}return}let v=B.slice(C,I),f=v.indexOf(":");if(f===-1){T(v,"",v);return}let m=v.slice(0,f),u=v.charCodeAt(f+1)===AX?2:1,g=v.slice(f+u);T(m,g,v)}function T(B,C,I){switch(B){case"event":O=C||void 0;break;case"data":H=w===0?C:`${H}
1019
1019
  ${C}`,w++;break;case"id":W=C.includes("\x00")?void 0:C;break;case"retry":/^\d+$/.test(C)?z(parseInt(C,10)):K(new N80(`Invalid \`retry\` value: "${C}"`,{type:"invalid-retry",value:C,line:I}));break;default:K(new N80(`Unknown field "${B.length>20?`${B.slice(0,20)}\u2026`:B}"`,{type:"unknown-field",field:B,value:C,line:I}));break}}function _(){w>0&&$({id:W,event:O,data:H}),W=void 0,H="",w=0,O=void 0}function F(B={}){if(B.consume&&q.length>0){let C=q.join("");V(C,0,C.length)}X=!0,W=void 0,H="",w=0,O=void 0,q.length=0}return{feed:N,reset:F}}function _e0(D,$,K){return K===100&&D.charCodeAt($+1)===97&&D.charCodeAt($+2)===116&&D.charCodeAt($+3)===97&&D.charCodeAt($+4)===58}function Fe0(D,$,K){return K===101&&D.charCodeAt($+1)===118&&D.charCodeAt($+2)===101&&D.charCodeAt($+3)===110&&D.charCodeAt($+4)===116&&D.charCodeAt($+5)===58}var N80,Te0=10,PW1=13,AX=32;var Be0=j(()=>{N80=class N80 extends Error{constructor(D,$){super(D),this.name="ParseError",this.type=$.type,this.field=$.field,this.value=$.value,this.line=$.line}}});var M80;var je0=j(()=>{Be0();M80=class M80 extends TransformStream{constructor({onError:D,onRetry:$,onComment:K}={}){let z;super({start(J){z=Ee0({onEvent:(q)=>{J.enqueue(q)},onError(q){D==="terminate"?J.error(q):typeof D=="function"&&D(q)},onRetry:$,onComment:K})},transform(J){z.feed(J)}})}}});class A80{constructor(D,$){this._hasCompletedAuthFlow=!1,this._url=D,this._resourceMetadataUrl=void 0,this._scope=void 0,this._requestInit=$?.requestInit,this._authProvider=$?.authProvider,this._fetch=$?.fetch,this._fetchWithInit=Ke0($?.fetch,$?.requestInit),this._sessionId=$?.sessionId,this._reconnectionOptions=$?.reconnectionOptions??LW1}async _authThenStart(){if(!this._authProvider)throw new Cq("No auth provider");let D;try{D=await fP(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})}catch($){throw this.onerror?.($),$}if(D!=="AUTHORIZED")throw new Cq;return await this._startOrAuthSse({resumptionToken:void 0})}async _commonHeaders(){let D={};if(this._authProvider){let K=await this._authProvider.tokens();if(K)D.Authorization=`Bearer ${K.access_token}`}if(this._sessionId)D["mcp-session-id"]=this._sessionId;if(this._protocolVersion)D["mcp-protocol-version"]=this._protocolVersion;let $=SI(this._requestInit?.headers);return new Headers({...D,...$})}async _startOrAuthSse(D){let{resumptionToken:$}=D;try{let K=await this._commonHeaders();if(K.set("Accept","text/event-stream"),$)K.set("last-event-id",$);let z=await(this._fetch??fetch)(this._url,{method:"GET",headers:K,signal:this._abortController?.signal});if(!z.ok){if(await z.body?.cancel(),z.status===401&&this._authProvider)return await this._authThenStart();if(z.status===405)return;throw new VX(z.status,`Failed to open SSE stream: ${z.statusText}`)}this._handleSseStream(z.body,D,!0)}catch(K){throw this.onerror?.(K),K}}_getNextReconnectionDelay(D){if(this._serverRetryMs!==void 0)return this._serverRetryMs;let $=this._reconnectionOptions.initialReconnectionDelay,K=this._reconnectionOptions.reconnectionDelayGrowFactor,z=this._reconnectionOptions.maxReconnectionDelay;return Math.min($*Math.pow(K,D),z)}_scheduleReconnection(D,$=0){let K=this._reconnectionOptions.maxRetries;if($>=K){this.onerror?.(Error(`Maximum reconnection attempts (${K}) exceeded.`));return}let z=this._getNextReconnectionDelay($);this._reconnectionTimeout=setTimeout(()=>{this._startOrAuthSse(D).catch((J)=>{this.onerror?.(Error(`Failed to reconnect SSE stream: ${J instanceof Error?J.message:String(J)}`)),this._scheduleReconnection(D,$+1)})},z)}_handleSseStream(D,$,K){if(!D)return;let{onresumptiontoken:z,replayMessageId:J}=$,q,X=!1,W=!1;(async()=>{try{let w=D.pipeThrough(new TextDecoderStream).pipeThrough(new M80({onRetry:(A)=>{this._serverRetryMs=A}})).getReader();while(!0){let{value:A,done:V}=await w.read();if(V)break;if(A.id)q=A.id,X=!0,z?.(A.id);if(!A.data)continue;if(!A.event||A.event==="message")try{let T=NG.parse(JSON.parse(A.data));if(qX(T)){if(W=!0,J!==void 0)T.id=J}this.onmessage?.(T)}catch(T){this.onerror?.(T)}}if((K||X)&&!W&&this._abortController&&!this._abortController.signal.aborted)this._scheduleReconnection({resumptionToken:q,onresumptiontoken:z,replayMessageId:J},0)}catch(w){if(this.onerror?.(Error(`SSE stream disconnected: ${w}`)),(K||X)&&!W&&this._abortController&&!this._abortController.signal.aborted)try{this._scheduleReconnection({resumptionToken:q,onresumptiontoken:z,replayMessageId:J},0)}catch(A){this.onerror?.(Error(`Failed to reconnect: ${A instanceof Error?A.message:String(A)}`))}}})()}async start(){if(this._abortController)throw Error("StreamableHTTPClientTransport already started! If using Client class, note that connect() calls start() automatically.");this._abortController=new AbortController}async finishAuth(D){if(!this._authProvider)throw new Cq("No auth provider");if(await fP(this._authProvider,{serverUrl:this._url,authorizationCode:D,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!=="AUTHORIZED")throw new Cq("Failed to authorize")}async close(){if(this._reconnectionTimeout)clearTimeout(this._reconnectionTimeout),this._reconnectionTimeout=void 0;this._abortController?.abort(),this.onclose?.()}async send(D,$){try{let{resumptionToken:K,onresumptiontoken:z}=$||{};if(K){this._startOrAuthSse({resumptionToken:K,replayMessageId:KP(D)?D.id:void 0}).catch((N)=>this.onerror?.(N));return}let J=await this._commonHeaders();J.set("content-type","application/json"),J.set("accept","application/json, text/event-stream");let q={...this._requestInit,method:"POST",headers:J,body:JSON.stringify(D),signal:this._abortController?.signal},X=await(this._fetch??fetch)(this._url,q),W=X.headers.get("mcp-session-id");if(W)this._sessionId=W;if(!X.ok){let N=await X.text().catch(()=>null);if(X.status===401&&this._authProvider){if(this._hasCompletedAuthFlow)throw new VX(401,"Server returned 401 after successful authentication");let{resourceMetadataUrl:A,scope:V}=G80(X);if(this._resourceMetadataUrl=A,this._scope=V,await fP(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetchWithInit})!=="AUTHORIZED")throw new Cq;return this._hasCompletedAuthFlow=!0,this.send(D)}if(X.status===403&&this._authProvider){let{resourceMetadataUrl:A,scope:V,error:T}=G80(X);if(T==="insufficient_scope"){let _=X.headers.get("WWW-Authenticate");if(this._lastUpscopingHeader===_)throw new VX(403,"Server returned 403 after trying upscoping");if(V)this._scope=V;if(A)this._resourceMetadataUrl=A;if(this._lastUpscopingHeader=_??void 0,await fP(this._authProvider,{serverUrl:this._url,resourceMetadataUrl:this._resourceMetadataUrl,scope:this._scope,fetchFn:this._fetch})!=="AUTHORIZED")throw new Cq;return this.send(D)}}throw new VX(X.status,`Error POSTing to endpoint: ${N}`)}if(this._hasCompletedAuthFlow=!1,this._lastUpscopingHeader=void 0,X.status===202){if(await X.body?.cancel(),ri0(D))this._startOrAuthSse({resumptionToken:void 0}).catch((N)=>this.onerror?.(N));return}let w=(Array.isArray(D)?D:[D]).filter((N)=>("method"in N)&&("id"in N)&&N.id!==void 0).length>0,O=X.headers.get("content-type");if(w)if(O?.includes("text/event-stream"))this._handleSseStream(X.body,{onresumptiontoken:z},!1);else if(O?.includes("application/json")){let N=await X.json(),A=Array.isArray(N)?N.map((V)=>NG.parse(V)):[NG.parse(N)];for(let V of A)this.onmessage?.(V)}else throw await X.body?.cancel(),new VX(-1,`Unexpected content type: ${O}`);else await X.body?.cancel()}catch(K){throw this.onerror?.(K),K}}get sessionId(){return this._sessionId}async terminateSession(){if(!this._sessionId)return;try{let D=await this._commonHeaders(),$={...this._requestInit,method:"DELETE",headers:D,signal:this._abortController?.signal},K=await(this._fetch??fetch)(this._url,$);if(await K.body?.cancel(),!K.ok&&K.status!==405)throw new VX(K.status,`Failed to terminate session: ${K.statusText}`);this._sessionId=void 0}catch(D){throw this.onerror?.(D),D}}setProtocolVersion(D){this._protocolVersion=D}get protocolVersion(){return this._protocolVersion}async resumeStream(D,$){await this._startOrAuthSse({resumptionToken:D,onresumptiontoken:$?.onresumptiontoken})}}var LW1,VX;var Re0=j(()=>{ZX();Le0();je0();LW1={initialReconnectionDelay:1000,maxReconnectionDelay:30000,reconnectionDelayGrowFactor:1.5,maxRetries:2};VX=class VX extends Error{constructor(D,$){super(`Streamable HTTP error: ${$}`);this.code=D}}});import{readFile as TW1,writeFile as Qe0,readdir as _W1}from"fs/promises";async function a4(D){return JSON.parse(await TW1(D,"utf-8"))}async function xG(D,$){await Qe0(D,JSON.stringify($,null,2),"utf-8")}async function Uq(D,$){await Qe0(D,$,"utf-8")}async function lI(D,$){try{return(await _W1($)).filter((z)=>D.test(z))}catch{return[]}}var oD=()=>{};import{join as Ue0}from"path";import{homedir as FW1}from"os";import{mkdir as EW1,appendFile as BW1}from"fs/promises";import{randomBytes as jW1}from"crypto";async function CW1(){if(Ce0)return;await EW1(Ie0,{recursive:!0}),Ce0=!0}async function w9(D){try{await CW1();let $=JSON.stringify({ts:new Date().toISOString(),...D})+`
1020
- `;await BW1(QW1,$,"utf-8")}catch{}}var Ie0,RW1,QW1,Ce0=!1;var V80=j(()=>{Ie0=Ue0(FW1(),".deepseek","logs"),RW1=`${Date.now()}-${jW1(3).toString("hex")}`,QW1=Ue0(Ie0,`session-${RW1}.jsonl`)});var g7;var bG=j(()=>{g7={name:"@hermenics/deepseek-code",version:"0.2.1",description:"An AI-powered coding assistant that lives in your terminal",keywords:["ai","cli","deepseek","coding-assistant","terminal","tui"],license:"Apache-2.0",type:"module",bin:{deepseek:"dist/deepseek"},files:["dist/","README.md","LICENSE"],repository:{type:"git",url:"git+https://github.com/Hermenics/deepseek-code.git"},bugs:{url:"https://github.com/Hermenics/deepseek-code/issues"},homepage:"https://github.com/Hermenics/deepseek-code#readme",publishConfig:{access:"public"},engines:{node:">=18",bun:">=1.0"},scripts:{start:"NODE_ENV=development bun src/index.tsx",dev:"NODE_ENV=development bun --watch src/index.tsx",build:"bun run build.ts",typecheck:"bunx tsc --noEmit",test:"bun test"},dependencies:{"@alcalzone/ansi-tokenize":"^0.3.0","@aws-crypto/sha256-js":"^5.2.0","@aws-sdk/client-bedrock":"^3.1048.0","@aws-sdk/credential-providers":"^3.1048.0","@modelcontextprotocol/sdk":"^1.29.0","@smithy/protocol-http":"^5.3.14","@smithy/signature-v4":"^5.3.14","@types/semver":"^7.7.1","auto-bind":"^5.0.1","bidi-js":"^1.0.3",chalk:"^5.6.2","cli-boxes":"^4.0.1","code-excerpt":"^4.0.0","emoji-regex":"^10.6.0",execa:"^9.6.1","fast-glob":"^3.3.3","fuse.js":"^7.0.0","get-east-asian-width":"^1.6.0","google-auth-library":"^10.6.2","indent-string":"^5.0.0","lodash-es":"^4.18.1",openai:"^6.34.0",react:"^19.2.0","react-reconciler":"^0.33.0",semver:"^7.8.1","signal-exit":"^4.1.0","stack-utils":"^2.0.6","strip-ansi":"^7.2.0","supports-hyperlinks":"^4.4.0","type-fest":"^5.6.0","usehooks-ts":"^3.1.1","wrap-ansi":"^10.0.0"},devDependencies:{"@types/bun":"^1.3.12","@types/react":"^19.2.0","@types/stack-utils":"^2.0.3","react-devtools-core":"^7.0.1",typescript:"^5.9.3",vitest:"^4.1.6"}}});import{join as IW1}from"path";function xW1(D,$){let K={...D};for(let[z,J]of Object.entries($)){if(SW1.has(z))continue;K[z]=J}return K}function bW1(D){if(D.trim()==="")throw Error("MCP command cannot be empty");if(fW1.test(D))throw Error(`MCP command contains path traversal: ${D}`);if(kW1.test(D))throw Error(`MCP command contains shell injection characters: ${D}`)}function hW1(D,$){return{type:"mcp_server_load",serverName:D,transport:$}}async function vW1(){let D=IW1(process.cwd(),".deepseek","mcp.json");try{return await a4(D)}catch{return null}}async function Se0(){let D=await vW1();if(!D?.servers)return{tools:[],errors:[]};let $=[],K=[];for(let[z,J]of Object.entries(D.servers))try{if(J.transport==="stdio")bW1(J.command);let q=new e00({name:"deepseek-code",version:g7.version}),X=J.transport==="stdio"?new K80({command:J.command,args:J.args??[],env:xW1(Object.fromEntries(Object.entries(process.env).filter((H)=>H[1]!==void 0)),J.env??{})}):new A80(new URL(J.url));await q.connect(X),await w9(hW1(z,J.transport));let{tools:W}=await q.listTools();for(let H of W)$.push({name:`${z}__${H.name}`,description:`[MCP:${z}] ${H.description??""}`,parameters:H.inputSchema,async execute(w){return(await Promise.race([q.callTool({name:H.name,arguments:w}),new Promise((V,T)=>setTimeout(()=>T(Error(`MCP tool '${H.name}' timed out after 30s`)),30000))])).content.filter((V)=>V.type==="text"&&V.text).map((V)=>V.text).join(`
1020
+ `;await BW1(QW1,$,"utf-8")}catch{}}var Ie0,RW1,QW1,Ce0=!1;var V80=j(()=>{Ie0=Ue0(FW1(),".deepseek","logs"),RW1=`${Date.now()}-${jW1(3).toString("hex")}`,QW1=Ue0(Ie0,`session-${RW1}.jsonl`)});var g7;var bG=j(()=>{g7={name:"@hermenics/deepseek-code",version:"0.2.2",description:"An AI-powered coding assistant that lives in your terminal",keywords:["ai","cli","deepseek","coding-assistant","terminal","tui"],license:"Apache-2.0",type:"module",bin:{deepseek:"dist/deepseek"},files:["dist/","README.md","LICENSE"],repository:{type:"git",url:"git+https://github.com/Hermenics/deepseek-code.git"},bugs:{url:"https://github.com/Hermenics/deepseek-code/issues"},homepage:"https://github.com/Hermenics/deepseek-code#readme",publishConfig:{access:"public"},engines:{node:">=18",bun:">=1.0"},scripts:{start:"NODE_ENV=development bun src/index.tsx",dev:"NODE_ENV=development bun --watch src/index.tsx",build:"bun run build.ts",typecheck:"bunx tsc --noEmit",test:"bun test"},dependencies:{"@alcalzone/ansi-tokenize":"^0.3.0","@aws-crypto/sha256-js":"^5.2.0","@aws-sdk/client-bedrock":"^3.1048.0","@aws-sdk/credential-providers":"^3.1048.0","@modelcontextprotocol/sdk":"^1.29.0","@smithy/protocol-http":"^5.3.14","@smithy/signature-v4":"^5.3.14","@types/semver":"^7.7.1","auto-bind":"^5.0.1","bidi-js":"^1.0.3",chalk:"^5.6.2","cli-boxes":"^4.0.1","code-excerpt":"^4.0.0","emoji-regex":"^10.6.0",execa:"^9.6.1","fast-glob":"^3.3.3","fuse.js":"^7.0.0","get-east-asian-width":"^1.6.0","google-auth-library":"^10.6.2","indent-string":"^5.0.0","lodash-es":"^4.18.1",openai:"^6.34.0",react:"^19.2.0","react-reconciler":"^0.33.0",semver:"^7.8.1","signal-exit":"^4.1.0","stack-utils":"^2.0.6","strip-ansi":"^7.2.0","supports-hyperlinks":"^4.4.0","type-fest":"^5.6.0","usehooks-ts":"^3.1.1","wrap-ansi":"^10.0.0"},devDependencies:{"@types/bun":"^1.3.12","@types/react":"^19.2.0","@types/stack-utils":"^2.0.3","react-devtools-core":"^7.0.1",typescript:"^5.9.3",vitest:"^4.1.6"}}});import{join as IW1}from"path";function xW1(D,$){let K={...D};for(let[z,J]of Object.entries($)){if(SW1.has(z))continue;K[z]=J}return K}function bW1(D){if(D.trim()==="")throw Error("MCP command cannot be empty");if(fW1.test(D))throw Error(`MCP command contains path traversal: ${D}`);if(kW1.test(D))throw Error(`MCP command contains shell injection characters: ${D}`)}function hW1(D,$){return{type:"mcp_server_load",serverName:D,transport:$}}async function vW1(){let D=IW1(process.cwd(),".deepseek","mcp.json");try{return await a4(D)}catch{return null}}async function Se0(){let D=await vW1();if(!D?.servers)return{tools:[],errors:[]};let $=[],K=[];for(let[z,J]of Object.entries(D.servers))try{if(J.transport==="stdio")bW1(J.command);let q=new e00({name:"deepseek-code",version:g7.version}),X=J.transport==="stdio"?new K80({command:J.command,args:J.args??[],env:xW1(Object.fromEntries(Object.entries(process.env).filter((H)=>H[1]!==void 0)),J.env??{})}):new A80(new URL(J.url));await q.connect(X),await w9(hW1(z,J.transport));let{tools:W}=await q.listTools();for(let H of W)$.push({name:`${z}__${H.name}`,description:`[MCP:${z}] ${H.description??""}`,parameters:H.inputSchema,async execute(w){return(await Promise.race([q.callTool({name:H.name,arguments:w}),new Promise((V,T)=>setTimeout(()=>T(Error(`MCP tool '${H.name}' timed out after 30s`)),30000))])).content.filter((V)=>V.type==="text"&&V.text).map((V)=>V.text).join(`
1021
1021
  `)}})}catch(q){let X=`MCP server '${z}': ${q.message}`;K.push(X)}return{tools:$,errors:K}}var SW1,kW1,fW1;var ke0=j(()=>{as0();$e0();Re0();oD();V80();bG();SW1=new Set(["PATH","LD_PRELOAD","LD_LIBRARY_PATH","DYLD_INSERT_LIBRARIES","DYLD_LIBRARY_PATH","HOME","USER","SHELL","PYTHONPATH","NODE_OPTIONS","NODE_PATH","BUN_INSTALL"]),kW1=/[;|`<>]|&&|\|\||\$\(|>>|<</,fW1=/\.\.[/\\]/});import{readFile as yW1}from"fs/promises";async function xe0(D){if(!D.length)return"";let $=await fe0.default(D,{cwd:process.cwd(),ignore:["**/node_modules/**","**/.git/**"],dot:!0,absolute:!0}),K=[];for(let z of $)try{let J=await yW1(z,"utf-8"),X=J.length>P80?J.slice(0,P80)+`
1022
1022
 
1023
1023
  ...(truncated \u2014 file exceeds ${P80} chars)`:J;K.push(`// File: ${z}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hermenics/deepseek-code",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "An AI-powered coding assistant that lives in your terminal",
5
5
  "keywords": [
6
6
  "ai",