@deveco-test/deveco-cli 1.3.0-Test.4 → 1.3.0-Test.5

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.
@@ -3626,36 +3626,6 @@ SOFTWARE.
3626
3626
 
3627
3627
  -----------
3628
3628
 
3629
- The following npm package may be included in this product:
3630
-
3631
- - @deveco-test/deveco-cli@1.3.0-Test.4
3632
-
3633
- This package contains the following license:
3634
-
3635
- MIT License
3636
-
3637
- Copyright (c) 2026 Huawei Device Co., Ltd.
3638
-
3639
- Permission is hereby granted, free of charge, to any person obtaining a copy
3640
- of this software and associated documentation files (the "Software"), to deal
3641
- in the Software without restriction, including without limitation the rights
3642
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3643
- copies of the Software, and to permit persons to whom the Software is
3644
- furnished to do so, subject to the following conditions:
3645
-
3646
- The above copyright notice and this permission notice shall be included in all
3647
- copies or substantial portions of the Software.
3648
-
3649
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3650
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3651
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3652
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3653
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3654
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3655
- SOFTWARE.
3656
-
3657
- -----------
3658
-
3659
3629
  The following npm package may be included in this product:
3660
3630
 
3661
3631
  - merge-descriptors@2.0.0
package/dist/cli.js CHANGED
@@ -30,7 +30,7 @@ Available runnable modules:
30
30
  `))}async function yp(n,e,t,r,i,o){o&&(console.log(`Uninstalling ${t}...`),await n.uninstallApp(e,t)||console.log(`App ${t} not installed; skipping uninstallation.`)),console.log(`
31
31
  Installing artifacts to device ${e}...`),await n.installApp(e,r),console.log(`Launching ${t}/${i}...`);let s=await n.launchApp(e,t,i);console.log(Ys(`
32
32
  Application '${t}': ${s}`))}var vp=new up("run").description("Build and run the project on a connected device").option("--module <modules...>","Module(s) to run (format: module or module@target)").option("--device <device>","Target device name or serial").option("--product <product>","Product name (default: default)").option("--build-mode <mode>","Build mode (options: debug, release; default: debug)").option("--ability <ability>","Ability name to launch").option("--uninstall","Uninstall existing app before installation").option("--skip-build","Skip build step and deploy existing artifacts").action(async n=>{try{await bp(n)}catch(e){console.error(pp(e.message)),process.exit(1)}});async function wp(n,e,t,r,i){let o=new ft(e,n.rootDir),s=new nt(e,n.rootDir),a=new Set;for(let{moduleName:f,targetName:P}of t)for(let C of n.collectNonHarDependentModuleList(f))a.add(`${C}@${P}`);let c=[...a],l=Hi(n,c),u={type:"modules",modulesToBuild:c,moduleTasks:l};await Kt(n.rootDir,()=>Fi(o,s,r,i,u,n.rootDir),()=>console.log("Another build is already running for this project. Waiting for completion...")),console.log(`
33
- `+Ys("Build completed successfully."))}async function bp(n){let e=tt.discover(process.cwd());console.warn(mp("Ensure the project source is trusted before proceeding."));let t=await N.new(),i=gp(e,n.module).map(hp);for(let{moduleName:ne}of i){let he=e.getModuleType(ne);if(he!=="entry"&&he!=="feature"&&he!=="shared")throw new Error(`Module '${ne}' '${he}' is not runnable. Specify an entry or feature module.`)}let o=new Kn(t),s=G.from(t),a=await fp(s,n.device),c=a.includes("127.0.0.1")||a.includes("localhost"),l=n.product||"default";e.validateProduct(l);let u=n.buildMode||"debug";n.skipBuild||await wp(e,t,i,l,u);let f=new Set;for(let{moduleName:ne,targetName:he}of i){let Wn=e.collectNonHarDependentModuleList(ne);for(let Lu of Wn)f.add(e.findArtifactPath(Lu,he,c,l));f.add(e.findArtifactPath(ne,he,c,l))}let P=[...f],C=e.getBundleName(),L=e.getMainAbility(i[0].moduleName,n.ability);await yp(o,a,C,P,L,!!n.uninstall)}var Js=vp;import{Command as Sp}from"commander";import{green as Ks,red as Zs,cyan as Bi}from"colorette";import{execa as Xs}from"execa";function Ep(){return"@deveco-test/deveco-cli"}function Pp(){return"1.3.0-Test.4"}var Cp=new Sp("update").description("Update deveco-cli to latest").action(async()=>{let n=Ep(),e=Pp();console.log(Bi("Checking for updates..."));try{let{stdout:t}=await Xs("npm",["view",n,"version"]),r=t.trim();if(r===e){console.log(Ks(`
33
+ `+Ys("Build completed successfully."))}async function bp(n){let e=tt.discover(process.cwd());console.warn(mp("Ensure the project source is trusted before proceeding."));let t=await N.new(),i=gp(e,n.module).map(hp);for(let{moduleName:ne}of i){let he=e.getModuleType(ne);if(he!=="entry"&&he!=="feature"&&he!=="shared")throw new Error(`Module '${ne}' '${he}' is not runnable. Specify an entry or feature module.`)}let o=new Kn(t),s=G.from(t),a=await fp(s,n.device),c=a.includes("127.0.0.1")||a.includes("localhost"),l=n.product||"default";e.validateProduct(l);let u=n.buildMode||"debug";n.skipBuild||await wp(e,t,i,l,u);let f=new Set;for(let{moduleName:ne,targetName:he}of i){let Wn=e.collectNonHarDependentModuleList(ne);for(let Lu of Wn)f.add(e.findArtifactPath(Lu,he,c,l));f.add(e.findArtifactPath(ne,he,c,l))}let P=[...f],C=e.getBundleName(),L=e.getMainAbility(i[0].moduleName,n.ability);await yp(o,a,C,P,L,!!n.uninstall)}var Js=vp;import{Command as Sp}from"commander";import{green as Ks,red as Zs,cyan as Bi}from"colorette";import{execa as Xs}from"execa";function Ep(){return"@deveco-test/deveco-cli"}function Pp(){return"1.3.0-Test.5"}var Cp=new Sp("update").description("Update deveco-cli to latest").action(async()=>{let n=Ep(),e=Pp();console.log(Bi("Checking for updates..."));try{let{stdout:t}=await Xs("npm",["view",n,"version"]),r=t.trim();if(r===e){console.log(Ks(`
34
34
  ${n} is already up to date (version ${e}.)`));return}console.log(Bi(`
35
35
  New version found: ${r} (current: ${e})`)),console.log(Bi(`Updating ${n}...`)),await Xs("npm",["install","-g",`${n}@latest`],{stdio:"inherit"}),console.log(`
