@microi.net/cli 5.7.4 → 5.7.6
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/.codebuddy-plugin/marketplace.json +2 -2
- package/.codebuddy-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.mcp.json +1 -1
- package/.workbuddy-plugin/marketplace.json +2 -2
- package/.workbuddy-plugin/plugin.json +1 -1
- package/README.md +71 -71
- package/assets/build-meta.json +7 -7
- package/cordis.patch.yml +2 -2
- package/package.json +1 -1
- package/scripts/mcp-server.js +101 -101
- package/scripts/microi-cli.js +5 -5
- package/scripts/microi-codex-broker.js +2 -2
- package/scripts/microi-codex-router.js +2 -2
- package/scripts/microi-skills.meta.json +221 -218
- package/skills/.microi-skills-version.json +3 -3
- package/skills/.progressive-disclosure-manifest.json +25 -25
- package/skills/ai-engine/SKILL.md +37 -37
- package/skills/ai-engine/references/ai-employees.md +6 -4
- package/skills/app-store/SKILL.md +253 -249
- package/skills/job-engine/SKILL.md +21 -20
- package/skills/message-notification/SKILL.md +156 -155
- package/skills/microi-ai-application/SKILL.md +7 -3
- package/skills/microi-client-frontend/SKILL.md +39 -35
- package/skills/microi-codex/SKILL.md +11 -9
- package/skills/microi-codex-installer/SKILL.md +5 -5
- package/skills/microi-datasource-mapping/SKILL.md +5 -1
- package/skills/microi-microservice/SKILL.md +35 -34
- package/skills/module-engine/SKILL.md +59 -46
- package/skills/page-engine/SKILL.md +11 -1
- package/skills/playwright-e2e/SKILL.md +3 -3
- package/skills/v8-explorer-tree/SKILL.md +228 -228
- package/skills/v8-file-upload/SKILL.md +189 -182
- package/skills/v8-mq-mqtt/SKILL.md +2 -1
- package/skills/v8-tcp-integration/SKILL.md +2 -2
- package/skills/v8-workflow/SKILL.md +93 -66
- package/skills/v8-workflow/references/workflow-configuration.md +49 -0
- package/skills/workspace-conventions/SKILL.md +261 -261
- package/skills/workspace-conventions/references/progressive-01-/347/211/210/346/234/254/346/233/264/346/226/260/346/227/245/345/277/227/344/277/235/346/212/244/350/247/204/345/210/231-/345/274/272/345/210/266.md +208 -208
- package/skills/workspace-conventions/references/progressive-02-microi-net-api-/346/234/254/345/234/260/345/220/257/345/212/250/347/272/246/345/256/232.md +7 -7
package/scripts/microi-cli.js
CHANGED
|
@@ -27,10 +27,10 @@ Content-Type: application/octet-stream\r
|
|
|
27
27
|
\r
|
|
28
28
|
`,"utf8"),f=Buffer.concat([...p,m]),y=Buffer.from(`\r
|
|
29
29
|
--${u}--\r
|
|
30
|
-
`,"utf8"),S=o?this.getTokenForServer(g,o.osClient,o.osClientType,o.osClientNetwork):await this.loadToken(),h=d.protocol==="https:",C=h?Qt:Yt,T=d.pathname.replace(/\/+$/,""),b={hostname:d.hostname,port:d.port||(h?443:80),path:T+e,method:"POST",timeout:a,rejectUnauthorized:this._strictTlsHosts.has(d.hostname.toLowerCase()),headers:{Accept:"application/json",...S?{Authorization:`Bearer ${S}`}:{},did:this.getDeviceId(),...o?.osClient?{OsClient:o.osClient}:{},"Content-Type":`multipart/form-data; boundary=${u}`,"Content-Length":f.length+l.size+y.length}};return new Promise((v,k)=>{let V=!1,Q=O=>{V||(V=!0,k(O))},N=C.request(b,O=>{let M=[];O.on("data",P=>M.push(P)),O.on("end",async()=>{if(V)return;let P=Buffer.concat(M).toString("utf8"),x;try{x=JSON.parse(P)}catch{Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u54CD\u5E94\u4E0D\u662F JSON\uFF08HTTP ${O.statusCode||0}\uFF09`));return}let z=String(O.headers.authorization||"");z&&await this.setToken(z,g,o?.osClient,o?.osClientType,o?.osClientNetwork),V=!0,v(x)})});N.on("error",O=>Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u5931\u8D25\uFF1A${vt(O)}`))),N.on("timeout",()=>{N.destroy(),Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u8D85\u65F6\uFF08${a}ms\uFF09`))}),N.write(f);let R=it.createReadStream(c);R.on("error",O=>{N.destroy(),Q(new Error(`\u8BFB\u53D6\u672C\u5730\u53D1\u5E03\u8D44\u4EA7\u5931\u8D25\uFF1A${vt(O)}`))}),R.on("end",()=>N.end(y)),R.pipe(N,{end:!1})})}};var ot=B(require("crypto")),W=B(require("fs")),_t=B(require("path"));var Dt=B(require("child_process")),Lr=require("crypto"),ne=B(require("fs")),nn=B(require("path")),Rt=".microi-workspace-secrets.dpapi.json",Br=["Add-Type -AssemblyName System.Security;","$inputBase64 = [Console]::In.ReadToEnd().Trim();","$plain = [Convert]::FromBase64String($inputBase64);","$cipher = [Security.Cryptography.ProtectedData]::Protect($plain, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($cipher));"].join(" "),Ur=["Add-Type -AssemblyName System.Security;","$inputBase64 = [Console]::In.ReadToEnd().Trim();","$cipher = [Convert]::FromBase64String($inputBase64);","$plain = [Security.Cryptography.ProtectedData]::Unprotect($cipher, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($plain));"].join(" ");function Zt(s,e){if(process.platform!=="win32")throw new Error("\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u4E0D\u652F\u6301 Windows DPAPI \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93");let t=process.env.SystemRoot||"C:\\Windows",n=nn.join(t,"System32","WindowsPowerShell","v1.0","powershell.exe"),r=Dt.spawnSync(n,["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",s],{input:e.toString("base64"),encoding:"utf8",windowsHide:!0,maxBuffer:4*1024*1024,timeout:15e3});if(r.error||r.status!==0
|
|
30
|
+
`,"utf8"),S=o?this.getTokenForServer(g,o.osClient,o.osClientType,o.osClientNetwork):await this.loadToken(),h=d.protocol==="https:",C=h?Qt:Yt,T=d.pathname.replace(/\/+$/,""),b={hostname:d.hostname,port:d.port||(h?443:80),path:T+e,method:"POST",timeout:a,rejectUnauthorized:this._strictTlsHosts.has(d.hostname.toLowerCase()),headers:{Accept:"application/json",...S?{Authorization:`Bearer ${S}`}:{},did:this.getDeviceId(),...o?.osClient?{OsClient:o.osClient}:{},"Content-Type":`multipart/form-data; boundary=${u}`,"Content-Length":f.length+l.size+y.length}};return new Promise((v,k)=>{let V=!1,Q=O=>{V||(V=!0,k(O))},N=C.request(b,O=>{let M=[];O.on("data",P=>M.push(P)),O.on("end",async()=>{if(V)return;let P=Buffer.concat(M).toString("utf8"),x;try{x=JSON.parse(P)}catch{Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u54CD\u5E94\u4E0D\u662F JSON\uFF08HTTP ${O.statusCode||0}\uFF09`));return}let z=String(O.headers.authorization||"");z&&await this.setToken(z,g,o?.osClient,o?.osClientType,o?.osClientNetwork),V=!0,v(x)})});N.on("error",O=>Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u5931\u8D25\uFF1A${vt(O)}`))),N.on("timeout",()=>{N.destroy(),Q(new Error(`\u6D41\u5F0F\u4E0A\u4F20\u8D85\u65F6\uFF08${a}ms\uFF09`))}),N.write(f);let R=it.createReadStream(c);R.on("error",O=>{N.destroy(),Q(new Error(`\u8BFB\u53D6\u672C\u5730\u53D1\u5E03\u8D44\u4EA7\u5931\u8D25\uFF1A${vt(O)}`))}),R.on("end",()=>N.end(y)),R.pipe(N,{end:!1})})}};var ot=B(require("crypto")),W=B(require("fs")),_t=B(require("path"));var Dt=B(require("child_process")),Lr=require("crypto"),ne=B(require("fs")),nn=B(require("path")),Rt=".microi-workspace-secrets.dpapi.json",Br=["$ErrorActionPreference = 'Stop';","Add-Type -AssemblyName System.Security;","$inputBase64 = [Console]::In.ReadToEnd().Trim();","$plain = [Convert]::FromBase64String($inputBase64);","$cipher = [Security.Cryptography.ProtectedData]::Protect($plain, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($cipher));"].join(" "),Ur=["$ErrorActionPreference = 'Stop';","Add-Type -AssemblyName System.Security;","$inputBase64 = [Console]::In.ReadToEnd().Trim();","$cipher = [Convert]::FromBase64String($inputBase64);","$plain = [Security.Cryptography.ProtectedData]::Unprotect($cipher, $null, [Security.Cryptography.DataProtectionScope]::CurrentUser);","[Console]::Out.Write([Convert]::ToBase64String($plain));"].join(" ");function Zt(s,e){if(process.platform!=="win32")throw new Error("\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u4E0D\u652F\u6301 Windows DPAPI \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93");let t=process.env.SystemRoot||"C:\\Windows",n=nn.join(t,"System32","WindowsPowerShell","v1.0","powershell.exe"),r=Dt.spawnSync(n,["-NoLogo","-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",s],{input:e.toString("base64"),encoding:"utf8",windowsHide:!0,maxBuffer:4*1024*1024,timeout:15e3}),i=String(r.stdout||"").trim();if(r.error||r.status!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(i))throw new Error("Windows DPAPI \u64CD\u4F5C\u5931\u8D25\uFF1B\u51ED\u636E\u672A\u5199\u5165\u660E\u6587\u6587\u4EF6");return Buffer.from(i,"base64")}function Zs(s){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,s)}var jn="dpapi-session-v1:",Pt="keychain-session-v1:",Un="net.microi.cli.workspace.v1",jr="net.microi.cli.session.v1",Kr=s=>(0,Lr.createHash)("sha256").update(s).digest("hex");function Kn(s,e){if(process.platform!=="darwin")throw new Error("macOS Keychain is unavailable on this platform");let t=Dt.spawnSync("/usr/bin/security",["find-generic-password","-s",s,"-a",e,"-w"],{encoding:"utf8",timeout:15e3,maxBuffer:4*1024*1024});if(t.status===44)return;if(t.error||t.status!==0)throw new Error("macOS Keychain \u8BFB\u53D6\u5931\u8D25\uFF1B\u51ED\u636E\u672A\u5199\u5165\u660E\u6587\u6587\u4EF6");let n=String(t.stdout||"").trim();if(!/^[A-Za-z0-9+/]+={0,2}$/.test(n))throw new Error("macOS Keychain \u51ED\u636E\u683C\u5F0F\u65E0\u6548");return Buffer.from(n,"base64").toString("utf8")}function Hr(s,e,t){if(process.platform!=="darwin")throw new Error("macOS Keychain is unavailable on this platform");let n=Buffer.from(t,"utf8").toString("base64"),r=`add-generic-password -U -s ${s} -a ${e} -w ${n}
|
|
31
31
|
`,i=Dt.spawnSync("/usr/bin/security",["-q","-i"],{input:r,encoding:"utf8",timeout:15e3,maxBuffer:4*1024*1024});if(i.error||i.status!==0||Kn(s,e)!==t)throw new Error("macOS Keychain \u5199\u5165\u6216\u56DE\u8BFB\u5931\u8D25\uFF1B\u51ED\u636E\u672A\u5199\u5165\u660E\u6587\u6587\u4EF6")}function ei(s,e){if(process.platform!=="darwin")throw new Error("macOS Keychain is unavailable on this platform");let t=Dt.spawnSync("/usr/bin/security",["delete-generic-password","-s",s,"-a",e],{encoding:"utf8",timeout:15e3,maxBuffer:4*1024*1024});if(t.error||t.status!==0&&t.status!==44)throw new Error("macOS Keychain \u5220\u9664\u5931\u8D25")}var en=class{constructor(e){this.workspaceTokenFile=e;this.onDidChange=()=>({dispose:()=>{}})}account(e){return Kr(`${this.workspaceTokenFile}\0${e}`)}async get(e){return Kn(Un,this.account(e))}async store(e,t){Hr(Un,this.account(e),t)}async delete(e){ei(Un,this.account(e))}},bt=new Map,kt=new Map;function It(s){return typeof s=="string"&&(s.startsWith(jn)||s.startsWith(Pt))}function Wr(s){if(!s||It(s))return s;if(process.platform==="darwin"){let e=Pt+Kr(s);return Hr(jr,e.slice(Pt.length),s),e}return kt.has(s)||(kt.size>256&&kt.clear(),kt.set(s,jn+Zt(Br,Buffer.from(s,"utf8")).toString("base64"))),kt.get(s)}function Hn(s){if(typeof s!="string")return"";if(!It(s))return s;if(s.startsWith(Pt)){let e=s.slice(Pt.length);if(!/^[a-f0-9]{64}$/.test(e))throw new Error("macOS Keychain Token \u5F15\u7528\u683C\u5F0F\u65E0\u6548");let t=Kn(jr,e);if(!t)throw new Error("macOS Keychain Token \u5F15\u7528\u4E0D\u5B58\u5728");return t}return bt.has(s)||(bt.size>256&&bt.clear(),bt.set(s,Zt(Ur,Buffer.from(s.slice(jn.length),"base64")).toString("utf8"))),bt.get(s)}function ti(s){if(!Number.isInteger(s)||s<=1)return!1;try{return process.kill(s,0),!0}catch(e){return e.code==="EPERM"}}function ni(s){try{let e=JSON.parse(ne.readFileSync(s,"utf8"));return ti(Number(e?.pid))}catch{return!1}}var tn=class{constructor(e,t){this.filePath=e;this.onDidChange=()=>({dispose:()=>{}});this.protect=t?.protect||(n=>Zt(Br,n)),this.unprotect=t?.unprotect||(n=>Zt(Ur,n))}async get(e){return this.readDocument().values[e]}async store(e,t){this.mutate(n=>{n.values[e]=t})}async delete(e){this.mutate(t=>{delete t.values[e]})}mutate(e){ne.mkdirSync(nn.dirname(this.filePath),{recursive:!0});let t=`${this.filePath}.lock`,n=Date.now()+3e3,r;for(;r===void 0;)try{r=ne.openSync(t,"wx",384),ne.writeFileSync(r,`${JSON.stringify({pid:process.pid,createdAt:new Date().toISOString()})}
|
|
32
|
-
`,"utf8")}catch(o){if(o.code!=="EEXIST")throw o;try{let a=Date.now()-ne.statSync(t).mtimeMs>3e4;(!ni(t)||a)&&ne.unlinkSync(t)}catch{}if(Date.now()>=n)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u6B63\u88AB\u53E6\u4E00\u8FDB\u7A0B\u66F4\u65B0\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");Zs(40)}let i=`${this.filePath}.${process.pid}.${Date.now()}.tmp`;try{let o=this.readDocument();e(o);let a=Buffer.from(JSON.stringify(o),"utf8"),c={version:1,protection:"windows-dpapi-current-user",ciphertext:this.protect(a).toString("base64")};ne.writeFileSync(i,`${JSON.stringify(c,null,2)}
|
|
33
|
-
`,{encoding:"utf8",mode:384}),ne.renameSync(i,this.filePath)}finally{try{ne.existsSync(i)&&ne.unlinkSync(i)}catch{}try{ne.closeSync(r)}catch{}try{ne.unlinkSync(t)}catch{}}}readDocument(){if(!ne.existsSync(this.filePath))return{version:1,values:{}};if(ne.statSync(this.filePath).size>2*1024*1024)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u8D85\u8FC7\u5B89\u5168\u5927\u5C0F\u9650\u5236\uFF0C\u5DF2\u62D2\u7EDD\u8BFB\u53D6");let e;try{e=JSON.parse(ne.readFileSync(this.filePath,"utf8"))}catch{throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\u4E14\u505C\u6B62\u8986\u76D6")}if(e.version!==1||e.protection!=="windows-dpapi-current-user"||typeof e.ciphertext!="string"||!e.ciphertext)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u683C\u5F0F\u65E0\u6548\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\u4E14\u505C\u6B62\u8986\u76D6");try{let t=this.unprotect(Buffer.from(e.ciphertext,"base64")),n=JSON.parse(t.toString("utf8"));if(n.version!==1||!n.values||typeof n.values!="object")throw new Error("invalid document");return n.values=Object.fromEntries(Object.entries(n.values).filter(r=>typeof r[0]=="string"&&typeof r[1]=="string")),n}catch{throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u65E0\u6CD5\u7531\u5F53\u524D Windows \u7528\u6237\u89E3\u5BC6\uFF0C\u5DF2\u505C\u6B62\u8986\u76D6")}}};var ri=60*60*1e3,si=5*60,Gr=24*60*60,ii=2*60*1e3,oi=60*1e3;function ai(s,e){let t=(e||"").trim();return t?ot.publicEncrypt({key:t,padding:ot.constants.RSA_PKCS1_PADDING},Buffer.from(s,"utf-8")).toString("base64"):s}var Ce=class s{constructor(){this._isLoggedIn=!1;this._refreshInProgress=!1;this._mcpTokenFilePath="";this._mcpAuthRecoveryDirPath="";this._mcpAuthRecoveryInProgress=new Set;this._mcpAuthRecoveryFailureUntil=new Map;this._mcpAuthRecoveryPassInProgress=!1;this._lastAuthWarning="";this._lastAuthWarningTime=0;this.protectedMcpTokenKeys=new Set}static getInstance(){return s._instance||(s._instance=new s),s._instance}setSecretStorage(e){this._secretStorage=e,j.getInstance().setTokenStateChangedHandler(async()=>{await this.writeMcpTokenFile()}),j.getInstance().setAuthRecoveryHandler(async t=>{let n=I.getInstance(),r=this.normalizeApiBaseUrl(t.apiBaseUrl),i=this.normalizeOsClient(t.osClient),o=this.normalizeIdentityPart(t.osClientType),a=this.normalizeIdentityPart(t.osClientNetwork),c=n.getProfiles().filter(d=>this.normalizeApiBaseUrl(d.apiBaseUrl)===r&&this.normalizeOsClient(d.osClient)===i),l=c.find(d=>this.normalizeIdentityPart(d.osClientType)===o&&this.normalizeIdentityPart(d.osClientNetwork)===a);if(!l&&!o&&!a&&c.length===1&&(l=c[0]),!l&&c.length===0&&(l={label:t.osClient||t.apiBaseUrl,apiBaseUrl:t.apiBaseUrl,osClient:t.osClient||"",osClientType:t.osClientType,osClientNetwork:t.osClientNetwork}),!l)return this.showAuthExpiredWarning("\u68C0\u6D4B\u5230\u540C\u4E00\u670D\u52A1\u5668\u4E0E\u79DF\u6237\u5B58\u5728\u591A\u4E2A\u8FDE\u63A5\u73AF\u5883\uFF0C\u65E0\u6CD5\u5B89\u5168\u5224\u65AD\u5E94\u6062\u590D\u54EA\u4E00\u4E2A\u767B\u5F55\u8EAB\u4EFD\u3002"),!1;let g=await this.reLoginForProfile(l);return g&&(this._isLoggedIn=!0,await Je.executeCommand("setContext",nt,!0)),await this.writeMcpTokenFile(),g})}setMcpTokenFilePath(e){this._mcpTokenFilePath=e,this._mcpAuthRecoveryDirPath=e?`${e}.recovery`:""}enableProtectedMcpTokens(e){let t=this.normalizeApiBaseUrl(e.apiBaseUrl),n=this.normalizeOsClient(e.osClient);this.protectedMcpTokenKeys.add(this.mcpRecoveryIdentity(t,n,e.osClientType,e.osClientNetwork)),this.protectedMcpTokenKeys.add(n?`${t}|${n}`:t)}get mcpTokenFilePath(){return this._mcpTokenFilePath}get mcpAuthRecoveryDirPath(){return this._mcpAuthRecoveryDirPath}async loadMcpTokenFile(){if(!this._mcpTokenFilePath||!W.existsSync(this._mcpTokenFilePath))return 0;let e;try{let i=JSON.parse(W.readFileSync(this._mcpTokenFilePath,"utf-8"));if(!i||typeof i!="object"||Array.isArray(i))return 0;for(let[o,a]of Object.entries(i))It(a)&&this.protectedMcpTokenKeys.add(o);e=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,Hn(a)]))}catch{return 0}let t=j.getInstance(),n=I.getInstance().getProfiles(),r=[];for(let i of n){let o=this.normalizeApiBaseUrl(i.apiBaseUrl),a=this.normalizeOsClient(i.osClient),c=this.mcpRecoveryIdentity(o,a,i.osClientType,i.osClientNetwork),g=n.filter(y=>this.normalizeApiBaseUrl(y.apiBaseUrl)===o&&this.normalizeOsClient(y.osClient)===a).length===1?[[o,a,i.osClientType,i.osClientNetwork].filter(Boolean).join("|"),[o,a,i.osClientType].filter(Boolean).join("|"),a?`${o}|${a}`:o]:[],d=typeof e[c]=="string"&&String(e[c]).trim()?String(e[c]).trim():"",u=g.map(y=>e[y]).find(y=>typeof y=="string"&&y.trim()),p=t.getTokenForServer(i.apiBaseUrl,i.osClient,i.osClientType,i.osClientNetwork),m=t.getExactTokenForServer(i.apiBaseUrl,i.osClient,i.osClientType,i.osClientNetwork),f=st(p,d||u,!!d&&!m);!f||m===f||r.push({token:f,apiBaseUrl:i.apiBaseUrl,osClient:i.osClient,osClientType:i.osClientType,osClientNetwork:i.osClientNetwork})}return t.adoptTokensFromSharedFile(r)}get isLoggedIn(){return this._isLoggedIn}secretKey(e){return I.getInstance().getWorkspaceSecretKey(e)}normalizeApiBaseUrl(e){return(e||"").trim().replace(/\/+$/,"")}normalizeOsClient(e){return(e||"").trim()}normalizeIdentityPart(e){return(e||"").trim()}mcpRecoveryIdentity(e,t,n,r){return[this.normalizeApiBaseUrl(e),this.normalizeOsClient(t),this.normalizeIdentityPart(n),this.normalizeIdentityPart(r)].join("|")}serverSecretKey(e,t,n){return this.secretKey(`${e}.${this.normalizeApiBaseUrl(t)}|${this.normalizeOsClient(n)}`)}getCredentialSecretKeys(e){return{usernameKey:this.serverSecretKey(we,e.apiBaseUrl,e.osClient),passwordKey:this.serverSecretKey(Te,e.apiBaseUrl,e.osClient)}}legacyServerSecretKey(e,t){return this.secretKey(`${e}.${this.normalizeApiBaseUrl(t)}`)}canUseLegacyCredential(e,t){let n=this.normalizeApiBaseUrl(e),r=this.normalizeOsClient(t);if(!n)return!1;let i=I.getInstance().getProfiles().filter(a=>this.normalizeApiBaseUrl(a.apiBaseUrl)===n);if(i.length===0)return!r;if(i.length===1)return!0;let o=i.filter(a=>this.normalizeOsClient(a.osClient)===r);return!!r&&o.length===i.length}async writeMcpTokenFile(){if(!this._mcpTokenFilePath)return;let e=j.getInstance(),t=I.getInstance(),n=t.getProfiles(),r=this._mcpTokenFilePath;if(!(n.some(f=>!!this.normalizeApiBaseUrl(f.apiBaseUrl)&&!!this.normalizeOsClient(f.osClient))||!!this.normalizeApiBaseUrl(t.getApiBaseUrl())&&!!this.normalizeOsClient(t.getOsClient()))&&!W.existsSync(r))return;let o={},a=new Set,c=[];for(let f of n){let y=this.normalizeApiBaseUrl(f.apiBaseUrl),S=this.normalizeOsClient(f.osClient),h=this.mcpRecoveryIdentity(y,S,f.osClientType,f.osClientNetwork);a.add(h);let C=n.filter(v=>this.normalizeApiBaseUrl(v.apiBaseUrl)===y&&this.normalizeOsClient(v.osClient)===S),T=S?`${y}|${S}`:y;C.length===1&&a.add(T);let b=e.getTokenForServer(f.apiBaseUrl,f.osClient,f.osClientType,f.osClientNetwork);c.push({profile:f,exactKey:h,legacyKey:C.length===1?T:void 0,currentToken:b,currentExactToken:e.getExactTokenForServer(f.apiBaseUrl,f.osClient,f.osClientType,f.osClientNetwork)}),b&&(o[h]=b,C.length===1&&(o[T]=b))}let l=_t.dirname(r);W.existsSync(l)||W.mkdirSync(l,{recursive:!0});let g=`${r}.lock`,d=Date.now()+3e3,u;for(;u===void 0;)try{u=W.openSync(g,"wx",384),W.writeFileSync(u,JSON.stringify({pid:process.pid,createdAt:Date.now()}),"utf-8")}catch(f){if(f.code!=="EEXIST")throw f;try{Date.now()-W.statSync(g).mtimeMs>3e4&&W.unlinkSync(g)}catch{}if(Date.now()>=d)throw new Error("Microi MCP Token \u6587\u4EF6\u6B63\u5728\u88AB CLI \u6216 VS Code \u63D2\u4EF6\u4FEE\u6539\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");await new Promise(y=>setTimeout(y,40))}let p=`${r}.${process.pid}.${Date.now()}.tmp`,m=[];try{let f={};if(W.existsSync(r)){let h=JSON.parse(W.readFileSync(r,"utf-8"));if(!h||typeof h!="object"||Array.isArray(h))throw new Error(`Microi MCP Token \u6587\u4EF6\u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\uFF1A${r}`);for(let[C,T]of Object.entries(h))It(T)&&this.protectedMcpTokenKeys.add(C);f=Object.fromEntries(Object.entries(h).filter(C=>typeof C[1]=="string"&&!!C[1]).map(([C,T])=>[C,Hn(T)]))}for(let h of c){let C=f[h.exactKey]||"",T=h.legacyKey&&f[h.legacyKey]||"",b=st(h.currentToken,C||T,!!C&&!h.currentExactToken);b&&(o[h.exactKey]=b,h.legacyKey&&(o[h.legacyKey]=b),b!==h.currentExactToken&&m.push({profile:h.profile,token:b}))}for(let h of a)delete f[h];let y={...f,...o},S=Object.fromEntries(Object.entries(y).map(([h,C])=>[h,this.protectedMcpTokenKeys.has(h)?Wr(C):C]));W.writeFileSync(p,`${JSON.stringify(S,null,2)}
|
|
32
|
+
`,"utf8")}catch(o){if(o.code!=="EEXIST")throw o;try{let a=Date.now()-ne.statSync(t).mtimeMs>3e4;(!ni(t)||a)&&ne.unlinkSync(t)}catch{}if(Date.now()>=n)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u6B63\u88AB\u53E6\u4E00\u8FDB\u7A0B\u66F4\u65B0\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");Zs(40)}let i=`${this.filePath}.${process.pid}.${Date.now()}.tmp`;try{let o=this.readDocument();e(o);let a=Buffer.from(JSON.stringify(o),"utf8"),c={version:1,protection:"windows-dpapi-current-user",ciphertext:this.protect(a).toString("base64")};if(!this.unprotect(Buffer.from(c.ciphertext,"base64")).equals(a))throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u52A0\u5BC6\u56DE\u8BFB\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u4FDD\u7559\u539F\u4FDD\u9669\u5E93");ne.writeFileSync(i,`${JSON.stringify(c,null,2)}
|
|
33
|
+
`,{encoding:"utf8",mode:384}),ne.renameSync(i,this.filePath)}finally{try{ne.existsSync(i)&&ne.unlinkSync(i)}catch{}try{ne.closeSync(r)}catch{}try{ne.unlinkSync(t)}catch{}}}readDocument(){if(!ne.existsSync(this.filePath))return{version:1,values:{}};if(ne.statSync(this.filePath).size>2*1024*1024)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u8D85\u8FC7\u5B89\u5168\u5927\u5C0F\u9650\u5236\uFF0C\u5DF2\u62D2\u7EDD\u8BFB\u53D6");let e;try{e=JSON.parse(ne.readFileSync(this.filePath,"utf8"))}catch{throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\u4E14\u505C\u6B62\u8986\u76D6")}if(e.version!==1||e.protection!=="windows-dpapi-current-user"||typeof e.ciphertext!="string"||!e.ciphertext)throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u683C\u5F0F\u65E0\u6548\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\u4E14\u505C\u6B62\u8986\u76D6");try{let t=this.unprotect(Buffer.from(e.ciphertext,"base64"));if(t.length===0)return{version:1,values:{}};let n=JSON.parse(t.toString("utf8"));if(n.version!==1||!n.values||typeof n.values!="object")throw new Error("invalid document");return n.values=Object.fromEntries(Object.entries(n.values).filter(r=>typeof r[0]=="string"&&typeof r[1]=="string")),n}catch{throw new Error("Microi \u5DE5\u4F5C\u533A\u51ED\u636E\u4FDD\u9669\u5E93\u65E0\u6CD5\u7531\u5F53\u524D Windows \u7528\u6237\u89E3\u5BC6\uFF0C\u5DF2\u505C\u6B62\u8986\u76D6")}}};var ri=60*60*1e3,si=5*60,Gr=24*60*60,ii=2*60*1e3,oi=60*1e3;function ai(s,e){let t=(e||"").trim();return t?ot.publicEncrypt({key:t,padding:ot.constants.RSA_PKCS1_PADDING},Buffer.from(s,"utf-8")).toString("base64"):s}var Ce=class s{constructor(){this._isLoggedIn=!1;this._refreshInProgress=!1;this._mcpTokenFilePath="";this._mcpAuthRecoveryDirPath="";this._mcpAuthRecoveryInProgress=new Set;this._mcpAuthRecoveryFailureUntil=new Map;this._mcpAuthRecoveryPassInProgress=!1;this._lastAuthWarning="";this._lastAuthWarningTime=0;this.protectedMcpTokenKeys=new Set}static getInstance(){return s._instance||(s._instance=new s),s._instance}setSecretStorage(e){this._secretStorage=e,j.getInstance().setTokenStateChangedHandler(async()=>{await this.writeMcpTokenFile()}),j.getInstance().setAuthRecoveryHandler(async t=>{let n=I.getInstance(),r=this.normalizeApiBaseUrl(t.apiBaseUrl),i=this.normalizeOsClient(t.osClient),o=this.normalizeIdentityPart(t.osClientType),a=this.normalizeIdentityPart(t.osClientNetwork),c=n.getProfiles().filter(d=>this.normalizeApiBaseUrl(d.apiBaseUrl)===r&&this.normalizeOsClient(d.osClient)===i),l=c.find(d=>this.normalizeIdentityPart(d.osClientType)===o&&this.normalizeIdentityPart(d.osClientNetwork)===a);if(!l&&!o&&!a&&c.length===1&&(l=c[0]),!l&&c.length===0&&(l={label:t.osClient||t.apiBaseUrl,apiBaseUrl:t.apiBaseUrl,osClient:t.osClient||"",osClientType:t.osClientType,osClientNetwork:t.osClientNetwork}),!l)return this.showAuthExpiredWarning("\u68C0\u6D4B\u5230\u540C\u4E00\u670D\u52A1\u5668\u4E0E\u79DF\u6237\u5B58\u5728\u591A\u4E2A\u8FDE\u63A5\u73AF\u5883\uFF0C\u65E0\u6CD5\u5B89\u5168\u5224\u65AD\u5E94\u6062\u590D\u54EA\u4E00\u4E2A\u767B\u5F55\u8EAB\u4EFD\u3002"),!1;let g=await this.reLoginForProfile(l);return g&&(this._isLoggedIn=!0,await Je.executeCommand("setContext",nt,!0)),await this.writeMcpTokenFile(),g})}setMcpTokenFilePath(e){this._mcpTokenFilePath=e,this._mcpAuthRecoveryDirPath=e?`${e}.recovery`:""}enableProtectedMcpTokens(e){let t=this.normalizeApiBaseUrl(e.apiBaseUrl),n=this.normalizeOsClient(e.osClient);this.protectedMcpTokenKeys.add(this.mcpRecoveryIdentity(t,n,e.osClientType,e.osClientNetwork)),this.protectedMcpTokenKeys.add(n?`${t}|${n}`:t)}get mcpTokenFilePath(){return this._mcpTokenFilePath}get mcpAuthRecoveryDirPath(){return this._mcpAuthRecoveryDirPath}async loadMcpTokenFile(){if(!this._mcpTokenFilePath||!W.existsSync(this._mcpTokenFilePath))return 0;let e;try{let i=JSON.parse(W.readFileSync(this._mcpTokenFilePath,"utf-8"));if(!i||typeof i!="object"||Array.isArray(i))return 0;for(let[o,a]of Object.entries(i))It(a)&&this.protectedMcpTokenKeys.add(o);e=Object.fromEntries(Object.entries(i).map(([o,a])=>[o,Hn(a)]))}catch{return 0}let t=j.getInstance(),n=I.getInstance().getProfiles(),r=[];for(let i of n){let o=this.normalizeApiBaseUrl(i.apiBaseUrl),a=this.normalizeOsClient(i.osClient),c=this.mcpRecoveryIdentity(o,a,i.osClientType,i.osClientNetwork),g=n.filter(y=>this.normalizeApiBaseUrl(y.apiBaseUrl)===o&&this.normalizeOsClient(y.osClient)===a).length===1?[[o,a,i.osClientType,i.osClientNetwork].filter(Boolean).join("|"),[o,a,i.osClientType].filter(Boolean).join("|"),a?`${o}|${a}`:o]:[],d=typeof e[c]=="string"&&String(e[c]).trim()?String(e[c]).trim():"",u=g.map(y=>e[y]).find(y=>typeof y=="string"&&y.trim()),p=t.getTokenForServer(i.apiBaseUrl,i.osClient,i.osClientType,i.osClientNetwork),m=t.getExactTokenForServer(i.apiBaseUrl,i.osClient,i.osClientType,i.osClientNetwork),f=st(p,d||u,!!d&&!m);!f||m===f||r.push({token:f,apiBaseUrl:i.apiBaseUrl,osClient:i.osClient,osClientType:i.osClientType,osClientNetwork:i.osClientNetwork})}return t.adoptTokensFromSharedFile(r)}get isLoggedIn(){return this._isLoggedIn}secretKey(e){return I.getInstance().getWorkspaceSecretKey(e)}normalizeApiBaseUrl(e){return(e||"").trim().replace(/\/+$/,"")}normalizeOsClient(e){return(e||"").trim()}normalizeIdentityPart(e){return(e||"").trim()}mcpRecoveryIdentity(e,t,n,r){return[this.normalizeApiBaseUrl(e),this.normalizeOsClient(t),this.normalizeIdentityPart(n),this.normalizeIdentityPart(r)].join("|")}serverSecretKey(e,t,n){return this.secretKey(`${e}.${this.normalizeApiBaseUrl(t)}|${this.normalizeOsClient(n)}`)}getCredentialSecretKeys(e){return{usernameKey:this.serverSecretKey(we,e.apiBaseUrl,e.osClient),passwordKey:this.serverSecretKey(Te,e.apiBaseUrl,e.osClient)}}legacyServerSecretKey(e,t){return this.secretKey(`${e}.${this.normalizeApiBaseUrl(t)}`)}canUseLegacyCredential(e,t){let n=this.normalizeApiBaseUrl(e),r=this.normalizeOsClient(t);if(!n)return!1;let i=I.getInstance().getProfiles().filter(a=>this.normalizeApiBaseUrl(a.apiBaseUrl)===n);if(i.length===0)return!r;if(i.length===1)return!0;let o=i.filter(a=>this.normalizeOsClient(a.osClient)===r);return!!r&&o.length===i.length}async writeMcpTokenFile(){if(!this._mcpTokenFilePath)return;let e=j.getInstance(),t=I.getInstance(),n=t.getProfiles(),r=this._mcpTokenFilePath;if(!(n.some(f=>!!this.normalizeApiBaseUrl(f.apiBaseUrl)&&!!this.normalizeOsClient(f.osClient))||!!this.normalizeApiBaseUrl(t.getApiBaseUrl())&&!!this.normalizeOsClient(t.getOsClient()))&&!W.existsSync(r))return;let o={},a=new Set,c=[];for(let f of n){let y=this.normalizeApiBaseUrl(f.apiBaseUrl),S=this.normalizeOsClient(f.osClient),h=this.mcpRecoveryIdentity(y,S,f.osClientType,f.osClientNetwork);a.add(h);let C=n.filter(v=>this.normalizeApiBaseUrl(v.apiBaseUrl)===y&&this.normalizeOsClient(v.osClient)===S),T=S?`${y}|${S}`:y;C.length===1&&a.add(T);let b=e.getTokenForServer(f.apiBaseUrl,f.osClient,f.osClientType,f.osClientNetwork);c.push({profile:f,exactKey:h,legacyKey:C.length===1?T:void 0,currentToken:b,currentExactToken:e.getExactTokenForServer(f.apiBaseUrl,f.osClient,f.osClientType,f.osClientNetwork)}),b&&(o[h]=b,C.length===1&&(o[T]=b))}let l=_t.dirname(r);W.existsSync(l)||W.mkdirSync(l,{recursive:!0});let g=`${r}.lock`,d=Date.now()+3e3,u;for(;u===void 0;)try{u=W.openSync(g,"wx",384),W.writeFileSync(u,JSON.stringify({pid:process.pid,createdAt:Date.now()}),"utf-8")}catch(f){if(f.code!=="EEXIST")throw f;try{Date.now()-W.statSync(g).mtimeMs>3e4&&W.unlinkSync(g)}catch{}if(Date.now()>=d)throw new Error("Microi MCP Token \u6587\u4EF6\u6B63\u5728\u88AB CLI \u6216 VS Code \u63D2\u4EF6\u4FEE\u6539\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");await new Promise(y=>setTimeout(y,40))}let p=`${r}.${process.pid}.${Date.now()}.tmp`,m=[];try{let f={};if(W.existsSync(r)){let h=JSON.parse(W.readFileSync(r,"utf-8"));if(!h||typeof h!="object"||Array.isArray(h))throw new Error(`Microi MCP Token \u6587\u4EF6\u5FC5\u987B\u662F JSON \u5BF9\u8C61\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\uFF1A${r}`);for(let[C,T]of Object.entries(h))It(T)&&this.protectedMcpTokenKeys.add(C);f=Object.fromEntries(Object.entries(h).filter(C=>typeof C[1]=="string"&&!!C[1]).map(([C,T])=>[C,Hn(T)]))}for(let h of c){let C=f[h.exactKey]||"",T=h.legacyKey&&f[h.legacyKey]||"",b=st(h.currentToken,C||T,!!C&&!h.currentExactToken);b&&(o[h.exactKey]=b,h.legacyKey&&(o[h.legacyKey]=b),b!==h.currentExactToken&&m.push({profile:h.profile,token:b}))}for(let h of a)delete f[h];let y={...f,...o},S=Object.fromEntries(Object.entries(y).map(([h,C])=>[h,this.protectedMcpTokenKeys.has(h)?Wr(C):C]));W.writeFileSync(p,`${JSON.stringify(S,null,2)}
|
|
34
34
|
`,{encoding:"utf-8",mode:384}),W.renameSync(p,r)}finally{try{W.existsSync(p)&&W.unlinkSync(p)}catch{}try{W.closeSync(u)}catch{}try{W.unlinkSync(g)}catch{}}await e.adoptTokensFromSharedFile(m.map(f=>({token:f.token,apiBaseUrl:f.profile.apiBaseUrl,osClient:f.profile.osClient,osClientType:f.profile.osClientType,osClientNetwork:f.profile.osClientNetwork})))}tokenFingerprint(e){return ot.createHash("sha256").update(String(e||"")).digest("hex")}deleteMcpAuthRecoveryRequests(e,t){let n=this._mcpAuthRecoveryDirPath;if(!n||!W.existsSync(n))return;let r=[];try{r=W.readdirSync(n).filter(i=>i.endsWith(".json")).slice(0,200)}catch{return}for(let i of r){let o=_t.join(n,i);try{let a=JSON.parse(W.readFileSync(o,"utf-8")),c=this.normalizeApiBaseUrl(String(a.apiBaseUrl||"")),l=this.normalizeOsClient(String(a.osClient||"")),g=this.normalizeIdentityPart(String(a.osClientType||"")),d=this.normalizeIdentityPart(String(a.osClientNetwork||"")),u=this.mcpRecoveryIdentity(c,l,g,d);if(!g&&!d){let p=t.filter(m=>this.normalizeApiBaseUrl(m.apiBaseUrl)===c&&this.normalizeOsClient(m.osClient)===l);p.length===1&&(u=this.mcpRecoveryIdentity(p[0].apiBaseUrl,p[0].osClient,p[0].osClientType,p[0].osClientNetwork))}u===e&&W.unlinkSync(o)}catch{}}}async processMcpAuthRecoveryRequests(){let e=this._mcpAuthRecoveryDirPath;if(!(!e||!W.existsSync(e)||this._mcpAuthRecoveryPassInProgress)){this._mcpAuthRecoveryPassInProgress=!0;try{let t=[];try{t=W.readdirSync(e).filter(o=>o.endsWith(".json")).slice(0,100)}catch{return}let r=I.getInstance().getProfiles(),i=j.getInstance();for(let o of t){let a=_t.join(e,o),c={};try{c=JSON.parse(W.readFileSync(a,"utf-8"))}catch{try{W.unlinkSync(a)}catch{}continue}let l=Number(c.requestedAt||0),g=this.normalizeApiBaseUrl(String(c.apiBaseUrl||"")),d=this.normalizeOsClient(String(c.osClient||"")),u=this.normalizeIdentityPart(String(c.osClientType||"")),p=this.normalizeIdentityPart(String(c.osClientNetwork||"")),m=String(c.failedTokenHash||"").trim().toLowerCase();if(Number(c.version)!==1||!g||!l||Math.abs(Date.now()-l)>ii||!Or(m)){try{W.unlinkSync(a)}catch{}continue}let f=r.filter(h=>this.normalizeApiBaseUrl(h.apiBaseUrl)===g&&this.normalizeOsClient(h.osClient)===d),y=u||p?f.find(h=>this.normalizeIdentityPart(h.osClientType)===u&&this.normalizeIdentityPart(h.osClientNetwork)===p):f.length===1?f[0]:void 0;if(!y){try{W.unlinkSync(a)}catch{}continue}let S=this.mcpRecoveryIdentity(y.apiBaseUrl,y.osClient,y.osClientType,y.osClientNetwork);if(!this._mcpAuthRecoveryInProgress.has(S)){if((this._mcpAuthRecoveryFailureUntil.get(S)||0)>Date.now()){this.deleteMcpAuthRecoveryRequests(S,r);continue}this._mcpAuthRecoveryInProgress.add(S);try{let h=i.getTokenForServer(y.apiBaseUrl,y.osClient,y.osClientType,y.osClientNetwork);h&&this.tokenFingerprint(h)!==m?(this._mcpAuthRecoveryFailureUntil.delete(S),await this.writeMcpTokenFile()):(h&&await i.clearTokenForServer(y.apiBaseUrl,y.osClient,y.osClientType,y.osClientNetwork,h),await this.reLoginForProfile(y)?this._mcpAuthRecoveryFailureUntil.delete(S):(this._mcpAuthRecoveryFailureUntil.set(S,Date.now()+oi),this.showAuthExpiredWarning("MCP \u8EAB\u4EFD\u5DF2\u5931\u6548\uFF0C\u4FDD\u5B58\u7684\u51ED\u636E\u65E0\u6CD5\u9759\u9ED8\u6062\u590D\uFF1B\u82E5\u670D\u52A1\u5668\u542F\u7528\u4E86\u9A8C\u8BC1\u7801\uFF0C\u8BF7\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u4EA4\u4E92\u5F0F\u91CD\u65B0\u767B\u5F55\u3002")))}finally{this._mcpAuthRecoveryInProgress.delete(S),this.deleteMcpAuthRecoveryRequests(S,r)}}}}finally{this._mcpAuthRecoveryPassInProgress=!1}}}startMcpAuthRecoveryWatcher(){this._mcpAuthRecoveryTimer||!this._mcpAuthRecoveryDirPath||(this._mcpAuthRecoveryTimer=setInterval(()=>{this.processMcpAuthRecoveryRequests()},1e3),this.processMcpAuthRecoveryRequests())}stopMcpAuthRecoveryWatcher(){this._mcpAuthRecoveryTimer&&(clearInterval(this._mcpAuthRecoveryTimer),this._mcpAuthRecoveryTimer=void 0)}async tryAutoLogin(){let e=j.getInstance(),n=I.getInstance().getProfiles(),r=!1,i=await e.loadToken(),o=await this.loadMcpTokenFile();r=!!i||o>0||e.hasToken;let a=n.filter(d=>!e.getTokenForServer(d.apiBaseUrl,d.osClient,d.osClientType,d.osClientNetwork)),c=0,l=async()=>{for(;c<a.length;){let d=a[c++];await this.reLoginForProfile(d)&&(r=!0)}},g=Math.min(4,a.length);return await Promise.all(Array.from({length:g},()=>l())),r&&(this._isLoggedIn=!0,await Je.executeCommand("setContext",nt,!0),await this.writeMcpTokenFile()),r}async getSysConfig(e,t,n,r=!1){let i=j.getInstance(),o=I.getInstance();try{let a=await i.request({method:"POST",path:H.GET_SYS_CONFIG,body:{_SearchEqual:{IsEnable:1},OsClient:t||o.getOsClient()||void 0},apiBaseUrl:e,osClient:t,allowAuthRetry:!1,silent:r});if(a.Code===1&&a.Data)return a.Data;n&&(n.message=a.Code!==1?`\u670D\u52A1\u5668\u8FD4\u56DE\u9519\u8BEF (Code: ${a.Code})${a.Msg?"\uFF1A"+a.Msg:""}\uFF0C\u8BF7\u68C0\u67E5 OsClient \u662F\u5426\u6B63\u786E`:"\u670D\u52A1\u5668\u672A\u8FD4\u56DE\u914D\u7F6E\u6570\u636E")}catch(a){n&&(n.message=a instanceof Error?a.message:String(a))}return null}async getCaptcha(e,t){let n=j.getInstance(),r=I.getInstance();try{let i=await n.getRaw(H.GET_CAPTCHA,{OsClient:t||r.getOsClient()||""},e);if(i.data&&i.captchaId){let o=i.data.toString("base64");return{captchaId:i.captchaId,imageBase64:`data:image/png;base64,${o}`}}}catch{}return null}async login(e,t,n={}){let r=j.getInstance(),i=I.getInstance(),o=n.osClient||i.getOsClient(),a=n.silent??!1;try{let c=await this.getSysConfig(n.apiBaseUrl,o,void 0,a),l=c?.EnableCaptcha;if((l===!0||l===1||String(l||"").trim().toLowerCase()==="true")&&(!n.captchaId||!n.captchaValue)){let S="\u670D\u52A1\u5668\u5DF2\u5F00\u542F\u56FE\u5F62\u9A8C\u8BC1\u7801\uFF0C\u8BF7\u5728\u63D2\u4EF6\u914D\u7F6E\u4E2D\u4EA4\u4E92\u5F0F\u767B\u5F55\u3002";return a||A.error(`Microi: \u767B\u5F55\u5931\u8D25 - ${S}`),{ok:!1,msg:S}}let d=typeof c?.LoginRsaPublicKey=="string"&&c.LoginRsaPublicKey.trim()?c.LoginRsaPublicKey:vr,u=ai(t,d),p={Account:e,Pwd:u,OsClient:o||void 0,_ClientType:"VSCode"};n.captchaId&&n.captchaValue&&(p._CaptchaId=n.captchaId,p._CaptchaValue=n.captchaValue);let m=await r.request({method:"POST",path:H.LOGIN,body:p,bodyFormat:"form",apiBaseUrl:n.apiBaseUrl,osClient:n.osClient,osClientType:n.osClientType,osClientNetwork:n.osClientNetwork,allowAuthRetry:!1,silent:a}),y=m._headers?.authorization||"";if(m.Code===1)return y&&await r.setToken(y,n.apiBaseUrl,n.osClient,n.osClientType,n.osClientNetwork),this._secretStorage&&(n.apiBaseUrl?(await this._secretStorage.store(this.serverSecretKey(we,n.apiBaseUrl,o),e),await this._secretStorage.store(this.serverSecretKey(Te,n.apiBaseUrl,o),t)):(await this._secretStorage.store(this.secretKey(we),e),await this._secretStorage.store(this.secretKey(Te),t))),m.Data?.OsClient&&!o&&await i.updateSettings({osClient:m.Data.OsClient}),this._isLoggedIn=!0,await Je.executeCommand("setContext",nt,!0),await this.writeMcpTokenFile(),a||A.info(`Microi: \u767B\u5F55\u6210\u529F\uFF0C\u6B22\u8FCE ${m.Data?.Name||m.Data?.Account||e}`),{ok:!0,msg:""};{let S=m.Msg||"\u8BF7\u68C0\u67E5\u8D26\u53F7\u5BC6\u7801";return a||A.error(`Microi: \u767B\u5F55\u5931\u8D25 - ${S}`),{ok:!1,msg:S}}}catch(c){let l=c instanceof Error?c.message:String(c);return a||A.error(`Microi: \u767B\u5F55\u5931\u8D25 - ${l}`),{ok:!1,msg:l}}}async refreshAllTokens(){if(this._refreshInProgress)return;this._refreshInProgress=!0;let e=j.getInstance(),n=I.getInstance().getProfiles();try{for(let r of n){let i=e.getTokenForServer(r.apiBaseUrl,r.osClient,r.osClientType,r.osClientNetwork);if(!i){await this.reLoginForProfile(r);continue}try{let u=await e.request({method:"GET",path:H.GET_STATUS,apiBaseUrl:r.apiBaseUrl,osClient:r.osClient,osClientType:r.osClientType,osClientNetwork:r.osClientNetwork,allowAuthRetry:!1,silent:!0});if(Et(u))continue;if(qt(u)){await e.clearTokenForServer(r.apiBaseUrl,r.osClient,r.osClientType,r.osClientNetwork,i),await this.reLoginForProfile(r)||this.showAuthExpiredWarning(u.Msg||"\u5F53\u524D\u767B\u5F55\u8EAB\u4EFD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002");continue}}catch{}let o=this.readJwtClientClaims(i),a=String(o?.ClientType||"").trim(),c=a.toLowerCase()!=="vscode",l=!a||a.toLowerCase()==="empty";if(c&&(await this.reLoginForProfile(r)||!l))continue;let g=String(o?.Did||"").trim(),d=a.toLowerCase()==="vscode"&&g!==e.getDeviceId();if(!(!c&&!d&&!this.shouldRefreshToken(i,o)))try{let u=await e.request({method:"POST",path:H.REFRESH_TOKEN,body:{authorization:i,OsClient:r.osClient,_ClientType:"VSCode"},apiBaseUrl:r.apiBaseUrl,osClient:r.osClient,osClientType:r.osClientType,osClientNetwork:r.osClientNetwork,allowAuthRetry:!1,silent:!0}),m=u._headers?.authorization||"";u.Code===1&&m?await e.setToken(m,r.apiBaseUrl,r.osClient,r.osClientType,r.osClientNetwork):(await e.clearTokenForServer(r.apiBaseUrl,r.osClient,r.osClientType,r.osClientNetwork,i),await this.reLoginForProfile(r)||this.showAuthExpiredWarning(u.Msg||"\u5F53\u524D\u767B\u5F55\u8EAB\u4EFD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002"))}catch{await this.reLoginForProfile(r)}}}finally{this._isLoggedIn=e.hasToken,await Je.executeCommand("setContext",nt,this._isLoggedIn),await this.writeMcpTokenFile(),this._refreshInProgress=!1}}showAuthExpiredWarning(e){let t=String(e||"\u5F53\u524D\u767B\u5F55\u8EAB\u4EFD\u5DF2\u5931\u6548\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55\u3002"),n=Date.now();t===this._lastAuthWarning&&n-this._lastAuthWarningTime<60*1e3||(this._lastAuthWarning=t,this._lastAuthWarningTime=n,A.warn(`Microi: ${t}`))}readJwtClientClaims(e){try{let n=e.replace(/^Bearer\s+/i,"").trim().split(".");if(n.length<2)return null;let r=n[1].replace(/-/g,"+").replace(/_/g,"/");return JSON.parse(Buffer.from(r,"base64").toString("utf-8"))}catch{return null}}shouldRefreshToken(e,t){let n=t??this.readJwtClientClaims(e),r=Number(n?.exp);if(!Number.isFinite(r)||r<=0)return!0;let i=Number(n?.MicroiTokenIssuedAt??n?.iat),o=Number.isFinite(i)&&i>0&&r>i?r-i:Gr,a=Math.min(Gr,Math.max(si,Math.floor(o/10)));return r-Math.floor(Date.now()/1e3)<=a}async getCredentialsForProfile(e,t){if(!this._secretStorage)return null;let n=this.normalizeApiBaseUrl(e),r=this.normalizeOsClient(t),i=n?await this._secretStorage.get(this.serverSecretKey(we,n,r)):void 0,o=n?await this._secretStorage.get(this.serverSecretKey(Te,n,r)):void 0;return(!i||!o)&&n&&this.canUseLegacyCredential(n,r)&&(i=i||await this._secretStorage.get(this.legacyServerSecretKey(we,n)),o=o||await this._secretStorage.get(this.legacyServerSecretKey(Te,n))),(!i||!o)&&!n&&!r&&(i=i||await this._secretStorage.get(this.secretKey(we)),o=o||await this._secretStorage.get(this.secretKey(Te))),!i||!o?null:{username:i,password:o}}async reLoginForProfile(e){if(!this._secretStorage)return!1;let t=await this.getCredentialsForProfile(e.apiBaseUrl,e.osClient);return t?(await this.login(t.username,t.password,{silent:!0,apiBaseUrl:e.apiBaseUrl,osClient:e.osClient,osClientType:e.osClientType,osClientNetwork:e.osClientNetwork})).ok:!1}async recoverProfileLogin(e){let t=await this.reLoginForProfile(e);return t&&(this._isLoggedIn=!0,await this.writeMcpTokenFile()),t}startTokenRefresh(){this.stopTokenRefresh(),this.startMcpAuthRecoveryWatcher(),this.refreshAllTokens(),this._refreshTimer=setInterval(()=>{this.refreshAllTokens()},ri),this._windowStateSubscription=fe.onDidChangeWindowState(e=>{e.focused&&this.refreshAllTokens()})}stopTokenRefresh(){this._refreshTimer&&(clearInterval(this._refreshTimer),this._refreshTimer=void 0),this._windowStateSubscription&&(this._windowStateSubscription.dispose(),this._windowStateSubscription=void 0),this.stopMcpAuthRecoveryWatcher()}async logoutProfile(e){await j.getInstance().clearTokenForServer(e.apiBaseUrl,e.osClient,e.osClientType,e.osClientNetwork),this._secretStorage&&(await this._secretStorage.delete(this.serverSecretKey(we,e.apiBaseUrl,e.osClient)),await this._secretStorage.delete(this.serverSecretKey(Te,e.apiBaseUrl,e.osClient)),this.canUseLegacyCredential(e.apiBaseUrl,e.osClient)&&(await this._secretStorage.delete(this.legacyServerSecretKey(we,e.apiBaseUrl)),await this._secretStorage.delete(this.legacyServerSecretKey(Te,e.apiBaseUrl)))),await this.writeMcpTokenFile()}async logout(){if(this.stopTokenRefresh(),await j.getInstance().clearToken(),this._secretStorage){await this._secretStorage.delete(this.secretKey(we)),await this._secretStorage.delete(this.secretKey(Te));let t=I.getInstance().getProfiles();for(let n of t)await this._secretStorage.delete(this.serverSecretKey(we,n.apiBaseUrl,n.osClient)),await this._secretStorage.delete(this.serverSecretKey(Te,n.apiBaseUrl,n.osClient)),await this._secretStorage.delete(this.legacyServerSecretKey(we,n.apiBaseUrl)),await this._secretStorage.delete(this.legacyServerSecretKey(Te,n.apiBaseUrl))}this._isLoggedIn=!1,await Je.executeCommand("setContext",nt,!1),A.info("Microi: \u5DF2\u9000\u51FA\u767B\u5F55")}};var ci=/^\s*\*?\s*Version\s*:\s*(v\d+\.\d+\.\d+)\s*$/im,qr=/^v(\d+)\.(\d+)\.(\d+)$/;function rn(s){let e=(s||"").trim();if(!e)return null;let t=e.match(qr);if(t)return`v${Number(t[1])}.${Number(t[2])}.${Number(t[3])}`;let n=e.match(ci);return n?rn(n[1]):null}function Qr(s){if(!s)return null;let e=s.match(qr);return e?{major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3])}:null}function li(s,e){return s.major!==e.major?s.major-e.major:s.minor!==e.minor?s.minor-e.minor:s.patch-e.patch}function di(s){let e=null;for(let t of s){let n=Qr(t);n&&(!e||li(n,e)>0)&&(e=n)}return e?`v${e.major}.${e.minor}.${e.patch}`:null}function ui(s){let e=Qr(s);if(!e)return"v1.0.0";let{major:t,minor:n,patch:r}=e;return r<9?`v${t}.${n}.${r+1}`:(r=0,n<9?`v${t}.${n+1}.${r}`:(n=0,t+=1,`v${t}.${n}.${r}`))}function gi(s){let e=(s||"").trim();return e?e.replace(/\r\n/g,`
|
|
35
35
|
`).split(`
|
|
36
36
|
`).map(t=>t.trim()).filter(Boolean):["\u8BF7\u8865\u5145\u8BE5 V8 \u4EE3\u7801\u7684\u5B8C\u6574\u529F\u80FD\u8BF4\u660E\u3002"]}function pi(s){let e=s.replace(/\r\n/g,`
|
|
@@ -1985,8 +1985,8 @@ ${ct}
|
|
|
1985
1985
|
`)}ensureJsConfig(e,t){let n=_.join(e,"jsconfig.json"),r=e,i=e,o;if(D.existsSync(n))try{o=JSON.parse(D.readFileSync(n,"utf-8"))}catch{o={}}else o={};let a=o.compilerOptions||{};a.target=a.target||"ES2020",a.module=a.module||"CommonJS",a.checkJs=!0;let c=_.relative(e,t),l=a.typeRoots||[];l.includes(`./${c}`)||l.push(`./${c}`),a.typeRoots=l,o.compilerOptions=a;let g=o.include||[],d=_.relative(e,r),u=_.relative(e,i),p=`${c}/**/*`;for(let f of[`${d}/**/*`,`${u}/**/*`,p])g.includes(f)||g.push(f);o.include=g;let m=o.exclude||[];m.includes("node_modules")||m.push("node_modules"),o.exclude=m,D.writeFileSync(n,JSON.stringify(o,null,2),"utf-8")}cleanup(){let e=I.getInstance(),t=e.getWorkspaceRoot();if(!t)return;let n=e.getSyncRootDir(),r=_.join(n,wt),i=_.join(r,Gt);D.existsSync(i)&&D.unlinkSync(i);let o=_.join(t,wt),a=_.join(o,Gt);if(D.existsSync(a)&&D.unlinkSync(a),_.resolve(n)!==_.resolve(t)){let c=_.join(t,Rn,In),l=_.join(t,_n),g=_.join(t,Mn),d=_.join(t,An),u=_.join(t,Nn,Fn),p=Xr.map(f=>_.join(t,f)),m=_.join(t,Zr);if(this.canRemoveGeneratedAiDoc(t,c))try{D.unlinkSync(c)}catch{}if(this.canRemoveGeneratedAiDoc(t,l))try{D.unlinkSync(l)}catch{}if(this.canRemoveGeneratedAiDoc(t,g))try{D.unlinkSync(g)}catch{}if(this.canRemoveGeneratedAiDoc(t,d))try{D.unlinkSync(d)}catch{}if(this.canRemoveGeneratedAiDoc(t,u))try{D.unlinkSync(u)}catch{}for(let f of p)if(this.canRemoveGeneratedAiDoc(t,f))try{D.unlinkSync(f)}catch{}if(this.canRemoveGeneratedAiDoc(t,m))try{D.unlinkSync(m)}catch{}}this.cleanupSchemaDocs(n)}cleanupSchemaDocs(e){try{for(let t of D.readdirSync(e)){if(t.startsWith(".")&&t!==Ke)continue;let n=_.join(e,t);if(t===Ke)try{D.unlinkSync(n)}catch{}else try{D.statSync(n).isDirectory()&&this.cleanupSchemaDocs(n)}catch{}}}catch{}}};function Nt(s,e){let t=i=>{if(!(!i||!/^\d+(?:\.\d+){2}$/.test(i)))return i.split(".").map(o=>Number(o))},n=t(s),r=t(e);if(!n||!r)return 0;for(let i=0;i<3;i+=1)if(n[i]!==r[i])return n[i]>r[i]?1:-1;return 0}function At(s){let e=s.env,t=String(e?.MICROI_TOOL_VERSION||"").trim();return/^\d+(?:\.\d+){2}$/.test(t)?t:""}function an(s){let e=s.env||{},t=s.headers||{},r=(o=>o.trim().replace(/\/+$/,"").toLowerCase())(String(e.MICROI_API_URL||s.url||"")),i=String(e.MICROI_OS_CLIENT||t["X-Microi-OsClient"]||"").trim().toLowerCase();return`${r}|${i}`}function ns(s,e,t){let n={...s},r={},i=new Set,o=[];for(let[c,l]of Object.entries(e)){let g=an(l),d=At(l),u=Object.entries(n).filter(([m,f])=>{if(!t.isManaged(m,f))return!1;let y=an(f);return m===c||g!=="|"&&y===g}),p=u.find(([,m])=>Nt(At(m),d)>0);if(p){let m=At(p[1]);for(let[f]of u)i.add(f);o.push({name:p[0],version:m});continue}r[c]=l}let a=new Set(Object.values(r).map(an).filter(c=>c!=="|"));for(let[c,l]of Object.entries(n)){if(!t.isManaged(c,l)||i.has(c))continue;if(Object.prototype.hasOwnProperty.call(r,c)){delete n[c];continue}let g=an(l);if(a.has(g)){delete n[c];continue}(t.removeManagedNotInNext||t.isStableName&&!t.isStableName(c))&&delete n[c]}return Object.assign(n,r),{servers:n,skippedNewerProviders:o}}var Zn=B(require("child_process")),K=B(require("fs")),rs=B(require("os")),G=B(require("path")),$e="microi-net",Ie="microi",Ae=`${Ie}@${$e}`,dn="@microi.net/cli",ss="@microi.net/codex-plugin",Ft="microi-official",cn=`${Ie}@${Ft}`;function Yn(s){return[s.stderr,s.stdout].filter(Boolean).join(`
|
|
1986
1986
|
`).trim()}function is(s,e,t=3e4){let n=Zn.spawnSync(s.command,[...s.prefixArgs,...e],{encoding:"utf8",windowsHide:!0,timeout:t,maxBuffer:16777216});return{status:typeof n.status=="number"?n.status:1,stdout:String(n.stdout||""),stderr:[n.error?.message,n.stderr].filter(Boolean).join(`
|
|
1987
1987
|
`)}}function Mi(s){let e=G.extname(s).toLowerCase();return e===".js"||e===".cjs"||e===".mjs"?{command:process.execPath,prefixArgs:[s],displayPath:s}:process.platform==="win32"&&(e===".cmd"||e===".bat")?{command:process.env.ComSpec||"cmd.exe",prefixArgs:["/d","/s","/c",s],displayPath:s}:{command:s,prefixArgs:[],displayPath:s}}function Ai(){let s=String(process.env.MICROI_CODEX_PATH||"").trim();if(s){let r=G.resolve(s);if(!K.existsSync(r))throw new Error(`MICROI_CODEX_PATH \u6307\u5411\u7684\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${r}`);return[r]}let e=process.platform==="win32"?[["where.exe",["codex.exe"]],["where.exe",["codex"]]]:[["which",["codex"]]],t=[];for(let[r,i]of e){let o=Zn.spawnSync(r,i,{encoding:"utf8",windowsHide:!0,timeout:3e3});o.status===0&&t.push(...String(o.stdout||"").split(/\r?\n/).map(a=>a.trim()).filter(Boolean))}return process.platform!=="win32"&&t.push("codex"),[...new Map(t.map(r=>[process.platform==="win32"?r.toLowerCase():r,r])).values()].sort((r,i)=>{let o=G.extname(r).toLowerCase()===".exe"?0:1,a=G.extname(i).toLowerCase()===".exe"?0:1;return o-a})}function os(){for(let s of Ai()){if(G.isAbsolute(s)&&!K.existsSync(s))continue;let e=Mi(s),t=is(e,["--version"],5e3);if(t.status!==0)continue;let n=t.stdout.trim()||t.stderr.trim();if(/codex/i.test(n))return{...e,version:n}}}function Re(s,e,t=!1){let n=is(s,["-c",'model_reasoning_effort="high"',...e]);if(!t&&n.status!==0)throw new Error(`Codex CLI \u6267\u884C\u5931\u8D25\uFF1Acodex ${e.join(" ")}
|
|
1988
|
-
${Yn(n)}`.trim());return n}function Ni(s){let e=[];for(let t of s.split(/\r?\n/)){let n=t.trim().split(/\s{2,}/);n.length<2||n[0]==="MARKETPLACE"||e.push({name:n[0],root:n.slice(1).join(" ")})}return e}function Fi(s){let e=[];for(let t of s.split(/\r?\n/)){let n=t.trim().split(/\s{2,}/);if(n.length<2||n[0]==="PLUGIN"||!n[0].includes("@"))continue;let r=/^not installed$/i.test(n[1]||"");e.push({selector:n[0],status:n[1]||"",version:r?"":n[2]||"",pluginPath:r?n.slice(2).join(" "):n.slice(3).join(" ")})}return e}function Vi(){let e=[G.join(__dirname,"codex-marketplace.json"),G.resolve(__dirname,"..","..","codex","marketplace.npm.json")].find(t=>K.existsSync(t));if(!e)throw new Error("CLI \u7F3A\u5C11 codex-marketplace.json\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248 @microi.net/cli");return e}function Xn(s,e){let t=G.join(s,".codex-plugin","plugin.json"),n=G.join(s,"package.json"),r,i;try{r=JSON.parse(K.readFileSync(t,"utf8")),i=JSON.parse(K.readFileSync(n,"utf8"))}catch(o){throw new Error(`${e}\u8EAB\u4EFD\u6587\u4EF6\u65E0\u6CD5\u89E3\u6790\uFF1A${o instanceof Error?o.message:String(o)}`)}return{name:String(r.name||""),version:String(r.version||""),packageName:String(i.name||"")}}function xi(){let s=[G.resolve(__dirname,".."),G.resolve(__dirname,"..","..","plugins",Ie)];for(let e of s){if(!K.existsSync(G.join(e,".codex-plugin","plugin.json"))||!K.existsSync(G.join(e,"package.json")))continue;let t=Xn(e,"\u5185\u7F6E Microi
|
|
1989
|
-
`,expectedVersion:n.version,pluginRoot:n.root}}function $i(s,e){let t=`${s}.${process.pid}.${Date.now()}.tmp`;try{K.writeFileSync(t,e,"utf8"),K.renameSync(t,s)}finally{try{K.existsSync(t)&&K.unlinkSync(t)}catch{}}}function cs(){return G.resolve(process.env.CODEX_HOME||G.join(rs.homedir(),".codex"))}function Li(s,e,t){let n=G.resolve(s),r=G.resolve(e),i=G.relative(n,r);if(!i||!i.startsWith("..")&&!G.isAbsolute(i))throw new Error(`Codex \u63D2\u4EF6\u76EE\u6807\u76EE\u5F55\u4E0D\u80FD\u4F4D\u4E8E npm \u5305\u5185\u90E8\uFF1A${r}`);if(K.existsSync(r)){let d=Xn(r,"\u73B0\u6709 Microi
|
|
1988
|
+
${Yn(n)}`.trim());return n}function Ni(s){let e=[];for(let t of s.split(/\r?\n/)){let n=t.trim().split(/\s{2,}/);n.length<2||n[0]==="MARKETPLACE"||e.push({name:n[0],root:n.slice(1).join(" ")})}return e}function Fi(s){let e=[];for(let t of s.split(/\r?\n/)){let n=t.trim().split(/\s{2,}/);if(n.length<2||n[0]==="PLUGIN"||!n[0].includes("@"))continue;let r=/^not installed$/i.test(n[1]||"");e.push({selector:n[0],status:n[1]||"",version:r?"":n[2]||"",pluginPath:r?n.slice(2).join(" "):n.slice(3).join(" ")})}return e}function Vi(){let e=[G.join(__dirname,"codex-marketplace.json"),G.resolve(__dirname,"..","..","codex","marketplace.npm.json")].find(t=>K.existsSync(t));if(!e)throw new Error("CLI \u7F3A\u5C11 codex-marketplace.json\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248 @microi.net/cli");return e}function Xn(s,e){let t=G.join(s,".codex-plugin","plugin.json"),n=G.join(s,"package.json"),r,i;try{r=JSON.parse(K.readFileSync(t,"utf8")),i=JSON.parse(K.readFileSync(n,"utf8"))}catch(o){throw new Error(`${e}\u8EAB\u4EFD\u6587\u4EF6\u65E0\u6CD5\u89E3\u6790\uFF1A${o instanceof Error?o.message:String(o)}`)}return{name:String(r.name||""),version:String(r.version||""),packageName:String(i.name||"")}}function xi(){let s=[G.resolve(__dirname,".."),G.resolve(__dirname,"..","..","plugins",Ie)];for(let e of s){if(!K.existsSync(G.join(e,".codex-plugin","plugin.json"))||!K.existsSync(G.join(e,"package.json")))continue;let t=Xn(e,"\u5185\u7F6E Microi Agentx \u63D2\u4EF6");if(t.name===Ie&&t.packageName===dn&&t.version)return{root:e,version:t.version}}throw new Error("CLI \u7F3A\u5C11\u5B8C\u6574\u7684 Microi Agentx \u63D2\u4EF6\u6587\u4EF6\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248 @microi.net/cli")}function Oi(s){if(!s||s.name!==Ie)return!1;if(s.source?.source==="local")return String(s.source.path||"").replace(/\\/g,"/").replace(/^\.\//,"")==="plugins/microi";let e=[dn,ss];return s.source?.source==="npm"&&e.includes(s.source.package||"")}function as(){let s=K.readFileSync(Vi(),"utf8"),e;try{e=JSON.parse(s)}catch(r){throw new Error(`Codex marketplace \u6A21\u677F\u65E0\u6CD5\u89E3\u6790\uFF1A${r instanceof Error?r.message:String(r)}`)}let t=e.plugins?.find(r=>r.name===Ie);if(e.name!==$e||t?.source?.source!=="local"||String(t.source.path||"").replace(/\\/g,"/").replace(/^\.\//,"")!=="plugins/microi")throw new Error("Codex marketplace \u6A21\u677F\u8EAB\u4EFD\u4E0D\u5408\u6CD5\uFF0C\u62D2\u7EDD\u5199\u5165\u5168\u5C40\u914D\u7F6E");let n=xi();return{manifest:e,content:`${JSON.stringify(e,null,2)}
|
|
1989
|
+
`,expectedVersion:n.version,pluginRoot:n.root}}function $i(s,e){let t=`${s}.${process.pid}.${Date.now()}.tmp`;try{K.writeFileSync(t,e,"utf8"),K.renameSync(t,s)}finally{try{K.existsSync(t)&&K.unlinkSync(t)}catch{}}}function cs(){return G.resolve(process.env.CODEX_HOME||G.join(rs.homedir(),".codex"))}function Li(s,e,t){let n=G.resolve(s),r=G.resolve(e),i=G.relative(n,r);if(!i||!i.startsWith("..")&&!G.isAbsolute(i))throw new Error(`Codex \u63D2\u4EF6\u76EE\u6807\u76EE\u5F55\u4E0D\u80FD\u4F4D\u4E8E npm \u5305\u5185\u90E8\uFF1A${r}`);if(K.existsSync(r)){let d=Xn(r,"\u73B0\u6709 Microi Agentx \u63D2\u4EF6"),u=[dn,ss];if(d.name!==Ie||!u.includes(d.packageName))throw new Error(`\u76EE\u6807\u76EE\u5F55\u5305\u542B\u975E Microi \u7BA1\u7406\u7684\u63D2\u4EF6\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${r}`)}let o=G.dirname(r);K.mkdirSync(o,{recursive:!0});let a=`${process.pid}-${Date.now()}`,c=G.join(o,`.microi-staging-${a}`),l=G.join(o,`.microi-backup-${a}`),g=!1;try{K.cpSync(n,c,{recursive:!0,errorOnExist:!0});let d=Xn(c,"\u5F85\u5B89\u88C5 Microi Agentx \u63D2\u4EF6");if(d.name!==Ie||d.packageName!==dn||d.version!==t)throw new Error("\u5F85\u5B89\u88C5\u7684 Microi Agentx \u63D2\u4EF6\u8EAB\u4EFD\u6216\u7248\u672C\u4E0D\u4E00\u81F4");K.existsSync(r)&&(K.renameSync(r,l),g=!0),K.renameSync(c,r)}catch(d){if(!K.existsSync(r)&&g&&K.existsSync(l))try{K.renameSync(l,r)}catch{}throw d}finally{try{K.existsSync(c)&&K.rmSync(c,{recursive:!0,force:!0})}catch{}}try{K.existsSync(l)&&K.rmSync(l,{recursive:!0,force:!0})}catch{}}function Bi(s,e,t){let n=cs(),r=G.join(n,"microi-net-marketplace"),i=G.join(r,".agents","plugins","marketplace.json"),o=G.join(r,"plugins",Ie);if(K.mkdirSync(G.dirname(i),{recursive:!0}),K.existsSync(i)){let a;try{a=JSON.parse(K.readFileSync(i,"utf8"))}catch(l){throw new Error(`\u5DF2\u5B58\u5728\u7684 Microi marketplace \u65E0\u6CD5\u89E3\u6790\uFF0C\u5DF2\u4FDD\u7559\u539F\u6587\u4EF6\uFF1A${i}\uFF08${l instanceof Error?l.message:String(l)}\uFF09`)}let c=a.plugins?.find(l=>l.name===Ie);if(a.name!==$e||!Oi(c))throw new Error(`\u76EE\u6807\u76EE\u5F55\u5305\u542B\u975E Microi \u7BA1\u7406\u7684 marketplace\uFF0C\u62D2\u7EDD\u8986\u76D6\uFF1A${i}`)}return Li(e,o,t),(!K.existsSync(i)||K.readFileSync(i,"utf8")!==s)&&$i(i,s),r}function Ui(s){let e=s.trim();if(!e||/[\r\n]/.test(e))throw new Error("Codex marketplace source \u65E0\u6548");let t=G.resolve(e);if(K.existsSync(t))return t;if(G.isAbsolute(e)||e.startsWith("."))throw new Error(`Codex marketplace \u672C\u5730\u8DEF\u5F84\u4E0D\u5B58\u5728\uFF1A${t}`);return e}function ln(s,e){let t=Ni(Re(s,["plugin","marketplace","list"]).stdout),n=Fi(Re(s,["plugin","list"]).stdout),r=t.find(u=>u.name===$e),i=n.find(u=>u.selector===Ae),o=t.some(u=>u.name===Ft),a=n.some(u=>u.selector===cn&&/^installed\b/i.test(u.status)),c=!!(i&&/^installed\b/i.test(i.status)),l=!!(i&&/enabled/i.test(i.status)),g=!e||i?.version===e,d=c?l?g?"none":"update":"enable":"install";return{ok:c&&l&&g,codex:{found:!0,command:s.displayPath,version:s.version},marketplace:{name:$e,configured:!!r,root:r?.root||""},plugin:{selector:Ae,installed:c,enabled:l,version:i?.version||"",expectedVersion:e},legacy:{marketplaceConfigured:o,pluginInstalled:a},action:d}}function ls(){let{expectedVersion:s}=as(),e=os();return e?ln(e,s):{ok:!1,codex:{found:!1,command:"",version:""},marketplace:{name:$e,configured:!1,root:""},plugin:{selector:Ae,installed:!1,enabled:!1,version:"",expectedVersion:s},legacy:{marketplaceConfigured:!1,pluginInstalled:!1},action:"install-codex"}}function ds(s={}){let{content:e,expectedVersion:t,pluginRoot:n}=as(),r=os();if(!r)throw new Error("\u672A\u627E\u5230\u53EF\u6267\u884C\u7684 Codex CLI\u3002\u8BF7\u5148\u5B89\u88C5\u6216\u66F4\u65B0 Codex\uFF0C\u518D\u6267\u884C microi codex install --yes");K.mkdirSync(cs(),{recursive:!0});let i=ln(r,t);if(i.ok&&!s.force){i.legacy.pluginInstalled&&Re(r,["plugin","remove",cn]),i.legacy.marketplaceConfigured&&Re(r,["plugin","marketplace","remove",Ft]);let d=i.legacy.pluginInstalled||i.legacy.marketplaceConfigured;return{installed:!0,changed:d,selector:Ae,version:i.plugin.version,migratedFrom:d?Ft:void 0,restartRequired:d}}let o=s.marketplaceSource?Ui(s.marketplaceSource):Bi(e,n,t);i.marketplace.configured||Re(r,["plugin","marketplace","add",o]);let a=ln(r,t);if(!a.marketplace.configured)throw new Error(`Codex \u672A\u80FD\u6CE8\u518C marketplace ${$e}`);let c;s.force&&a.plugin.installed?(Re(r,["plugin","remove",Ae]),c=Re(r,["plugin","add",Ae],!0)):c=Re(r,["plugin","add",Ae],!0);let l=ln(r,t);if(!l.plugin.installed||!l.plugin.enabled){let d=s.force?"--force \u5DF2\u6267\u884C\u663E\u5F0F\u91CD\u88C5\uFF0C\u8BF7\u68C0\u67E5\u4E0A\u65B9\u9519\u8BEF\u540E\u91CD\u8BD5\u3002":"\u539F\u6709\u63D2\u4EF6\u672A\u88AB\u5220\u9664\u3002";throw new Error(`\u5B89\u88C5 ${Ae} \u5931\u8D25\uFF0C${d}${Yn(c)?`
|
|
1990
1990
|
${Yn(c)}`:""}`.trim())}if(l.plugin.version!==t)throw new Error(`\u5F53\u524D\u5DF2\u5B89\u88C5 ${l.plugin.version||"\u672A\u77E5\u7248\u672C"}\uFF0C\u76EE\u6807\u63D2\u4EF6\u5FEB\u7167\u4E3A ${t}\u3002\u8BF7\u4F7F\u7528 --force \u663E\u5F0F\u91CD\u88C5\u3002`);let g=i.legacy.pluginInstalled?cn:"";return i.legacy.pluginInstalled&&Re(r,["plugin","remove",cn]),i.legacy.marketplaceConfigured&&Re(r,["plugin","marketplace","remove",Ft]),{installed:!0,changed:!0,selector:Ae,version:l.plugin.version,marketplace:$e,marketplaceSource:o,migratedFrom:g||void 0,restartRequired:!0,next:"\u65B0\u5EFA Codex \u4EFB\u52A1\u6216\u91CD\u8F7D Codex\uFF0C\u4F7F\u63D2\u4EF6 Skills \u4E0E MCP \u751F\u6548\u3002"}}var nr=B(require("child_process")),ke=B(require("fs")),un=B(require("os")),Z=B(require("path")),Fe="@microi.net/cli",ji=["web","headless"],Ki="https://registry.npmjs.org/";function gn(s){try{let e=JSON.parse(ke.readFileSync(s,"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}catch{return}}function Ne(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:void 0}function us(){let s=[Z.resolve(__dirname,".."),Z.resolve(__dirname,"..","..","plugins","microi")];for(let e of s){let t=gn(Z.join(e,"package.json")),n=Ne(t?.dsh),r=Ne(n?.bundle),i=String(r?.patch||""),o=String(t?.version||"");if(!(t?.name!==Fe||!o||i!=="./cordis.patch.yml")&&ke.existsSync(Z.join(e,"cordis.patch.yml")))return{root:e,version:o,patch:i}}throw new Error("CLI \u7F3A\u5C11\u5B8C\u6574\u7684 Microi DeepSeek Harness bundle\uFF0C\u8BF7\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248 @microi.net/cli")}function Hi(s){let e=Z.extname(s).toLowerCase();return e===".js"||e===".cjs"||e===".mjs"?{command:process.execPath,prefixArgs:[s],displayPath:s}:process.platform==="win32"&&(e===".cmd"||e===".bat")?{command:process.env.ComSpec||"cmd.exe",prefixArgs:["/d","/s","/c",s],displayPath:s}:{command:s,prefixArgs:[],displayPath:s}}function gs(s,e,t=3e4){let n=nr.spawnSync(s.command,[...s.prefixArgs,...e],{cwd:process.cwd(),encoding:"utf8",windowsHide:!0,timeout:t,maxBuffer:33554432,env:{...process.env}});return{status:typeof n.status=="number"?n.status:1,stdout:String(n.stdout||""),stderr:[n.error?.message,n.stderr].filter(Boolean).join(`
|
|
1991
1991
|
`)}}function Wi(){let s=String(process.env.MICROI_DSH_PATH||"").trim();if(s){let n=Z.resolve(s);if(!ke.existsSync(n))throw new Error(`MICROI_DSH_PATH \u6307\u5411\u7684\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${n}`);return[n]}let e=process.platform==="win32"?[["where.exe",["dsh.exe"]],["where.exe",["dsh.cmd"]],["where.exe",["dsh"]]]:[["which",["dsh"]]],t=[];for(let[n,r]of e){let i=nr.spawnSync(n,r,{encoding:"utf8",windowsHide:!0,timeout:3e3});i.status===0&&t.push(...String(i.stdout||"").split(/\r?\n/).map(o=>o.trim()).filter(Boolean))}return process.platform!=="win32"&&t.push("dsh"),[...new Map(t.map(n=>[process.platform==="win32"?n.toLowerCase():n,n])).values()]}function ps(){for(let s of Wi()){if(Z.isAbsolute(s)&&!ke.existsSync(s))continue;let e=Hi(s),t=gs(e,["--version"],5e3);if(t.status!==0)continue;let n=t.stdout.trim()||t.stderr.trim();if(n)return{...e,version:n}}}function Gi(s){return s==="~"?un.homedir():s.startsWith("~/")||s.startsWith("~\\")?Z.join(un.homedir(),s.slice(2)):s}function er(){let s=String(process.env.DSH_HOME||"").trim();return Z.resolve(Gi(s||Z.join(un.homedir(),".dsh")))}function zi(s){let e=s.trim();if(!e||e==="."||e===".."||e==="node_modules"||/[/\\]/.test(e))throw new Error(`DeepSeek Harness profile \u540D\u79F0\u65E0\u6548\uFF1A${JSON.stringify(s)}`);return e}function ms(s){return s?[zi(s)]:[...ji]}function Ji(s,e){if(!e)return;let t=Z.resolve(s,e),n=Z.relative(s,t);if(!(!n||n.startsWith("..")||Z.isAbsolute(n)))return t}function tr(s,e,t){let n=Z.join(s,"profiles",e),r=gn(Z.join(n,"package.json")),i=Ne(r?.dependencies),o=Ne(r?.dsh),a=Ne(o?.profile),c=Array.isArray(a?.bundles)?a?.bundles.map(String):[],l=Z.join(n,"node_modules","@microi.net","cli"),g=gn(Z.join(l,"package.json")),d=Ne(g?.dsh),u=Ne(d?.bundle),p=String(u?.patch||""),m=Ji(l,p),f=!!r,y=typeof i?.[Fe]=="string",S=g?.name===Fe,h=S?String(g?.version||""):"",C=c.includes(Fe),T=p==="./cordis.patch.yml"&&!!(m&&ke.existsSync(m)),b=h===t;return{profile:e,profileDir:n,initialized:f,dependencyDeclared:y,installed:S,active:C,installedVersion:h,expectedVersion:t,bundlePatch:p,bundlePatchExists:T,ok:f&&y&&S&&C&&T&&b,action:!S||!y?"install":!b||!T?"update":C?"none":"activate"}}function qi(s,e){let t=us(),n=er(),r=e.map(o=>tr(n,o,t.version)),i=s?r.some(o=>o.action==="install")?"install":r.some(o=>o.action==="update")?"update":r.some(o=>o.action==="activate")?"activate":"none":"install-dsh";return{ok:!!s&&r.every(o=>o.ok),dsh:{found:!!s,command:s?.displayPath||"",version:s?.version||"",home:n},package:{name:Fe,expectedVersion:t.version,bundlePatch:t.patch},profiles:r,action:i,requiresNewSession:i!=="none"&&i!=="install-dsh"}}function fs(s){return qi(ps(),ms(s))}function Qi(s){let e=Z.resolve(s);if(!ke.existsSync(e))throw new Error(`DeepSeek Harness bundle \u672C\u5730\u6765\u6E90\u4E0D\u5B58\u5728\uFF1A${e}`);if(!ke.statSync(e).isDirectory()){if(!/\.(?:tgz|tar\.gz)$/i.test(e))throw new Error("DeepSeek Harness bundle --source \u53EA\u63A5\u53D7\u672C\u5730\u76EE\u5F55\u6216 .tgz/.tar.gz");return e}let t=[e,Z.join(e,"plugins","microi")];for(let n of t){let r=gn(Z.join(n,"package.json")),i=Ne(r?.dsh),o=Ne(i?.bundle);if(r?.name===Fe&&o?.patch==="./cordis.patch.yml"&&ke.existsSync(Z.join(n,"cordis.patch.yml")))return n}throw new Error(`\u672C\u5730\u6765\u6E90\u4E0D\u662F\u5B8C\u6574\u7684 ${Fe} DeepSeek Harness bundle\uFF1A${e}`)}function Yi(s){return[s.stderr,s.stdout].filter(Boolean).join(`
|
|
1992
1992
|
`).trim().slice(0,5e3)}function hs(s={}){let e=ps();if(!e)throw new Error("\u672A\u68C0\u6D4B\u5230 DeepSeek Harness dsh CLI\uFF1B\u8BF7\u5148\u6267\u884C npm install -g @deepseek-ai/dsh\uFF0C\u518D\u91CD\u8BD5 microi dsh install");let t=us(),n=ms(s.profile),r=s.source?Qi(s.source):"",i=r||`${Fe}@${t.version}`,o=[];for(let c of n){let l=tr(er(),c,t.version);if(l.ok&&!s.force){o.push({...l,changed:!1});continue}let g=["plugin","--profile",c,"add",i,"--save-exact",...r?[]:[`--registry=${Ki}`]],d=gs(e,g,5*6e4);if(d.status!==0)throw new Error(`DeepSeek Harness profile ${c} \u5B89\u88C5 Microi bundle \u5931\u8D25\uFF1A${Yi(d)||`exit ${d.status}`}`);let u=tr(er(),c,t.version);if(!u.ok)throw new Error(`DeepSeek Harness profile ${c} \u5B89\u88C5\u540E\u6821\u9A8C\u5931\u8D25\uFF08action=${u.action}\uFF0Cversion=${u.installedVersion||"missing"}\uFF09`);o.push({...u,changed:!0})}let a=o.some(c=>c.changed);return{ok:!0,package:`${Fe}@${t.version}`,source:i,profiles:o,requiresNewSession:a,message:a?"Microi\u543E\u7801\u5DF2\u5B89\u88C5\u4E3A DeepSeek Harness profile bundle\uFF1B\u8BF7\u65B0\u5EFA DSH \u4F1A\u8BDD\u52A0\u8F7D\u65B0\u589E MCP \u5DE5\u5177\uFF0C\u5F53\u524D\u4F1A\u8BDD\u4E0D\u4F1A\u88AB\u7EC8\u6B62\u3002":"DeepSeek Harness \u4E2D\u7684 Microi\u543E\u7801 bundle \u5DF2\u662F\u5F53\u524D\u7248\u672C\uFF0C\u65E0\u9700\u6539\u52A8\u3002"}}var pn=B(require("crypto")),$=B(require("fs")),Ot=B(require("os")),U=B(require("path"));function rr(s){return s.normalize("NFKD").replace(/[^\x00-\x7F]/g,"").replace(/[^A-Za-z0-9_]+/g,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"").toLowerCase().slice(0,48)}function Ss(s){try{return rr(new URL(s.apiBaseUrl.trim().replace(/\/+$/,"")).host)}catch{return rr(s.apiBaseUrl)}}function ys(s){return rr(s.osClient||s.sysShortTitle||s.sysTitle||s.label||"")||Ss(s)||"default"}function lt(s){let e=new Map;for(let r of s){let i=ys(r);e.set(i,(e.get(i)||0)+1)}let t=new Set(Array.from(e).filter(([,r])=>r>1).map(([r])=>r)),n=new Set;return s.map(r=>{let i=Ss(r),o=ys(r),a=`microi_${o}`,c=t.has(o)&&i&&i!==o?`${a}_${i}`:a;n.has(c)&&i&&(c=`${a}_${i}`);let l=2;for(;n.has(c);)c=`${a}_${l++}`;return n.add(c),{profile:r,mcpName:c}})}var Vt="";function Le(){if(Vt)return Vt;try{let s=JSON.parse($.readFileSync(U.join(__dirname,"..","package.json"),"utf8"));Vt=/^\d+(?:\.\d+){2}$/.test(String(s.version||""))?String(s.version):"0.0.0"}catch{Vt="0.0.0"}return Vt}function Xi(s){return s.trim().replace(/\/+$/,"")}function Zi(){let s=`MCP:${Ot.hostname()||"Unknown"}`;return/^[\x20-\x7E]{1,128}$/.test(s)?s:`MCP-${pn.createHash("sha256").update(s).digest("hex").slice(0,16)}`}function ws(s){let e=U.basename(s).toLowerCase();return!!process.versions.electron||["code.exe","code - insiders.exe","cursor.exe","windsurf.exe","trae.exe","electron.exe"].includes(e)}function eo(){return{command:process.execPath,isElectron:ws(process.execPath)}}function to(s,e){let t=e.env;return/^microi(?:_|-|$)/i.test(s)||typeof t?.MICROI_API_URL=="string"}function Ts(s,e){let t=`${s}.${process.pid}.${Date.now()}.tmp`;try{$.writeFileSync(t,e,"utf8"),$.renameSync(t,s)}finally{try{$.existsSync(t)&&$.unlinkSync(t)}catch{}}}function _e(s,e){if($.existsSync(s)&&$.readFileSync(s).equals(e))return;$.mkdirSync(U.dirname(s),{recursive:!0});let t=`${process.pid}.${Date.now()}.${pn.randomBytes(4).toString("hex")}`,n=`${s}.${t}.stage`,r=`${s}.${t}.backup`,i=!1;try{$.writeFileSync(n,e),$.existsSync(s)&&($.renameSync(s,r),i=!0),$.renameSync(n,s),i&&$.rmSync(r,{force:!0})}catch(o){if(!$.existsSync(s)&&i&&$.existsSync(r))try{$.renameSync(r,s)}catch{}throw o}finally{try{$.existsSync(n)&&$.rmSync(n,{force:!0})}catch{}}}function no(){let s=Le();if(!/^\d+(?:\.\d+){2}$/.test(s))throw new Error(`CLI \u7248\u672C\u4E0D\u5408\u6CD5\uFF0C\u65E0\u6CD5\u521B\u5EFA MCP \u8FD0\u884C\u65F6\uFF1A${s}`);let e={launcher:U.join(__dirname,"microi-cli-mcp.js"),server:U.join(__dirname,"mcp-server.js"),adapter:U.join(__dirname,"mcp-codex-stdio-adapter.js"),router:U.join(__dirname,"microi-codex-router.js"),broker:U.join(__dirname,"microi-codex-broker.js"),cli:U.join(__dirname,"microi-cli.js"),trae:U.join(__dirname,"mcp-trae-windows-launcher.cmd")},t=Object.values(e).filter(u=>!$.existsSync(u));if(t.length>0)throw new Error(`CLI \u5B89\u88C5\u5305\u7F3A\u5C11\u5185\u7F6E MCP \u8FD0\u884C\u6587\u4EF6\uFF1A${t.join(", ")}`);let n=U.resolve(process.env.MICROI_RUNTIME_HOME||U.join(Ot.homedir(),".microi","runtime")),r=U.join(n,"versions"),i=U.join(r,s);$.mkdirSync(i,{recursive:!0}),_e(U.join(i,"microi-cli-mcp.js"),$.readFileSync(e.launcher)),_e(U.join(i,"mcp-server.js"),$.readFileSync(e.server)),_e(U.join(i,"microi-codex-router.js"),$.readFileSync(e.router)),_e(U.join(i,"microi-codex-broker.js"),$.readFileSync(e.broker)),_e(U.join(i,"microi-cli.js"),$.readFileSync(e.cli));let o=`#!/usr/bin/env node
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
|
-
* Shared Microi
|
|
3
|
+
* Shared Microi Agentx MCP broker.
|
|
4
4
|
*
|
|
5
5
|
* Every Codex task still owns a tiny stdio router, but all routers for the same
|
|
6
6
|
* workspace and tool version share this broker. The broker owns at most one
|
|
@@ -92,7 +92,7 @@ function writeLeaseRecord(record, exclusive = false) {
|
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
94
|
const current = readLease();
|
|
95
|
-
if (!current || current.token !== ownerToken) throw new Error('Microi
|
|
95
|
+
if (!current || current.token !== ownerToken) throw new Error('Microi Agentx broker lease ownership changed');
|
|
96
96
|
const staged = `${leasePath}.${process.pid}.${Date.now()}.tmp`;
|
|
97
97
|
try {
|
|
98
98
|
fs.writeFileSync(staged, text, { encoding: 'utf8', mode: 0o600 });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/*
|
|
3
|
-
* Microi
|
|
3
|
+
* Microi Agentx Plugin 多连接路由器。
|
|
4
4
|
*
|
|
5
5
|
* 它只负责发现 VS Code/CLI 共用的工作区配置、选择连接并把请求转发给
|
|
6
6
|
* 同一份 Microi MCP bundle。所有业务 schema、确认口令、审计和写后回读
|
|
@@ -444,7 +444,7 @@ async function callRouterTool(args) {
|
|
|
444
444
|
arguments: { action, params: args?.params || {} },
|
|
445
445
|
});
|
|
446
446
|
} catch (error) {
|
|
447
|
-
return resultText(`Microi
|
|
447
|
+
return resultText(`Microi Agentx 路由失败:${error instanceof Error ? error.message : String(error)}`, true);
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
|