36
36
  `+Ks(`${n} updated successfully to version ${r}.`))}catch(t){let r=t;console.error(Zs(`Failed to update ${n}`)),r.message&&console.error(Zs(r.message)),process.exit(1)}}),Qs=Cp;import{Command as Kp}from"commander";import{execa as Xn}from"execa";function V(n){return n.normalize("NFKC").replace(/\s+/g," ").trim()}import{spawn as Dp}from"child_process";var Ip=2500;function Ap(n,e,t,r,i,o){n.once("exit",s=>{if(o())return;clearTimeout(e);let a=t();s===0||s===null?r():i(a||`Emulator process exited with code ${s}`)})}function xp(n,e,t,r){let i=!1,o=()=>i,s=()=>Buffer.concat(e).toString("utf8").trim(),a=()=>{i||(i=!0,clearTimeout(l),n.removeAllListeners(),n.stderr?.removeAllListeners(),n.stderr?.destroy(),n.unref(),t())},c=u=>{if(!i){i=!0,clearTimeout(l),n.removeAllListeners(),n.stderr?.removeAllListeners();try{n.kill()}catch{}r(new Error(u))}},l=setTimeout(a,Ip);n.once("error",u=>c(u.message)),Ap(n,l,s,a,c,o)}function ea(n,e,t){return g(`Spawning emulator: ${n} ${t.join(" ")}`),new Promise((r,i)=>{let o=[],s=Dp(n,t,{detached:!0,stdio:["ignore","ignore","pipe"],env:{...process.env,DEVECO_SDK_HOME:e},windowsHide:!0});s.stderr?.on("data",a=>o.push(a)),xp(s,o,r,i)})}import*as vt from"path";function Tp(n){let e=new Set,t=[];for(let r of n){let i=JSON.stringify(r);e.has(i)||(e.add(i),t.push(r))}return t}function kp(n){let e=n.instancePath?.trim();if(e)return vt.dirname(vt.normalize(e)).replace(/\\/g,"/");let t=n.path?.trim();return t?vt.dirname(vt.normalize(t)).replace(/\\/g,"/"):""}function Rp(n){let e=[];return n&&e.push(["-imageRoot",n]),e.push([]),e}function ta(n,e){return e?[...n,"-bootmode",e]:n}function Mp(n,e,t){let r=[ta(["-start",n],t)],i=kp(e);if(i)for(let o of Rp(e.imageRoot))r.push(ta(["-hvd",n,"-path",i,...o],t));return Tp(r)}async function na(n,e,t,r){let i=new Error("No start strategy ran"),o=Mp(n,e,r);for(let s of o)try{return await t(s),{ok:!0}}catch(a){i=a}return{ok:!1,lastError:i}}async function Wi(n){return(await G.withHdcPath(n).listDevices()).map(t=>t.serial).filter(Xt)}async function Ui(n){let e=await Wi(n);return e.length===0?[]:(await Promise.all(e.map(r=>Jn(n,r,"ohos.qemu.hvd.name")))).filter(r=>!!r)}async function ra(n,e){return(await Ui(n)).includes(e)}import*as bt from"path";import{existsSync as Op,statSync as Lp}from"fs";function wt(n,e){for(let t of e){let r=n[t];if(typeof r=="string"&&r.trim())return r.trim()}return""}function Np(n){let e=wt(n,["instancePath","instance_path","InstancePath","instancepath","instanceDir","instance_dir","InstanceDir","deployPath","deploy_path","deployedPath","deployed_path","workPath","work_path","dataPath","data_path"]);if(e)return e;for(let[t,r]of Object.entries(n)){if(typeof r!="string"||!r.trim())continue;let i=t.toLowerCase();if(i.includes("instance")&&(i.includes("path")||i.includes("dir"))||i==="deployedpath")return r.trim()}return""}function _p(n){return wt(n,["uuid","UUID","Uuid","instanceUuid","instance_uuid","InstanceUuid"])}function Hp(n){let e=n.find(r=>r.instancePath?.trim());if(!e?.instancePath?.trim())return;let t=bt.dirname(bt.normalize(e.instancePath));for(let r of n){if(r.instancePath?.trim())continue;let i=bt.join(t,r.name);Op(i)&&Lp(i).isDirectory()&&(r.instancePath=i.replace(/\\/g,"/"))}}function Fp(n){try{let e=JSON.parse(n);return Array.isArray(e)?e.map(t=>{let r=_p(t),i=wt(t,["deviceType","DeviceType","devicetype"]),o=wt(t,["os.osVersion","osVersion","OsVersion","OSVersion"]);return{name:t.name||t.Name||"",isRunning:t.isRunning===!0||String(t.isRunning).toLowerCase()==="true",instancePath:Np(t),path:wt(t,["path","Path","hvdPath","hvd_path"]),imageRoot:wt(t,["imageRoot","image_root","ImageRoot"]),uuid:r||void 0,deviceType:i||void 0,osVersion:o||void 0}}).filter(t=>t.name):null}catch{return null}}function jp(n){let e=[],t=/^(name|isrunning|instancepath|path|imageroot|devicetype|os\.osversion)\s*:\s*(.+)/gim,r=null,i;for(;(i=t.exec(n))!==null;){let[,o,s]=i;if(o.toLowerCase()==="name")r&&e.push(r),r={name:s.trim()};else if(r){let a=o.toLowerCase();a==="isrunning"?r.isRunning=s.trim().toLowerCase()==="true":a==="instancepath"?r.instancePath=s.trim():a==="path"?r.path=s.trim():a==="imageroot"?r.imageRoot=s.trim():a==="devicetype"?r.deviceType=s.trim():a==="os.osversion"&&(r.osVersion=s.trim())}}return r&&e.push(r),e}function ia(n){let t=Fp(n)??jp(n);return Hp(t),t}function zi(n,e){for(let t of e){let r=n[t];if(typeof r=="string"&&r.trim())return r.trim()}return""}function $p(n){let e=n.downloaded??n.Downloaded;return e===!0||String(e).toLowerCase()==="true"}function Bp(n){if(!$p(n))return null;let e=zi(n,["osVersion","OsVersion","OSVersion"]),t=zi(n,["SoftWareVersion","SoftwareVersion","softwareVersion"]),r=zi(n,["deviceType","DeviceType"]);return!e&&!t?null:{osVersion:e,softwareVersion:t,deviceType:r}}function Zn(n){let e=n.trim();if(!e)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let r=[];for(let i of t){if(!i||typeof i!="object")continue;let o=Bp(i);o&&r.push(o)}return r}catch{return[]}}function oa(n){let t=Zn(n).map(r=>r.osVersion).filter(Boolean);return[...new Set(t)]}var sa=/no images are available/i,Wp="7.0.0";function De(n){return n.normalize("NFKC").trim().toLowerCase()}function Up(n){let e=n.message||"";return sa.test(e)}function zp(n){return n.normalize("NFKC").match(/(\d+(?:\.\d+){1,3})/)?.[1]}function qp(n,e){let t=n.split(".").map(o=>Number(o)),r=e.split(".").map(o=>Number(o)),i=Math.max(t.length,r.length);for(let o=0;o<i;o++){let s=(t[o]??0)-(r[o]??0);if(s!==0)return s}return 0}function Qt(n,e){return`${n} ${e.join(" ")}`.trim()}function Gp(n){switch(n.type){case"gps":return`${n.type}:${n.key}=${n.value}`;case"sensor":return`${n.type}:${n.key}=${n.value}`;case"rotation":case"volume":return`${n.type}:${n.direction}`;case"folded-state":return`${n.type}:${n.state}`;case"battery":return`${n.type}:${n.level}`;case"battery-status":return`${n.type}:${n.status}`;default:return n.type}}var St=class n{static supportedControlPaths=new Set;emulatorPath;sdkPath;hdcPath;constructor(e,t,r){this.emulatorPath=e,this.sdkPath=t,this.hdcPath=r}static from(e){return new n(e.emulatorPath,e.sdkPath,e.hdcPath)}async executeEmulator(e){return g(`Executing: ${Qt(this.emulatorPath,e)}`),Xn(this.emulatorPath,e,{stdio:["ignore","pipe","pipe"],env:{...process.env,DEVECO_SDK_HOME:this.sdkPath}})}executeEmulatorDetached(e){return ea(this.emulatorPath,this.sdkPath,e)}async listEmulators(){let{stdout:e}=await this.executeEmulator(["-list","-details"]);return ia(e)}async getDeviceTypeByName(){let e=new Map;try{let t=await this.listEmulators();for(let r of t)r.name&&r.deviceType&&e.set(V(r.name),r.deviceType)}catch{}return e}async startEmulator(e){let t=await this.listEmulators(),r=V(e),i=t.find(a=>V(a.name)===r);if(!i)throw new Error(`Emulator "${e}" not found.`);let o=i.name;if(await this.isAlreadyRunning(o,i))return"already-running";await this.assertSystemImageAvailable(i);let s=await na(o,i,a=>this.executeEmulatorDetached(a),"snapshot");if(s.ok)return"started";if(await this.isAlreadyRunning(o))return"already-running";throw new Error(`Unable to start emulator "${e}". All methods failed.
@@ -1277,7 +1277,7 @@ Output so far:
1277
1277
  `).length,o=await this.withOpenFile(t,async a=>this.manager.sendFeatureRequest(y.INLAY_HINT,{textDocument:{uri:a},range:{start:{line:0,character:0},end:{line:i,character:0}}}));return{content:[{type:"text",text:o==null?"inlayHint: no result":`inlayHint: ${JSON.stringify(o,null,2)}`}]}}catch(r){return this.buildErrorResponse("inlayHint",r)}}async handleDocumentLink(e){if(!this.initialized)return this.buildNotReadyResponse();let t=this.resolveSingleFile(e);if(!t)return{content:[{type:"text",text:`\u6587\u4EF6\u4E0D\u5B58\u5728\u6216\u4E0D\u662F .ets \u6587\u4EF6: ${e}`}],isError:!0};try{let r=await this.withOpenFile(t,async o=>this.manager.sendFeatureRequest(y.DOCUMENT_LINK,{textDocument:{uri:o}}));return{content:[{type:"text",text:r==null?"documentLink: no result":`documentLink: ${JSON.stringify(r,null,2)}`}]}}catch(r){return this.buildErrorResponse("documentLink",r)}}buildErrorResponse(e,t){let r=t instanceof Error?t.message:String(t);return h.error(`${e} failed: ${r}`),{content:[{type:"text",text:`${e} failed: ${r}`}],isError:!0}}async withOpenFile(e,t){let r=at(e),i=await re.promises.readFile(e,"utf8"),s=`deveco.apptool.${Y.extname(e).replace(/^\./,"")||"plaintext"}`;h.debug(`withOpenFile didOpen uri=${r} len=${i.length}`),this.sendNotification("textDocument/didOpen",{textDocument:{uri:r,text:i,languageId:s,version:i.length}});try{return await t(r)}finally{this.sendNotification("textDocument/didClose",{textDocument:{uri:r},isManual:!1})}}resolveSingleFile(e){let t=Y.isAbsolute(e)?e:Y.join(this.projectPath,e);return!re.existsSync(t)||!re.statSync(t).isFile()||!t.endsWith(".ets")?null:t}buildNotReadyResponse(){return{content:[{type:"text",text:this.initializing?"LSP \u6B63\u5728\u521D\u59CB\u5316\u4E2D\uFF0C\u8BF7\u7A0D\u540E\u518D\u8BD5":this.projectPath?"LSP\u672A\u521D\u59CB\u5316":"\u6CA1\u6709\u914D\u7F6E\u5DE5\u7A0B\u8DEF\u5F84\uFF0C\u8BF7\u914D\u7F6EPROJECT_PATH\u53C2\u6570"}],isError:!0}}collectValidFiles(e,t){let r=this.projectPath,i=[];for(let o of e){let s=Y.isAbsolute(o)?o:Y.join(r,o);if(!re.existsSync(s)){t.push(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${o}`);continue}if(!re.statSync(s).isFile()){t.push(`\u4E0D\u662F\u666E\u901A\u6587\u4EF6: ${o}`);continue}if(!s.endsWith(".ets")){t.push(`\u4E0D\u662F .ets \u6587\u4EF6: ${o}`);continue}i.push(s)}return i}async runDiagnosticsForFiles(e,t,r){for(let i of e){await zc(500);try{let o=await this.checkFile(i);r.push(qg(i,o))}catch(o){t.push(`${i} => wait for diagnostics failed: ${o.message}`)}}}formatCallResult(e,t){let r=[];e.length>0&&r.push(e.join(`
1278
1278
  `)),t.length>0&&r.push(t.join(`
1279
1279
  `));let i=r.join(`
1280
- `).trim(),o=e.length>0;return!o&&t.length===0&&(i="\u672A\u6536\u96C6\u5230\u8BCA\u65AD\u4FE1\u606F"),{content:[{type:"text",text:i}],isError:o}}async shutdown(){let e=this.initReject;if(this.clearInitHandlers(),e?.(new Error("LSP shutting down")),this.manager){try{await this.manager.dispose()}catch(t){h.warn(`Failed to dispose ArktsLspManager: ${t}`)}this.manager=null}this.initialized=!1,this.initializing=!1,this.initPromise=null}sendNotification(e,t){if(!this.manager)throw new Error("ArktsLspManager not initialized");this.manager.sendNotification({jsonrpc:"2.0",method:e,params:t})}handleLspMessage(e){let t=e,r=t.method;if(r)switch(r){case"textDocument/publishDiagnostics":{this.handleDiagnosticsNotification(t.params);break}case"arkts/indexingProgress":this.initResolve&&(this.armInitTimer(We),h.debug("Received arkts/indexingProgress, reset init timeout"));break;case"arkts/initialized":{h.info("Received arkts/initialized");let i=this.initResolve;this.clearInitHandlers(),i?.();break}case"arkts/initializationFailed":{let o=t.params?.message??"unknown";h.error(`LSP initialization failed: ${o}`);let s=this.initReject;this.clearInitHandlers(),s?.(new Error(`LSP initialize failed: ${o}`));break}case"workspace/didChangeConfiguration":h.info("Received workspace/didChangeConfiguration, sync deferred to next check");break;default:break}}handleDiagnosticsNotification(e){if(!e)return;let t=e.uri;if(!t)return;let r=this.popDiagnosticWaiter(t);if(!r&&this.diagnosticWaiters.size===1){let s=this.diagnosticWaiters.keys().next().value;r=this.popDiagnosticWaiter(s)}if(!r)return;if(typeof e.errorMessage=="string"){h.warn(`diagnostics error uri=${t} message=${e.errorMessage}`),r.resolve({errorMessage:e.errorMessage});return}let i=e.diagnostics,o=Array.isArray(i)?i.length:0;h.debug(`diagnostics received uri=${t} count=${o}`),r.resolve(Array.isArray(i)?i:[])}popDiagnosticWaiter(e){let t=this.diagnosticWaiters.get(e);if(t)return this.diagnosticWaiters.delete(e),clearTimeout(t.timer),t}getLogAndIndexPath(e){try{let t=Y.join(At(),"ArkTSCheck"),r=Y.join(t,"mapping-config.properties"),i=Gc(e,r),o=`${Date.now()}${process.hrtime.bigint()%1000000n}`,s=Y.join(t,"lsp-log",String(i),o),a=Y.join(t,"lsp-index",String(i));return re.mkdirSync(s,{recursive:!0}),re.mkdirSync(a,{recursive:!0}),{logPath:ue(s),indexPath:ue(a)}}catch{return{logPath:"auto",indexPath:"auto"}}}};function zg(n){if(Array.isArray(n))return n;if(n&&typeof n=="object"){let e=n;if(e.kind==="full"&&Array.isArray(e.items))return e.items}return[]}function qg(n,e){if(Array.isArray(e))return e.length===0?`${n} => no diagnostics`:`${n} => Diagnostic: ${JSON.stringify(e)}`;if(e&&typeof e=="object"&&typeof e.errorMessage=="string"){let t=e.errorMessage;return`${n} diagnostic failed, error_message: ${t}`}return`${n} => diagnostic failed, result: ${JSON.stringify(e)}`}import{spawn as Gg}from"child_process";import*as M from"fs";import*as B from"path";import{z as No}from"zod";var vl=60*1e3,Vg=30*1e3,Yg=new Set(["textDocument/didOpen","textDocument/didChange","textDocument/didClose","textDocument/didSave"]),Jg=1e3,_o=class{nextRequestId=1;pendingRequests=new Map;diagnosticWaiters=new Map;fileCheckLock=Promise.resolve();closed=!1;wrapperState="preInitialize";queuedDocumentNotifications=[];backendReady=!1;projectPath=null;clangdStdin=null;clangdStdout=null;clangdBuffer=Buffer.alloc(0);constructor(){}isClosed(){return this.closed}async initialize(e){this.projectPath=e,this.wrapperState="waitingForDatabase"}async connectClangdProcess(e,t){if(this.closed)throw new Error("Client is already closed");this.clangdStdin=e,this.clangdStdout=t,this.wrapperState="startingBackend",this.clangdStdout.on("data",a=>this.handleClangdData(a)),this.clangdStdout.on("error",a=>{h.warn(`[CppCheck] clangd stdout error: ${a}`),this.failAll(new Error(`clangd stdout error: ${a}`))}),this.clangdStdout.on("end",()=>{this.failAll(new Error("C++ language server connection closed"))});let r=ue(this.projectPath),i=at(r),o=B.basename(r)||"workspace",s={processId:null,clientInfo:{name:"devecocli-mcp-server",version:"1.3.0-Test.4"},rootPath:r,rootUri:i,workspaceFolders:[{uri:i,name:o}],capabilities:{}};await this.sendRequestToClangd("initialize",s,vl),await this.sendNotificationToClangd("initialized",{}),this.backendReady=!0,this.wrapperState="proxying";for(let a of this.queuedDocumentNotifications)await this.writeToClangd(a);this.queuedDocumentNotifications.length=0,h.info("[CppCheck] clangd backend ready, switched to proxying mode")}async waitForBackendReady(){if(this.backendReady)return;let e=vl,t=Date.now();for(;!this.backendReady&&!this.closed&&Date.now()-t<e;)await new Promise(r=>setTimeout(r,500));if(!this.backendReady)throw new Error("Timed out waiting for clangd backend to be ready")}async checkFile(e){await this.waitForBackendReady();let t=await this.acquireFileCheckLock();try{return await this.doCheckFile(e)}finally{t()}}async doCheckFile(e){let t;try{t=M.realpathSync(e)}catch{t=e}let r=at(t),i=qc(t),o=await M.promises.readFile(t,"utf8"),s=new Promise((a,c)=>{let l=setTimeout(()=>{this.diagnosticWaiters.delete(r)&&c(new Error(`Timed out waiting for diagnostics: ${e}`))},Vg);this.diagnosticWaiters.set(r,{resolve:a,reject:c,timer:l})});try{await this.sendNotification("textDocument/didOpen",{textDocument:{uri:r,languageId:i,version:1,text:o}})}catch(a){let c=this.diagnosticWaiters.get(r);throw c&&(clearTimeout(c.timer),this.diagnosticWaiters.delete(r)),a}try{return await s}finally{await this.closeFile(r).catch(a=>{h.warn(`[CppCheck] didClose failed for ${r}: ${a}`)})}}async close(){if(!this.closed&&(this.closed=!0,this.wrapperState="shuttingDown",this.backendReady&&this.clangdStdin)){try{await this.sendRequestToClangd("shutdown",null,3e3)}catch(e){h.warn(`[CppCheck] shutdown request failed: ${e}`)}try{await this.sendNotificationToClangd("exit",null)}catch(e){h.warn(`[CppCheck] exit notification failed: ${e}`)}try{this.clangdStdin.end()}catch(e){h.warn(`[CppCheck] stdin.end() failed: ${e}`)}}}async sendNotification(e,t){let r={jsonrpc:"2.0",method:e,params:t??void 0};if(this.backendReady&&this.clangdStdin){await this.writeToClangd(r);return}Yg.has(e)&&this.queuedDocumentNotifications.push(r)}async closeFile(e){await this.sendNotification("textDocument/didClose",{textDocument:{uri:e}})}async sendRequestToClangd(e,t,r){let i=this.nextRequestId++;return new Promise((o,s)=>{let a=setTimeout(()=>{this.pendingRequests.delete(i)&&s(new Error(`Timed out waiting for ${e} response`))},r);this.pendingRequests.set(i,{resolve:o,reject:s,timer:a}),this.writeToClangd({jsonrpc:"2.0",id:i,method:e,params:t??void 0}).catch(c=>{this.pendingRequests.delete(i)&&(clearTimeout(a),s(c))})})}async sendNotificationToClangd(e,t){await this.writeToClangd({jsonrpc:"2.0",method:e,params:t??void 0})}async writeToClangd(e){if(!this.clangdStdin)throw new Error("clangd stdin not available");return new Promise((t,r)=>{let i;try{i=JSON.stringify(e)}catch(u){r(new Error(`Failed to encode LSP message: ${u}`));return}let o=Buffer.from(i,"utf8"),s=Buffer.from(`Content-Length: ${o.length}\r
1280
+ `).trim(),o=e.length>0;return!o&&t.length===0&&(i="\u672A\u6536\u96C6\u5230\u8BCA\u65AD\u4FE1\u606F"),{content:[{type:"text",text:i}],isError:o}}async shutdown(){let e=this.initReject;if(this.clearInitHandlers(),e?.(new Error("LSP shutting down")),this.manager){try{await this.manager.dispose()}catch(t){h.warn(`Failed to dispose ArktsLspManager: ${t}`)}this.manager=null}this.initialized=!1,this.initializing=!1,this.initPromise=null}sendNotification(e,t){if(!this.manager)throw new Error("ArktsLspManager not initialized");this.manager.sendNotification({jsonrpc:"2.0",method:e,params:t})}handleLspMessage(e){let t=e,r=t.method;if(r)switch(r){case"textDocument/publishDiagnostics":{this.handleDiagnosticsNotification(t.params);break}case"arkts/indexingProgress":this.initResolve&&(this.armInitTimer(We),h.debug("Received arkts/indexingProgress, reset init timeout"));break;case"arkts/initialized":{h.info("Received arkts/initialized");let i=this.initResolve;this.clearInitHandlers(),i?.();break}case"arkts/initializationFailed":{let o=t.params?.message??"unknown";h.error(`LSP initialization failed: ${o}`);let s=this.initReject;this.clearInitHandlers(),s?.(new Error(`LSP initialize failed: ${o}`));break}case"workspace/didChangeConfiguration":h.info("Received workspace/didChangeConfiguration, sync deferred to next check");break;default:break}}handleDiagnosticsNotification(e){if(!e)return;let t=e.uri;if(!t)return;let r=this.popDiagnosticWaiter(t);if(!r&&this.diagnosticWaiters.size===1){let s=this.diagnosticWaiters.keys().next().value;r=this.popDiagnosticWaiter(s)}if(!r)return;if(typeof e.errorMessage=="string"){h.warn(`diagnostics error uri=${t} message=${e.errorMessage}`),r.resolve({errorMessage:e.errorMessage});return}let i=e.diagnostics,o=Array.isArray(i)?i.length:0;h.debug(`diagnostics received uri=${t} count=${o}`),r.resolve(Array.isArray(i)?i:[])}popDiagnosticWaiter(e){let t=this.diagnosticWaiters.get(e);if(t)return this.diagnosticWaiters.delete(e),clearTimeout(t.timer),t}getLogAndIndexPath(e){try{let t=Y.join(At(),"ArkTSCheck"),r=Y.join(t,"mapping-config.properties"),i=Gc(e,r),o=`${Date.now()}${process.hrtime.bigint()%1000000n}`,s=Y.join(t,"lsp-log",String(i),o),a=Y.join(t,"lsp-index",String(i));return re.mkdirSync(s,{recursive:!0}),re.mkdirSync(a,{recursive:!0}),{logPath:ue(s),indexPath:ue(a)}}catch{return{logPath:"auto",indexPath:"auto"}}}};function zg(n){if(Array.isArray(n))return n;if(n&&typeof n=="object"){let e=n;if(e.kind==="full"&&Array.isArray(e.items))return e.items}return[]}function qg(n,e){if(Array.isArray(e))return e.length===0?`${n} => no diagnostics`:`${n} => Diagnostic: ${JSON.stringify(e)}`;if(e&&typeof e=="object"&&typeof e.errorMessage=="string"){let t=e.errorMessage;return`${n} diagnostic failed, error_message: ${t}`}return`${n} => diagnostic failed, result: ${JSON.stringify(e)}`}import{spawn as Gg}from"child_process";import*as M from"fs";import*as B from"path";import{z as No}from"zod";var vl=60*1e3,Vg=30*1e3,Yg=new Set(["textDocument/didOpen","textDocument/didChange","textDocument/didClose","textDocument/didSave"]),Jg=1e3,_o=class{nextRequestId=1;pendingRequests=new Map;diagnosticWaiters=new Map;fileCheckLock=Promise.resolve();closed=!1;wrapperState="preInitialize";queuedDocumentNotifications=[];backendReady=!1;projectPath=null;clangdStdin=null;clangdStdout=null;clangdBuffer=Buffer.alloc(0);constructor(){}isClosed(){return this.closed}async initialize(e){this.projectPath=e,this.wrapperState="waitingForDatabase"}async connectClangdProcess(e,t){if(this.closed)throw new Error("Client is already closed");this.clangdStdin=e,this.clangdStdout=t,this.wrapperState="startingBackend",this.clangdStdout.on("data",a=>this.handleClangdData(a)),this.clangdStdout.on("error",a=>{h.warn(`[CppCheck] clangd stdout error: ${a}`),this.failAll(new Error(`clangd stdout error: ${a}`))}),this.clangdStdout.on("end",()=>{this.failAll(new Error("C++ language server connection closed"))});let r=ue(this.projectPath),i=at(r),o=B.basename(r)||"workspace",s={processId:null,clientInfo:{name:"devecocli-mcp-server",version:"1.3.0-Test.5"},rootPath:r,rootUri:i,workspaceFolders:[{uri:i,name:o}],capabilities:{}};await this.sendRequestToClangd("initialize",s,vl),await this.sendNotificationToClangd("initialized",{}),this.backendReady=!0,this.wrapperState="proxying";for(let a of this.queuedDocumentNotifications)await this.writeToClangd(a);this.queuedDocumentNotifications.length=0,h.info("[CppCheck] clangd backend ready, switched to proxying mode")}async waitForBackendReady(){if(this.backendReady)return;let e=vl,t=Date.now();for(;!this.backendReady&&!this.closed&&Date.now()-t<e;)await new Promise(r=>setTimeout(r,500));if(!this.backendReady)throw new Error("Timed out waiting for clangd backend to be ready")}async checkFile(e){await this.waitForBackendReady();let t=await this.acquireFileCheckLock();try{return await this.doCheckFile(e)}finally{t()}}async doCheckFile(e){let t;try{t=M.realpathSync(e)}catch{t=e}let r=at(t),i=qc(t),o=await M.promises.readFile(t,"utf8"),s=new Promise((a,c)=>{let l=setTimeout(()=>{this.diagnosticWaiters.delete(r)&&c(new Error(`Timed out waiting for diagnostics: ${e}`))},Vg);this.diagnosticWaiters.set(r,{resolve:a,reject:c,timer:l})});try{await this.sendNotification("textDocument/didOpen",{textDocument:{uri:r,languageId:i,version:1,text:o}})}catch(a){let c=this.diagnosticWaiters.get(r);throw c&&(clearTimeout(c.timer),this.diagnosticWaiters.delete(r)),a}try{return await s}finally{await this.closeFile(r).catch(a=>{h.warn(`[CppCheck] didClose failed for ${r}: ${a}`)})}}async close(){if(!this.closed&&(this.closed=!0,this.wrapperState="shuttingDown",this.backendReady&&this.clangdStdin)){try{await this.sendRequestToClangd("shutdown",null,3e3)}catch(e){h.warn(`[CppCheck] shutdown request failed: ${e}`)}try{await this.sendNotificationToClangd("exit",null)}catch(e){h.warn(`[CppCheck] exit notification failed: ${e}`)}try{this.clangdStdin.end()}catch(e){h.warn(`[CppCheck] stdin.end() failed: ${e}`)}}}async sendNotification(e,t){let r={jsonrpc:"2.0",method:e,params:t??void 0};if(this.backendReady&&this.clangdStdin){await this.writeToClangd(r);return}Yg.has(e)&&this.queuedDocumentNotifications.push(r)}async closeFile(e){await this.sendNotification("textDocument/didClose",{textDocument:{uri:e}})}async sendRequestToClangd(e,t,r){let i=this.nextRequestId++;return new Promise((o,s)=>{let a=setTimeout(()=>{this.pendingRequests.delete(i)&&s(new Error(`Timed out waiting for ${e} response`))},r);this.pendingRequests.set(i,{resolve:o,reject:s,timer:a}),this.writeToClangd({jsonrpc:"2.0",id:i,method:e,params:t??void 0}).catch(c=>{this.pendingRequests.delete(i)&&(clearTimeout(a),s(c))})})}async sendNotificationToClangd(e,t){await this.writeToClangd({jsonrpc:"2.0",method:e,params:t??void 0})}async writeToClangd(e){if(!this.clangdStdin)throw new Error("clangd stdin not available");return new Promise((t,r)=>{let i;try{i=JSON.stringify(e)}catch(u){r(new Error(`Failed to encode LSP message: ${u}`));return}let o=Buffer.from(i,"utf8"),s=Buffer.from(`Content-Length: ${o.length}\r
1281
1281
  \r
1282
1282
  `,"ascii"),a=!1,c=u=>{a||(a=!0,u?r(u):t())};if(this.clangdStdin.write(Buffer.concat([s,o]),u=>{u?c(u):a||c()}))c();else{let u=()=>c();this.clangdStdin.once("drain",u)}})}handleClangdData(e){for(this.clangdBuffer=this.clangdBuffer.length===0?e:Buffer.concat([this.clangdBuffer,e]);;){let t=this.clangdBuffer.indexOf(`\r
1283
1283
  \r
@@ -1363,4 +1363,4 @@ CREATE INDEX segments_doc_id_idx ON segments(doc_id);
1363
1363
  Detail: ${n.message}`):n}try{await Xe()}catch(n){let e=n instanceof Error?n.message:String(n);throw new $n(`${tb()}
1364
1364
 
1365
1365
  Detail: ${e}`)}try{await Hn()}catch(n){let e=n instanceof Error?n.message:String(n);throw new $n(nb(e))}}var Ps=class extends Error{constructor(t,r){super(r);this.code=t;this.name="DocNotReadyError"}code};function ob(n){return new Promise(e=>setTimeout(e,n))}async function sb(n){let e=qt();await z.promises.mkdir(Jt.dirname(e),{recursive:!0}),await z.promises.appendFile(e,`${new Date().toISOString()} ${n}
1366
- `)}async function ab(n){let e=Je();if(!e)throw new Error("docs.zip not found");await z.promises.rm(n,{recursive:!0,force:!0}),await z.promises.mkdir(n,{recursive:!0}),new rb(e).extractAllTo(n,!0),await Au(n)}async function cb(){let n=te(),e=zt(),t=await z.promises.readdir(e);for(let r of t){let i=Jt.join(n,r);await z.promises.rm(i,{force:!0}),await z.promises.rename(Jt.join(e,r),i)}await z.promises.rm(e,{recursive:!0,force:!0}),await z.promises.rm(Jt.join(n,"orama.dpack"),{force:!0})}async function lb(n,e){e?.start("Installing documentation index\u2026"),await Ze({state:"installing",phase:1,phaseLabel:"Installing index",message:"Installing documentation index\u2026"}),await hd(n),e&&(e.text="Documentation index installed.")}async function db(n,e,t){let r=zt(),i=await Iu();await z.promises.mkdir(te(),{recursive:!0}),await z.promises.rm(r,{recursive:!0,force:!0}),t?.start("Building search index\u2026"),await Ze({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"});try{await ab(i),await Du({docsDir:i,tmpDir:r,docsZipSha256:e,termsHash:ui(),synonymsHash:di(),builtBy:n.builtBy??"doc-init",onProgress:async o=>{t&&(t.text=o.message),await Ze({state:"indexing",current:o.current,total:o.total,message:o.message})}})}finally{await z.promises.rm(i,{recursive:!0,force:!0})}await Ze({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await cb(),eu()}async function Tu(n){await Ze({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),n?.succeed("Documentation ready.")}async function ub(n){let e=await rs(),t=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";n?.succeed(t),await Ze({state:"done",message:t,error:null})}async function pb(n,e){let t=n instanceof Error?n.message:String(n);throw await Ze({state:"error",error:t}),await sb(`ERROR: ${t}`),e?.fail(t),n}async function mb(){let n=te();await z.promises.mkdir(n,{recursive:!0});let e=td();return z.existsSync(e)||await z.promises.writeFile(e,"","utf-8"),e}async function hb(){let n=await mb();return ib.lock(n,{stale:1800*1e3})}async function fb(){let n=Je(),e=(n?await li(n):null)??await ns();if(!e)throw new Error("docs.zip not found");return e}async function gb(n,e){let t=await fb(),r=n.force||await os(n.force),i=await is(n.force);if(!r&&!i&&kn()){await ub(e);return}if(Xo()&&!n.force){await lb(t,e),await Tu(e);return}await db(n,t,e),await Tu(e)}var Cs=class{static async run(e={}){let t=e.background??!1,i=e.quiet??t?void 0:Ru({text:"Checking documentation\u2026",color:"cyan"}),o;try{o=await hb(),await ts(wd("Starting documentation setup\u2026")),await gb(e,i)}catch(s){return pb(s,i)}finally{o&&await o()}}};async function yb(n){for(;;){let e=await pi();if(e.state==="done"&&kn())return;if(e.state==="error")throw new Ps("build-failed",e.error??"Documentation setup failed. Try your docs command again in a moment.");n.text=e.message||"Documentation is being prepared\u2026",await ob(500)}}async function ku(n,e=!1){n.text=e?"Repairing documentation index\u2026":"Starting documentation setup\u2026",await Cs.run({builtBy:"doc-init",force:e,quiet:!0})}async function vb(){if(kn())return;let n=Ru({text:"Documentation is being prepared\u2026",color:"cyan"}).start();try{if(await bd()){await yb(n),n.succeed("Documentation ready.");return}if(await os()){await ku(n),n.succeed("Documentation ready.");return}await ku(n,!0),n.succeed("Documentation ready.")}catch(e){throw n.fail(e.message),e}}async function Bn(){await vb(),await xu()}var Ds=class{async search(e,t,r=20){return await Bn(),ru(e,t,r)}async readDocument(e){return await Bn(),ud(e)}},Is=new Ds;function Mu(...n){return e=>{if(!n.includes(e))throw new As(`Allowed values: ${n.join(", ")}`);return e}}function Sb(n){let e=Number(n);if(!Number.isInteger(e)||e<=0)throw new As("Must be a positive integer.");return e}var Eb=Mu("json","default"),Pb=Mu("json","default"),Ti=new wb("docs").description("Search and read HarmonyOS documentation from local docs directory");Ti.command("search <keywords...>").description("Search documentation by keywords").option("--catalog <name>","Catalog name (all for all catalogs)",Db,"all").option("--format <fmt>","Output format (default, json)",Eb,"default").option("--limit <n>","Max number of results",Sb,20).action(async(n,e)=>{try{let t=Cb(n),r=e.catalog&&e.catalog!=="all"?e.catalog:void 0,i=await Is.search(t,r,e.limit);e.format==="json"?console.log(JSON.stringify(i,null,2)):Ib(i)}catch(t){console.error(xi(t.message)),process.exit(1)}});Ti.command("read <documentId>").description("Read full content of a document by document ID").action(async n=>{try{let e=n.trim();e||(console.error(xi("Document ID cannot be empty.")),process.exit(1));let t=await Is.readDocument(e);console.log(t)}catch(e){console.error(xi(e.message)),process.exit(1)}});Ti.command("catalog").description("List all available catalogs").option("--format <fmt>","Output format (default, json)",Pb,"default").action(async n=>{try{if(await Bn(),n.format==="json"){let e=Ve.map(t=>({name:t,title:pt[t]}));console.log(JSON.stringify(e,null,2))}else for(let e of Ve)console.log(` ${e.padEnd(20)} ${bb(pt[e])}`)}catch(e){console.error(xi(e.message)),process.exit(1)}});function Cb(n){let e=n.map(r=>r.trim()).filter(Boolean);if(e.length===0)throw new Error("Keywords cannot be empty.");if(e.join(" ").length>In)throw new Error(`Query exceeds ${In} characters.`);return e}function Db(n){if(n==="all")return"all";if(!Ve.includes(n))throw new As(`Invalid catalog "${n}". Allowed: all, ${Ve.join(", ")}`);return n}function Ib(n){for(let e=0;e<n.length;e++){let t=n[e];console.log(t.documentId),console.log(` Title: ${t.title}`),t.snippet&&console.log(` Content: ${t.snippet}`),e<n.length-1&&console.log()}}var Ou=Ti;process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE="";Ab();X.name("devecocli").description("HarmonyOS application development command line tool").version("1.3.0-Test.4");X.addCommand(Bs);X.addCommand(Js);X.addCommand(Qs);X.addCommand(ua);X.addCommand(Na);X.addCommand(Ba);X.addCommand(mc);X.addCommand(yc);X.addCommand(Ac);X.addCommand(Nc);X.addCommand(Il);X.addCommand(Ou);var xs=process.argv.slice(2);xs.length>=2&&xs[xs.length-1]==="help"&&(process.argv=[...process.argv.slice(0,-1),"--help"]);var Tb=new Set(["update"]);X.hook("preAction",async(n,e)=>{if(process.env.DEVECO_CLI_SKIP_VERSION_CHECK)return;let t=e;for(;t.parent&&t.parent!==X;)t=t.parent;Tb.has(t.name())||await N.checkVersion()});X.parseAsync(process.argv).catch(n=>{let e=n instanceof Error?n.message:String(n??"Unknown error");console.error(xb(`Error: ${e}`)),process.exit(1)});
1366
+ `)}async function ab(n){let e=Je();if(!e)throw new Error("docs.zip not found");await z.promises.rm(n,{recursive:!0,force:!0}),await z.promises.mkdir(n,{recursive:!0}),new rb(e).extractAllTo(n,!0),await Au(n)}async function cb(){let n=te(),e=zt(),t=await z.promises.readdir(e);for(let r of t){let i=Jt.join(n,r);await z.promises.rm(i,{force:!0}),await z.promises.rename(Jt.join(e,r),i)}await z.promises.rm(e,{recursive:!0,force:!0}),await z.promises.rm(Jt.join(n,"orama.dpack"),{force:!0})}async function lb(n,e){e?.start("Installing documentation index\u2026"),await Ze({state:"installing",phase:1,phaseLabel:"Installing index",message:"Installing documentation index\u2026"}),await hd(n),e&&(e.text="Documentation index installed.")}async function db(n,e,t){let r=zt(),i=await Iu();await z.promises.mkdir(te(),{recursive:!0}),await z.promises.rm(r,{recursive:!0,force:!0}),t?.start("Building search index\u2026"),await Ze({state:"indexing",phase:2,phaseLabel:"Building search index",message:"Building search index\u2026"});try{await ab(i),await Du({docsDir:i,tmpDir:r,docsZipSha256:e,termsHash:ui(),synonymsHash:di(),builtBy:n.builtBy??"doc-init",onProgress:async o=>{t&&(t.text=o.message),await Ze({state:"indexing",current:o.current,total:o.total,message:o.message})}})}finally{await z.promises.rm(i,{recursive:!0,force:!0})}await Ze({state:"persisting",phase:3,phaseLabel:"Persisting index",message:"Persisting index\u2026"}),await cb(),eu()}async function Tu(n){await Ze({state:"done",phase:3,phaseLabel:"Done",message:"Documentation ready.",error:null}),n?.succeed("Documentation ready.")}async function ub(n){let e=await rs(),t=e?`Documentation already up to date. Documents: ${e.segmentCount.toLocaleString()}`:"Documentation already up to date.";n?.succeed(t),await Ze({state:"done",message:t,error:null})}async function pb(n,e){let t=n instanceof Error?n.message:String(n);throw await Ze({state:"error",error:t}),await sb(`ERROR: ${t}`),e?.fail(t),n}async function mb(){let n=te();await z.promises.mkdir(n,{recursive:!0});let e=td();return z.existsSync(e)||await z.promises.writeFile(e,"","utf-8"),e}async function hb(){let n=await mb();return ib.lock(n,{stale:1800*1e3})}async function fb(){let n=Je(),e=(n?await li(n):null)??await ns();if(!e)throw new Error("docs.zip not found");return e}async function gb(n,e){let t=await fb(),r=n.force||await os(n.force),i=await is(n.force);if(!r&&!i&&kn()){await ub(e);return}if(Xo()&&!n.force){await lb(t,e),await Tu(e);return}await db(n,t,e),await Tu(e)}var Cs=class{static async run(e={}){let t=e.background??!1,i=e.quiet??t?void 0:Ru({text:"Checking documentation\u2026",color:"cyan"}),o;try{o=await hb(),await ts(wd("Starting documentation setup\u2026")),await gb(e,i)}catch(s){return pb(s,i)}finally{o&&await o()}}};async function yb(n){for(;;){let e=await pi();if(e.state==="done"&&kn())return;if(e.state==="error")throw new Ps("build-failed",e.error??"Documentation setup failed. Try your docs command again in a moment.");n.text=e.message||"Documentation is being prepared\u2026",await ob(500)}}async function ku(n,e=!1){n.text=e?"Repairing documentation index\u2026":"Starting documentation setup\u2026",await Cs.run({builtBy:"doc-init",force:e,quiet:!0})}async function vb(){if(kn())return;let n=Ru({text:"Documentation is being prepared\u2026",color:"cyan"}).start();try{if(await bd()){await yb(n),n.succeed("Documentation ready.");return}if(await os()){await ku(n),n.succeed("Documentation ready.");return}await ku(n,!0),n.succeed("Documentation ready.")}catch(e){throw n.fail(e.message),e}}async function Bn(){await vb(),await xu()}var Ds=class{async search(e,t,r=20){return await Bn(),ru(e,t,r)}async readDocument(e){return await Bn(),ud(e)}},Is=new Ds;function Mu(...n){return e=>{if(!n.includes(e))throw new As(`Allowed values: ${n.join(", ")}`);return e}}function Sb(n){let e=Number(n);if(!Number.isInteger(e)||e<=0)throw new As("Must be a positive integer.");return e}var Eb=Mu("json","default"),Pb=Mu("json","default"),Ti=new wb("docs").description("Search and read HarmonyOS documentation from local docs directory");Ti.command("search <keywords...>").description("Search documentation by keywords").option("--catalog <name>","Catalog name (all for all catalogs)",Db,"all").option("--format <fmt>","Output format (default, json)",Eb,"default").option("--limit <n>","Max number of results",Sb,20).action(async(n,e)=>{try{let t=Cb(n),r=e.catalog&&e.catalog!=="all"?e.catalog:void 0,i=await Is.search(t,r,e.limit);e.format==="json"?console.log(JSON.stringify(i,null,2)):Ib(i)}catch(t){console.error(xi(t.message)),process.exit(1)}});Ti.command("read <documentId>").description("Read full content of a document by document ID").action(async n=>{try{let e=n.trim();e||(console.error(xi("Document ID cannot be empty.")),process.exit(1));let t=await Is.readDocument(e);console.log(t)}catch(e){console.error(xi(e.message)),process.exit(1)}});Ti.command("catalog").description("List all available catalogs").option("--format <fmt>","Output format (default, json)",Pb,"default").action(async n=>{try{if(await Bn(),n.format==="json"){let e=Ve.map(t=>({name:t,title:pt[t]}));console.log(JSON.stringify(e,null,2))}else for(let e of Ve)console.log(` ${e.padEnd(20)} ${bb(pt[e])}`)}catch(e){console.error(xi(e.message)),process.exit(1)}});function Cb(n){let e=n.map(r=>r.trim()).filter(Boolean);if(e.length===0)throw new Error("Keywords cannot be empty.");if(e.join(" ").length>In)throw new Error(`Query exceeds ${In} characters.`);return e}function Db(n){if(n==="all")return"all";if(!Ve.includes(n))throw new As(`Invalid catalog "${n}". Allowed: all, ${Ve.join(", ")}`);return n}function Ib(n){for(let e=0;e<n.length;e++){let t=n[e];console.log(t.documentId),console.log(` Title: ${t.title}`),t.snippet&&console.log(` Content: ${t.snippet}`),e<n.length-1&&console.log()}}var Ou=Ti;process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE="";Ab();X.name("devecocli").description("HarmonyOS application development command line tool").version("1.3.0-Test.5");X.addCommand(Bs);X.addCommand(Js);X.addCommand(Qs);X.addCommand(ua);X.addCommand(Na);X.addCommand(Ba);X.addCommand(mc);X.addCommand(yc);X.addCommand(Ac);X.addCommand(Nc);X.addCommand(Il);X.addCommand(Ou);var xs=process.argv.slice(2);xs.length>=2&&xs[xs.length-1]==="help"&&(process.argv=[...process.argv.slice(0,-1),"--help"]);var Tb=new Set(["update"]);X.hook("preAction",async(n,e)=>{if(process.env.DEVECO_CLI_SKIP_VERSION_CHECK)return;let t=e;for(;t.parent&&t.parent!==X;)t=t.parent;Tb.has(t.name())||await N.checkVersion()});X.parseAsync(process.argv).catch(n=>{let e=n instanceof Error?n.message:String(n??"Unknown error");console.error(xb(`Error: ${e}`)),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveco-test/deveco-cli",
3
- "version": "1.3.0-Test.4",
3
+ "version": "1.3.0-Test.5",
4
4
  "description": "HarmonyOS application development command line tool",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,7 +61,6 @@
61
61
  "typescript-eslint": "^8.59.1"
62
62
  },
63
63
  "dependencies": {
64
- "@deveco-test/deveco-cli": "file:deveco-test-deveco-cli-1.3.0-Test.4.tgz",
65
64
  "@modelcontextprotocol/sdk": "^1.29.0",
66
65
  "@node-rs/jieba": "^2.0.1",
67
66
  "@sqlite.org/sqlite-wasm": "^3.49.1-build4",