@zacktt/test 0.0.1
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/LICENSE +21 -0
- package/SKILL.md +116 -0
- package/THIRD-PARTY-LICENSES +3572 -0
- package/dist/cli.js +1264 -0
- package/docs.zip +0 -0
- package/package.json +76 -0
- package/templates/application/AppScope/app.json5 +10 -0
- package/templates/application/AppScope/resources/base/element/string.json +8 -0
- package/templates/application/AppScope/resources/base/media/layered_image.json +7 -0
- package/templates/application/build-profile.json5 +42 -0
- package/templates/application/code-linter.json5 +32 -0
- package/templates/application/entry/build-profile.json5 +33 -0
- package/templates/application/entry/hvigorfile.ts +7 -0
- package/templates/application/entry/obfuscation-rules.txt +20 -0
- package/templates/application/entry/oh-package.json5 +10 -0
- package/templates/application/entry/src/main/ets/entryability/EntryAbility.ets +63 -0
- package/templates/application/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets +31 -0
- package/templates/application/entry/src/main/ets/pages/Index.ets +38 -0
- package/templates/application/entry/src/main/module.json5 +50 -0
- package/templates/application/entry/src/main/resources/base/element/color.json +8 -0
- package/templates/application/entry/src/main/resources/base/element/float.json +8 -0
- package/templates/application/entry/src/main/resources/base/element/string.json +16 -0
- package/templates/application/entry/src/main/resources/base/media/layered_image.json +7 -0
- package/templates/application/entry/src/main/resources/base/profile/backup_config.json +3 -0
- package/templates/application/entry/src/main/resources/base/profile/main_pages.json +5 -0
- package/templates/application/entry/src/main/resources/dark/element/color.json +8 -0
- package/templates/application/hvigor/hvigor-config.json5 +23 -0
- package/templates/application/hvigorfile.ts +7 -0
- package/templates/application/oh-package.json5 +10 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{bootstrap as np}from"global-agent";import{program as B}from"commander";import{red as rp}from"colorette";import{Command as ca}from"commander";import{green as fi,red as Zn,yellow as gi}from"colorette";import _ from"fs";import*as W from"path";import ke from"json5";import*as Gn from"fs";import*as H from"path";function g(r){process.env.DEVECO_CLI_DEBUG&&console.log(`[DEBUG] ${r}`)}var E=class r{static ASCII_CONTROL_MAX=31;static ASCII_DELETE=127;static parsePositiveInteger(e,t="value"){let n=e.trim();if(!/^\d+$/.test(n))throw new Error(`${t} must be a positive integer`);let i=Number.parseInt(n,10);if(!Number.isInteger(i)||i<=0)throw new Error(`${t} must be a positive integer`);return i}static getLastLines(e,t){return!t||t<=0?e:e.split(/\r?\n/).slice(-t).join(`
|
|
3
|
+
`)}static parseDurationToSeconds(e,t="value"){let i=e.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)([sm])?$/);if(!i)throw new Error(`${t} must be like 30s, 5m or 2.5m (only s/m supported)`);let o=i[1];if((i[2]??"s")==="s")return r.parsePositiveInteger(o,t);if(!/^\d+(?:\.\d)?$/.test(o))throw new Error(`${t} minute value supports at most one decimal place, e.g. 2.5m`);let a=Number.parseFloat(o);if(!Number.isFinite(a)||a<=0)throw new Error(`${t} must be a positive duration`);return Math.round(a*60)}static assertRelativeTimeRange(e,t){if(e!==void 0&&t!==void 0&&e<t)throw new Error("--from must be greater than or equal to --to when both are provided (e.g. --from 30s --to 10s)")}static filterLogsByRelativeWindow(e,t,n,i=new Date){if(!t&&!n)return e;let[o,s]=r.resolveTimeBounds(t,n,i),a=e.split(/\r?\n/),c=[],d=!1;for(let u of a){let b=r.extractTimestampFromLogLine(u,i);b&&(d=r.isWithinBounds(b,o,s)),d&&c.push(u)}return c.join(`
|
|
4
|
+
`)}static resolveTimeBounds(e,t,n){let i=e?new Date(n.getTime()-e*1e3):null,o=t?new Date(n.getTime()-t*1e3):null;return i&&o?i<o?[i,o]:[o,i]:i?[i,n]:o?[null,o]:[null,null]}static isWithinBounds(e,t,n){let i=e.getTime(),o=t?Math.floor(t.getTime()/1e3)*1e3:null,s=n?Math.floor(n.getTime()/1e3)*1e3+999:null;return!(o!==null&&i<o||s!==null&&i>s)}static extractTimestampFromLogLine(e,t){let n=e.match(/(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,6}))?/);if(!n)return null;let i=t.getFullYear(),o=Number.parseInt(n[1],10)-1,s=Number.parseInt(n[2],10),a=Number.parseInt(n[3],10),c=Number.parseInt(n[4],10),d=Number.parseInt(n[5],10),u=n[6]??"0",b=Number.parseInt(u.padEnd(3,"0").slice(0,3),10),k=new Date(i,o,s,a,c,d,b);return k.getTime()>t.getTime()+1440*60*1e3&&k.setFullYear(i-1),k}static assertBundleName(e){if(!/^[A-Za-z0-9_.]{1,128}$/.test(e))throw new Error(`Invalid bundleName: ${JSON.stringify(e)}`)}static assertHilogToken(e,t){if(!/^[A-Za-z0-9_.:\\-]{1,64}$/.test(e))throw new Error(`Invalid ${t}: ${JSON.stringify(e)}`)}static assertHilogKeyword(e){if(e.length===0||e.length>128)throw new Error(`Invalid keyword: ${JSON.stringify(e)}`);if([...e].some(n=>{let i=n.charCodeAt(0);return i<=r.ASCII_CONTROL_MAX||i===r.ASCII_DELETE}))throw new Error(`Invalid keyword: ${JSON.stringify(e)}`)}static quotePosixShellArg(e){let n=`'${e.replace(/'/g,"'\\''")}'`;return g(`quotePosixShellArg: ${e} -> ${n}`),n}static assertCrashFilename(e){if(!/^\w+-.+\d+-\d+$/.test(e))throw new Error(`Invalid crash log filename: ${JSON.stringify(e)}`)}static assertHilogLevel(e){if(!/^[DIWEF]$/.test(e))throw new Error(`Invalid log level: ${e}`)}static resolvePathWithinRoot(e,t){if(H.isAbsolute(t))throw new Error(`Absolute paths are not allowed: ${t}`);let n=H.resolve(H.normalize(e),t);return r.ensurePathWithinRoot(e,n)}static ensurePathWithinRoot(e,t){let n=H.normalize(e),i=H.relative(n,t);if(i.split(H.sep)[0]===".."||H.isAbsolute(i))throw new Error(`Path escapes project root: ${t}`);return t}static isPathEscaping(e){let t=e.replace(/\\/g,"/");return t===".."||t.startsWith("../")||H.isAbsolute(e)}static isPathContained(e,t){let n=H.resolve(t,e),i=H.relative(t,n);return r.isPathEscaping(i)?{contained:!1,reason:`Path escapes project root directory: ${e}`}:{contained:!0}}static isPathContainedWithSymlink(e,t){if(H.isAbsolute(e))return{contained:!1,reason:`Absolute path is not allowed: ${e}`};let n=r.isPathContained(e,t);if(!n.contained)return n;let i;try{i=Gn.realpathSync(t)}catch{return{contained:!1,reason:`Project root directory does not exist or cannot be resolved: ${t}`}}let o=H.resolve(i,e),s;try{s=Gn.realpathSync(o)}catch{return{contained:!1,reason:`Path does not exist or cannot be resolved: ${o}`}}return r.isPathContained(s,i)}};var Te=class r{rootDir;profile;constructor(e,t){this.rootDir=e,this.profile=t}static discover(e){let t=e;for(;;){let n=r.tryLoadProjectProfile(t);if(n)return new r(t,n);let i=W.dirname(t);if(i===t)break;t=i}throw new Error("Not in a valid project directory (project-level build-profile.json5 not found)")}static tryLoadProjectProfile(e){let t=W.join(e,"build-profile.json5");if(!_.existsSync(t))return null;try{let n=_.readFileSync(t,"utf-8"),i=ke.parse(n);return i.app?i:null}catch(n){return console.error(`Error parsing ${t}:`,n),null}}getModuleType(e){let t=this.profile.modules.find(o=>o.name===e);if(!t)throw new Error(`Module '${e}' not found in project build-profile.json5.`);let n=E.resolvePathWithinRoot(this.rootDir,t.srcPath),i=W.join(n,"src","main","module.json5");if(!_.existsSync(i))return"entry";try{let o=_.readFileSync(i,"utf-8");return ke.parse(o)?.module?.type||"entry"}catch(o){return console.warn(`Warning: Failed to parse ${i}:`,o),"entry"}}getModuleProfile(e){let t=this.profile.modules.find(a=>a.name===e);if(!t)throw new Error(`Module '${e}' not found in project build-profile.json5.`);let n=E.resolvePathWithinRoot(this.rootDir,t.srcPath),i=W.join(n,"build-profile.json5");if(!_.existsSync(i))throw new Error(`Build profile for module '${e}' not found at ${i}`);let o=_.readFileSync(i,"utf-8");return ke.parse(o)}getBundleName(){let e=W.join(this.rootDir,"AppScope","app.json5");if(_.existsSync(e))try{let t=_.readFileSync(e,"utf-8"),n=ke.parse(t);if(n?.app?.bundleName)return n.app.bundleName}catch(t){console.warn(`Warning: Failed to parse ${e}:`,t)}throw new Error("Could not find bundleName in AppScope/app.json5")}getMainAbility(e,t){if(t)return t;let n=this.profile.modules.find(s=>s.name===e);if(!n)return"EntryAbility";let i=E.resolvePathWithinRoot(this.rootDir,n.srcPath),o=W.join(i,"src","main","module.json5");if(!_.existsSync(o))return"EntryAbility";try{let s=_.readFileSync(o,"utf-8"),c=ke.parse(s)?.module?.abilities||[];if(c.length===0)return"EntryAbility";let d=c.find(u=>u.name==="EntryAbility");return d?d.name:c[0].name}catch(s){return console.warn(`Warning: Failed to parse ${o}:`,s),"EntryAbility"}}validateProduct(e){if(!/^[\da-zA-Z_-]+$/.test(e))throw new Error(`Invalid product name '${e}'. Product names must only contain letters, digits, underscores, and hyphens.`);if(!this.profile.app.products?.some(n=>n.name===e)){let n=this.profile.app.products?.map(i=>i.name).join(", ")||"none";throw new Error(`Product '${e}' not found in project configuration. Available products: ${n}`)}}getModuleDependencies(e){let t=this.profile.modules.find(s=>s.name===e);if(!t)return[];let n=E.resolvePathWithinRoot(this.rootDir,t.srcPath),i=W.join(n,"oh-package.json5");if(!_.existsSync(i))return[];let o=[];try{let s=_.readFileSync(i,"utf-8"),c=ke.parse(s)?.dependencies||{};for(let d of Object.values(c)){if(typeof d!="string")continue;let u=d;if(!(u.startsWith("file:")||u.startsWith(".")||u.startsWith("..")))continue;u.startsWith("file:")&&(u=u.substring(5));let k=W.join(t.srcPath,u),de=E.resolvePathWithinRoot(this.rootDir,k),$e=this.profile.modules.find(_e=>W.resolve(this.rootDir,_e.srcPath)===de);$e&&o.push($e.name)}}catch{}return o}collectNonHarDependentModuleList(e){let t=[],n=[],i=new Set;for(n.push(e),i.add(e);n.length>0;){let o=n.shift();this.getModuleType(o)!=="har"&&t.push(o);let a=this.getModuleDependencies(o);for(let c of a)i.has(c)||(n.push(c),i.add(c))}return t}findArtifactPath(e,t,n,i="default"){this.validateProduct(i);let o=this.profile.modules.find(de=>de.name===e);if(!o)throw new Error(`Module '${e}' not found`);let a=this.getModuleType(e)==="shared",c=a?"hspName":"hapName",d=this.buildOutputPath(o.srcPath,i,["intermediates",a?"hsp_metadata":"hap_metadata",t,"output_metadata.json"]);if(!_.existsSync(d))throw new Error(`Build metadata not found for module '${e}' at ${d}. Please build the project first.`);let{packageName:u,isSigned:b}=this.parseOutputMetadata(d,c);if(!n&&!b)throw new Error(`Target device is a real device, but the artifact for '${e}' is not signed. Real devices cannot install unsigned packages.`);let k=this.buildOutputPath(o.srcPath,i,["outputs",t,u]);if(!_.existsSync(k))throw new Error(`Generated package file does not exist: ${k}`);return k}buildOutputPath(e,t,n){let i=E.resolvePathWithinRoot(this.rootDir,e),o=W.resolve(i,"build",t,...n);return E.ensurePathWithinRoot(this.rootDir,o)}parseOutputMetadata(e,t){let n=_.readFileSync(e,"utf-8"),i=ke.parse(n),o,s=!1;if(Array.isArray(i)){let a=i[0];a&&(o=a[t],s=a.isSigned===!0)}else i&&typeof i=="object"&&(o=i[t],s=i.isSigned===!0);if(!o)throw new Error(`Could not find ${t} in output_metadata.json at ${e}`);return this.validatePackageName(o),{packageName:o,isSigned:s}}validatePackageName(e){let t=W.basename(e);if(t!==e)throw new Error(`Invalid package name: contains path characters. Expected filename only, got '${e}'`);if(!t.endsWith(".hap")&&!t.endsWith(".hsp"))throw new Error(`Invalid package name: must be a .hap or .hsp file. Got '${t}'`)}};import{execFileSync as Jn}from"child_process";import x,{existsSync as ci}from"fs";import*as P from"path";import*as Y from"os";import Zs from"regedit";import{join as li}from"path";import{red as Xs}from"colorette";import*as ai from"os";function O(){return Ks()==="openharmony"}function Ks(){return ai.platform()}import{execaSync as di}from"execa";var ui="https://developer.huawei.com/consumer/cn/download/",pi="6.1.0",Kn=r=>new Promise((e,t)=>{Zs.list(r,(n,i)=>{n?t(n):e(i)})}),N=class r{_devecoStudioPath;_nodePath;_ohpmJsPath;_hvigorJsPath;_javaPath;_sdkPath;_hdcPath;_emulatorPath;_emulatorLauncherPath;static _verifiedPaths=new Set;static _powerShellPath;static verifyAndCache(e){!e||e===""||O()||r._verifiedPaths.has(e)||(r.verifySignature(e),r._verifiedPaths.add(e))}get devecoStudioPath(){return this._devecoStudioPath}get nodePath(){return r.verifyAndCache(this._nodePath),this._nodePath}get ohpmJsPath(){return this._ohpmJsPath}get hvigorJsPath(){return this._hvigorJsPath}get javaPath(){return r.verifyAndCache(this._javaPath),this._javaPath}get sdkPath(){return this._sdkPath}get hdcPath(){return r.verifyAndCache(this._hdcPath),this._hdcPath}get emulatorPath(){return r.verifyAndCache(this._emulatorPath),this._emulatorPath}get emulatorLauncherPath(){return this._emulatorLauncherPath&&r.verifyAndCache(this._emulatorLauncherPath),this._emulatorLauncherPath}constructor(e,t,n,i,o,s,a,c,d){this._devecoStudioPath=e,this._nodePath=t,this._ohpmJsPath=n,this._hvigorJsPath=i,this._javaPath=o,this._sdkPath=s,this._hdcPath=a,this._emulatorPath=c,this._emulatorLauncherPath=d}static async checkVersion(){O()||await r.findDevEcoStudio()}static async new(){if(O())return r.newForOpenHarmony();let e=await r.findDevEcoStudio(),{nodePath:t,ohpmJsPath:n,hvigorJsPath:i,javaPath:o,sdkPath:s,hdcPath:a,emulatorPath:c}=r.resolveTools(e),d=r.getEmulatorExe(e);return new r(e,t,n,i,o,s,a,c,d??void 0)}static async newForOpenHarmony(){let e=[];for(let[t,n]of[["ohpm","-v"],["hvigorw","-v"],["hdc","-v"]])try{di(t,[n])}catch{e.push(t)}if(e.length>0)throw new Error(`commandLineTools not found. The following tools are missing from PATH: ${e.join(", ")}. `);return new r("","","ohpm","hvigorw","","","hdc","",void 0)}static _cachedInstallRoot;static async findDevEcoStudio(){if(r._cachedInstallRoot!==void 0)return g(`[ToolProvider] findDevEcoStudio: cache hit -> ${r._cachedInstallRoot}`),r._cachedInstallRoot;let e=Y.platform(),t=e==="win32"?await r.collectCandidatesWindows():e==="darwin"?r.collectCandidatesMac():(()=>{throw new Error("Linux is not fully supported yet for automatic DevEco Studio detection")})();return r._cachedInstallRoot=r.pickLatestByProductInfo(t),r._cachedInstallRoot}static async collectCandidatesWindows(){let e=new Set,t=[],n=(i,o)=>{if(!r.isExistingDirectory(i))return;let s=P.normalize(i).toLowerCase();e.has(s)||(e.add(s),t.push(i),g(`[ToolProvider] Found via ${o}: ${i}`))};if(await r.addFromUninstallKey(n),await r.addFromWow64Key(n),r.addFromDefaultWindowsPath(n),t.length===0)throw new Error("DevEco Studio installation not found in registry or default locations");return t}static async addFromUninstallKey(e){try{let t="HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\DevEco Studio",i=(await Kn([t]))[t]?.values?.InstallLocation?.value;e(i,"Uninstall registry key")}catch{}}static async addFromWow64Key(e){try{let t="HKLM\\SOFTWARE\\WOW6432Node\\Huawei\\DevEco Studio",i=(await Kn([t]))[t]?.keys??[];if(i.length===0)return;let o=i.map(a=>`${t}\\${a}`),s=await Kn(o);for(let a of o){let c=s[a]?.values?.[""]?.value;e(c,`WOW6432Node subkey ${a}`)}}catch{}}static addFromDefaultWindowsPath(e){let t=P.join("C:","Program Files","Huawei","DevEco Studio");e(t,"default installation path")}static collectCandidatesMac(){let e=Y.homedir(),t=[P.join(e,"Applications"),"/Applications"],n=[],i=new Set;for(let o of t){if(!x.existsSync(o))continue;let s;try{s=x.readdirSync(o)}catch{continue}for(let a of s){if(!a.endsWith(".app")||!a.toLowerCase().includes("deveco"))continue;let d=P.join(o,a);r.isExistingDirectory(d)&&(i.has(d)||(i.add(d),n.push(d),g(`[ToolProvider] Found macOS candidate: ${d}`)))}}if(n.length===0)throw new Error("DevEco Studio not found in /Applications or ~/Applications");return n}static productInfoPath(e){return Y.platform()==="darwin"?P.join(e,"Contents","product-info.json"):P.join(e,"product-info.json")}static macInfoPlistPath(e){return P.join(e,"Contents","Info.plist")}static readMacInfoPlistKey(e,t){if(!x.existsSync(e)){g(`[ToolProvider] Info.plist not found at: ${e}`);return}try{let n=Jn("defaults",["read",e,t],{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:5e3}).trim();if(n.length>0&&n!=="(null)")return n}catch{g(`[ToolProvider] defaults read failed for ${e} key ${t}`)}}static extractCompactBuildCode(e){let t=e.split(".").at(-1);if(t!==void 0&&/^\d+$/.test(t))return t}static compactPrefixFromShortVersion(e){let t=e.split(".").slice(0,3);if(!(t.length<3||!t.every(n=>/^\d+$/.test(n))))return t.join("")}static extractFourthSegmentMatchingShortVersion(e,t){let n=r.compactPrefixFromShortVersion(e),i=r.extractCompactBuildCode(t);if(n===void 0||i===void 0)return;if(!i.startsWith(n)){g(`[ToolProvider] CFBundleVersion suffix ${i} does not match short-version prefix ${n} (${e})`);return}let o=i.slice(n.length);if(!(o.length===0||!/^\d+$/.test(o)))return o}static readMacFourthSegmentFromPlist(e,t){let n=r.readMacInfoPlistKey(e,"CFBundleVersion");if(n!==void 0){let s=r.extractFourthSegmentMatchingShortVersion(t,n);if(s!==void 0)return s}let i=r.readMacInfoPlistKey(e,"CFBundleGetInfoString");if(i===void 0)return;let o=i.match(/DS-[\d.]+/);if(o!==null)return r.extractFourthSegmentMatchingShortVersion(t,o[0])}static parseMacInfoPlistVersion(e){let t=r.macInfoPlistPath(e),n=r.readMacInfoPlistKey(t,"CFBundleShortVersionString");if(n!==void 0){let i=r.readMacFourthSegmentFromPlist(t,n);return i!==void 0?`${n}.${i}`:n}return r.readMacInfoPlistKey(t,"CFBundleVersion")}static parseProductInfoVersion(e){if(Y.platform()==="darwin"){let n=r.parseMacInfoPlistVersion(e);if(n!==void 0)return n}let t=r.productInfoPath(e);if(!x.existsSync(t)){g(`[ToolProvider] product-info.json not found at: ${t}`);return}try{let i=JSON.parse(x.readFileSync(t,"utf-8"))?.version;if(typeof i!="string"||i.trim()===""){g(`[ToolProvider] product-info.json at ${t} has no valid "version" field`);return}return i.trim()}catch{g(`[ToolProvider] Failed to parse product-info.json at: ${t}`);return}}static compareVersion(e,t){let n=e.split(".").map(s=>parseInt(s,10)||0),i=t.split(".").map(s=>parseInt(s,10)||0),o=Math.max(n.length,i.length);for(let s=0;s<o;s++){let a=(n[s]??0)-(i[s]??0);if(a!==0)return a}return 0}static pickLatestByProductInfo(e){let t=r.selectHighestVersion(e);return r.assertMinVersion(t.installRoot,t.version),g(`[ToolProvider] Selected DevEco Studio ${t.version} at ${t.installRoot}`),t.installRoot}static selectHighestVersion(e){let t=[];for(let n of e){let i=r.parseProductInfoVersion(n);i!==void 0?(t.push({installRoot:n,version:i}),g(`[ToolProvider] ${n} => version ${i}`)):g(`[ToolProvider] Skipping ${n}: could not read version (Info.plist / product-info.json)`)}if(t.length===0){let n=e.join(`
|
|
5
|
+
`),i=Y.platform()==="darwin"?"Contents/Info.plist (CFBundleShortVersionString / CFBundleVersion) and Contents/product-info.json":"product-info.json";throw new Error(`Failed to determine DevEco Studio version from ${i}.
|
|
6
|
+
Searched locations:
|
|
7
|
+
${n}
|
|
8
|
+
Please reinstall DevEco Studio or download the latest version from:
|
|
9
|
+
`+ui)}return t.reduce((n,i)=>r.compareVersion(i.version,n.version)>0?i:n)}static assertMinVersion(e,t){r.compareVersion(t,pi)>=0||(g(`[ToolProvider] Selected DevEco Studio ${t} at ${e} \u2014 below minimum`),console.error(Xs(`Error: The detected DevEco Studio version is ${t}, which is below the minimum required version ${pi}. Please upgrade to the latest version before using deveco-cli:`)+`
|
|
10
|
+
`+ui),process.exit(1))}static isExistingDirectory(e){return!!e&&x.existsSync(e)&&x.statSync(e).isDirectory()}static resolveWindowsTools(e){let t=P.join(e,"tools");return{nodePath:P.join(t,"node","node.exe"),ohpmJsPath:P.join(t,"ohpm","bin","pm-cli.js"),hvigorJsPath:P.join(t,"hvigor","bin","hvigorw.js"),javaPath:P.join(e,"jbr","bin","java.exe"),sdkPath:P.join(e,"sdk")}}static resolveMacTools(e){let t=P.join(e,"Contents","tools");return{nodePath:P.join(t,"node","bin","node"),ohpmJsPath:P.join(t,"ohpm","bin","pm-cli.js"),hvigorJsPath:P.join(t,"hvigor","bin","hvigorw.js"),javaPath:P.join(e,"Contents","jbr","Contents","Home","bin","java"),sdkPath:P.join(e,"Contents","sdk")}}static resolveTools(e){let t=Y.platform(),n=t==="win32"?r.resolveWindowsTools(e):t==="darwin"?r.resolveMacTools(e):(()=>{throw new Error("Linux is not fully supported yet")})();r.verifyTools(n.nodePath,n.ohpmJsPath,n.hvigorJsPath,n.javaPath);let i=r.resolveHdcPath(n.sdkPath,t),o=r.resolveEmulatorPath(e,t);return{...n,hdcPath:i,emulatorPath:o}}static resolveHdcPath(e,t){let n=t==="win32"?".exe":"",i=[P.join(e,"default","openharmony","toolchains",`hdc${n}`),P.join(e,"toolchains",`hdc${n}`)];for(let o of i)if(x.existsSync(o))return o;throw new Error(`hdc executable not found. Searched in:
|
|
11
|
+
${i.join(`
|
|
12
|
+
`)}`)}static resolveEmulatorPath(e,t){let n;if(t==="win32")n=P.join(e,"tools","emulator","Emulator.exe");else if(t==="darwin")n=P.join(e,"Contents","tools","emulator","Emulator");else throw new Error("Linux is not fully supported yet");if(!x.existsSync(n))throw new Error(`Emulator executable not found at: ${n}`);return n}static verifyTools(e,t,n,i){if(!x.existsSync(e))throw new Error(`Node executable not found at: ${e}`);if(!x.existsSync(t))throw new Error(`ohpm js file not found at: ${t}`);if(!x.existsSync(n))throw new Error(`hvigor js file not found at: ${n}`);if(!x.existsSync(i))throw new Error(`java executable not found at: ${i}`)}static getEmulatorExe(e){let t=Y.platform(),n;if(t==="win32")n=li(e,"tools","emulator","Emulator.exe");else if(t==="darwin")n=li(e,"Contents","tools","emulator","Emulator");else return;return ci(n)?n:void 0}static isValidApiLevel(e,t){let n=t??23;return Number.isInteger(e)&&e>=17&&e<=n}static parseApiLevelFromFile(e){if(x.existsSync(e))try{let t=x.readFileSync(e,"utf-8"),n=JSON.parse(t),i=n?.apiVersion??n?.data?.apiVersion;if(typeof i!="string"&&typeof i!="number")return;let o=Number(i);return Number.isInteger(o)&&o>=17?o:void 0}catch{return}}static detectFromSdkPkg(e){let t=P.join(e,"default","sdk-pkg.json");return r.parseApiLevelFromFile(t)}static detectFromOhUniPackage(e){let t=[P.join(e,"default","openharmony","toolchains","oh-uni-package.json"),P.join(e,"default","openharmony","native","oh-uni-package.json"),P.join(e,"default","openharmony","previewer","oh-uni-package.json")];for(let n of t){let i=r.parseApiLevelFromFile(n);if(i!==void 0)return i}}static detectApiLevelFromHvigor(){try{let t=di("hvigorw",["-v"]).stdout.trim();g(`[ToolProvider] hvigorw -v output: ${t}`);let n=t.match(/^(\d+)\.(\d+)\./);if(n&&n[2]){let i=parseInt(n[2],10);if(Number.isInteger(i)&&i>=17)return i}return g(`[ToolProvider] Could not parse API level from hvigorw version: ${t}`),23}catch(e){let t=e.message||String(e);if(t.includes("ENOENT")||t.includes("not found")||t.includes("command not found"))throw new Error("commandLineTools not found. Please install commandLineTools to use devecocli on OpenHarmony.",{cause:e});return g(`[ToolProvider] hvigorw -v failed: ${t}`),23}}getMaxApiLevel(){if(O())return r.detectApiLevelFromHvigor();let e=r.detectFromSdkPkg(this.sdkPath);if(e!==void 0)return e;let t=r.detectFromOhUniPackage(this.sdkPath);return t!==void 0?t:23}detectApiLevel(){return this.getMaxApiLevel()}static findPowerShellPath(){if(r._powerShellPath)return r._powerShellPath;if(Y.platform()!=="win32")return r._powerShellPath="",r._powerShellPath;let e=P.join(process.env.SystemRoot||"C:\\Windows","System32","WindowsPowerShell","v1.0","powershell.exe");return ci(e)?(g(`[ToolProvider] Found PowerShell at: ${e}`),r._powerShellPath=e,e):(r._powerShellPath="",r._powerShellPath)}static verifySignature(e){if(!x.existsSync(e))throw new Error(`executable not found at: ${e}`);let t=Y.platform();if(r.isExecutableFile(e,t)){if(t==="win32"){if(!r.verifyWindowsSignature(e).signed)throw new Error(`The executable is not digitally signed: ${e}`)}else if(t==="darwin"&&!r.verifyMacSignature(e).signed)throw new Error(`The executable is not digitally signed: ${e}`)}}static isExecutableFile(e,t){if(t==="win32")return P.extname(e).toLowerCase()===".exe";if(t==="darwin")try{return x.accessSync(e,x.constants.X_OK),!0}catch{return!1}return!1}static createSignatureScript(){let e=x.mkdtempSync(P.join(Y.tmpdir(),"deveco-verify-")),t=P.join(e,"Verify-Signature.ps1");return x.writeFileSync(t,"$env:PSModulePath = ($env:PSModulePath -split ';' | Where-Object { $_ -notmatch 'windowsapps' }) -join ';'; Get-AuthenticodeSignature -FilePath $args[0] | ConvertTo-Json -Depth 3 -Compress","utf-8"),{tmpDir:e,scriptPath:t}}static verifyWindowsSignature(e){let t=r.findPowerShellPath();if(!t)throw new Error("The PowerShell application was not found");let{tmpDir:n,scriptPath:i}=r.createSignatureScript();try{let o=Jn(t,["-NoProfile","-ExecutionPolicy","Bypass","-File",i,e],{encoding:"utf-8",timeout:5e3,stdio:["pipe","pipe","ignore"]}),s=JSON.parse(o);return{signed:s?.Status===0,signer:s?.SignerCertificate?.Subject??void 0}}catch(o){return g(`[ToolProvider] verify Windows Signature, error msg: ${o}`),{signed:!0}}finally{try{x.rmSync(n,{recursive:!0,force:!0})}catch{}}}static verifyMacSignature(e){try{return Jn("codesign",["-v",e],{encoding:"utf-8",timeout:5e3}),{signed:!0}}catch{return{signed:!1}}}};import{execa as Qs}from"execa";import*as jt from"path";var Me=class{toolProvider;projectRoot;env;constructor(e,t){if(this.toolProvider=e,this.projectRoot=t,O())this.env={...process.env};else{let i=`${jt.dirname(e.javaPath)}${jt.delimiter}${process.env.PATH||""}`;this.env={...process.env,PATH:i,DEVECO_SDK_HOME:e.sdkPath}}}async sync(e,t){let n=["--sync","-p",`product=${e}`,"-p",`buildMode=${t}`,"--analyze=normal","--parallel","--incremental"];await this.runHvigor(n)}async buildProduct(e,t){let n=["assembleApp","-p",`product=${e}`,"-p",`buildMode=${t}`,"--analyze=normal","--parallel","--incremental"];await this.runHvigor(n)}async buildModules(e,t,n,i){let o=[...Array.from(i),"--mode","module","-p",`module=${n.join(",")}`,"-p",`product=${e}`,"-p",`buildMode=${t}`,"--analyze=normal","--parallel","--incremental"];await this.runHvigor(o)}async clean(){let e=["clean","--analyze=normal","--parallel","--no-daemon"];await this.runHvigor(e)}async stopDaemon(){O()||await this.runHvigor(["--stop-daemon"])}async runHvigor(e){let t,n;O()?(t="hvigorw",n=e.includes("--no-daemon")?e:["--no-daemon",...e]):(t=this.toolProvider.nodePath,n=[this.toolProvider.hvigorJsPath,...e]),g(`Executing: ${t} ${n.join(" ")}`),await Qs(t,n,{cwd:this.projectRoot,env:this.env,stdout:"inherit",stderr:"inherit"})}};import{execa as ea}from"execa";var We=class{toolProvider;projectRoot;constructor(e,t){this.toolProvider=e,this.projectRoot=t}async installAll(){let e,t;O()?(e="ohpm",t=["install","--all"]):(e=this.toolProvider.nodePath,t=[this.toolProvider.ohpmJsPath,"install","--all"]),g(`Executing: ${e} ${t.join(" ")}`),await ea(e,t,{cwd:this.projectRoot,stdout:"inherit",stderr:"inherit"})}};import{mkdir as ta}from"fs/promises";import{dirname as na,resolve as ra}from"path";import{execa as ia}from"execa";import hi from"proper-lockfile";function mi(r){return ra(r,".hvigor",".build-lock")}function oa(r){let e=!1;return()=>{e||(e=!0,r?.())}}async function sa(r){let e=na(mi(r));if(await ta(e,{recursive:!0}),process.platform==="win32")try{await ia("attrib",["+h",e])}catch{}}async function aa(r,e){let t=new AbortController,n=oa(e);await sa(r);let i={lockfilePath:mi(r),realpath:!1,stale:5e3,update:2e3,onCompromised:()=>t.abort()};try{return{release:await hi(r,{...i,retries:0}),signal:t.signal}}catch(s){if(s&&typeof s=="object"&&"code"in s&&s.code!=="ELOCKED")throw s}return n(),{release:await hi(r,{...i,retries:{forever:!0,minTimeout:1e3,maxTimeout:1e3}}),signal:t.signal}}async function pt(r,e,t){let{release:n,signal:i}=await aa(r,t);try{return await e(i)}finally{await n()}}function la(r,e){if(e.product&&r.validateProduct(e.product),e.buildMode&&!r.profile.app.buildModeSet.some(n=>n.name===e.buildMode))throw new Error(`Build mode '${e.buildMode}' not found in project build-profile.json5.`)}function da(r,e){let t;if(e.modules&&e.modules.length>0)t=e.modules;else{let i=r.profile.modules,o=i.filter(s=>r.getModuleType(s.name)==="entry");if(i.length===1)t=[i[0].name];else if(o.length===1)t=[o[0].name];else throw o.length>1?new Error(`Multiple entry modules found (${o.map(s=>s.name).join(", ")}). Please specify which module to build with --modules.`):new Error(`No entry module found and multiple modules available (${i.map(s=>s.name).join(", ")}). Please specify which module to build with --modules.`)}let n=new Set;for(let i of t){let o=i.indexOf("@"),s=o!==-1?i.substring(0,o):i,a=o!==-1?i.substring(o+1):"default";n.add(`${s}@${a}`)}return Array.from(n)}function Xn(r,e){let t=new Set;for(let n of e){let i=n.indexOf("@"),o=i!==-1?n.substring(0,i):n,s=r.getModuleType(o);s==="shared"?t.add("assembleHsp"):s==="har"?t.add("assembleHar"):t.add("assembleHap")}return t}function ht(r,e){let t=e,n=`${r} failed`;console.error(Zn(n));let i=t.stdout||t.message;throw i&&console.error(i),t.stderr&&console.error(t.stderr),new Error(n,{cause:e})}async function Qn(r,e,t,n,i){console.log(`
|
|
13
|
+
[1/3] Running ohpm install...`);try{await r.installAll()}catch(o){ht("ohpm install",o)}console.log(`
|
|
14
|
+
[2/3] Running hvigor sync...`);try{await e.sync(t,n)}catch(o){ht("hvigor sync",o)}console.log(`
|
|
15
|
+
[3/3] Running hvigor build...`);try{i.type==="product"?await e.buildProduct(t,n):await e.buildModules(t,n,i.modulesToBuild,i.moduleTasks)}catch(o){ht("hvigor build",o)}}var yi=new ca("build").description("Build the HarmonyOS project").option("--product <product>","Product name defined in build-profile.json5 (default: default)").option("--modules <modules...>","Modules to build (format: module or module@target)").option("--build-mode <mode>","Build mode (buildModeSet in build-profile.json5; e.g. debug, release; default: debug)").action(async r=>{try{let e=process.cwd(),t=Te.discover(e);console.warn(gi("Please ensure the project source is trustworthy before proceeding."));let n=await N.new();la(t,r);let i=r.product||"default",o=r.buildMode||"debug",s;if(r.product&&!r.modules)s={type:"product"};else{let d=da(t,r),u=Xn(t,d);s={type:"modules",modulesToBuild:d,moduleTasks:u}}let a=new We(n,t.rootDir),c=new Me(n,t.rootDir);await pt(t.rootDir,async()=>Qn(a,c,i,o,s),()=>{console.log("Another build is already running for this project. Waiting for it to finish...")}),console.log(`
|
|
16
|
+
`+fi("Build completed successfully!"))}catch(e){console.error(Zn(e.message)),process.exit(1)}});yi.command("clean").description("Clean the HarmonyOS project build outputs").action(async()=>{try{let r=process.cwd(),e=Te.discover(r);console.warn(gi("Please ensure the project source is trustworthy before proceeding."));let t=await N.new(),n=new Me(t,e.rootDir);await pt(e.rootDir,async()=>{console.log(`
|
|
17
|
+
[1/2] Running hvigor clean...`);try{await n.clean()}catch(i){ht("hvigor clean",i)}console.log(`
|
|
18
|
+
[2/2] Running hvigor --stop-daemon...`);try{await n.stopDaemon()}catch(i){ht("hvigor --stop-daemon",i)}},()=>{console.log("Another build is already running for this project. Waiting for it to finish...")}),console.log(`
|
|
19
|
+
`+fi("Clean completed successfully!"))}catch(r){console.error(Zn(r.message)),process.exit(1)}});var vi=yi;import{Command as Ia}from"commander";import{green as Ii,red as Ca,yellow as Aa}from"colorette";import{randomUUID as Ea}from"crypto";import{execa as Da}from"execa";import{execa as Pa}from"execa";import{execFile as ua,spawn as pa}from"child_process";import{promisify as ha}from"util";var ma=ha(ua);function wi(r,e,t){let i=r.replace(/\r\n/g,`
|
|
20
|
+
`).split(`
|
|
21
|
+
`),o=i.pop()??"",s=i.map(a=>a.endsWith("\r")?a.slice(0,-1):a).filter(a=>a.length>0);return s.length>0&&t.onData(s,e),o}function bi(r,e,t){let n=r.endsWith("\r")?r.slice(0,-1):r;n.length>0&&t.onData([n],e)}function fa(r,e){return{stdout:r.stdoutChunks.join(""),stderr:r.stderrChunks.join(""),exitCode:e??0}}function ga(){return{stdoutChunks:[],stderrChunks:[],stdoutLineBuffer:"",stderrLineBuffer:"",settled:!1}}function ya(r,e,t,n,i){r.stdout?.on("data",o=>{let s=o.toString();e.stdoutChunks.push(s),e.stdoutLineBuffer=wi(e.stdoutLineBuffer+s,"stdout",t)}),r.stderr?.on("data",o=>{let s=o.toString();e.stderrChunks.push(s),e.stderrLineBuffer=wi(e.stderrLineBuffer+s,"stderr",t)}),r.on("error",o=>{e.settled||(e.settled=!0,t.onError(o),i(o))}),r.on("close",o=>{if(e.settled)return;e.settled=!0,bi(e.stdoutLineBuffer,"stdout",t),bi(e.stderrLineBuffer,"stderr",t),t.onClose(o);let s=fa(e,o);s.exitCode!==0&&t.onError(new Error(`Command process exited with code ${s.exitCode}`)),n(s)})}async function Si(r,e=[],t={}){try{let{stdout:n,stderr:i}=await ma(r,e,t);return{stdout:typeof n=="string"?n.trim():"",stderr:typeof i=="string"?i.trim():"",exitCode:0}}catch(n){let i=n;return{stdout:i.stdout?.trim()||"",stderr:i.stderr?.trim()||i.message,exitCode:typeof i.code=="number"?i.code:1}}}async function Pi(r,e,t){return await new Promise((n,i)=>{let o=pa(r,e,{stdio:["inherit","pipe","pipe"]}),s=ga();ya(o,s,t,n,i)})}function Ei(r){let e=r.trim(),t=e.indexOf("=");return t!==-1?e.slice(t+1).trim():e}var va=[/communication channel is being established/i,/please wait for several seconds and try again/i,/device offline/i,/\[E0+04\]/i],wa=[/\[fail\]/i,/\bfail!/i,/not found/i];function Ue(r){return r?va.some(e=>e.test(r))?"transient":wa.some(e=>e.test(r))?"fatal":"ok":"ok"}var er=[800,1500,2500];function ba(r){return new Promise(e=>setTimeout(e,r))}async function be(r,e){let t=1+er.length,n={stdout:"",stderr:"",exitCode:-1};for(let i=0;i<t;i++){n=await Si(r,e);let o=n.exitCode===0?n.stdout:n.stderr||n.stdout;if(Ue(o)!=="transient"||i>=t-1)return n;g(`hdc transient failure on \`${e.join(" ")}\`: retrying in ${er[i]}ms`),await ba(er[i])}return n}async function nr(r,e,t){let n=await be(r,["-t",e,"shell","param","get",t]);if(n.exitCode!==0)return;let i=n.stdout.trim();if(!(!i||Ue(i)!=="ok"))return Ei(i)}var tr="__DEVECO_PARAM_DELIM__";function Sa(r,e){let t=new Map,n=r.split(tr);for(let i=0;i<e.length;i++){let o=(n[i]??"").trim();if(!o||Ue(o)!=="ok")continue;let s=Ei(o);s&&t.set(e[i],s)}return t}async function Be(r,e,t){if(t.length===0)return new Map;if(t.length===1){let o=new Map,s=await nr(r,e,t[0]);return s&&o.set(t[0],s),o}let n=t.map(o=>`param get ${o}`).join(`; echo ${tr}; `)+`; echo ${tr}`,i=await be(r,["-t",e,"shell",n]);return i.exitCode!==0?new Map:Sa(i.stdout,t)}function mt(r){return r.startsWith("127.0.0.1:")}var Di=["ohos.qemu.hvd.name","const.product.name","const.product.model","const.product.brand","const.product.devicetype"],z=class r{hdcPath;constructor(e){this.hdcPath=e}static from(e){return new r(e.hdcPath)}static withHdcPath(e){return new r(e)}escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}stripBrandPrefix(e,t){let n=e.trim(),i=t?.trim();if(!n||!i)return n;let o=new RegExp(`^${this.escapeRegExp(i)}(\\s+|[-_]+)?`,"i");return n.replace(o,"").trim()||n}async executeHdc(e){return Pa(this.hdcPath,e,{stdio:["ignore","pipe","pipe"]})}async listDevices(){let{stdout:e}=await this.executeHdc(["list","targets"]),t=[];for(let n of e.split(`
|
|
22
|
+
`)){let i=n.trim();if(!i||i.startsWith("[Empty]"))continue;let o=i.split(/\s+/),s=o[0];!s||s.startsWith("[Empty]")||t.push({serial:s,status:o.length>=2?o[1]:"device"})}return t}extractDisplayName(e){let t=e.get("ohos.qemu.hvd.name");if(t)return t;let n=e.get("const.product.name");if(n&&n!=="emulator")return n;let i=e.get("const.product.model");if(i&&i!=="emulator"){let o=e.get("const.product.brand");return this.stripBrandPrefix(i,o)}}async getDeviceName(e){let t=await Be(this.hdcPath,e,[...Di]);return this.extractDisplayName(t)??e}async getDeviceInfo(e,t){if(e.length===0)return null;if(t){let n=e.find(s=>s.serial===t);if(n)return n;let i=t.toLowerCase(),o=[];for(let s of e){let a=await this.getDeviceName(s.serial);a.toLowerCase()===i&&o.push({device:s,name:a})}if(o.length===1)return o[0].device;throw o.length>1?new Error(`Multiple devices match "${t}". Please use a serial instead:
|
|
23
|
+
`+o.map(s=>` - ${s.name} (${s.device.serial})`).join(`
|
|
24
|
+
`)):new Error(`Device "${t}" not found. Use \`devecocli device list\` to see available targets.`)}return e[0]}async getDeviceDetail(e){let t={serial:e,status:"device"};try{let n=await Be(this.hdcPath,e,["const.product.devicetype","const.ohos.apiversion","const.ohos.releasetype"]);t.deviceType=n.get("const.product.devicetype");let i=n.get("const.ohos.apiversion"),o=n.get("const.ohos.releasetype");i&&(t.osVersion=o?`API ${i} (${o})`:`API ${i}`)}catch{}return t}async listDevicesWithName(){let e=await this.listDevices();return Promise.all(e.map(async t=>({serial:t.serial,name:await this.getDeviceName(t.serial)})))}async getConnectedEntries(){let e=await this.listDevices();return Promise.all(e.map(t=>this.buildConnectedEntry(t.serial)))}async buildConnectedEntry(e){let t=mt(e),n,i;try{let o=await Be(this.hdcPath,e,[...Di]);n=this.extractDisplayName(o),i=o.get("const.product.devicetype")}catch{}return{serial:e,name:n,isEmulator:t,deviceType:i}}};var Ft=class{toolProvider;deviceManager;constructor(e){this.toolProvider=e,this.deviceManager=z.from(e)}async runHdc(e,t=!0){let n=this.toolProvider.hdcPath;g(`Executing: ${n} ${e.join(" ")}`);try{let{stdout:i}=await Da(n,e,{env:{...process.env}});return i}catch(i){if(t)throw i;return i.stdout||""}}async listTargets(){return(await this.deviceManager.listDevicesWithName()).map(t=>({name:t.name,id:t.serial}))}async uninstallApp(e,t){let n=await this.runHdc(["-t",e,"shell","bm","uninstall","-n",t],!1);if(n.includes("uninstall bundle successfully"))return!0;if(n.includes("uninstall missing installed bundle"))return!1;throw new Error(`Uninstall failed: ${n}`)}async installApp(e,t){if(t.length===0)return;let i=`/data/local/tmp/${Ea()}`;try{await this.runHdc(["-t",e,"shell","mkdir",i]);for(let s of t){let a=await this.runHdc(["-t",e,"file","send",s,i+"/"]);if(!a.startsWith("FileTransfer finish"))throw new Error(a)}let o=await this.runHdc(["-t",e,"shell","bm","install","-p",i]);if(!o.includes("install bundle successfully."))throw new Error(o);console.log("App installed successfully")}finally{await this.runHdc(["-t",e,"shell","rm","-rf",i],!1)}}async launchApp(e,t,n){let i=["-t",e,"shell","aa","start","-a",n,"-b",t];return await this.runHdc(i)}};function ka(r){let e=r.indexOf("@"),t=e!==-1?r.substring(0,e):r,n=e!==-1?r.substring(e+1):"default";return{moduleName:t,targetName:n}}async function Ta(r,e){let t=await r.listDevices();if(t.length===0)throw new Error("No active devices found. Please start an emulator or connect a physical device.");if(!e&&t.length>1){let i=await r.listDevicesWithName();throw new Error("Multiple devices found. Please specify a target device using `--device <Name>` or `--device <ID>`.\nAvailable devices:\n"+i.map(o=>` - ${o.name} (${o.serial})`).join(`
|
|
25
|
+
`))}let n=await r.getDeviceInfo(t,e);if(!n)throw new Error("No active devices found.");if(!e){let i=await r.getDeviceName(n.serial);console.log(`Auto-selected device: ${i} (${n.serial})`)}return n.serial}function Ma(r,e){if(e)return e;let t=r.profile.modules.filter(n=>{let i=r.getModuleType(n.name);return i==="entry"||i==="feature"||i==="shared"});if(t.length===1){let n=t[0].name;return console.log(`Auto-selected module: ${n}`),n}throw new Error(`No module specified. Please specify a module using --module <name>.
|
|
26
|
+
Available runnable modules:
|
|
27
|
+
`+t.map(n=>` - ${n.name}`).join(`
|
|
28
|
+
`))}function xa(r,e,t,n,i){let o=[],s=r.collectNonHarDependentModuleList(e);for(let c of s){let d=r.findArtifactPath(c,t,n,i);o.push(d)}let a=r.findArtifactPath(e,t,n,i);return o.push(a),o}async function Ra(r,e,t,n,i,o){o&&(console.log(`Uninstalling ${t}...`),await r.uninstallApp(e,t)||console.log(`App ${t} is not installed, skipping uninstall.`)),console.log(`
|
|
29
|
+
Installing artifacts to device ${e}...`),await r.installApp(e,n),console.log(`Launching ${t}/${i}...`);let s=await r.launchApp(e,t,i);console.log(Ii(`
|
|
30
|
+
Application '${t}': ${s}`))}var Oa=new Ia("run").description("Build and run the project on a connected device").option("--module <module>","Module 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 (e.g. debug, release; default: debug)").option("--ability <ability>","Ability name to launch").option("--uninstall","Uninstall existing app before installation").option("--skip-build","Skip the build step and deploy the existing artifacts").action(async r=>{try{await La(r)}catch(e){console.error(Ca(e.message)),process.exit(1)}});async function Na(r,e,t,n,i,o){let s=new We(e,r.rootDir),a=new Me(e,r.rootDir),d=r.collectNonHarDependentModuleList(t).map(k=>`${k}@${n}`),u=Xn(r,d),b={type:"modules",modulesToBuild:d,moduleTasks:u};await pt(r.rootDir,()=>Qn(s,a,i,o,b),()=>console.log("Another build is already running for this project. Waiting for it to finish...")),console.log(`
|
|
31
|
+
`+Ii("Build completed successfully!"))}async function La(r){let e=Te.discover(process.cwd());console.warn(Aa("Please ensure the project source is trustworthy before proceeding."));let t=await N.new(),n=Ma(e,r.module),{moduleName:i,targetName:o}=ka(n),s=e.getModuleType(i);if(s!=="entry"&&s!=="feature"&&s!=="shared")throw new Error(`Module '${i}' is of type '${s}', which is not runnable. Please specify an entry or feature module.`);let a=new Ft(t),c=z.from(t),d=await Ta(c,r.device),u=d.includes("127.0.0.1")||d.includes("localhost"),b=r.product||"default";e.validateProduct(b);let k=r.buildMode||"debug";r.skipBuild||await Na(e,t,i,o,b,k);let de=xa(e,i,o,u,b),$e=e.getBundleName(),_e=e.getMainAbility(i,r.ability);await Ra(a,d,$e,de,_e,!!r.uninstall)}var Ci=Oa;import{Command as Ha}from"commander";import{green as Ai,red as ki,cyan as rr}from"colorette";import{execa as Ti}from"execa";function ja(){return"@zacktt/test"}function Fa(){return"0.0.1"}var $a=new Ha("update").description("Update deveco-cli to the latest version").action(async()=>{let r=ja(),e=Fa();console.log(rr("Checking for updates..."));try{let{stdout:t}=await Ti("npm",["view",r,"version"]),n=t.trim();if(n===e){console.log(Ai(`
|
|
32
|
+
${r} is already up to date (version ${e})`));return}console.log(rr(`
|
|
33
|
+
New version found: ${n} (current: ${e})`)),console.log(rr(`Updating ${r}...`)),await Ti("npm",["install","-g",`${r}@latest`],{stdio:"inherit"}),console.log(`
|
|
34
|
+
`+Ai(`${r} updated successfully to version ${n}!`))}catch(t){let n=t;console.error(ki(`Failed to update ${r}`)),n.message&&console.error(ki(n.message)),process.exit(1)}}),Mi=$a;import{Command as ac}from"commander";import{execa as ar}from"execa";function j(r){return r.normalize("NFKC").replace(/\s+/g," ").trim()}import{spawn as _a}from"child_process";var Wa=2500;function Ua(r,e,t,n,i,o){r.once("exit",s=>{if(o())return;clearTimeout(e);let a=t();s===0||s===null?n():i(a||`Emulator process exited with code ${s}`)})}function Ba(r,e,t,n){let i=!1,o=()=>i,s=()=>Buffer.concat(e).toString("utf8").trim(),a=()=>{i||(i=!0,clearTimeout(d),r.removeAllListeners(),r.stderr?.removeAllListeners(),r.stderr?.destroy(),r.unref(),t())},c=u=>{if(!i){i=!0,clearTimeout(d),r.removeAllListeners(),r.stderr?.removeAllListeners();try{r.kill()}catch{}n(new Error(u))}},d=setTimeout(a,Wa);r.once("error",u=>c(u.message)),Ua(r,d,s,a,c,o)}function xi(r,e,t){return g(`Spawning emulator: ${r} ${t.join(" ")}`),new Promise((n,i)=>{let o=[],s=_a(r,t,{detached:!0,stdio:["ignore","ignore","pipe"],env:{...process.env,DEVECO_SDK_HOME:e},windowsHide:!0});s.stderr?.on("data",a=>o.push(a)),Ba(s,o,n,i)})}import*as ze from"path";function za(r){let e=new Set,t=[];for(let n of r){let i=JSON.stringify(n);e.has(i)||(e.add(i),t.push(n))}return t}function Va(r){let e=r.instancePath?.trim();if(e)return ze.dirname(ze.normalize(e)).replace(/\\/g,"/");let t=r.path?.trim();return t?ze.dirname(ze.normalize(t)).replace(/\\/g,"/"):""}function qa(r){let e=[];return r&&e.push(["-imageRoot",r]),e.push([]),e}function Ri(r,e){return e?[...r,"-bootmode",e]:r}function Ya(r,e,t){let n=[Ri(["-start",r],t)],i=Va(e);if(i)for(let o of qa(e.imageRoot))n.push(Ri(["-hvd",r,"-path",i,...o],t));return za(n)}async function Oi(r,e,t,n){let i=new Error("No start strategy ran"),o=Ya(r,e,n);for(let s of o)try{return await t(s),{ok:!0}}catch(a){i=a}return{ok:!1,lastError:i}}async function ir(r){return(await z.withHdcPath(r).listDevices()).map(t=>t.serial).filter(mt)}async function or(r){let e=await ir(r);return e.length===0?[]:(await Promise.all(e.map(n=>nr(r,n,"ohos.qemu.hvd.name")))).filter(n=>!!n)}async function Ni(r,e){return(await or(r)).includes(e)}import*as qe from"path";import{existsSync as Ga,statSync as Ja}from"fs";function Ve(r,e){for(let t of e){let n=r[t];if(typeof n=="string"&&n.trim())return n.trim()}return""}function Ka(r){let e=Ve(r,["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,n]of Object.entries(r)){if(typeof n!="string"||!n.trim())continue;let i=t.toLowerCase();if(i.includes("instance")&&(i.includes("path")||i.includes("dir"))||i==="deployedpath")return n.trim()}return""}function Za(r){return Ve(r,["uuid","UUID","Uuid","instanceUuid","instance_uuid","InstanceUuid"])}function Xa(r){let e=r.find(n=>n.instancePath?.trim());if(!e?.instancePath?.trim())return;let t=qe.dirname(qe.normalize(e.instancePath));for(let n of r){if(n.instancePath?.trim())continue;let i=qe.join(t,n.name);Ga(i)&&Ja(i).isDirectory()&&(n.instancePath=i.replace(/\\/g,"/"))}}function Qa(r){try{let e=JSON.parse(r);return Array.isArray(e)?e.map(t=>{let n=Za(t),i=Ve(t,["deviceType","DeviceType","devicetype"]),o=Ve(t,["os.osVersion","osVersion","OsVersion","OSVersion"]);return{name:t.name||t.Name||"",isRunning:t.isRunning===!0||String(t.isRunning).toLowerCase()==="true",instancePath:Ka(t),path:Ve(t,["path","Path","hvdPath","hvd_path"]),imageRoot:Ve(t,["imageRoot","image_root","ImageRoot"]),uuid:n||void 0,deviceType:i||void 0,osVersion:o||void 0}}).filter(t=>t.name):null}catch{return null}}function ec(r){let e=[],t=/^(name|isrunning|instancepath|path|imageroot|devicetype|os\.osversion)\s*:\s*(.+)/gim,n=null,i;for(;(i=t.exec(r))!==null;){let[,o,s]=i;if(o.toLowerCase()==="name")n&&e.push(n),n={name:s.trim()};else if(n){let a=o.toLowerCase();a==="isrunning"?n.isRunning=s.trim().toLowerCase()==="true":a==="instancepath"?n.instancePath=s.trim():a==="path"?n.path=s.trim():a==="imageroot"?n.imageRoot=s.trim():a==="devicetype"?n.deviceType=s.trim():a==="os.osversion"&&(n.osVersion=s.trim())}}return n&&e.push(n),e}function Li(r){let t=Qa(r)??ec(r);return Xa(t),t}function sr(r,e){for(let t of e){let n=r[t];if(typeof n=="string"&&n.trim())return n.trim()}return""}function tc(r){let e=r.downloaded??r.Downloaded;return e===!0||String(e).toLowerCase()==="true"}function nc(r){if(!tc(r))return null;let e=sr(r,["osVersion","OsVersion","OSVersion"]),t=sr(r,["SoftWareVersion","SoftwareVersion","softwareVersion"]),n=sr(r,["deviceType","DeviceType"]);return!e&&!t?null:{osVersion:e,softwareVersion:t,deviceType:n}}function $t(r){let e=r.trim();if(!e)return[];try{let t=JSON.parse(e);if(!Array.isArray(t))return[];let n=[];for(let i of t){if(!i||typeof i!="object")continue;let o=nc(i);o&&n.push(o)}return n}catch{return[]}}function Hi(r){let t=$t(r).map(n=>n.osVersion).filter(Boolean);return[...new Set(t)]}var ji=/no images are available/i;function ie(r){return r.normalize("NFKC").trim().toLowerCase()}function rc(r){let e=r.message||"";return ji.test(e)}var Ye=class r{emulatorPath;sdkPath;hdcPath;constructor(e,t,n){this.emulatorPath=e,this.sdkPath=t,this.hdcPath=n}static from(e){return new r(e.emulatorPath,e.sdkPath,e.hdcPath)}async executeEmulator(e){return ar(this.emulatorPath,e,{stdio:["ignore","pipe","pipe"],env:{...process.env,DEVECO_SDK_HOME:this.sdkPath}})}executeEmulatorDetached(e){return xi(this.emulatorPath,this.sdkPath,e)}async listEmulators(){let{stdout:e}=await this.executeEmulator(["-list","-details"]);return Li(e)}async getDeviceTypeByName(){let e=new Map;try{let t=await this.listEmulators();for(let n of t)n.name&&n.deviceType&&e.set(j(n.name),n.deviceType)}catch{}return e}async startEmulator(e){let t=await this.listEmulators(),n=j(e),i=t.find(a=>j(a.name)===n);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 Oi(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.
|
|
35
|
+
Last error: ${s.lastError.message||"unknown"}`)}async isAlreadyRunning(e,t){return t?.isRunning===!0||t===void 0&&(await this.listEmulators()).find(i=>i.name===e)?.isRunning===!0?!0:Ni(this.hdcPath,e)}async stopEmulator(e){let t=await this.listEmulators(),n=j(e),i=t.find(a=>j(a.name)===n);if(!i)throw new Error(`Emulator "${e}" not found.`);let o=i.name;return await this.isAlreadyRunning(o,i)?(await this.executeEmulator(["-stop",o]),"stopped"):"already-stopped"}async executeEmulatorInherit(e){let{exitCode:t}=await ar(this.emulatorPath,e,{stdio:"inherit",env:{...process.env,DEVECO_SDK_HOME:this.sdkPath},reject:!1});if(t!==0)throw new Error(`emulator exited with code ${t===null?"null":t}`)}async installEmulatorImage(e){let t=["-install","-deviceType",e.deviceType,"-osVersion",e.osVersion];e.force&&t.push("-force"),await this.executeEmulatorInherit(t)}async uninstallEmulatorImage(e){let t=await this.resolveSoftwareVersionsForUninstall(e);if(t.length===0)throw new Error(`No downloaded image matches --os-version "${e.osVersion}" for --device-type "${e.deviceType}".`);let n;try{await this.runUninstallImageChecked(e.deviceType,e.osVersion)}catch(o){if(!rc(o))throw o;n=o}(n!==void 0||await this.hasMatchingDownloadedImage(e))&&await this.runSoftwareVersionFallback(e,t,n)}async listEmulatorImages(e){let t=["-imageList"];e.deviceType&&t.push("-deviceType",e.deviceType),e.downloaded!==void 0&&t.push("-downloaded",e.downloaded?"true":"false");let{stdout:n}=await this.executeEmulator(t);return n}async listDownloadedImageOsVersions(){let e=await this.listEmulatorImages({downloaded:!0});return Hi(e)}async hasMatchingDownloadedImage(e){return(await this.findMatchingDownloadedImages(e)).length>0}async runSoftwareVersionFallback(e,t,n){try{for(let i of t)await this.runUninstallImageChecked(e.deviceType,i)}catch(i){let o=n!==void 0?`Primary uninstall failed: ${n.message}
|
|
36
|
+
`:"";throw new Error(`${o}Fallback uninstall failed: ${i.message}`,{cause:i})}if(await this.hasMatchingDownloadedImage(e))throw new Error(`Image for --device-type "${e.deviceType}" and --os-version "${e.osVersion}" is still listed as downloaded after uninstall.`)}async resolveSoftwareVersionsForUninstall(e){let t=await this.findMatchingDownloadedImages(e);return[...new Set(t.map(n=>n.softwareVersion).filter(Boolean))]}async findMatchingDownloadedImages(e){let t=await this.listEmulatorImages({deviceType:e.deviceType,downloaded:!0}),n=$t(t),i=ie(e.deviceType),o=ie(e.osVersion);return n.filter(s=>ie(s.deviceType)===i&&(ie(s.osVersion)===o||ie(s.softwareVersion)===o))}async hasDownloadedSystemImage(e,t){let n=await this.listEmulatorImages({downloaded:!0}),i=$t(n),o=ie(t),s=e?.trim()?ie(e):void 0;return i.some(a=>ie(a.osVersion)===o||ie(a.softwareVersion)===o?s===void 0?!0:ie(a.deviceType)===s:!1)}async assertSystemImageAvailable(e){let t=e.osVersion?.trim();if(!t)throw new Error("The system image file cannot be found, download it again.");if(!await this.hasDownloadedSystemImage(e.deviceType,t))throw new Error(`The system image file ${t} cannot be found, download it again.`)}async runUninstallImageChecked(e,t){await this.runEmulatorChecked(["-uninstall","-deviceType",e,"-osVersion",t,"-force"],{printOutputOnSuccess:!0,extraReject:[ji]})}async runEmulatorChecked(e,t){let{stdout:n,stderr:i,exitCode:o}=await ar(this.emulatorPath,e,{stdio:["ignore","pipe","pipe"],env:{...process.env,DEVECO_SDK_HOME:this.sdkPath},reject:!1,maxBuffer:20971520}),s=[n,i].filter(Boolean).join(`
|
|
37
|
+
`).trim(),a=/Invalid command|无效命令|鏃犳晥鍛戒护/i.test(s)||/please attach the correct parameter/i.test(s),c=(t?.extraReject??[]).some(u=>u.test(s));if(o!==0||a||c)throw new Error(s||`emulator exited with code ${o===null?"null":o}`);if(t?.printOutputOnSuccess!==!1&&s){let u=(t?.transformOutput?t.transformOutput(s):s).trim();u&&console.log(u)}}async checkExistingVirtualDevice(e,t){let n=await this.listEmulators(),i=j(e),o=n.find(s=>j(s.name)===i);if(o)if(t)await this.deleteVirtualDevice(o.name);else throw new Error(`Emulator "${e}" already exists. Use --force to overwrite.`);return i}async createVirtualDevice(e){let t=await this.checkExistingVirtualDevice(e.name,e.force),n=["-create",e.name,"-deviceType",e.deviceType,"-osVersion",e.osVersion];if(await this.runEmulatorChecked(n,{extraReject:[/Device create fail/i,/already exists/i,/Invalid OS version/i,/cannot be empty/i],printOutputOnSuccess:!0,transformOutput:o=>o.split(/\r?\n/).map(s=>s.trim().startsWith("Device create success.")?"Device create success.":s).join(`
|
|
38
|
+
`)}),!await this.waitForEmulatorPresenceByList(t))throw new Error(`Emulator "${e.name}" was reported as created, but it did not appear in the emulator list within the timeout. Please open the device manager list in DevEco Studio, then run this command again.`)}async waitForEmulatorPresenceByList(e,t=1e4,n=500){let i=Date.now()+t;for(;Date.now()<i;){if((await this.listEmulators()).some(a=>j(a.name)===e))return!0;await new Promise(a=>setTimeout(a,n))}return!1}async deleteVirtualDevice(e){let t=await this.listEmulators(),n=j(e),i=t.find(s=>j(s.name)===n);if(!i)throw new Error(`Emulator "${e}" not found.`);let o=i.name;if(i.isRunning===!0||await this.isAlreadyRunning(o,i))throw new Error(`Failed to delete device: ${o}
|
|
39
|
+
The device may be running.`);return await this.runEmulatorChecked(["-delete",o,"-force"],{printOutputOnSuccess:!1}),o}};import{red as cr,yellow as $i,gray as _i}from"colorette";import cc from"ora";import{red as ic}from"colorette";function _t(r,e){r?r.fail(e):console.error(ic(e)),process.exit(1)}import{green as oc}from"colorette";function Fi(r,e){return r+" ".repeat(Math.max(0,e-r.length))}function sc(r,e){return r.map((t,n)=>{let i=t.length;for(let o of e){let s=o.cells[n]??"";i=Math.max(i,s.length)}return i})}function ft(r,e){let t=sc(r,e),n=[];n.push(r.map((i,o)=>Fi(i,t[o])).join(" ")),n.push(t.map(i=>"-".repeat(i)).join(" "));for(let i of e){let o=i.cells.map((s,a)=>Fi(s??"",t[a])).join(" ").trimEnd();n.push(i.highlight?oc(o):o)}return n.join(`
|
|
40
|
+
`)}function lc(r,e){if(e.size!==0)for(let t of r){if(!t.isEmulator||!t.name)continue;let n=e.get(j(t.name));n&&(t.deviceType=n)}}var dc=["Name","Serial","Kind","Device Type"];function uc(r){return{cells:[r.name??r.serial,r.serial,r.isEmulator?"emulator":"device",r.deviceType??"-"],highlight:!0}}function pc(r,e){return r.isEmulator!==e.isEmulator?r.isEmulator?1:-1:(r.name??r.serial).localeCompare(e.name??e.serial)}function hc(){console.log($i(" No active devices.")),console.log(_i(" Connect a USB device with debugging enabled, or start an emulator with `devecocli emulator start <name>`."))}function mc(r){let t=[...r].sort(pc).map(uc);console.log(ft(dc,t))}async function fc(r,e){if(O()||!r.some(i=>i.isEmulator)||!e.emulatorPath)return;let n=await Ye.from(e).getDeviceTypeByName();lc(r,n)}async function gc(r,e,t){try{let n=await r.getConnectedEntries();await fc(n,e),t?.stop(),n.length===0?hc():mc(n)}catch(n){_t(t,`Failed to list devices: ${n.message}`)}}async function yc(r,e){let t=await r.listDevices();if(!(t.length<2)){console.error(cr("Multiple devices connected. Please specify a device with:"));for(let n of t){let i=await r.getDeviceName(n.serial);console.error(_i(` ${e} -t ${n.serial} # ${i}`))}process.exit(1)}}async function vc(r,e){try{e||await yc(r,"devecocli device view");let t=await r.listDevices(),n=await r.getDeviceInfo(t,e);n||(console.log($i("No connected device found.")),process.exit(1));let i=await r.getDeviceDetail(n.serial),o=await r.getDeviceName(n.serial);console.log(` Serial: ${n.serial}`),console.log(` Device Name: ${o}`),i.deviceType&&console.log(` Device Type: ${i.deviceType}`),i.osVersion&&console.log(` OS Version: ${i.osVersion}`)}catch(t){console.error(cr(`Failed to show device details: ${t.message}`)),process.exit(1)}}async function Wi(){try{let r=await N.new();return{manager:z.from(r),toolProvider:r}}catch(r){console.error(cr(`Failed to initialize device manager: ${r.message}`)),process.exit(1);return}}var lr=new ac("device").description("Manage connected devices");lr.command("list").description("List all connected devices").action(async()=>{let{manager:r,toolProvider:e}=await Wi(),t=cc({text:"Querying connected devices\u2026",color:"cyan"}).start();await gc(r,e,t)});lr.command("view").description("Show detailed device information").option("-t, --target <serialOrName>","Target device serial or device name").action(async r=>{let{manager:e}=await Wi();await vc(e,r.target)});var Ui=lr;import{Command as mr,Option as ro}from"commander";import{green as Ut,cyan as Je,red as V,yellow as oe,gray as Ke}from"colorette";import jc from"ora";import wc from"readline/promises";import{execa as zi}from"execa";import*as Se from"fs/promises";import*as ur from"os";import*as xe from"path";var dr=`1/4:\r
|
|
41
|
+
---------------------------------------\r
|
|
42
|
+
Statement About HarmonyOS and Privacy\r
|
|
43
|
+
\r
|
|
44
|
+
Last updated: July 10, 2025\r
|
|
45
|
+
\r
|
|
46
|
+
HarmonyOS is a next-generation operating system for smart devices, providing a unified language for enabling intelligence, interconnection, and collaboration across different devices. It gives a neat, smooth, seamless, secure, and reliable interaction experience in all scenarios. HarmonyOS and related system services (hereinafter referred to as the "Services") are provided for you by Huawei Device Co., Ltd. (hereinafter referred to as "Huawei", "we", "us", or "our"), which is registered at No. 2 Xincheng Road, Songshan Lake Zone, Dongguan, Guangdong.\r
|
|
47
|
+
\r
|
|
48
|
+
Huawei takes your personal information and privacy seriously, and is committed to taking appropriate security measures to protect your personal information in accordance with relevant laws and established industry security standards. We have specially formulated this Statement to help you learn about how the Services collect, use, disclose, protect, store, and transmit your personal information. Please read this Statement carefully.\r
|
|
49
|
+
\r
|
|
50
|
+
In addition to the Services, HarmonyOS enables you to access and use Huawei or third-party apps and services that are pre-installed or downloaded by you. For information such as that about how these apps and services process your personal information, please refer to their privacy statements.\r
|
|
51
|
+
\r
|
|
52
|
+
1 How We Collect and Use Your Personal Information\r
|
|
53
|
+
\r
|
|
54
|
+
We will provide you with the system services described below based on HarmonyOS. We will process information required for providing the features/services as described below when you use them. If you do not provide the related information, your use of the Services may be affected.\r
|
|
55
|
+
\r
|
|
56
|
+
1.1 Software update services\r
|
|
57
|
+
\r
|
|
58
|
+
Software update services are basic services for updating the system on your device. During use, the services need to connect to the Internet to check for and download updates as well as to perform business operation and maintenance analysis, thereby providing the system update services.\r
|
|
59
|
+
\r
|
|
60
|
+
(1) System ROM updates\r
|
|
61
|
+
\r
|
|
62
|
+
To update your system in a timely manner for improving our products (or services), we need to collect your following information: device identifiers (including SN and SOCID), device model, system settings, operating system, system configuration information, system properties, IP address, and WLAN information (Wi-Fi status). Among the information, the WLAN information (Wi-Fi status) will only be processed locally and will not be uploaded to any Huawei server.\r
|
|
63
|
+
\r
|
|
64
|
+
We will use your personal information in the following ways: The aforementioned information you provide will be used to find and push suitable ROM versions for your device. To address potential risks in the system, the latest version will be downloaded and then used for an automatic update with your consent or when required to fix urgent system security loopholes.\r
|
|
65
|
+
\r
|
|
66
|
+
(2) Business operation and maintenance analysis\r
|
|
67
|
+
\r
|
|
68
|
+
To improve your update experience, we need to collect your following information: device identifiers (including SN), device model, system settings, operating system, system configuration information, system properties, IP address, and WLAN information (Wi-Fi status). A device analysis report will be generated for business operation and service analysis and improvement. Information in the report is statistically aggregated and cannot be used to identify you.\r
|
|
69
|
+
\r
|
|
70
|
+
1.2 Message pushing services\r
|
|
71
|
+
\r
|
|
72
|
+
Message pushing services enable us and other app developers to send push messages to your device. To ensure the delivery of messages, we need to establish a secure and reliable message sending channel between your device and the push server. During your use of an app or service, we will collect and use your following information and upload the information to the Huawei server: network information, device model, device identifier, system settings, operating system, device hardware information, device status and running records, WLAN information (Wi-Fi status), and basic app information. To locate app problems and improve services, we will collect and use your following information for product O&M during your app or service use: network information, device model, device identifier, system settings, operating system, device hardware information, device status and running records, WLAN information (Wi-Fi status), and basic app information.\r
|
|
73
|
+
\r
|
|
74
|
+
1.3 System-level web services\r
|
|
75
|
+
\r
|
|
76
|
+
System-level web services provide you with basic features related to web browsing. The services need to connect to the Internet. During your use of the services, relevant configuration data will be downloaded based on the enabled features.\r
|
|
77
|
+
\r
|
|
78
|
+
1.4 Digital rights management services\r
|
|
79
|
+
\r
|
|
80
|
+
Digital rights management (DRM) services provide secure data encryption and decryption to furnish copyright protection for digital assets on your device. The services need to connect to the Internet and collect and use your device name, device model, SOCID, and operating system version to issue DRM certificates and perform copyright protection.\r
|
|
81
|
+
\r
|
|
82
|
+
1.5 Basic AppGallery services\r
|
|
83
|
+
\r
|
|
84
|
+
Basic AppGallery services provide download, installation, and management features based on apps. During use, the services need to connect to the Internet and read the WLAN information (Wi-Fi status and Wi-Fi parameters) to provide features such as app download and network notification, and read and transmit your list of installed apps to provide features such as security check and risk alerts, unified privacy pop-up information, on-demand app loading, and malicious redirection control. This ensures secure app download and use, and prevents fraud and other malicious activities. Among the information, your list of installed apps will not be stored on the cloud.\r
|
|
85
|
+
\r
|
|
86
|
+
1.6 System storage services\r
|
|
87
|
+
\r
|
|
88
|
+
System storage services include calendar storage services. Calendar storage services provide basic capabilities such as calendar event storage, access, and reminder notification. During use, the services need to read the calendar event data to record and save event reminders so that they can be made available to apps.\r
|
|
89
|
+
\r
|
|
90
|
+
1.7 Auto-discovery services\r
|
|
91
|
+
\r
|
|
92
|
+
Auto-discovery services provide the capability to automatically discover supported devices nearby and prompt you to complete the connection and authentication process. During use, the services need to connect to the Internet, use Bluetooth, and read and transmit the Bluetooth MAC address and WLAN MAC address for the purposes of near-field device discovery, authentication, and connection.\r
|
|
93
|
+
\r
|
|
94
|
+
1.8 Common security services\r
|
|
95
|
+
\r
|
|
96
|
+
Common security services provide basic security capabilities for your device, such as device certificate management and encrypted data sharing. During your use of the services, device certificate management needs to connect to the Internet and read and transmit the device identifier, which will be used to apply for and update the device certificates, thereby providing device identity authentication services based on the device certificates. Encrypted data sharing needs to connect to the Internet, read and transmit the HUAWEI ID information and device identifier for applying for data protection credentials, and use the phone number or email address you submit to query the corresponding HUAWEI ID (account UID, profile picture, and nickname), thereby providing the HUAWEI ID-based feature to share data with encryption security.\r
|
|
97
|
+
\r
|
|
98
|
+
1.9 Basic HarmonyOS Connect services\r
|
|
99
|
+
\r
|
|
100
|
+
Basic HarmonyOS Connect services provide upper-layer apps with APIs for device discovery, network configuration, registration and addition, and control and management. Information involved in the APIs includes the HUAWEI ID information, device information (including device hardware information, device identifier (including SN), MAC address, and device name), and personalized device settings (including IoT smart device service parameters). The aforementioned information will only be collected when the upper-layer apps use the APIs provided by the services. For details about the collection scenarios, please refer to the descriptions provided by the upper-layer apps. During use, the services need to connect to the Internet and use Bluetooth, NearLink (supported only by some devices), and WLAN.\r
|
|
101
|
+
\r
|
|
102
|
+
1.10 Picker services\r
|
|
103
|
+
\r
|
|
104
|
+
Picker services are system component capabilities we provide for developers and users. If an app that has integrated the picker services requests access to any sensitive data stored in the system (including media data, and file data) or any sensitive system components (including camera and microphone), the operating system will provide an interface to directly interact with the user, thereby restricting direct access by the app. In this way, user privacy can be better protected while the related app functionality is maintained.\r
|
|
105
|
+
\r
|
|
106
|
+
To provide the aforementioned feature, the picker services need to do the following: locally read the media data (images, videos, and audio) and file data, in order to display sensitive data to the user and allow the user to select sensitive data that can be accessed by the app; or enable the camera or microphone, in order to allow the user to easily access features such as taking photos or recording videos. Particularly, in the case of accessing file data, the file picker service will locally read the list of installed apps to display the file processing capabilities (such as format conversion, compression, and encryption) that file processing apps provide for the user.\r
|
|
107
|
+
\r
|
|
108
|
+
1.11 Basic system analysis services\r
|
|
109
|
+
\r
|
|
110
|
+
Basic system analysis services provide the capabilities to measure system running and interface calling, to ensure long-term stable running of the device. During use, the services need to connect to the Internet and collect the random device identifier, system settings, system properties, device model, MAC address, WLAN information (Wi-Fi connection status, Wi-Fi parameters, and Wi-Fi list), Bluetooth device list, motion status, approximate location information, operating system information, network information, running records, basic app information, app running status, and interface calling information, which will be used for product operation and user experience improvement.\r
|
|
111
|
+
\r
|
|
112
|
+
1.12 Management services in Security & Privacy Center\r
|
|
113
|
+
\r
|
|
114
|
+
Management services in Security & Privacy Center provide you with the permission management capabilities related to security and privacy. During your use of the services, permission management needs to read the images, videos, and list of installed apps to display the number of images and videos in the section of the Images & videos permission, and display the status of the permission for different apps on the permission's details screen, thereby alerting you to risks of granting the permission.\r
|
|
115
|
+
\r
|
|
116
|
+
1.13 Device activation services\r
|
|
117
|
+
\r
|
|
118
|
+
During use, the services need to connect to the Internet and read and transmit the device identifiers (including SN), approximate location information, device model, and operating system information to identify and activate the device and generate benefit information, thereby protecting your benefits.\r
|
|
119
|
+
\r
|
|
120
|
+
1.14 Authentication proxy services\r
|
|
121
|
+
\r
|
|
122
|
+
Authentication proxy services provide capabilities such as HUAWEI ID authentication proxy and app identity legitimacy verification proxy, improving performance, experience, and reliability in authentication scenarios. During use, the services need to connect to the Internet, read the list of installed apps, and collect and use your HUAWEI ID information and device identifier to verify the legitimacy of your account and your apps' identities in advance. Among the information, the list of installed apps will only be processed locally and will not be uploaded to any Huawei server.\r
|
|
123
|
+
\r
|
|
124
|
+
2 Protection of Minors\r
|
|
125
|
+
\r
|
|
126
|
+
We attach great importance to the protection of minors' personal information. Huawei will provide services and protection for minors in strict accordance with national laws and regulations. If you are a minor, your parents or legal guardians must agree to your use of the Services, and agree to the applicable terms and conditions. Parents or legal guardians should also take appropriate precautions to protect minors, including monitoring their use of the Services.\r
|
|
127
|
+
\r
|
|
128
|
+
In particular, if you are a child (a minor under the age of 14), please make sure to notify your parents or legal guardians about carefully reading with you this Statement and the Huawei Consumer Business Statement About Children's Privacy Protection (https://legal.cloud.huawei.com/legal/child/privacy-statement.htm?code=CN&language=en-US) specifically formulated by us before you use our services, and use our services or provide information to us with the consent and guidance of your parents or legal guardians. If you are a parent or legal guardian, please ensure that the child under your guardianship uses our services and provides us with information with your consent or guidance.\r
|
|
129
|
+
\r
|
|
130
|
+
3 Entrusted Processing and Sharing of Information\r
|
|
131
|
+
\r
|
|
132
|
+
3.1 Entrusted processing\r
|
|
133
|
+
\r
|
|
134
|
+
In some service scenarios, we will entrust other companies to process your personal information on our behalf, for example, companies that handle hotline calls, send emails, or provide technical support on behalf of Huawei. Such companies can only use your personal information for the purposes of providing services to you on behalf of Huawei. Huawei will enter into strict entrusted processing agreements or personal information processing terms with the entrusted party. The entrusted party is obligated to process related personal information in accordance with this Statement and our instructions and to take relevant confidentiality and security measures to ensure personal information security.\r
|
|
135
|
+
\r
|
|
136
|
+
3.2 Sharing with third parties\r
|
|
137
|
+
\r
|
|
138
|
+
Currently, the Services do not involve sharing personal information with third parties.\r
|
|
139
|
+
\r
|
|
140
|
+
4 Managing Your Personal Information\r
|
|
141
|
+
\r
|
|
142
|
+
Huawei highly respects your concerns regarding personal information. You can submit to us requests to exercise your rights as a personal information subject, such as those to access, rectify, copy, or delete your personal information, through the official website of Huawei Consumer BG, the My HUAWEI app, or the privacy center based on HUAWEI ID.\r
|
|
143
|
+
\r
|
|
144
|
+
If you submit a request through any other channels, such as hotline, service email address, online customer service, and service center, we will guide you to submit a formal request through the aforementioned channels to facilitate communication and feedback on the handling progress and result. Huawei maintains a dedicated request channel for personal information subjects, which serves to protect legitimate interests of personal information subjects, safeguard Huawei's normal operations, and prevent unauthorized or abusive use of the request rights in relation to personal information.\r
|
|
145
|
+
\r
|
|
146
|
+
We will make every effort to ensure that a response is made within one month after a personal information subject's access request is submitted. Given the complexity and volume of requests, this timeframe may be appropriately extended when necessary. If the provision of information is delayed, we will notify the personal information subject of the situation and the reasons for the delay.\r
|
|
147
|
+
\r
|
|
148
|
+
If you have any further requests, questions, comments, or suggestions regarding your rights as a data subject, please contact us using the contact information provided under the "Contacting Us" section of this Statement.\r
|
|
149
|
+
\r
|
|
150
|
+
5 Information Storage Location and Retention Period\r
|
|
151
|
+
\r
|
|
152
|
+
5.1 Storage location\r
|
|
153
|
+
\r
|
|
154
|
+
The aforementioned information will be sent to and stored on servers in the People's Republic of China.\r
|
|
155
|
+
\r
|
|
156
|
+
5.2 Retention period\r
|
|
157
|
+
\r
|
|
158
|
+
During the provision of the Services, we will process your personal information on your device wherever possible. We will retain your personal information we collect only for the period necessary to fulfill the purposes described in this Statement, and delete or anonymize your personal information beyond the retention period, except as otherwise stipulated by applicable laws and regulations.\r
|
|
159
|
+
\r
|
|
160
|
+
In the software update services, personal information collected for system ROM updates will be retained for six (6) months, and personal information for business operation and maintenance analysis will be retained for five (5) years.\r
|
|
161
|
+
\r
|
|
162
|
+
Among information collected in the message pushing services: information used for product O&M will be retained on the server for up to five (5) years; while other personal information will be retained on the server for up to one (1) year.\r
|
|
163
|
+
\r
|
|
164
|
+
DRM certificates in the DRM services will remain valid for the lifecycle of your device and will be retained for ten (10) years together with the device information.\r
|
|
165
|
+
\r
|
|
166
|
+
Personal information collected in the common security services will be retained for up to three (3) years. Personal information collected by the encrypted data sharing services will be deleted immediately after you delete your HUAWEI ID.\r
|
|
167
|
+
\r
|
|
168
|
+
Information collected by the basic system analysis services will be retained for five (5) years.\r
|
|
169
|
+
\r
|
|
170
|
+
Personal information collected by the device activation services will be retained for seven (7) years.\r
|
|
171
|
+
\r
|
|
172
|
+
Personal information collected by the authentication proxy services will be retained for two (2) years.\r
|
|
173
|
+
\r
|
|
174
|
+
In the event that we discontinue our products or services, we will notify you in the form of a push notification, announcement, or by other means, and delete or anonymize your personal information within a reasonable period of time.\r
|
|
175
|
+
\r
|
|
176
|
+
6 Contacting Us\r
|
|
177
|
+
\r
|
|
178
|
+
We have appointed the person responsible for personal information protection who you can contact from here (https://consumer.huawei.com/en/legal/privacy-questions/). You may also contact us by visiting the Privacy Questions page (https://consumer.huawei.com/en/legal/privacy-questions/). We will reply as soon as possible.\r
|
|
179
|
+
\r
|
|
180
|
+
If you are not satisfied with the response you receive, especially if you feel that our processing or handling of your personal information has violated or infringed on your legal rights and/or interests, you may seek external resolution, whether by filing a lawsuit with the people's court in the relevant jurisdiction, submitting a complaint to the industry self-regulation association or relevant government regulatory agencies, or by other means. You may also consult us regarding the available channels for voicing your complaint. Huawei's collection and use of your personal information is governed by our privacy policy. For more information, please refer to the Huawei Consumer Business Privacy Statement (https://legal.cloud.huawei.com/legal/privacy/statement.htm?country=CN&language=en_US).\r
|
|
181
|
+
\r
|
|
182
|
+
\r
|
|
183
|
+
2/4:\r
|
|
184
|
+
---------------------------------------\r
|
|
185
|
+
Statement About HUAWEI ID and Privacy\r
|
|
186
|
+
\r
|
|
187
|
+
Last updated: September 2, 2025\r
|
|
188
|
+
\r
|
|
189
|
+
HUAWEI ID comprises basic services that help you better use Huawei apps, services, websites, or non-Huawei services and enjoy a consistent and convenient service experience across devices logged in to the same account. It is provided by Huawei Software Technologies Co., Ltd. (hereinafter referred to as "Huawei", "we", "us", or "our"), which is registered at No. 101, Software Avenue, Yuhuatai District, Nanjing, Jiangsu. Huawei takes your personal information and privacy seriously, and is committed to taking appropriate security measures to protect your personal information in accordance with relevant laws and established industry security standards.\r
|
|
190
|
+
\r
|
|
191
|
+
Version Change Description\r
|
|
192
|
+
\r
|
|
193
|
+
Added the "Account contact picker service" subsection to the "How We Collect and Use Your Personal Information" section.\r
|
|
194
|
+
\r
|
|
195
|
+
Summary\r
|
|
196
|
+
\r
|
|
197
|
+
You can access the List of Personal Information Collected (https://legal.cloud.huawei.com/terms/scope/huawei/id-hmos/privacy-statement.htm?code=CN&branchid=0&language=en-US&contenttag=di) to briefly learn about the purpose, method, and scope of personal information collection and/or use in HUAWEI ID.\r
|
|
198
|
+
\r
|
|
199
|
+
Important Notes\r
|
|
200
|
+
\r
|
|
201
|
+
As your ID for accessing Huawei services, HUAWEI ID provides you with a consistent user experience and security authentication when you use services such as AppGallery, HUAWEI CLOUD, HUAWEI CLOUD Meeting, HUAWEI Video, and HUAWEI Music, as well as Huawei terminal devices and related services provided by partners.\r
|
|
202
|
+
\r
|
|
203
|
+
To provide you with a coherent, convenient, and secure account login experience when using Huawei services, your HUAWEI ID information may be shared among and used by the Huawei affiliates. We will only use your HUAWEI ID information within the Huawei affiliates for specific, clear, and legitimate purposes, and will only provide information that is necessary to provide the services.\r
|
|
204
|
+
\r
|
|
205
|
+
Information requested from you for real-name authentication (including your ID card and bank card information) as required by the authority will be provided to relevant organizations in encrypted form for verification to ensure security in accordance with regulatory provisions. We also maintain a risk control system to protect the rights of Huawei, you, and other Huawei customers, prevent fraud and other illegal activities, and reduce account risks.\r
|
|
206
|
+
\r
|
|
207
|
+
During the authentication of your HUAWEI ID, a Huawei app or service will first connect to the Internet to check your agreement signing records to verify whether you can normally access the app or service.\r
|
|
208
|
+
\r
|
|
209
|
+
HUAWEI ID may be launched in turn to provide you with the basic running services when you use a Huawei or third-party app.\r
|
|
210
|
+
\r
|
|
211
|
+
To ensure login and data security for your account and display the status of service cards you use, the Find Device, device management, Family Sharing, and Cloud services will be launched when you log in to your HUAWEI ID.\r
|
|
212
|
+
\r
|
|
213
|
+
Cloud will launch AppGallery when you restore apps, in order to help you restore apps to their latest versions in AppGallery.\r
|
|
214
|
+
\r
|
|
215
|
+
If a family organizer has enabled Mobile Guardian for a child or teenager, Mobile Guardian will be secondarily launched by Family Sharing on the device where the child or teenager logs in to their account.\r
|
|
216
|
+
\r
|
|
217
|
+
When you use the device management services of HUAWEI ID, AI Life will be secondarily launched to facilitate the management of devices under your control.\r
|
|
218
|
+
\r
|
|
219
|
+
On device running HarmonyOS 6.0 or later, during your use of the real-name authentication service of HUAWEI ID, Huawei Pay will be secondarily launched for completing facial verification.\r
|
|
220
|
+
\r
|
|
221
|
+
During your use of the profile picture setting feature of HUAWEI ID, Celia Photo Studio will be secondarily launched to provide you with the ability to generate photos with AI. In addition, Contacts will be secondarily launched to help you set who can view your profile picture in Contacts.\r
|
|
222
|
+
\r
|
|
223
|
+
The scope of services provided by HUAWEI ID and its underlying services may vary depending on the device type or operating system. Please acknowledge that some services may not be applicable to your device type or operating system. Services that are not provided will not collect your personal information or share your personal information with any third party.\r
|
|
224
|
+
\r
|
|
225
|
+
1 How We Collect and Use Your Personal Information\r
|
|
226
|
+
\r
|
|
227
|
+
1.1 We will provide you with the services described below through HUAWEI ID. To fulfill our contractual obligations and ensure that you can use the related features, we will process information required for providing the services as described below when you use the basic services of HUAWEI ID.\r
|
|
228
|
+
\r
|
|
229
|
+
1.1.1 Account features\r
|
|
230
|
+
\r
|
|
231
|
+
Registration and login\r
|
|
232
|
+
\r
|
|
233
|
+
You can register a HUAWEI ID using a mobile number. During the registration process , you need to provide your mobile number and set an account password for registration and login. We may also request you to provide your birthday information to determine whether you are an adult user. After completing the registration, you can add your profile picture, nickname, gender, account name, and other basic information to get a better experience with your HUAWEI ID. You can also use a registered email address to log in to your HUAWEI ID. During the process of managing your profile picture, you can select Create with AI to generate one. We will use the AI capabilities of Celia Photo Studio to create your profile picture. When you set your profile picture, we will also launch Contacts for you to set who can see the profile picture, helping you better protect your privacy. In addition, when you create your profile picture using Gallery, we will use the best-performing AI algorithms in the system to provide a better profile picture display.\r
|
|
234
|
+
\r
|
|
235
|
+
During the registration or login process, we will also collect your device identifiers (including SN and ODID), device information (including device model and device name), HUAWEI ID information, WLAN information (Wi-Fi name), carrier information (including IMSI and PLMN), basic system settings (country code, language, registration location, and service location), operating system information, basic app information, approximate location information (including SSID and BSSID), and browser settings (if applicable), in order to identify your frequently used trusted devices for security purposes and enable you to easily log in on your frequently used devices or trusted browsers. To help you quickly and securely log in or register an account, we will read your SIM card mobile number. In addition, when you use an SMS verification code to log in, we will receive the SMS message to automatically fill in the SMS verification code for you. When changing your profile picture, you can select an image or video from the image picker to make the change. When you use the code scanning feature, we will use the code picker to identify the QR code. During your use of the security verification feature, it is necessary to display the verification code on the device where you have logged in to your HUAWEI ID, so that you can use the security verification code to log in to your HUAWEI ID on the new device. This feature is supported on phones, tablets, and computers, and needs to use the service message feature and collect your HUAWEI ID information, device identifiers (including SN and ODID), device information (device model and device name), and system user name.\r
|
|
236
|
+
\r
|
|
237
|
+
In addition, during the login process, you can use the facial or fingerprint information enrolled on your device instead of your account password to complete the process. Such information will only be stored in the secure trusted zone on your device. We will not collect any biometric information enrolled on your device but will only collect your face ID or fingerprint ID.\r
|
|
238
|
+
\r
|
|
239
|
+
Account security\r
|
|
240
|
+
\r
|
|
241
|
+
To protect the information in your HUAWEI ID , we have set up a variety of identity authentication methods, which include adding information to your HUAWEI ID, setting a security mobile number or security email address, adding emergency contacts, and completing real-name authentication. During your use of the aforementioned features , you will need to provide your security mobile number, security email address, or valid identity documents as applicable. You can grant the Contacts permission when adding emergency contacts , so that you can quickly sync contacts from your Contacts app to the emergency contacts list. On devices running HarmonyOS 6.0 or later, we will no longer use the Contacts permission. You can use the contact picker to quickly select a contact to sync to the emergency contacts list. It is recommended that you use a screen lock on your device to enhance your account security. In addition, we will use CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) to assist in identifying machine-simulated actions, thereby securing the account login or usage environment.\r
|
|
242
|
+
\r
|
|
243
|
+
For the purpose of securing your account when you request to recover your account password, modify your HUAWEI ID registration information, or freeze or unfreeze your account , we may need you to provide your HUAWEI ID information, device identifiers (including SN), WLAN information (Wi-Fi name), approximate location information (including SSID and BSSID), and previous usage information (such as information about previous purchases on VMALL ), and will, when necessary, ask you to upload your selfies with identity documents (ID card, passport, Exit/Entry Permit for Traveling to and from Hong Kong and Macao, or Mainland Travel Permit for Taiwan Residents) or facial images to verify your identity. You can use the file picker to quickly upload your files during the account recovery request process.\r
|
|
244
|
+
\r
|
|
245
|
+
Account risk control\r
|
|
246
|
+
\r
|
|
247
|
+
For the purpose of protecting the rights of Huawei, you, or other Huawei customers, in situations like sign-ups, logins, and payments, we will collect and use your device identifiers (including SN), device type information, approximate location information, network information (IP address), carrier information (including IMSI), HUAWEI ID information (profile picture and nickname), personalized device settings, and system settings for risk control to prevent violations of public policy and restrict fraud and other illegal activities. We will freeze or even clear accounts that are identified as abnormal.\r
|
|
248
|
+
\r
|
|
249
|
+
If we find that the mobile number used by you to log in to your account is likely to be recycled by the communications carrier, we will provide the number and the time of your account registration with the number to the carrier to check whether the number is recycled and thereby ensure your account security.\r
|
|
250
|
+
\r
|
|
251
|
+
If there are abnormalities with your HUAWEI ID when you are using it to log in to a third-party service, we will send information about the abnormalities (such as the account being frozen or compromised) to the third-party service to support its risk control.\r
|
|
252
|
+
\r
|
|
253
|
+
Real-name authentication\r
|
|
254
|
+
\r
|
|
255
|
+
Before allowing you to use Huawei services that involve payment, gaming, content, e-commerce, and developer community features, we need your cooperation in real-name authentication to comply with national laws and regulations as well as regulatory requirements. When you perform real-name authentication as described below, we need to collect information such as HUAWEI ID information to complete the real-name authentication.\r
|
|
256
|
+
\r
|
|
257
|
+
If you use an ID card or eID for the real-name authentication , we will transmit the valid ID card information you provide, in encrypted form, to an authoritative identity authentication organization to have your real identity verified. If we need to further verify the validity of the information you provide , we may also request you to provide photos or videos of your face , which will not be stored by us. We will use the Camera permission on your device when you use the real-name authentication feature described above.\r
|
|
258
|
+
\r
|
|
259
|
+
If you use a bank card for the real-name authentication , we will transmit the bank card information, name, and ID card number you provide in encrypted form to UnionPay for verification.\r
|
|
260
|
+
\r
|
|
261
|
+
We will store the valid ID card information you provide in encrypted form, in order to (a) help authenticate you upon events such as when you request to recover your account password or submit other appeals concerning your account ; and (b) verify your identity when you use our user authentication feature based on real-name information verification or facial recognition , by checking whether the identity information you submit to the third party is consistent with your HUAWEI ID real-name information. After you complete the real-name authentication , we may verify and update the date of birth you submitted when creating your HUAWEI ID, so that we can provide you with appropriate services.\r
|
|
262
|
+
\r
|
|
263
|
+
Address management\r
|
|
264
|
+
\r
|
|
265
|
+
We use your shipping addresses in VMALL to provide you with unified address management services, which save the need for you to manually enter the addresses in different apps or services. You can go to Settings > HUAWEI ID > Personal info > My addresses to manage all your address information (contact name, phone number, and address information) there. Your address updates will be synced to VMALL. You can withdraw your consent by touching the info icon in the upper right corner of the My addresses screen and selecting Withdraw consent from the information displayed. To make it easier for you to enter address information when managing your addresses, we will collect your HUAWEI ID information. You can also quickly add contact names and phone numbers by using the contacts picker, quickly add address information by using the map picker, or quickly paste content by using the clipboard picker.\r
|
|
266
|
+
\r
|
|
267
|
+
If you need to obtain address information when using an app or service, you can grant the address information to the app or service.\r
|
|
268
|
+
\r
|
|
269
|
+
How you can manage your address information differs on different devices or in different versions because the services provided there are different.\r
|
|
270
|
+
\r
|
|
271
|
+
Device interconnectivity\r
|
|
272
|
+
\r
|
|
273
|
+
To help you easily and securely use the distributed interconnection capability, when you have started up your device, log in to your HUAWEI ID, enable Internet access, or use the device interconnection capability, we may secondarily launch the Device Interconnection service in the background to collect your HUAWEI ID information and device identifiers and store them to the Huawei server over the Internet. During your use of the distributed interconnection capability, we will exchange your HUAWEI ID information and device identifiers between the devices for connection establishment.\r
|
|
274
|
+
\r
|
|
275
|
+
1.1.2 Family Sharing\r
|
|
276
|
+
\r
|
|
277
|
+
Family member management\r
|
|
278
|
+
\r
|
|
279
|
+
Family Sharing allows you to seamlessly share your selected content with your family members. When you enable Family Sharing, we will use your family member information and account information to help you and your family members share benefits, subscriptions, and more. You can manage your family members in Family Sharing. For example, you can add family members to Family Sharing by entering a registered HUAWEI ID (mobile number or email address), or create a child account in Family Sharing. To display family member information and send notifications to family members during your use of Family Sharing, we will collect information such as the mobile number, email address, HUAWEI ID information (profile picture and nickname), age information, device identifiers (including ODID), network type, device type, network information, and approximate location information (SSID and BSSID). In addition, after you log in to your account, we will collect the device identifiers (including ODID) to facilitate your receipt of invitation notifications.\r
|
|
280
|
+
\r
|
|
281
|
+
Benefit sharing\r
|
|
282
|
+
\r
|
|
283
|
+
Benefits of purchased Cloud storage plans can be shared among family members. Data of all members will be securely stored on Cloud. Each family member's stored data is visible only to themselves.\r
|
|
284
|
+
\r
|
|
285
|
+
Mobile Guardian\r
|
|
286
|
+
\r
|
|
287
|
+
In Family Sharing, the organizer can enable Mobile Guardian to guide their child to properly use Huawei devices and services. With the feature enabled, the organizer and administrators can manage the Away time, Screen time, App and service limits, and Content access restrictions for the child's device. If the organizer has enabled Mobile Guardian for the child or teenager, Mobile Guardian will be automatically enabled on the device where the child or teenager logs in to their account.\r
|
|
288
|
+
\r
|
|
289
|
+
1.1.3 Cloud\r
|
|
290
|
+
\r
|
|
291
|
+
Cloud provides you with secure and reliable digital asset management services. Cloud will be automatically enabled if you log in to your HUAWEI ID on devices (including but not limited to phones, tablets, and PCs) that provide the Cloud services. Such services allow you to store photos, videos, contacts, notes, calendar events, app data, and so on on the cloud.\r
|
|
292
|
+
\r
|
|
293
|
+
Cloud adopts industry-leading privacy protection technologies and security protection mechanisms based on multi-layer encryption to ensure that no one else can view or obtain your information without your authorization. For more information about Cloud security and privacy, see Cloud Security and Privacy (https://cloud.huawei.com/security).\r
|
|
294
|
+
\r
|
|
295
|
+
Cloud Backup\r
|
|
296
|
+
\r
|
|
297
|
+
Cloud Backup will automatically back up your data when your device is locked and connected to a WLAN network. Cloud Backup is only available on phones and tablets. During your use of the Cloud Backup feature, we will collect the following information to help you restore data on other Huawei devices at any time and improve your experience when switching to a new device: device identifier, WLAN information (Wi-Fi status, Wi-Fi parameters, and Wi-Fi list), BSSID, SSID, images, Notepad, list of installed apps, app settings, files, calendar events, local voice recordings, browser data, SMS messages, Notes, system settings, contacts list, Bluetooth device list, videos, call records, call blocklist, music, GoPaint (created content), and device status information. We will launch AppGallery when you restore apps, in order to help you restore apps to their latest versions in AppGallery.\r
|
|
298
|
+
\r
|
|
299
|
+
If no data has been backed up from your Huawei device to Cloud for more than one hundred and eighty (180) days, we may clear the information already backed up from the device to protect the legitimate rights and interests of all Cloud Backup users and assure their experience.\r
|
|
300
|
+
\r
|
|
301
|
+
Cloud Backup does not provide the backup services on your PC. None of your personal information will be collected or used for features you do not use.\r
|
|
302
|
+
\r
|
|
303
|
+
Apps using the cloud\r
|
|
304
|
+
\r
|
|
305
|
+
You can enable an app under Apps using the cloud to store its data on the cloud in real time and keep the data synced across devices logged in to the same account. During your use of the aforementioned feature , we will collect the following information to store the data on Cloud in real time, keep the data synced across devices logged in to the same account , help you restore data on other Huawei devices at any time, and improve your experience when switching to a new device: precise location information , WLAN information (Wi-Fi status, Wi-Fi parameters, and Wi-Fi list), Password Vault (including automatically saved or manually entered data, card document data, and Wi-Fi data), SmartFill (historical form input and user settings), BSSID, SSID, images, Notepad, list of installed apps, app settings, calendar events, browser data, Notes, Focus, contacts list, data of apps using the cloud syncing services such as Video. To ensure faster and more stable collaboration between your devices, we will collect the following information when you use the Multi-Device Collaboration services: your device name (text you actively upload), device identifier, and Bluetooth MAC address. Such information is only used for collaboration between your devices.\r
|
|
306
|
+
\r
|
|
307
|
+
Data in Password Vault is protected with end-to-end encryption, and the data encryption key is stored on your trusted device, making it impossible for others, including Huawei, to access the data.\r
|
|
308
|
+
\r
|
|
309
|
+
Drive\r
|
|
310
|
+
\r
|
|
311
|
+
Drive allows you to upload and download files, and more. During your use of the aforementioned features, we will collect the Drive files, app usage information, and device status information to allow you to search for your Drive files using the global search service on your device.\r
|
|
312
|
+
\r
|
|
313
|
+
Cloud storage management\r
|
|
314
|
+
\r
|
|
315
|
+
Cloud provides you with Cloud storage management services. For this purpose, we need to access the Internet. When you enable Cloud to view and manage your Cloud storage data and enable or disable features, we will collect your following information so that you can view and manage your Cloud storage at any time and we can improve our service quality: network information, system settings, system properties, nickname, profile picture, basic app information, and app settings.\r
|
|
316
|
+
\r
|
|
317
|
+
Marketing notifications\r
|
|
318
|
+
\r
|
|
319
|
+
Cloud provides you with marketing notification services. If you turn on the Promotional notifications switch, we will collect your HUAWEI ID information, app usage information, operating system, and device identifier.\r
|
|
320
|
+
\r
|
|
321
|
+
Cloud website\r
|
|
322
|
+
\r
|
|
323
|
+
You can log in to the Cloud website (cloud.huawei.com) to view and manage your data. For this purpose, we will collect the basic app information, app settings, app usage information, system settings, and IP address or IP location. In Settings of the Cloud website, you can disable or delete your cards linked in HUAWEI Wallet. When you use this feature, HUAWEI Wallet will send the card information to Cloud. However, we will not store such information on the cloud. If you are a paying user of Cloud, you can also go to Settings > Advanced > Contacts Time Machine to restore your contacts information within the last 30 days.\r
|
|
324
|
+
\r
|
|
325
|
+
Plan purchases\r
|
|
326
|
+
\r
|
|
327
|
+
We offer paid membership services to provide you with more and better services and improve your experience. You can purchase a cloud storage plan that fits your needs. You can also get a Cloud membership through benefit redemption. If you purchase a plan, we will collect the transaction record and benefit information to ensure that you can enjoy the benefits you have paid for.\r
|
|
328
|
+
\r
|
|
329
|
+
1.1.4 Find Service\r
|
|
330
|
+
\r
|
|
331
|
+
During your use of Find Service for locating your device , we will collect the following information to show you the mobile number and network information of the lost device and increase your chances of getting the device back : SN, device status information, WLAN information (Wi-Fi parameters), WLAN information (Wi-Fi status), SSID, network information, basic app information, carrier information, device identifier, SIM card number, approximate location information, and precise location information. For supported devices, Find Service is available even if the devices have been powered off or restored to factory settings. Features provided by the services or the data processing may vary depending on the device or version. Features you haven't used will not collect your personal information. The services are available to you on phones, tablets, and PCs.\r
|
|
332
|
+
\r
|
|
333
|
+
Finding auxiliary devices\r
|
|
334
|
+
\r
|
|
335
|
+
If you have logged in to your HUAWEI ID on your device, enabled Find Service, and completed security verification, Find Service will be automatically enabled for the accessories paired with the device to ensure your device security.\r
|
|
336
|
+
\r
|
|
337
|
+
During your use of Find Service, we will collect the device identifier, SN, device status information, and device model. You can go to the Find Device app and select Remove device to disable Find Service for the auxiliary device.\r
|
|
338
|
+
\r
|
|
339
|
+
To display the last location of the Bluetooth device before it is disconnected, the Location permission will be used upon the disconnection to automatically report the location of your device.\r
|
|
340
|
+
\r
|
|
341
|
+
For sports watches and bands, you can only find and manage these devices through the Health app after pairing with these devices in the app.\r
|
|
342
|
+
\r
|
|
343
|
+
The feature for finding auxiliary devices is available only on mobile phones and tablets.\r
|
|
344
|
+
\r
|
|
345
|
+
Finding items\r
|
|
346
|
+
\r
|
|
347
|
+
To discover and manage a HUAWEI Tag paired with your device , we will collect the device identifier, Bluetooth device list , system properties, device model, device hardware information, and device status information after the item is successfully paired with your device. In the event that your HUAWEI Tag is off from the linked device, we need to disclose your information limited to the item's device identifier to ensure device security and personal safety. In addition, you can use Find Network to check the item's location (as described below).\r
|
|
348
|
+
\r
|
|
349
|
+
The feature for finding items is available only on mobile phones and tablets.\r
|
|
350
|
+
\r
|
|
351
|
+
Find Network\r
|
|
352
|
+
\r
|
|
353
|
+
Find Network is a short-range information network consisting of a large number of Huawei devices. After a device or item joins Find Network, you can locate it through Find Network or anonymously help locate other devices and items that have joined Find Network.\r
|
|
354
|
+
\r
|
|
355
|
+
Find Network detects lost devices and items nearby using the device discovery and connection capabilities, anonymizes the detected precise location information, and encrypts and uploads the information to the Huawei server. (Such precise location information will be collected only when a nearby lost device or item is detected, and the collection will take place at a minimum interval of 5 minutes.) Huawei cannot decrypt the location, and will not share the encrypted data of the location with any third party.\r
|
|
356
|
+
\r
|
|
357
|
+
During your use of the finding feature for an item or device, your following information will be collected to provide you with the ability to locate your device when it is offline or powered off : HUAWEI ID information, device identifier, device hardware information, device model, device status information, MAC address, BSSID, network information, carrier information, SIM card number, and precise location information.\r
|
|
358
|
+
\r
|
|
359
|
+
If your device supports NFC, Find Network will identify information about an item via NFC when the item is in Pairing or Lost mode.\r
|
|
360
|
+
\r
|
|
361
|
+
The Find Network services are available to you on phones, tablets, and PCs.\r
|
|
362
|
+
\r
|
|
363
|
+
Cloud website\r
|
|
364
|
+
\r
|
|
365
|
+
You can log in to the Cloud website (cloud.huawei.com) to view your device's location. We will collect your IP address or IP location, basic app information, system settings, app settings, and app usage information to allow you to log in to the Cloud website (cloud.huawei.com) to view and manage your devices.\r
|
|
366
|
+
\r
|
|
367
|
+
1.1.5 Device management\r
|
|
368
|
+
\r
|
|
369
|
+
To make it easier for you to view your device information, we will sync the list of devices under your account from apps such as AI Life. You can view the list by going to Settings > HUAWEI ID > My devices. To display information about devices linked with your account, we will collect information such as the HUAWEI ID information, device identifiers (including SN), personalized device settings, Bluetooth MAC address, device status and running records, and device information (device model and device name) when you log in to your HUAWEI ID. You can manage the nickname of the current device by going to Settings > About , or Settings > NearLink & Bluetooth , or Settings > Mobile network > Personal hotspot. In addition, for easier management of devices under your control, you can further manage your devices through the device cards or by touching More devices to access AI Life.\r
|
|
370
|
+
\r
|
|
371
|
+
How you can manage your device information differs on different devices or in different versions because the services provided there are different.\r
|
|
372
|
+
\r
|
|
373
|
+
1.1.6 In-App Purchases\r
|
|
374
|
+
\r
|
|
375
|
+
Huawei In-App Purchases comprises services that help you purchase products in apps. For more information about the privacy statement about Huawei In-App Purchases, please refer to Statement About Huawei In-App Purchases and Privacy (https://legal.cloud.huawei.com.cn/terms/scope/huawei/iap-hmos/privacy-statement.htm?code=cn&language=en_us). Please understand that the data type of the Huawei In-App Purchases services may change due to reasons such as version updates or policy adjustments. For details, please refer to Statement About Huawei In-App Purchases and Privacy.\r
|
|
376
|
+
\r
|
|
377
|
+
Purchases via Huawei In-App Purchases\r
|
|
378
|
+
\r
|
|
379
|
+
If you use Huawei In-App Purchases to purchase offerings, we will collect the following information to help you complete the purchase, display your purchase records to you, and determine whether parental authorization is required for payment based on your age : basic account information, HUAWEI ID information, network information, benefit information, device hardware information, age, device identifier, app settings, system settings, subscription information, transaction records, basic app information, and account payment credential.\r
|
|
380
|
+
\r
|
|
381
|
+
Payment verification method management\r
|
|
382
|
+
\r
|
|
383
|
+
To ensure the security of your funds, payment can only be processed after your verification. This requires you to set the payment password and security question and answer. If you forget your payment password, you can retrieve it using your contact information (phone number or email address) and security question. You can also choose to perform verification using your fingerprint or face. To facilitate payment completion, we will collect the account payment credential , device identifier, face ID, fingerprint ID, HUAWEI ID information, and security questions and answers to help you quickly complete the payment verification during subsequent purchases.\r
|
|
384
|
+
\r
|
|
385
|
+
Your fingerprint or facial information will only be stored in the security zone of your device. We will not access your original fingerprint or facial information. If you have enabled Huawei Pay, your device identifier and HUAWEI ID information will be stored in Petalpay (Shenzhen) Co., Ltd. to ensure payment security.\r
|
|
386
|
+
\r
|
|
387
|
+
HUAWEI Points top-up, claiming, and usage\r
|
|
388
|
+
\r
|
|
389
|
+
HUAWEI Points can only be used for purchasing digital offerings provided by Huawei Mobile Services, and can be used for purchases in Huawei apps such as Cloud, Video, Music, Themes, Books, GameCenter, and AppGallery. HUAWEI Points cannot be used to purchase phones, tablets, watches, Visions, and other physical offerings. You can top up your HUAWEI Points by entering your HUAWEI Gift card password or by purchasing them directly. When you top up and use your HUAWEI Points, we will collect the transaction records, customer service messages, redemption code, and virtual assets to show you the top-up and usage details and provide you with the benefits.\r
|
|
390
|
+
\r
|
|
391
|
+
You can top up your HUAWEI Points and view your HUAWEI Points balance and usage records by going to Settings > HUAWEI ID > Payment and purchases > HUAWEI Points. We will send customer service messages to notify you about expiration of your HUAWEI Points balance.\r
|
|
392
|
+
\r
|
|
393
|
+
Coupon claiming and usage\r
|
|
394
|
+
\r
|
|
395
|
+
You can obtain coupons through promotion activities of Huawei or third-party apps that cooperate with Huawei. You can only use coupons for discounts when you purchase the digital offerings and value-added services provided by Huawei Mobile Services. When you claim coupons through promotion activities of Huawei or third-party apps that cooperate with Huawei, we will collect the benefit information and redemption code to record the activities you participate in and provide you with the benefits.\r
|
|
396
|
+
\r
|
|
397
|
+
You can go to Settings > HUAWEI ID > Payment and purchases > Coupons to view the related information. Your coupons will be linked with your HUAWEI ID.\r
|
|
398
|
+
\r
|
|
399
|
+
Invoice management\r
|
|
400
|
+
\r
|
|
401
|
+
To help you easily manage invoice headers and request invoices from your purchase record details, we will collect your email address, transaction records, corporate contact information, and name, which will be used to allow you to quickly select invoice header information during subsequent invoice requests and help you complete your invoice requests based on tax requirements.\r
|
|
402
|
+
\r
|
|
403
|
+
Refund\r
|
|
404
|
+
\r
|
|
405
|
+
If you request a refund, we will collect the following information, in order to verify your identity and check whether you meet the refund eligibility criteria and refund request policies : supporting materials, records of communication with the customer service, basic account information, HUAWEI ID information, name, contact number, bill information, disability certificate , medical certificate confirming the diagnosis of critical illness , certificate of entitlement to subsistence allowance , identification materials , photos of the medical certificate of birth , household register photos , and ID card photos.\r
|
|
406
|
+
\r
|
|
407
|
+
The supporting materials required for a refund request may vary depending on the circumstances. Some app developers may require you to provide additional supporting materials for you to be entitled to more preferential treatment under the refund policy. For details, please refer to the information provided by the developer to you. We will send the above supporting materials and your HUAWEI ID information to the developer for verification. The information will be stored for up to two (2) years or deleted after you delete your HUAWEI ID.\r
|
|
408
|
+
\r
|
|
409
|
+
Risk control\r
|
|
410
|
+
\r
|
|
411
|
+
To protect the rights of Huawei, you, and other Huawei users, we will collect your basic account information, device model, device hardware information, app settings, device identifier, age, IP address, basic app information, HUAWEI ID information, operating system, and transaction records to conduct risk control, prevent fraud and other illegal activities, and reduce credit risks.\r
|
|
412
|
+
\r
|
|
413
|
+
1.1.7 Account-related global services\r
|
|
414
|
+
\r
|
|
415
|
+
Account suggestions\r
|
|
416
|
+
\r
|
|
417
|
+
When providing you with HUAWEI ID app suggestions, we will collect the following information to provide suggestions for you to improve your app settings to obtain better app experiences and security assurance: HUAWEI ID information, device identifier (ODID), basic app information, system settings, device model, device hardware information, operating system, system properties, and IP address. For example, you may be notified to get a free trial of Cloud+ services or to promptly take care of your Cloud data that will be deleted soon. These suggestions will disappear after you have processed them, to ensure a better service experience.\r
|
|
418
|
+
\r
|
|
419
|
+
1.1.8 Account contact picker service\r
|
|
420
|
+
\r
|
|
421
|
+
We will provide the service for selecting contacts who have HUAWEI IDs based on the linking between your local contacts and HUAWEI ID information. During your use of this feature, we will collect the contact numbers of your contacts and the HUAWEI ID information of your contacts who have HUAWEI IDs, in order to allow you to use the account contact picker service. Your contacts information will only be used to link each contact with information about whether it has a HUAWEI ID. We will not store your contacts information. You can go to Huawei Privacy Center and turning off the switch for allowing your HUAWEI ID to be found by your mobile number. After the switch is turned off, your contacts will not be able to find your HUAWEI ID via your mobile number.\r
|
|
422
|
+
\r
|
|
423
|
+
1.1.9 Privacy center\r
|
|
424
|
+
\r
|
|
425
|
+
The Privacy center allows you to manage your personal information in one place. You can access the Privacy center to exercise your rights as the data subject.\r
|
|
426
|
+
\r
|
|
427
|
+
Managing your personal preferences\r
|
|
428
|
+
\r
|
|
429
|
+
We will use your HUAWEI ID information, basic account information, app settings, device identifier, basic app information, and device model to show you your personal preferences. You can modify your personal preferences at any time. We will match content that you may be more interested in for you based on your preference settings.\r
|
|
430
|
+
\r
|
|
431
|
+
Messages from Huawei\r
|
|
432
|
+
\r
|
|
433
|
+
Huawei may send you the latest information such as product news and promotional campaigns through your email address, SMS, MMS, or notifications. You can enable or disable such messages from Huawei at any time. For this purpose, we may use your HUAWEI ID information, app settings, and basic app information.\r
|
|
434
|
+
\r
|
|
435
|
+
Obtaining your data copy\r
|
|
436
|
+
\r
|
|
437
|
+
If you request and download a copy of your personal data, we will strictly verify your identity information to ensure your personal information security. For this purpose, we may need to verify your HUAWEI ID information, basic account information, basic app information, email address, and contact number. For children, we will verify information about their parents.\r
|
|
438
|
+
\r
|
|
439
|
+
To ensure the security of your personal data, when you request to obtain your data copies, we will use your app usage information and display your data copy requests to provide transparency for your personal data copy requests and downloads.\r
|
|
440
|
+
\r
|
|
441
|
+
You need to set a password for the data copy package you are requesting to ensure your data security. Such password is known only to you. Your system settings information and device hardware information may be used to adapt the display effects for different languages and devices.\r
|
|
442
|
+
\r
|
|
443
|
+
Clearing historical preferences\r
|
|
444
|
+
\r
|
|
445
|
+
If you request to clear your historical preferences, we will strictly verify your identity information to ensure your personal information security. For this purpose, we may need to verify your HUAWEI ID information, basic account information, email address, contact number, and basic app information. For children, we will verify information about their parents.\r
|
|
446
|
+
\r
|
|
447
|
+
1.1.10 Feedback\r
|
|
448
|
+
\r
|
|
449
|
+
The Feedback feature allows you to submit your questions and suggestions regarding your use of the services.\r
|
|
450
|
+
\r
|
|
451
|
+
When you use the Feedback feature, we will collect your contact number, records of communication with the customer service, network information, images you actively upload, videos you actively upload, system properties, basic app information, ODID, email address, app logs, HUAWEI ID information, device identifier, device model, device hardware information, and system settings. The purpose of collecting such information is to analyze the collected information, improve the app and services, and provide you with a better user experience. If you select the option to share app logs for more accurate issue diagnosis, your operation records will be included in the app logs, and will be used only for issue locating purposes.\r
|
|
452
|
+
\r
|
|
453
|
+
1.1.11 Help\r
|
|
454
|
+
\r
|
|
455
|
+
The Help feature provides you with solutions to common issues. When you use this feature, we may collect the following information to provide you with relevant answers based on the issue you have encountered: your transaction records, basic app information, records of communication with the customer service, HUAWEI ID information, nickname, images you actively upload, videos you actively upload, device model, device hardware information, system properties, operating system, system settings, app usage information, and other information you provide for substantiating relevant facts.\r
|
|
456
|
+
\r
|
|
457
|
+
1.1.12 Product O&M\r
|
|
458
|
+
\r
|
|
459
|
+
To ensure smooth operation of the product, ensure cyber security as required by laws and regulations, fulfill statistics and settlement purposes, and improve operational strategies of the product, we will collect your following information when you use the aforementioned features: HUAWEI ID information, device identifiers (including ODID), operating system, system settings, approximate location information (including SSID and BSSID), system properties, device model, profile picture, nickname, app usage information, basic app information, app settings, device hardware information, network information (including IP address), carrier information, records of views and use in this app, content you post, and app error information.\r
|
|
460
|
+
\r
|
|
461
|
+
If you do not provide the preceding information, your use of related features in this app may be affected.\r
|
|
462
|
+
\r
|
|
463
|
+
1.2 To provide you with more valuable and tailored services, we will provide you with the features and services described below and process related information with your consent. You can disable or enable a service or feature concerned based on the management path described in the section for the service or feature.\r
|
|
464
|
+
\r
|
|
465
|
+
1.2.1 Login to third-party services\r
|
|
466
|
+
\r
|
|
467
|
+
You can use your HUAWEI ID to log in to a third-party service, and the third-party service provider will obtain the HUAWEI ID information your grant (profile picture and nickname) after obtaining your consent. In addition, some third-party services have integrated the quick login capability of HUAWEI ID. When you access such services, the third parties can only link your HUAWEI ID for login authentication. We will not share any of your other personal information with the third-party services.\r
|
|
468
|
+
\r
|
|
469
|
+
In addition, if a third-party service has integrated the feature for instant login with HUAWEI ID, you can easily log in to the third-party service and authorize the third-party service to access your mobile number.\r
|
|
470
|
+
\r
|
|
471
|
+
When a third-party app requests to use your additional personal information (which may include your phone number, email address, ID card information , or address information), your separate consent will be requested again. Such information will be shared with the third-party app only with your consent.\r
|
|
472
|
+
\r
|
|
473
|
+
1.2.2 Find Service\r
|
|
474
|
+
\r
|
|
475
|
+
When you enable and use Find Service, we will collect precise location information to show you the device location and increase your chances of getting the device back.\r
|
|
476
|
+
\r
|
|
477
|
+
If you do not want to receive the aforementioned content or services, you can withdraw your consent by going to Settings > Privacy & security > Location > System services > Find My Device.\r
|
|
478
|
+
\r
|
|
479
|
+
Your device's last location will be sent to the server when the device's battery is about to run out or when the device gets separated from an accessory.\r
|
|
480
|
+
\r
|
|
481
|
+
If you do not want to receive the aforementioned content or services, you can withdraw your consent by going to Settings > HUAWEI ID > Find Device > Send last location.\r
|
|
482
|
+
\r
|
|
483
|
+
If you use the Precise search services, we may turn on the NearLink switch of the device you are looking for to display the distance and direction during the search process.\r
|
|
484
|
+
\r
|
|
485
|
+
If you do not want to receive the aforementioned content or services, you can exit Precise search to withdraw your consent.\r
|
|
486
|
+
\r
|
|
487
|
+
Features provided by the services or the data processing may vary depending on the device or version. Features you haven't used will not collect your personal information. The services are available to you on phones, tablets, and PCs.\r
|
|
488
|
+
\r
|
|
489
|
+
Lost mode\r
|
|
490
|
+
\r
|
|
491
|
+
Lost mode allows you to lock your lost device. In this mode, the Location permission will be used to automatically report the location information every ten minutes. We will collect the travel track to help you track the location of your lost device, and collect the device's travel track in order to display it on the map after obtaining your consent. We will encrypt the track information and only save the records generated over the last 24 hours. You can also set lock screen information (text you actively upload) and contact number or email address for your device in Lost mode, so that anyone who finds the device can then contact you. Such uploaded travel track , lock screen information, and contact number or email address will all be automatically cleared when you disable Lost mode.\r
|
|
492
|
+
\r
|
|
493
|
+
If you do not want to receive the aforementioned content or services, you can withdraw your consent by opening the Find Device app, going to Device details > Lost mode , and disabling Lost mode.\r
|
|
494
|
+
\r
|
|
495
|
+
The Lost mode settings are available on phones, tablets, and PCs.\r
|
|
496
|
+
\r
|
|
497
|
+
Location sharing\r
|
|
498
|
+
\r
|
|
499
|
+
You can use the Location sharing feature to share the location of this device with a family member or friend of yours, and we will collect the precise location information and profile picture, so that they can help you locate this device in case it is lost or view your current location. After Location sharing is enabled, your device will use the Location permission to report its location only when the family member or friend you share with requests the location. Your family member or friend can access this location information within 24 hours, and we will delete this location information after this period of time.\r
|
|
500
|
+
\r
|
|
501
|
+
If you do not want to receive the aforementioned content or services, you can disable the Location sharing service at any time by going to Settings > HUAWEI ID > Find Device > Location sharing.\r
|
|
502
|
+
\r
|
|
503
|
+
The Location sharing feature is available on phones, tablets, and PCs.\r
|
|
504
|
+
\r
|
|
505
|
+
Separation alerts\r
|
|
506
|
+
\r
|
|
507
|
+
Find Service provides you with the separation alert feature. After you enable this feature, we will use the device discovery and connection capabilities to continuously check whether your item has been left behind. Once your item has been separated from its linked device for a certain period of time, we will send a separation notification for you, including the precise location information of the device at the last moment before it gets separated.\r
|
|
508
|
+
\r
|
|
509
|
+
In the event that you select Do not notify me here for a location, we will set the location as grid data to provide you with intelligent alert services. If you want to continue to have separation alerts triggered for a location set as an exception for alerts, you can remove the location on the separation alert screen.\r
|
|
510
|
+
\r
|
|
511
|
+
If you do not want to receive the aforementioned content or services, you can disable the Separation alerts service at any time by opening the Find Device app and going to Device details > Separation alerts.\r
|
|
512
|
+
\r
|
|
513
|
+
The separation alert feature is available on phones, tablets, and PCs.\r
|
|
514
|
+
\r
|
|
515
|
+
1.2.3 Advertising and marketing\r
|
|
516
|
+
\r
|
|
517
|
+
With your consent, we will provide you with advertising and marketing services. For details about advertising and marketing, please refer to the "Advertising and Marketing" section.\r
|
|
518
|
+
\r
|
|
519
|
+
2 Required Permissions\r
|
|
520
|
+
\r
|
|
521
|
+
The following permissions are required during the running of the app. Any permissions that are not explicitly granted will not be used.\r
|
|
522
|
+
\r
|
|
523
|
+
Contacts: This permission is required for you to specify an emergency contact by selecting the contact from the Contacts app. On devices running HarmonyOS 6.0 or later, we will no longer use the Contacts permission for selecting emergency contacts. In addition, you can grant this permission for linking your contacts in the Contacts app that have HUAWEI IDs, so that you can use the account contact picker service.\r
|
|
524
|
+
\r
|
|
525
|
+
Camera: This permission is used to perform real-name authentication for you account. You can choose to grant or revoke this permission.\r
|
|
526
|
+
\r
|
|
527
|
+
Location: The permission is required to obtain the location information, which is used to allow you to view your current location or to provide you with information and services relevant to your location. You can also choose to revoke this permission. In addition, this permission is required for you to use Find Service.\r
|
|
528
|
+
\r
|
|
529
|
+
Images & videos: The permission is required by Cloud to read Gallery data and display the number of synced images and videos.\r
|
|
530
|
+
\r
|
|
531
|
+
Device connection: We may use this permission to provide you with the device discovery and location capabilities when you use Find Service.\r
|
|
532
|
+
\r
|
|
533
|
+
You can manage the permissions requested for your HUAWEI ID and its underlying services at any time by going to system Settings > Privacy & security. Because the services and system permissions vary depending on the device or version, the system permissions that we request may be different accordingly. In addition, how you can manage the permissions may vary.\r
|
|
534
|
+
\r
|
|
535
|
+
3 Advertising and Marketing\r
|
|
536
|
+
\r
|
|
537
|
+
We will push service notifications, activities, and promotions to you based on your HUAWEI ID information, device identifier, operating system, and app usage information. If you want to unsubscribe from such marketing messages, you can go to Settings > HUAWEI ID > Cloud > More settings > Notifications to stop receiving the messages.\r
|
|
538
|
+
\r
|
|
539
|
+
4 Protection of Minors\r
|
|
540
|
+
\r
|
|
541
|
+
We attach great importance to the protection of minors' personal information. Huawei provides services and protects minors in strict accordance with national laws and regulations. If you are a minor, your parents or legal guardians must agree to your use of this app, and agree to the applicable terms and conditions. Parents or legal guardians should also take appropriate precautions to protect minors, including monitoring their use of this app.\r
|
|
542
|
+
\r
|
|
543
|
+
In particular, if you are a child (a minor under the age of 14), please make sure to notify your parents or legal guardians about carefully reading with you this Statement and the Huawei Consumer Business Statement About Children's Privacy Protection (https://legal.cloud.huawei.com/legal/child/privacy-statement.htm?code=CN&language=en-US) specifically formulated by us before you use our services, and use our services or provide information to us with the consent and guidance of your parents or legal guardians. If you are a parent or legal guardian, please ensure that the child under your guardianship uses our services and provides us with information with your consent or guidance.\r
|
|
544
|
+
\r
|
|
545
|
+
You can add a minor's account to Family Sharing or create an account for a minor in Family Sharing, to easily manage the minor's account.\r
|
|
546
|
+
\r
|
|
547
|
+
To help you manage your child's access to certain types of content or resources, we will enable the mode for protecting minors when you enable Digital Balance and select Enable for a child. You can go to Settings > Digital Balance to change the content access restrictions. We will limit the screen time and content access for protection purpose based on your settings. When you enable the Youth mode feature for your child , we will collect your child's profile picture, nickname, and age group , and provide the age group information to the app, so that the app can provide age-appropriate content to effectively guide minors to use electronic devices healthily and care for their healthy growth. The data generated in this scenario will be linked to the HUAWEI ID you are currently logged in to.\r
|
|
548
|
+
\r
|
|
549
|
+
In the interest of protecting children, child users are only permitted to use a child account. Parents or legal guardians must ensure that their child is using a child account. After you create a child account for your child (under the age of 14), you can view and approve their requests for purchases (including in-app purchases and downloads). In the event that any child account linked with your account requests to link a bank card or make a payment, we will send you an authorization request. Only after you grant the authorization will the child account be able to link the bank card or make the payment as intended.\r
|
|
550
|
+
\r
|
|
551
|
+
As required by applicable laws and regulations in China, we will set a payment limit for child accounts that have passed real-name authentication in order to protect minors.\r
|
|
552
|
+
\r
|
|
553
|
+
The services provided may vary between different devices or versions, and may change based on updates of features available on your device.\r
|
|
554
|
+
\r
|
|
555
|
+
5 Sharing with Third Parties\r
|
|
556
|
+
\r
|
|
557
|
+
Some of our services are provided by third parties. To provide you with such services, we need to share your account information with the third parties. The third parties also provide security protection measures. The shared data is transmitted securely in encrypted form, and your data will not be shared without your consent. In order to protect the security and privacy of your data, we have signed data security protection agreements with our partners, which clarify our partners' responsibilities, obligations, and requirements when it comes to protecting your data. For details, please refer to the Details About Information Sharing with Third Parties (https://legal.cloud.huawei.com/terms/scope/huawei/id/list-privacy-statement.htm?&code=CN&language=en-US).\r
|
|
558
|
+
\r
|
|
559
|
+
6 Third-Party SDKs\r
|
|
560
|
+
\r
|
|
561
|
+
To provide you with certain services, such as third-party payment services (Alipay and China UnionPay), we require joint efforts with the partners. Therefore, we have integrated software development kits (hereinafter referred to as "SDKs") or other similar programs of our partners. For details, please refer to the Third-Party SDK List (https://legal.cloud.huawei.com/terms/scope/huawei/id-hmos/privacy-statement.htm?code=CN&language=en-US&contenttag=3rdsdk).\r
|
|
562
|
+
\r
|
|
563
|
+
7 Managing Your Personal Information\r
|
|
564
|
+
\r
|
|
565
|
+
Huawei highly respects your concerns regarding personal information, and you are provided with the following data subject rights and options. If you have used the In-App Purchases services, you can refer to the privacy statement for the In-App Purchases services to learn how to manage your personal information.\r
|
|
566
|
+
\r
|
|
567
|
+
7.1 Access your information\r
|
|
568
|
+
\r
|
|
569
|
+
During your use of HUAWEI ID, you can access your HUAWEI ID, profile picture, nickname, and other personal information by going to Settings > HUAWEI ID.\r
|
|
570
|
+
\r
|
|
571
|
+
You can log in to Huawei Privacy Center (https://privacy.consumer.huawei.com/tool?lang=en-us) using your HUAWEI ID to obtain a copy of your data. To ensure your data security, we need to verify your identity when you request a copy of your data.\r
|
|
572
|
+
\r
|
|
573
|
+
If you use Cloud, you can access your Cloud data by going to Settings > HUAWEI ID > Cloud or logging in to the Cloud website (cloud.huawei.com).\r
|
|
574
|
+
\r
|
|
575
|
+
If you use Find Service, you can access your Find Service data by going to Settings > HUAWEI ID > Find Device or logging in to the Cloud website (cloud.huawei.com).\r
|
|
576
|
+
\r
|
|
577
|
+
How you can manage your information differs on different devices or in different versions because the services provided there are different.\r
|
|
578
|
+
\r
|
|
579
|
+
7.2 Rectify your information\r
|
|
580
|
+
\r
|
|
581
|
+
You can access and modify your profile picture, nickname, and other personal information by going to Settings > HUAWEI ID.\r
|
|
582
|
+
\r
|
|
583
|
+
You can manage the name of the current device by going to Settings > About , or Settings > NearLink & Bluetooth , or Settings > Mobile network > Personal hotspot.\r
|
|
584
|
+
\r
|
|
585
|
+
You can enable or disable advanced protection for your account by going to Settings > HUAWEI ID > Account security > Advanced account protection.\r
|
|
586
|
+
\r
|
|
587
|
+
You can enable or disable enhanced verification for instant login with your account by going to Settings > HUAWEI ID > Account security > Instant login verification.\r
|
|
588
|
+
\r
|
|
589
|
+
How you can manage your information differs on different devices or in different versions because the services provided there are different.\r
|
|
590
|
+
\r
|
|
591
|
+
7.3 Delete your information\r
|
|
592
|
+
\r
|
|
593
|
+
You can erase your real-name authentication information by going to Settings > HUAWEI ID > Personal info > Real-name authentication.\r
|
|
594
|
+
\r
|
|
595
|
+
You can erase your address information by going to Settings > HUAWEI ID > Personal info > My addresses.\r
|
|
596
|
+
\r
|
|
597
|
+
You can erase the account security information you have added, such as emergency contacts and security mobile number, by going to Settings > HUAWEI ID > Account security.\r
|
|
598
|
+
\r
|
|
599
|
+
You can view or delete your Cloud data by going to Settings > HUAWEI ID > Cloud or logging in to the Cloud website (cloud.huawei.com).\r
|
|
600
|
+
\r
|
|
601
|
+
If you use Find Service, you can view or delete your Find Service data by going to Settings > HUAWEI ID > Find Device or logging in to the Cloud website (cloud.huawei.com).\r
|
|
602
|
+
\r
|
|
603
|
+
How you can manage your information differs on different devices or in different versions because the services provided there are different.\r
|
|
604
|
+
\r
|
|
605
|
+
7.4 Withdraw your consent\r
|
|
606
|
+
\r
|
|
607
|
+
You can control access to your account and the receiving of subscription notifications by logging in to Huawei Privacy Center (https://privacy.consumer.huawei.com/tool?lang=en-us) using your HUAWEI ID in a browser on your computer or mobile device and then clicking or touching Control account access.\r
|
|
608
|
+
\r
|
|
609
|
+
You can also control access to your account by going to Settings > HUAWEI ID > Account security > Apps using my HUAWEI ID.\r
|
|
610
|
+
\r
|
|
611
|
+
You can withdraw your consent for address information by going to Settings > HUAWEI ID > Personal info > My addresses , touching the info icon in the upper right corner of the My addresses screen, and selecting Withdraw consent from the information displayed.\r
|
|
612
|
+
\r
|
|
613
|
+
You can control whether to have your data uploaded to Cloud by going to Settings > HUAWEI ID > Cloud and turning on or off the switches for the features or data elements concerned.\r
|
|
614
|
+
\r
|
|
615
|
+
You can disable Find Service at any time by going to Settings > HUAWEI ID > Find Device and disabling Find My Phone / Find My Tablet.\r
|
|
616
|
+
\r
|
|
617
|
+
How you can manage your information differs on different devices or in different versions because the services provided there are different.\r
|
|
618
|
+
\r
|
|
619
|
+
7.5 Disable service\r
|
|
620
|
+
\r
|
|
621
|
+
You can go to Settings > HUAWEI ID > Account security > Security center to delete your account. If you delete your HUAWEI ID, your personal information in all the linked Huawei apps you use will be permanently deleted and cannot be restored. Exercise caution when performing this operation.\r
|
|
622
|
+
\r
|
|
623
|
+
How you can manage your information differs on different devices or in different versions because the services provided there are different.\r
|
|
624
|
+
\r
|
|
625
|
+
If you have any further requests, questions, comments, or suggestions regarding your rights as a data subject, please contact us using the contact information provided under the "Contacting Us" ( #EN-US_TOPIC_0000002364447914 ) section of this Statement.\r
|
|
626
|
+
\r
|
|
627
|
+
8 Information Storage Location and Retention Period\r
|
|
628
|
+
\r
|
|
629
|
+
8.1 Storage location\r
|
|
630
|
+
\r
|
|
631
|
+
The aforementioned will be sent to and stored on servers in the People's Republic of China (Beijing Municipality and Guiyang City of Guizhou Province).\r
|
|
632
|
+
\r
|
|
633
|
+
We will transfer your personal information outside the borders only with your consent or on other lawful bases for processing.\r
|
|
634
|
+
\r
|
|
635
|
+
(1) Due to the need for worldwide account login, when you log in to your HUAWEI ID (registered for China) in a different location, the Huawei affiliate responsible for operations in the different location will forward your account information (HUAWEI ID information, mobile number, and email address) outside the borders to the account server in China for authentication. In this case, no servers outside the borders will retain your account information.\r
|
|
636
|
+
\r
|
|
637
|
+
(2) To ensure that you can continue to log in to the current HUAWEI ID and use Huawei apps with it after switching to a service location outside the borders, we will provide your account information (HUAWEI ID information, mobile number, and email address) to the Huawei affiliate responsible for service operations in that service region after you agree to switch to that service location. Depending on the foreign country or region you select, the aforementioned information will be processed on the servers deployed in the EU, Singapore, or Russia by relevant Huawei affiliates.\r
|
|
638
|
+
\r
|
|
639
|
+
We will take necessary technical and administrative measures in accordance with laws, regulations, and regulatory requirements to ensure that the recipients outside the borders have sufficient data security capabilities to protect your personal information. If you want to further learn about how Huawei affiliates process your data or to exercise your rights in relation thereto, you can visit the Privacy Questions (https://consumer.huawei.com/en/legal/privacy-questions/) page to contact Huawei.\r
|
|
640
|
+
\r
|
|
641
|
+
8.2 Retention period\r
|
|
642
|
+
\r
|
|
643
|
+
We will retain your personal information for the period necessary to fulfill the purposes described in this Statement, and delete or anonymize your personal information beyond the time set out below, except as otherwise required by applicable laws and regulations.\r
|
|
644
|
+
\r
|
|
645
|
+
After you delete your HUAWEI ID, we will delete all personal information linked with your account, including basic personal information, app usage information, and your backup content. The specific retention time of your personal information is set out below:\r
|
|
646
|
+
\r
|
|
647
|
+
Cloud\r
|
|
648
|
+
\r
|
|
649
|
+
Data copies for you to restore contacts data using the Time Machine feature of the Cloud website will be retained for up to thirty (30) days, or will be immediately deleted after you delete your account.\r
|
|
650
|
+
\r
|
|
651
|
+
Your order information related to your Cloud storage plan purchases will be retained for seven (7) years.\r
|
|
652
|
+
\r
|
|
653
|
+
Data collected from you when you use the marketing notifications feature will be retained for up to fourteen (14) days, or will be immediately deleted after your HUAWEI ID is deleted.\r
|
|
654
|
+
\r
|
|
655
|
+
Find Service\r
|
|
656
|
+
\r
|
|
657
|
+
Your device's location information obtained by Find Service will be retained for up to one hundred and eighty (180) days and will be immediately deleted when you turn off the Find My Phone / Find My Tablet switch. A lost device's mobile number, network status information, and remaining battery level displayed in Find Device will be retained for up to one hundred and eighty (180) days. If you request to unlock the device when you forgot the password, the device verification code delivered to your device will be deleted immediately after you disable the Find Device feature.\r
|
|
658
|
+
\r
|
|
659
|
+
Offline location information obtained by Find Network will be retained for up to one hundred and eighty (180) days, or will be deleted immediately after your account is deleted or after you disable the Find Network feature.\r
|
|
660
|
+
\r
|
|
661
|
+
A device's track information, lock screen information, contact information, and screen lock will be retained for up to twenty-four (24) hours after the device gets offline. Such saved track information, lock screen information, contact information, and screen lock will all be automatically cleared when you disable Lost mode.\r
|
|
662
|
+
\r
|
|
663
|
+
In-App Purchases\r
|
|
664
|
+
\r
|
|
665
|
+
We retain personal information only for as long as necessary to fulfill the purposes for which it was collected and in accordance with legal or regulatory requirements. For details about how In-App Purchases retains your personal information, please refer to the Statement About Huawei In-App Purchases and Privacy (https://legal.cloud.huawei.com.cn/terms/scope/huawei/iap-hmos/privacy-statement.htm?code=cn&language=en_us).\r
|
|
666
|
+
\r
|
|
667
|
+
Information in your address management section will be retained indefinitely until you delete such information or delete your account.\r
|
|
668
|
+
\r
|
|
669
|
+
Data collected from you when you use the Help feature will be retained for up to two (2) years, or will be immediately deleted after your HUAWEI ID is deleted.\r
|
|
670
|
+
\r
|
|
671
|
+
Data collected from you when you use the Feedback feature will be retained for up to two (2) years, or will be immediately deleted after your HUAWEI ID is deleted.\r
|
|
672
|
+
\r
|
|
673
|
+
Information used for product O&M will be retained for up to five (5) years.\r
|
|
674
|
+
\r
|
|
675
|
+
Personal data processed for customer relationship management such as data subject requests, complaints, and customer interaction records will be retained for up to six (6) years from the last interaction.\r
|
|
676
|
+
\r
|
|
677
|
+
We will delete or anonymize your personal information beyond the time set out above, except as otherwise required by applicable laws and regulations.\r
|
|
678
|
+
\r
|
|
679
|
+
In the event that we discontinue our products or services, we will notify you in the form of a push notification, announcement, or by other means, and delete or anonymize your personal information within a reasonable period of time.\r
|
|
680
|
+
\r
|
|
681
|
+
9 Contacting Us\r
|
|
682
|
+
\r
|
|
683
|
+
We have appointed the person responsible for personal information protection who you can contact from here (https://consumer.huawei.com/en/legal/privacy-questions/). You may also contact us by visiting the Privacy Questions (https://consumer.huawei.com/en/legal/privacy-questions/) page. We will reply as soon as possible.\r
|
|
684
|
+
\r
|
|
685
|
+
If you are not satisfied with the response you receive, especially if you feel that our processing or handling of your personal information has violated or infringed on your legal rights and/or interests, you may seek external resolution, whether by filing a lawsuit with the people's court in the relevant jurisdiction, submitting a complaint to the industry self-regulation association or relevant government regulatory agencies, or by other means. You may also consult us regarding the available channels for voicing your complaint.\r
|
|
686
|
+
\r
|
|
687
|
+
Huawei's collection and use of your personal information is governed by our privacy policy. For more information, please refer to the Huawei Consumer Business Privacy Statement (https://legal.cloud.huawei.com/legal/privacy/statement.htm?country=CN&language=en_US).\r
|
|
688
|
+
\r
|
|
689
|
+
\r
|
|
690
|
+
3/4:\r
|
|
691
|
+
---------------------------------------\r
|
|
692
|
+
Statement About HarmonyOS and Privacy\r
|
|
693
|
+
\r
|
|
694
|
+
Last updated: July 15, 2025\r
|
|
695
|
+
\r
|
|
696
|
+
HarmonyOS is a next-generation operating system for smart devices, providing a unified language for enabling intelligence, interconnection, and collaboration across different devices. It gives a neat, smooth, seamless, secure, and reliable interaction experience in all scenarios. HarmonyOS and related system services (hereinafter referred to as the "Services") are provided for you by Huawei Device Co., Ltd. (hereinafter referred to as "Huawei", "we", "us", or "our"), which is registered at No. 2 Xincheng Road, Songshan Lake Zone, Dongguan, Guangdong.\r
|
|
697
|
+
\r
|
|
698
|
+
Huawei takes your personal information and privacy seriously, and is committed to taking appropriate security measures to protect your personal information in accordance with relevant laws and established industry security standards. We have specially formulated this Statement to help you learn about how the Services collect, use, disclose, protect, store, and transmit your personal information. Please read this Statement carefully.\r
|
|
699
|
+
\r
|
|
700
|
+
In addition to the Services, HarmonyOS enables you to access and use Huawei or third-party apps and services that are pre-installed or downloaded by you. For information such as that about how these apps and services process your personal information, please refer to their privacy statements.\r
|
|
701
|
+
\r
|
|
702
|
+
1 How We Collect and Use Your Personal Information\r
|
|
703
|
+
\r
|
|
704
|
+
We will provide you with the system services described below based on HarmonyOS. We will process information required for providing the features/services as described below when you use them. If you do not provide the related information, your use of the Services may be affected.\r
|
|
705
|
+
\r
|
|
706
|
+
1.1 Software update services\r
|
|
707
|
+
\r
|
|
708
|
+
Software update services are basic services for updating the system on your device. During use, the services need to connect to the Internet to check for and download updates as well as to perform business operation and maintenance analysis, thereby providing the system and custom service update services.\r
|
|
709
|
+
\r
|
|
710
|
+
(1) System ROM updates\r
|
|
711
|
+
\r
|
|
712
|
+
To update your system and parameters (including the time zone and device parameters) in a timely manner for improving our products (or services), we need to collect your following information: device identifiers (including SN and SOCID), device model, system settings, operating system, system configuration information, system properties, battery level information, IP address, and WLAN information (Wi-Fi status). Among the information, the WLAN information (Wi-Fi status) will only be processed locally and will not be uploaded to any Huawei server.\r
|
|
713
|
+
\r
|
|
714
|
+
We will use your personal information in the following ways: The aforementioned information you provide will be used to find and push suitable ROM versions for your device. To address potential risks in the system, the latest version will be downloaded and then used for an automatic update with your consent or when required to fix urgent system security loopholes.\r
|
|
715
|
+
\r
|
|
716
|
+
(2) Custom service updates\r
|
|
717
|
+
\r
|
|
718
|
+
To update custom services, we need to collect your device identifier (SN), device model, and operating system information, thereby providing custom service updates that match your device. We will not store your personal information on the cloud.\r
|
|
719
|
+
\r
|
|
720
|
+
(3) Business operation and maintenance analysis\r
|
|
721
|
+
\r
|
|
722
|
+
To improve your update experience, we need to collect your following information: device identifiers (including SN), device model, system settings, operating system, system configuration information, system properties, battery level information, IP address, and WLAN information (Wi-Fi status). A device analysis report will be generated for business operation and service analysis and improvement. Information in the report is statistically aggregated and cannot be used to identify you.\r
|
|
723
|
+
\r
|
|
724
|
+
1.2 Message pushing services\r
|
|
725
|
+
\r
|
|
726
|
+
Message pushing services enable us and other app developers to send push messages to your device. To ensure the delivery of messages, we need to establish a secure and reliable message sending channel between your device and the push server. During your use of an app or service, we will collect and use your following information and upload the information to the Huawei server: network information, device model, device identifier, system settings, operating system, device hardware information, device status and running records, WLAN information (Wi-Fi status), and basic app information. To locate app problems and improve services, we will collect and use your following information for product O&M during your app or service use: network information, device model, device identifier, system settings, operating system, device hardware information, device status and running records, WLAN information (Wi-Fi status), and basic app information.\r
|
|
727
|
+
\r
|
|
728
|
+
1.3 System-level web services\r
|
|
729
|
+
\r
|
|
730
|
+
System-level web services provide you with basic features related to web browsing. The services need to connect to the Internet. During your use of the services, relevant configuration data will be downloaded based on the enabled features. Malicious website blocking is enabled by default, and your web browsing records will be uploaded in anonymized and encrypted form to identify and block malicious websites when you browse web pages. Once the identification is complete, the data will be deleted and will not be stored. You can also manage the malicious website blocking scope by going to system Settings > Privacy & security.\r
|
|
731
|
+
\r
|
|
732
|
+
1.4 Finding services\r
|
|
733
|
+
\r
|
|
734
|
+
Finding services are provided for you to protect your device's security. In case your device is lost or subject to unauthorized use or unexpected restoration to factory settings, the finding services will provide the Activation lock feature to secure your device. To prevent others from activating your device without your permission and increase your chances of getting your device back, the finding services need to connect to the Internet and collect and use your HUAWEI ID information, device identifier (SN and SOCID), and information about your use of the services. We will not store your personal information on the cloud.\r
|
|
735
|
+
\r
|
|
736
|
+
1.5 Digital rights management services\r
|
|
737
|
+
\r
|
|
738
|
+
Digital rights management (DRM) services provide secure data encryption and decryption to furnish copyright protection for digital assets on your device. The services require an Internet connection and need to collect and use your device name, device model, SOCID, and operating system version to issue DRM certificates and perform copyright protection.\r
|
|
739
|
+
\r
|
|
740
|
+
1.6 Basic AppGallery services\r
|
|
741
|
+
\r
|
|
742
|
+
Basic AppGallery services provide download, installation, and management features based on apps and lite services. During use, the services require an Internet connection. In addition, they need to read the WLAN information (Wi-Fi status and Wi-Fi parameters) to provide features such as app and lite services download and network notification, and read and transmit your list of installed apps to provide features such as security check and risk alerts, unified privacy pop-up information, on-demand app and lite services loading, and malicious redirection control. This ensures secure app and lite services download and use, and prevents fraud and other malicious activities. Among the information, your list of installed apps will not be stored on the cloud.\r
|
|
743
|
+
\r
|
|
744
|
+
1.7 System storage services\r
|
|
745
|
+
\r
|
|
746
|
+
System storage services include calendar storage services and contacts storage services. Calendar storage services provide basic capabilities such as calendar event storage, access, and reminder notification. During use, the services need to read the calendar event data to record and save event reminders so that they can be made available to apps. Contacts storage services provide basic capabilities such as storing and accessing contacts and call logs. During use, the services need to read and modify the contacts and call log data for managing the contacts and call logs.\r
|
|
747
|
+
\r
|
|
748
|
+
1.8 Auto-discovery services\r
|
|
749
|
+
\r
|
|
750
|
+
Auto-discovery services provide the capability to automatically discover supported devices nearby and prompt you to complete the connection and authentication process. During use, the services require an Internet connection, need to use Bluetooth and NFC, and need to read and transmit the Bluetooth MAC address, WLAN MAC address, and NFC tag information for the purposes of near-field device discovery, authentication, and connection.\r
|
|
751
|
+
\r
|
|
752
|
+
1.9 Common security services\r
|
|
753
|
+
\r
|
|
754
|
+
Common security services provide basic security capabilities for your device, such as security check and management, device certificate management, device authentication credential management, and encrypted data sharing. During the use of the services, security check and management need to connect to the Internet and read and transmit the device identifier, HUAWEI ID information, and list of installed apps to perform device security check and obtain applicable security protection policies. Device certificate management needs to connect to the Internet and read and transmit the device identifier to apply for and update the device certificates, thereby providing device identity authentication services based on the device certificates. Device authentication credential management needs to connect to the Internet and read and transmit the HUAWEI ID information, device identifier, device model, and system username to apply for and update the authentication credentials. In this way, we can provide protection for cross-device data transmission based on the authentication credentials, and provide the feature to complete verification using security verification codes when you log in to your HUAWEI ID or when you use services such as those for locating devices that are offline. Encrypted data sharing needs to connect to the Internet, read and transmit the HUAWEI ID information and device identifier for applying for data protection credentials, and use the phone number or email address you submit to query the corresponding HUAWEI ID (account UID, profile picture, and nickname), thereby providing the HUAWEI ID-based feature to share data with encryption security. Data encryption & recovery needs to connect to the Internet and read and transmit the password, HUAWEI ID information, device identifier, device hardware information (including device model), and personalized device settings. Such information will be used to identify your data and provide identifier-based data storage capabilities, thereby helping recover data when the device hardware is faulty. In addition, it is necessary to read the nickname, profile picture, and HUAWEI ID information to display information about your currently linked and logged-in HUAWEI ID. Data encryption & recovery will be enabled by default. If your device and HUAWEI ID meet the requirements, you will be able to use your HUAWEI ID to assist in data recovery.\r
|
|
755
|
+
\r
|
|
756
|
+
1.10 Smart Diagnosis Basic Services\r
|
|
757
|
+
\r
|
|
758
|
+
Smart Diagnosis Basic Services provide the device fault detection feature, and can alert you to send your device for repair in a timely manner when serious problems such as memory aging and mainboard errors occur on your device. Smart Diagnosis services require an Internet connection to update the fault diagnosis logic, and need to collect your device identifier (SN) to provide you with timely maintenance services as well the operation analysis services.\r
|
|
759
|
+
\r
|
|
760
|
+
1.11 Super Device services\r
|
|
761
|
+
\r
|
|
762
|
+
Super Device services support display of and quick collaboration between trusted devices. During use, the services and their underlying services need to do the following for the purposes of automatically discovering, authenticating, and connecting trusted devices and enabling collaboration across the devices: connect to the Internet, enable Bluetooth and WLAN, and read and transmit information about this device and the trusted devices (including Bluetooth and WLAN MAC addresses, device identifiers, device names, and device types), network information (whether WLAN is connected), and account information (nickname and login status). This data is only used locally on trusted devices and will not be uploaded to any server. You can use distributed collaboration services such as Multi-Screen Collaboration, wireless projection, and audio projection. For example, when you use the Multi-Screen Collaboration feature in the services, the feature needs to use the Bluetooth and WLAN features and read and transmit the Bluetooth MAC address, in order to allow you to view and operate your phone and sync clipboard data on your tablet and PC. When you select a Vision device and use the wireless projection feature in the services, the feature needs to use the system's screen recording capability to project the screen contents and system sounds from this device to the Vision. When you use the audio projection feature in the services, which allows you to cast audio from this device to a paired audio device, the feature needs to obtain information about the audio device (including Bluetooth MAC address, device type, and device name) to transfer audio across the devices in real time.\r
|
|
763
|
+
\r
|
|
764
|
+
1.12 Fusion Search Service\r
|
|
765
|
+
\r
|
|
766
|
+
Fusion Search Service is a basic data indexing service of the system, which provides data search interfaces for apps such as Celia, Celia Search, and Gallery to enable efficient and accurate searches. During use, this service requires an Internet connection (for experience improvement, wherein your personal information will not be collected), and needs to read the list of installed apps, media data (such as photos, videos, and audio), file data, contacts, and calendar event data to provide local data search services for related apps.\r
|
|
767
|
+
\r
|
|
768
|
+
1.13 Basic HarmonyOS Connect services\r
|
|
769
|
+
\r
|
|
770
|
+
Basic HarmonyOS Connect services provide upper-layer apps with APIs for device discovery, network configuration, registration and addition, and control and management. Information involved in the APIs includes the HUAWEI ID information, device information (including device hardware information, device identifier (including SN), MAC address, and device name), and personalized device settings (including IoT smart device service parameters). The aforementioned information will only be collected when the upper-layer apps use the APIs provided by the services. For details about the collection scenarios, please refer to the descriptions provided by the upper-layer apps. During use, the services need to connect to the Internet and use Bluetooth, NearLink (supported only by some devices), and WLAN.\r
|
|
771
|
+
\r
|
|
772
|
+
1.14 Picker services\r
|
|
773
|
+
\r
|
|
774
|
+
Picker services are system component capabilities we provide for developers and users. If an app that has integrated the picker services requests access to any sensitive data stored in the system (including media data, contacts, file data, and location information) or any sensitive system components (including camera and microphone), the operating system will provide an interface to directly interact with the user, thereby restricting direct access by the app. In this way, user privacy can be better protected while the related app functionality is maintained.\r
|
|
775
|
+
\r
|
|
776
|
+
To provide the aforementioned feature, the picker services need to do the following: locally read the media data (images, videos, and audio), contacts, and file data, in order to display sensitive data to the user and allow the user to select sensitive data that can be accessed by the app; or enable the camera or microphone, in order to allow the user to easily access features such as taking photos, recording videos, or scanning cards or documents. Particularly, in the case of accessing file data, the file picker service will locally read the list of installed apps to display the file processing capabilities (such as format conversion, compression, and encryption) that file processing apps provide for the user.\r
|
|
777
|
+
\r
|
|
778
|
+
The map picker service provides features such as viewing place details and selecting places. During use, this service requires an Internet connection and needs to collect and use your location information, in order to provide the ability to view locations and select places on the map. We will not store your personal information on the cloud.\r
|
|
779
|
+
\r
|
|
780
|
+
1.15 Basic system analysis services\r
|
|
781
|
+
\r
|
|
782
|
+
Basic system analysis services provide the capabilities to measure system running and interface calling, to ensure long-term stable running of the device. During use, the services need to connect to the Internet and collect the random device identifier, system settings, system properties, device model, MAC address, WLAN information (Wi-Fi connection status, Wi-Fi parameters, and Wi-Fi list), Bluetooth device list, motion status, approximate location information, operating system information, network information, running records, basic app information, app running status, and interface calling information, which will be used for product operation and user experience improvement.\r
|
|
783
|
+
\r
|
|
784
|
+
1.16 Lite service framework\r
|
|
785
|
+
\r
|
|
786
|
+
The atomic service framework provides atomic services with features such as unified service panel, recents and favorites records, and service notifications and updates. During use, the services need to connect to the Internet. We need to collect and use your HUAWEI ID information, device identifier, device model, device hardware information, network information, application usage information, application settings information, system properties, and list of installed apps to provide features for service assurance, such as service usage records and order status notifications, thereby ensuring security and reliability during the service usage and transaction processes. Among the information, the list of installed apps will not be stored on the cloud.\r
|
|
787
|
+
\r
|
|
788
|
+
1.17 Device activation services\r
|
|
789
|
+
\r
|
|
790
|
+
During use, the services require an Internet connection, and the device identifiers (including SN), approximate location information, device model, and operating system information need to be read and transmitted, to identify and activate the device and generate benefit information, thereby protecting your benefits.\r
|
|
791
|
+
\r
|
|
792
|
+
1.18 Pre-installed app management services\r
|
|
793
|
+
\r
|
|
794
|
+
Pre-installed app management services enable the installation, uninstallation, and restoration of pre-installed apps. During use, the services require Internet access, and need to collect your device identifier and device model and upload them to the Huawei server for policy configuration for the pre-installed apps.\r
|
|
795
|
+
\r
|
|
796
|
+
1.19 Authentication proxy services\r
|
|
797
|
+
\r
|
|
798
|
+
Authentication proxy services provide capabilities such as HUAWEI ID authentication proxy and app identity legitimacy verification proxy, improving performance, experience, and reliability in authentication scenarios. During use, the services need to connect to the Internet, read the list of installed apps, and collect and use your HUAWEI ID information and device identifier to verify the legitimacy of your account and your apps' identities in advance. Among the information, the list of installed apps will only be processed locally and will not be uploaded to any Huawei server.\r
|
|
799
|
+
\r
|
|
800
|
+
1.20 License management services\r
|
|
801
|
+
\r
|
|
802
|
+
During use, the services need to connect to the Internet to update the license file. We need to collect your device identifier (SN) and operating system information, and update the license file for the device based on the aforementioned information, in order to activate related licensed features. We will not store your personal information on the cloud.\r
|
|
803
|
+
\r
|
|
804
|
+
2 Protection of Minors\r
|
|
805
|
+
\r
|
|
806
|
+
We attach great importance to the protection of minors' personal information. Huawei will provide services and protection for minors in strict accordance with national laws and regulations. If you are a minor, your parents or legal guardians must agree to your use of the Services, and agree to the applicable terms and conditions. Parents or legal guardians should also take appropriate precautions to protect minors, including monitoring their use of the Services.\r
|
|
807
|
+
\r
|
|
808
|
+
In particular, if you are a child (a minor under the age of 14), please make sure to notify your parents or legal guardians about carefully reading with you this Statement and the Huawei Consumer Business Statement About Children's Privacy Protection (https://legal.cloud.huawei.com/legal/child/privacy-statement.htm?code=CN&language=en-US) specifically formulated by us before you use our services, and use our services or provide information to us with the consent and guidance of your parents or legal guardians. If you are a parent or legal guardian, please ensure that the child under your guardianship uses our services and provides us with information with your consent or guidance.\r
|
|
809
|
+
\r
|
|
810
|
+
3 Entrusted Processing and Sharing of Information\r
|
|
811
|
+
\r
|
|
812
|
+
3.1 Entrusted processing\r
|
|
813
|
+
\r
|
|
814
|
+
In some service scenarios, we will entrust other companies to process your personal information on our behalf, for example, companies that handle hotline calls, send emails, or provide technical support on behalf of Huawei. Such companies can only use your personal information for the purposes of providing services to you on behalf of Huawei. Huawei will enter into strict entrusted processing agreements or personal information processing terms with the entrusted party. The entrusted party is obligated to process related personal information in accordance with this Statement and our instructions and to take relevant confidentiality and security measures to ensure personal information security.\r
|
|
815
|
+
\r
|
|
816
|
+
3.2 Sharing with third parties\r
|
|
817
|
+
\r
|
|
818
|
+
Currently, the Services do not involve sharing personal information with third parties.\r
|
|
819
|
+
\r
|
|
820
|
+
4 Managing Your Personal Information\r
|
|
821
|
+
\r
|
|
822
|
+
Huawei highly respects your concerns regarding personal information. You can submit to us requests to exercise your rights as a personal information subject, such as those to access, rectify, copy, or delete your personal information, through the official website of Huawei Consumer BG, the My HUAWEI app, or the privacy center based on HUAWEI ID.\r
|
|
823
|
+
\r
|
|
824
|
+
If you submit a request through any other channels, such as hotline, service email address, online customer service, and service center, we will guide you to submit a formal request through the aforementioned channels to facilitate communication and feedback on the handling progress and result. Huawei maintains a dedicated request channel for personal information subjects, which serves to protect legitimate interests of personal information subjects, safeguard Huawei's normal operations, and prevent unauthorized or abusive use of the request rights in relation to personal information.\r
|
|
825
|
+
\r
|
|
826
|
+
We will make every effort to ensure that a response is made within one month after a personal information subject's access request is submitted. Given the complexity and volume of requests, this timeframe may be appropriately extended when necessary. If the provision of information is delayed, we will notify the personal information subject of the situation and the reasons for the delay.\r
|
|
827
|
+
\r
|
|
828
|
+
If you have any further requests, questions, comments, or suggestions regarding your rights as a data subject, please contact us using the contact information provided under the "Contacting Us" section of this Statement.\r
|
|
829
|
+
\r
|
|
830
|
+
5 Information Storage Location and Retention Period\r
|
|
831
|
+
\r
|
|
832
|
+
5.1 Storage location\r
|
|
833
|
+
\r
|
|
834
|
+
The aforementioned information will be sent to and stored on servers in the People's Republic of China.\r
|
|
835
|
+
\r
|
|
836
|
+
5.2 Retention period\r
|
|
837
|
+
\r
|
|
838
|
+
During the provision of the Services, we will process your personal information on your device wherever possible. We will retain your personal information we collect only for the period necessary to fulfill the purposes described in this Statement, and delete or anonymize your personal information beyond the retention period, except as otherwise stipulated by applicable laws and regulations.\r
|
|
839
|
+
\r
|
|
840
|
+
In the software update services, personal information collected for system ROM updates will be retained for six (6) months, and personal information for business operation and maintenance analysis will be retained for five (5) years.\r
|
|
841
|
+
\r
|
|
842
|
+
Among information collected in the message pushing services: information used for product O&M will be retained on the server for up to five (5) years; while other personal information will be retained on our server for up to one (1) year.\r
|
|
843
|
+
\r
|
|
844
|
+
DRM certificates in the DRM services will remain valid for the lifecycle of your device and will be retained for ten (10) years together with the device information.\r
|
|
845
|
+
\r
|
|
846
|
+
Personal information collected in the common security services will be retained for up to three (3) years. Among such information, personal information collected by the device authentication credential management services, data encryption & recovery services, and encrypted data sharing services will be deleted immediately after you delete your HUAWEI ID.\r
|
|
847
|
+
\r
|
|
848
|
+
Personal information collected in the Smart Diagnosis Basic Services will be retained for two (2) years.\r
|
|
849
|
+
\r
|
|
850
|
+
Information collected by the basic system analysis services will be retained for five (5) years.\r
|
|
851
|
+
\r
|
|
852
|
+
Personal information collected by the atomic service framework will be deleted immediately after you delete your HUAWEI ID.\r
|
|
853
|
+
\r
|
|
854
|
+
Personal information collected by the device activation services will be retained for seven (7) years.\r
|
|
855
|
+
\r
|
|
856
|
+
Personal information collected in the pre-installed app management services will be retained for six (6) months.\r
|
|
857
|
+
\r
|
|
858
|
+
Personal information collected by the authentication proxy services will be retained for two (2) years.\r
|
|
859
|
+
\r
|
|
860
|
+
In the event that we discontinue our products or services, we will notify you in the form of a push notification, announcement, or by other means, and delete or anonymize your personal information within a reasonable period of time.\r
|
|
861
|
+
\r
|
|
862
|
+
6 Contacting Us\r
|
|
863
|
+
\r
|
|
864
|
+
We have appointed the person responsible for personal information protection who you can contact from here (https://consumer.huawei.com/en/legal/privacy-questions/). You may also contact us by visiting the Privacy Questions page (https://consumer.huawei.com/en/legal/privacy-questions/). We will reply as soon as possible.\r
|
|
865
|
+
\r
|
|
866
|
+
If you are not satisfied with the response you receive, especially if you feel that our processing or handling of your personal information has violated or infringed on your legal rights and/or interests, you may seek external resolution, whether by filing a lawsuit with the people's court in the relevant jurisdiction, submitting a complaint to the industry self-regulation association or relevant government regulatory agencies, or by other means. You may also consult us regarding the available channels for voicing your complaint. Huawei's collection and use of your personal information is governed by our privacy policy. For more information, please refer to the Huawei Consumer Business Privacy Statement (https://legal.cloud.huawei.com/legal/privacy/statement.htm?country=CN&language=en_US).\r
|
|
867
|
+
\r
|
|
868
|
+
\r
|
|
869
|
+
4/4:\r
|
|
870
|
+
---------------------------------------\r
|
|
871
|
+
HarmonyOS Software License and Service Agreement\r
|
|
872
|
+
Last updated: July 30, 2024\r
|
|
873
|
+
\r
|
|
874
|
+
The HarmonyOS Software License and Service Agreement (hereinafter referred to as this "Agreement") is entered into and concluded by and between you (an individual, a company, or any other entity) and Huawei Device Co., Ltd. (hereinafter referred to as "Huawei", "we", "us", or "our") regarding the use of this Software (as defined in Section 2 herein) and its services. Before you use your Huawei wearable device or download any updates to this Software contemplated under this Agreement, please read this Agreement carefully, especially any clauses about exclusion or limitation of liability, governing laws, dispute resolution, and other important terms written in bold to draw your attention. This Agreement is applicable only to Huawei wearable devices (HUAWEI WATCH Series smart watches), including the corresponding industry edition devices. An industry edition device refers to a Huawei wearable device that can be paired with non-Huawei apps (hereinafter referred to as an "industry edition smart watch").\r
|
|
875
|
+
\r
|
|
876
|
+
Contents\r
|
|
877
|
+
\r
|
|
878
|
+
1 Acceptance of Our Terms\r
|
|
879
|
+
\r
|
|
880
|
+
2 About This Software\r
|
|
881
|
+
\r
|
|
882
|
+
3 Software License Grant\r
|
|
883
|
+
\r
|
|
884
|
+
4 Limitations of Use\r
|
|
885
|
+
\r
|
|
886
|
+
5 Software Updates\r
|
|
887
|
+
\r
|
|
888
|
+
6 Services of This Software\r
|
|
889
|
+
\r
|
|
890
|
+
7 Data Use and Privacy Protection\r
|
|
891
|
+
\r
|
|
892
|
+
8 Third-Party Software Statement\r
|
|
893
|
+
\r
|
|
894
|
+
9 Termination and Survival\r
|
|
895
|
+
\r
|
|
896
|
+
10 Disclaimers\r
|
|
897
|
+
\r
|
|
898
|
+
11 Limitation of Liability\r
|
|
899
|
+
\r
|
|
900
|
+
12 Technical Support\r
|
|
901
|
+
\r
|
|
902
|
+
13 Export Controls\r
|
|
903
|
+
\r
|
|
904
|
+
14 Contacting Huawei\r
|
|
905
|
+
\r
|
|
906
|
+
15 Dispute Resolution and Governing Laws\r
|
|
907
|
+
\r
|
|
908
|
+
16 Entire Agreement\r
|
|
909
|
+
\r
|
|
910
|
+
1 Acceptance of Our Terms\r
|
|
911
|
+
By using the Huawei wearable device or downloading updates to this Software, you indicate that you agree and accept to be bound by the terms of this Agreement.\r
|
|
912
|
+
\r
|
|
913
|
+
If you do not agree to this Agreement, please do not use this Huawei wearable device or download any updates to this Software. You can request a refund by returning the Huawei wearable device to the franchise store, authorized distributor, or retail store where you purchased the device, subject to the applicable return policy. However, you should be aware that, if you request a refund from a retail store, the store's own return policy may also apply. The return policy shall be governed by the relevant laws and regulations of the country/region where the goods are purchased.\r
|
|
914
|
+
\r
|
|
915
|
+
Currently, the Huawei wearable devices are not intended for use by children. If you have paired and connected such a wearable device to the Health app or another companion app using a child account, please stop using the device. If you attempt to pair and connect the wearable device with the Health app or another companion app using a child account, the pairing and connection will fail. If a child uses our services without logging in with a child account, we will be unable to implement the aforementioned restrictive protection measure. If a child is allowed to use this wearable device without a child account, such use shall be under sole supervision of the parent or guardian.\r
|
|
916
|
+
\r
|
|
917
|
+
If you are a minor, please read this Agreement with your parents or legal guardians to ensure that they clearly understand the content of this Agreement before you decide on whether to use this device or download updates to the Software. Please do not use this device or download updates to the Software before you have obtained consent from your parents or legal guardians. Some apps may not be available for use by minors, depending on the circumstances.\r
|
|
918
|
+
\r
|
|
919
|
+
You may visit the Huawei website (consumer.huawei.com) to view a copy of this Agreement at any time and retain a copy of this Agreement for future reference. If you have any questions regarding this Agreement, please contact us using the contact information provided in Section 14 "Contacting Huawei".\r
|
|
920
|
+
\r
|
|
921
|
+
2 About This Software\r
|
|
922
|
+
Software under this Agreement refers to:\r
|
|
923
|
+
\r
|
|
924
|
+
(1) Software components provided to you along with the Huawei wearable device, including but not limited to the code and other embedded software, documents, interfaces, content, and fonts that are stored on the Huawei wearable device, as well as any data protected by the copyright of Huawei or its licensors;\r
|
|
925
|
+
\r
|
|
926
|
+
(2) Updates or upgrades to the software specified in (1).\r
|
|
927
|
+
\r
|
|
928
|
+
You agree that this Agreement will apply to any Huawei software (including but not limited to operating systems, apps, and Feature Abilities) that may be installed on your wearable device, unless such software is accompanied by a separate software license agreement, in which case, you agree that the separate software license agreement will apply to your use of such software.\r
|
|
929
|
+
\r
|
|
930
|
+
This Software may also contain software components that are protected by copyright of third parties and granted open source software licenses by such third parties ("Open Source Software Components"). Such Open Source Software Components are identified as such through license information provided within the wearable device, which also indicates the open source software licenses applicable to such components. For this reason, the terms and conditions of the open source software licenses shall apply when you are using such Open Source Software Components. This Agreement does not alter any rights or obligations you may have under such open source software licenses. If there are any conflicts between the license conditions set forth in this Agreement and anything about any Open Source Software Components in their open source software licenses, such open source software licenses shall prevail.\r
|
|
931
|
+
\r
|
|
932
|
+
Unless otherwise agreed upon, this Software shall be bound by this Agreement, regardless of whether this Software is stored in a read-only memory or any other media or form, or is from any online download location authorized by Huawei.\r
|
|
933
|
+
\r
|
|
934
|
+
3 Software License Grant\r
|
|
935
|
+
You are granted a limited and non-exclusive license to use this Software on one Huawei wearable device, subject to and in accordance with this Agreement, and may not sell, transfer, or use it for any other commercial purposes.\r
|
|
936
|
+
\r
|
|
937
|
+
Huawei licenses this Software to you for use, rather than sells or transfers it to you. You shall only use this Software in conformity with the terms and conditions of this Agreement. Huawei and its licensors own and retain all rights and titles to the Software and reserve any other rights not expressly granted to you by this Agreement.\r
|
|
938
|
+
\r
|
|
939
|
+
4 Limitations of Use\r
|
|
940
|
+
4.1 You may not use Huawei's technologies or intellectual properties to develop software or design, develop, manufacture, sell, or license third-party devices/accessories associated with the Huawei wearable device without prior permission from Huawei.\r
|
|
941
|
+
\r
|
|
942
|
+
4.2 You may make a copy of this Software and save it on a computer hard drive or other storage media for the purpose of archiving. However, you may not distribute or make available this Software over a network where it could be used by multiple devices at the same time.\r
|
|
943
|
+
\r
|
|
944
|
+
4.3 You may not sell, rent, lease, lend, sublicense, or distribute the entirety or part of the Software (including but not limited to apps, services, code, and source code operated under this Software) to any third party without prior written permission from Huawei. You may make a one-off permanent transfer of the entire license to the Software to another party along with the transfer of ownership of your Huawei wearable device, provided that: (1) the transfer includes your Huawei wearable device and all the Huawei Software; (2) you do not retain copies of all or part of this Software; and (3) the party that receives the Huawei wearable device and this Software has read and accepted all the terms and conditions of this Agreement.\r
|
|
945
|
+
\r
|
|
946
|
+
4.4 You shall not allow any third party to copy, decompose, reverse engineer, decompile, disassemble, or create derivatives of this Software without prior written permission from Huawei. In addition, you shall not allow any third party to or attempt to export the source code of this Software, or decode or alter this Software or any part of this Software or any service that it provides.\r
|
|
947
|
+
\r
|
|
948
|
+
4.5 You acknowledge and agree that you shall not use this Software to carry out the following activities:\r
|
|
949
|
+
\r
|
|
950
|
+
Copy or use this Software beyond the authorized scope under this Agreement;\r
|
|
951
|
+
Use this Software in a deceptive manner or for a deceptive purpose;\r
|
|
952
|
+
Delete any copyright statement or notice contained in this Software;\r
|
|
953
|
+
Attempt to damage, bypass, change, invalidate, or evade any digital rights management (DRM) system that is related to this Software and/or is intrinsic to this Software;\r
|
|
954
|
+
Engage in any other improper or illegal acts.\r
|
|
955
|
+
4.6 While using this Software for storage or copying, you need to be authorized by relevant right holders in particular countries or regions. Huawei Software may only be used to reproduce non-copyrighted materials, materials for which you own the copyright, or materials you are authorized or legally permitted to reproduce. You understand that ownership and intellectual property rights of any material displayed, stored, or accessed via your device belong to the owner of the material. Such materials may be protected by copyright law or other intellectual property laws and treaties, and you may need to comply with the agreement or terms of use stipulated by the third party that provides such materials. Unless otherwise agreed upon, this Agreement does not grant you any right to use such materials, nor does it guarantee that you can continue to use them.\r
|
|
956
|
+
\r
|
|
957
|
+
4.7 You agree that you shall only use the Software in compliance with all applicable laws and regulations of your country or region of residence or use, including but not limited to the local laws of the country or region where you reside or download or use the Software and services.\r
|
|
958
|
+
\r
|
|
959
|
+
5 Software Updates\r
|
|
960
|
+
5.1 To provide you with a better user experience, Huawei may provide you with software update services, including but not limited to system software updates and app updates. We provide update services for this Software to improve the performance, safety, and reliability of products or wearable devices, or to meet functional customization requirements from carriers. Updates to this Software can be installed in different ways, and include bug fixes, system software updates, app updates, updates to any previously installed software (including all-new versions), and performance enhancements.\r
|
|
961
|
+
\r
|
|
962
|
+
5.2 Your Huawei wearable device will automatically search for and download update packages over the Internet to provide you with timely update services. These updates are designed to fix cyber security loopholes and prevent new security threats. You acknowledge the necessity of receiving and installing system security update patches in a timely manner. Due to the importance of these updates, your wearable device may automatically install some downloaded updates, and provide timely update notifications to help you understand the related information. We strongly recommend that you keep the default configurations of your wearable device to avoid software issues resulting from delayed updates. If you want to change the default settings for system software updates, you can go to Settings, touch the device name to enter the About screen, touch the system card to enter the Software update screen, touch Settings, and turn off the switches concerned. You also understand that some apps are provided with an automatic update feature and can automatically download and install updates to your device. Huawei apps will only be automatically updated over WLAN. You can disable this feature on the settings screen in the app concerned.\r
|
|
963
|
+
\r
|
|
964
|
+
5.3 Updates that Huawei provides to replace or supplement this Software shall be governed by this Agreement, unless such updates are accompanied by a separate software license agreement, in which case you will be governed by that separate software license agreement.\r
|
|
965
|
+
\r
|
|
966
|
+
5.4 You understand and acknowledge that if you decide not to install the software updates provided by Huawei, this may put your wearable device and Software at security risks and may cause the Software to be unavailable or unstable. Some features of the Software may be subject to version restrictions, and you need to update to the latest version to experience them.\r
|
|
967
|
+
\r
|
|
968
|
+
6 Services of This Software\r
|
|
969
|
+
6.1 This Software allows you to access such relevant apps and services of Huawei and its affiliates as well as third parties that come with this Software (collectively the "services" and individually a "service"), including but not limited to HarmonyOS and system-related services, Huawei Mobile Services, and third-party services and websites. The specific contents of the services are provided by the respective service providers according to the actual situation. Each of the service providers may change the services they provide at any time, and the provided service contents may vary from time to time.\r
|
|
970
|
+
\r
|
|
971
|
+
(1) HarmonyOS and system-related services: HarmonyOS is a next-generation operating system for smart devices, providing a unified language for enabling intelligence, interconnection, and collaboration across different devices. It gives a neat, smooth, seamless, secure, and reliable interaction experience in all scenarios. Based on HarmonyOS, Huawei and its affiliates will provide you with system-related services such as system settings, file management, security management, device communication, software updates, message pushing, wearable system services, and wearable collaboration services. After your device is paired with the (Huawei) Health app or another companion app on your phone, the wearable system services allow the app to display the device information and app information.\r
|
|
972
|
+
\r
|
|
973
|
+
(2) Huawei Mobile Services: This Software enables you to access and use such products, apps, and services provided by Huawei and its affiliates that are pre-installed by us or available for you to download and install, such as HUAWEI ID, AppGallery, HUAWEI Music, and HUAWEI Assistant. To use such services, you may be required to create and log in to your HUAWEI ID and agree to additional service agreements, and some services may also require you to pay additional fees. By creating your HUAWEI ID and using these services, you indicate that you agree to and accept the applicable terms & conditions.\r
|
|
974
|
+
\r
|
|
975
|
+
(3) Huawei Pay services: Such services are provided and operated by Petalpay (Shenzhen) Co., Ltd. You must agree to and accept the terms and conditions such as Huawei Pay Service Agreement before you can activate and use the Huawei Pay services.\r
|
|
976
|
+
\r
|
|
977
|
+
(4) Health & fitness apps & services include various apps and services provided by Huawei with a focus on promoting fitness and health for consumers. For example, the fitness apps may include Workout, Workout status, Activity records, Workout records, Barometer, and Stay Fit, and the health apps may include Heart rate, Sleep, Breathing exercises, Emotional wellbeing, SpO2, Blood pressure, Cycle Calendar, Health Clovers, Body temperature, Skin temperature, High altitude monitoring, ECG, Arterial stiffness detection, Pulse wave arrhythmia analysis, Health Glance, and Health summary. Your consent is required for the aforementioned fitness and health apps to obtain your fitness and health data from the underlying services, which will collect such data and store it locally. We will sync the fitness and health data to the (Huawei) Health app or another companion app on the phone paired with the wearable device. You can cancel the data sync by disabling Bluetooth on the wearable device. In addition, your fitness and health data will be synced to Health Service Kit on your watch. You can choose whether to authorize the data to be uploaded to the Huawei server by going to Settings > Privacy & security > Health Service Kit. However, some services are regional and may therefore not be available in all languages or in all areas. Features may vary by area, and some may be restricted or may not be provided by your service provider. In addition, certain features may be affected or restricted by the wearable device's hardware and data access and are not necessarily available on all wearable devices. You understand and agree that the availability on different wearable devices is not exactly the same, and what apps and services are available to you may vary depending on the wearable device and software you use. To ensure and improve your user experience, the aforementioned services will collect your fitness data such as workout route, workout type, workout duration, step count, and distance covered, as well as your health data such as sleep, heart rate, blood oxygen, and body temperature data.\r
|
|
978
|
+
\r
|
|
979
|
+
6.2 You understand and acknowledge that some of the aforementioned services are regional and therefore are not necessarily available in all languages or in all areas. Some features may vary by area, and some may be restricted or may not be provided by your service provider. Certain features of this Software may require Internet access. Unless your wearable device is connected to the Internet through WLAN, this Software will access the Internet using your mobile data and may incur additional costs as a result. For details, please contact your carrier. Some of the services may provide you with various kinds of information (including but not limited to stock information and location information). Huawei and its affiliates and licensors do not guarantee the availability, accuracy, integrity, reliability, or timeliness of such information. In addition, you understand and acknowledge that certain features of this Software may be affected or restricted by device hardware and data access and are not necessarily available on all devices.\r
|
|
980
|
+
\r
|
|
981
|
+
7 Data Use and Privacy Protection\r
|
|
982
|
+
7.1 We will provide you with relevant system services based on HarmonyOS. We will process information required for providing the features/services when you use them. If you do not provide the related information, your use of the features/services may be affected. For example, for the purpose of enabling us and third-party app developers to push messages to your wearable device, we need to collect your device information, network information, and app information to establish a secure and reliable messaging channel between your device and the push server. For details about how HarmonyOS and related basic system services process your personal information, please refer to the Statement About HarmonyOS and Privacy.\r
|
|
983
|
+
\r
|
|
984
|
+
7.2 If you use Huawei Mobile Services, Huawei Wallet Pay services, or other services or features provided by Huawei or its affiliates, you are likely to be presented with a special privacy statement or supplemental notice (hereinafter referred to as "Product-specific Privacy Notice") made available by the service provider in respect of the product or service. Please carefully read such Product-specific Privacy Notice, which will provide basic information such as how the service or feature processes your personal information, how you can exercise your data subject rights, who is the data controller, and how to contact the data controller.\r
|
|
985
|
+
\r
|
|
986
|
+
7.3 Huawei fully respects your privacy rights. In addition to each Product-specific Privacy Notice, we have specially formulated the Huawei Consumer Business Privacy Statement(https://legal.cloud.huawei.com.cn/terms/scope/huawei/privacy/statement.htm?code=CN&branchid=0&language=en-US&contenttag=default) to help you get information such as that about the overall situation of our personal information collection and use, as well as our measures for protecting personal information security. We will collect, use, disclose, protect, store, and transmit your personal information always in strict accordance with the Huawei Consumer Business Privacy Statement.\r
|
|
987
|
+
\r
|
|
988
|
+
8 Third-Party Software Statement\r
|
|
989
|
+
8.1 Your Huawei wearable device may include certain third-party apps or services ("third-party software"). Such third-party software may display, contain, or provide content, data, information, apps, or materials from third parties, or provide links to certain third-party websites. Huawei does not own such third-party software or its related intellectual property rights. Therefore, you understand and acknowledge that Huawei does not assume obligations to provide support for such third-party software, does not guarantee that such third-party software's content or services will stay available at any time, and is not liable for any content, ads, products, services, and other materials provided in such third-party software.\r
|
|
990
|
+
\r
|
|
991
|
+
8.2 You understand and acknowledge that names, logos, and content of third-party software will be loaded and displayed on your wearable device for your convenience, and such display does not constitute any endorsement, warranty, or recommendation by us of the third-party software. You further understand and acknowledge that when using third-party software, you may be subject to the terms of use and license agreement related to the third-party software. Therefore, your use of third-party software is at your own risk.\r
|
|
992
|
+
\r
|
|
993
|
+
8.3 Except as agreed between you and the provider of the third-party software, you agree not to modify, rent, lease, sub-license, distribute, or create derivative works based on the third-party software, and may not use the third-party software in any unauthorized manner, including but not limited to, using such software to transmit any type of computer virus, worm, Trojan, or other malicious software, invade a network, and overburden a network. You further agree not to use the third-party software in any manner that harasses, abuses, threatens, defames, or otherwise infringes upon the rights of any third party, and warrant that Huawei does not assume any liability for your such actions, or any harassing, threatening, defamatory, offensive, infringing, or illegal information or transmission that is incurred due to your use of the third-party software.\r
|
|
994
|
+
\r
|
|
995
|
+
9 Termination and Survival\r
|
|
996
|
+
9.1 This Agreement is effective from the first date you install this Software. If you want to terminate this Agreement, you shall permanently delete, destroy, and return, at your own cost, this Software, all backup copies, and all related materials provided by Huawei. If you fail to comply with any of the terms or conditions of this Agreement, Huawei or its licensors have the right to terminate this Agreement at any time without prior notice. Upon the termination, you must immediately stop using this Software and delete all the Software and related materials that have been copied to and/or installed on your Huawei wearable device.\r
|
|
997
|
+
\r
|
|
998
|
+
9.2 Sections 7, 9, 10, 11, 12, 13, 14, 15, and 16 herein shall survive the termination of this Agreement.\r
|
|
999
|
+
\r
|
|
1000
|
+
9.3 If a court of competent jurisdiction finds on any ground that any provision or any part of this Agreement shall be invalid, other provisions of this Agreement shall remain in force.\r
|
|
1001
|
+
\r
|
|
1002
|
+
10 Disclaimers\r
|
|
1003
|
+
10.1 YOU ACKNOWLEDGE THAT THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, AND TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, NEITHER HUAWEI OR ITS AFFILIATES OR LICENSORS NOR THE COPYRIGHT HOLDERS MAKE ANY REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, RIGHT TO CONFIDENTIALITY, AND NON-INFRINGEMENT OF THIRD PARTY RIGHTS. THERE IS NO WARRANTY BY HUAWEI OR BY ANY OTHER PARTY THAT THE FEATURES CONTAINED IN THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. YOU SHALL BEAR ALL RESPONSIBILITIES AND RISKS ARISING FROM YOU SELECTING THIS SOFTWARE TO ACHIEVE YOUR EXPECTED RESULTS, INSTALLING AND USING THIS SOFTWARE, AND OBTAINING RESULTS FROM IT.\r
|
|
1004
|
+
\r
|
|
1005
|
+
10.2 INSTALLING THIS SOFTWARE MAY AFFECT THE AVAILABILITY OF THIRD-PARTY SOFTWARE, APPS, OR SERVICES. THERE IS NO WARRANTY BY HUAWEI THAT THE FEATURES OR SERVICES CONTAINED IN THIS SOFTWARE WILL MEET YOUR REQUIREMENTS, THAT THIS SOFTWARE AND ITS SERVICES WILL BE FREE FROM ERRORS/BUGS, OR THAT THIS SOFTWARE WILL PROVIDE CONTINUOUS, PERMANENT SERVICES. IN ADDITION, HUAWEI MAKES NO WARRANTY THAT THIS SOFTWARE WILL BE COMPATIBLE WITH ANY THIRD-PARTY SOFTWARE OR SERVICES.\r
|
|
1006
|
+
\r
|
|
1007
|
+
10.3 YOU FURTHER ACKNOWLEDGE THAT HUAWEI SOFTWARE AND SERVICES ARE NOT INTENDED OR SUITABLE FOR USE IN SITUATIONS OR ENVIRONMENTS WHERE THE FAILURE OR TIME DELAYS OF, OR ERRORS OR INACCURACIES IN, THE CONTENT, DATA, OR INFORMATION PROVIDED BY THE HUAWEI SOFTWARE OR SERVICES COULD LEAD TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE, INCLUDING BUT NOT LIMITED TO THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT NAVIGATION OR COMMUNICATIONS SYSTEMS, AIR TRAFFIC CONTROL SYSTEMS, OR LIFE SUPPORT OR WEAPONS SYSTEMS.\r
|
|
1008
|
+
\r
|
|
1009
|
+
11 Limitation of Liability\r
|
|
1010
|
+
11.1 HUAWEI WILL NOT TAKE ANY RESPONSIBILITY FOR SOFTWARE USE PROBLEMS CAUSED BY ABUSE, MISUSE, OR UNAUTHORIZED MODIFICATION.\r
|
|
1011
|
+
\r
|
|
1012
|
+
11.2 TO THE EXTENT NOT EXPRESSLY PROHIBITED BY APPLICABLE LAW, IN NO EVENT SHALL HUAWEI OR ITS EMPLOYEES, LICENSORS, OR AFFILIATES BE LIABLE FOR ANY LOSS OF PROFITS, REVENUE, SALES, OR DATA, COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, PROPERTY DAMAGE, PERSONAL INJURY, BUSINESS INTERRUPTION, OR LOSS OF BUSINESS INFORMATION, OR FOR ANY SPECIAL, DIRECT, INDIRECT, INCIDENTAL, ECONOMIC, PUNITIVE, OR CONSEQUENTIAL DAMAGES, ARISING OUT OF OR RELATED TO YOUR USE OF OR INABILITY TO USE THIS SOFTWARE, HOWEVER CAUSED, REGARDLESS OF THE THEORY OF LIABILITY (CONTRACT, TORT, NEGLIGENCE, OR OTHERWISE) AND EVEN IF SUCH PARTIES HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF LIABILITY FOR PERSONAL INJURY, OR OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY TO YOU.\r
|
|
1013
|
+
\r
|
|
1014
|
+
11.3 IN NO EVENT SHALL HUAWEI'S TOTAL LIABILITY TO YOU FOR ALL DAMAGES (OTHER THAN AS MAY BE REQUIRED BY APPLICABLE LAW IN CASES INVOLVING DEATH OR PERSONAL INJURY RESULTING FROM HUAWEI'S NEGLIGENCE) EXCEED THE AMOUNT YOU PAID FOR YOUR HUAWEI WEARABLE DEVICE.\r
|
|
1015
|
+
\r
|
|
1016
|
+
11.4 The laws of some countries/regions do not allow certain warranties, guarantees, or liabilities to be excluded or limited by an agreement. If these laws apply to you, some or all of the exclusions or limitations mentioned herein may not be applicable and you may have additional rights. Nothing in this Agreement affects the rights that you are legally entitled to as a consumer, or which you cannot contractually agree to alter or waive.\r
|
|
1017
|
+
\r
|
|
1018
|
+
12 Technical Support\r
|
|
1019
|
+
Huawei is not obligated to provide you with any technical support for the Software under this Agreement except as required by law. No oral or written information or opinion given by Huawei or its authorized representatives constitutes any warranty. If you discover that the Software or its services are defective, you must bear all necessary maintenance or correction costs.\r
|
|
1020
|
+
\r
|
|
1021
|
+
13 Export Controls\r
|
|
1022
|
+
You may not use or otherwise export or re-export Huawei Software except as authorized by applicable laws and the laws of the jurisdictions in which the Huawei Software was obtained.\r
|
|
1023
|
+
\r
|
|
1024
|
+
14 Contacting Huawei\r
|
|
1025
|
+
If you have any questions, comments, or suggestions, please contact us via the customer service hotline 950800, via the online customer service, or at our global offices. For a complete list of our offices, please visit the Contact Huawei(https://consumer.huawei.com/en/support/contact-us/) page.\r
|
|
1026
|
+
\r
|
|
1027
|
+
15 Dispute Resolution and Governing Laws\r
|
|
1028
|
+
The validation, interpretation, modification, performance, and dispute resolution of this Agreement shall be governed by the laws of the People's Republic of China, without regard to its conflict of laws rules. You agree that this Agreement is signed in Longgang District, Shenzhen. Any dispute arising in relation to the content or performance of this Agreement shall be settled through negotiation made in good faith. If such negotiation fails, either party may submit the dispute for resolution by litigation at the people's court with proper jurisdiction in the place where this Agreement is signed. You will also benefit from any and all mandatory provisions of the laws of your country/region of residence. Nothing in this Agreement affects any rights you have as a consumer under mandatory provisions of local law.\r
|
|
1029
|
+
\r
|
|
1030
|
+
16 Entire Agreement\r
|
|
1031
|
+
This Agreement constitutes the entire agreement between you and Huawei in respect of the use of this Software and supersedes any prior agreements between you and Huawei relating to the use of this Software. You may also be subject to additional terms and conditions that may apply when you use or purchase open-source software, third-party content, or other Huawei services.\r
|
|
1032
|
+
\r
|
|
1033
|
+
Copyright (c) Huawei Device Co., Ltd. 2024. All rights reserved.\r
|
|
1034
|
+
\r
|
|
1035
|
+
---------------------------------------\r
|
|
1036
|
+
HarmonyOS SDK License Agreement\r
|
|
1037
|
+
\r
|
|
1038
|
+
1. Definition\r
|
|
1039
|
+
\r
|
|
1040
|
+
1.1 Huawei refers to the signing entity, in accordance with Clause 11 herein, which provides you with the HarmonyOS SDKs.\r
|
|
1041
|
+
\r
|
|
1042
|
+
1.2 HarmonyOS SDKs refers to the software development kits provided by Huawei that contains system files, integrated APIs, toolchains, previewer, technical documents, and subsequent updates.\r
|
|
1043
|
+
\r
|
|
1044
|
+
1.3 HarmonyOS refers to a brand-new distributed operating system that is oriented to a wide range of scenarios.\r
|
|
1045
|
+
\r
|
|
1046
|
+
1.4 Compatible device refers to a device that complies with the Product Compatibility Specifications, which can be obtained by going to Design Compatibility on https://device.harmonyos.com and may be updated in the future.\r
|
|
1047
|
+
\r
|
|
1048
|
+
2. About This Agreement\r
|
|
1049
|
+
\r
|
|
1050
|
+
2.1 The HarmonyOS SDK License Agreement (hereinafter referred to as this Agreement) is a legally binding agreement made and entered into between you and Huawei. Huawei will license you to use the HarmonyOS SDKs in accordance with this Agreement. By reading this Agreement, you will understand the rules for using the HarmonyOS SDKs and other important information. Please read this Agreement carefully. By clicking the Accept button below this Agreement or by using the HarmonyOS SDKs, you shall be deemed as having fully understood and accepted the terms contained herein. If you do not agree to the terms of this Agreement, you shall not use the HarmonyOS SDKs.\r
|
|
1051
|
+
\r
|
|
1052
|
+
2.2 You must meet the following criteria You have reached the legal age of majority so that you are competent to enter into a legally binding agreement with Huawei; you possess full legal capacity to conclude, understand, and perform this Agreement with Huawei and are able to assume the legal liability for any and all breaches thereof; you are not otherwise forbidden to use HarmonyOS SDKs in accordance with applicable laws. If you enter into this Agreement on behalf of an entity, you undertake that you have the qualification and ability to enter into this Agreement on behalf of the entity and that the entity possesses the qualification, authorization, or license(s) required to enter into this Agreement with Huawei.\r
|
|
1053
|
+
\r
|
|
1054
|
+
3. License\r
|
|
1055
|
+
\r
|
|
1056
|
+
3.1 Huawei grants you a limited, non-exclusive, free, non-transferable, non-sublicensable, and revocable license worldwide for you to download, install, copy, integrate, and run the HarmonyOS SDKs to develop applications that run on compatible devices.\r
|
|
1057
|
+
\r
|
|
1058
|
+
3.2 You shall not use HarmonyOS SDKs to develop applications or other SDKs for incompatible devices. If you do not use HarmonyOS SDKs, you can develop applications for other platforms, including incompatible devices.\r
|
|
1059
|
+
\r
|
|
1060
|
+
3.3 All rights and interests related to HarmonyOS SDKs are owned by Huawei, including any intellectual property rights. Huawei reserves all rights that are not explicitly granted to you.\r
|
|
1061
|
+
\r
|
|
1062
|
+
3.4 This Agreement does not contain any terms that grant you the right to use any of Huawei's trademarks, logos, domain names, company names, product names, or other brands.\r
|
|
1063
|
+
\r
|
|
1064
|
+
3.5 Huawei agrees not to obtain any rights or interests, including any intellectual property rights, of the applications that you have developed using HarmonyOS SDKs from you (or your licensor) in accordance with this Agreement.\r
|
|
1065
|
+
\r
|
|
1066
|
+
4. Usage Rules\r
|
|
1067
|
+
\r
|
|
1068
|
+
You agree that you will not perform the following activities, or allow or encourage any third party to perform the following activities\r
|
|
1069
|
+
\r
|
|
1070
|
+
(a) Use HarmonyOS SDKs for any purposes that are not explicitly allowed by this Agreement or that are not allowed by applicable laws and regulations;\r
|
|
1071
|
+
\r
|
|
1072
|
+
(b) Use HarmonyOS SDKs to implement functions that are prohibited by applicable laws and regulations during application development;\r
|
|
1073
|
+
\r
|
|
1074
|
+
(c) Use HarmonyOS SDKs to interfere with, damage, disrupt, or access without authorization the server, network, or other services of any subject;\r
|
|
1075
|
+
\r
|
|
1076
|
+
(d) Modify, adapt, redistribute, decompile, reverse-engineer, or disassemble HarmonyOS SDKs or any part of HarmonyOS SDKs, or create derivatives of HarmonyOS SDKs or any part of HarmonyOS SDKs;\r
|
|
1077
|
+
\r
|
|
1078
|
+
(e) Delete, cover, or modify any proprietary right statements (including copyright statements and trademark statements) that may be attached to or contained in HarmonyOS SDKs.\r
|
|
1079
|
+
\r
|
|
1080
|
+
5. Privacy and Data\r
|
|
1081
|
+
\r
|
|
1082
|
+
5.1 HarmonyOS SDKs will not collect any personal information from you or end users of your applications.\r
|
|
1083
|
+
\r
|
|
1084
|
+
5.2 To understand developers' requirements and improve the quality and experience of HarmonyOS SDKs, Huawei will collect information about your usage of HarmonyOS SDKs, such as the usage frequency of each function and operation logs.\r
|
|
1085
|
+
\r
|
|
1086
|
+
6. Cyber Security and Personal Information Protection\r
|
|
1087
|
+
\r
|
|
1088
|
+
6.1 During application development, you shall comply with the following network security requirements\r
|
|
1089
|
+
\r
|
|
1090
|
+
(a) Comply with local laws and regulations and ensure that there are no securitysafety risks or issues;\r
|
|
1091
|
+
\r
|
|
1092
|
+
(b) Do not attack or damage Huawei networks. Do not steal any data or information from Huawei or user devices. Do not crack accounts or passwords of Huawei users;\r
|
|
1093
|
+
\r
|
|
1094
|
+
(c) Do not implant unwanted code, malware, or backdoors in Huawei networks or user devices. Do not reserve any undisclosed interfaces or accounts;\r
|
|
1095
|
+
\r
|
|
1096
|
+
(d) Do not introduce any form of Trojan horse, backdoor, worm, virus, malicious code, unknown function, or unknown permission into your applications.\r
|
|
1097
|
+
\r
|
|
1098
|
+
6.2 If the applications you develop using HarmonyOS SDKs will collect and process user data, you shall inform users of the type of data that will be collected, the purpose of the collection, and the data processing methods, and you shall also obtain users' consent and provide users with privacy statements and protection measures that comply with applicable laws. You shall be responsible for resolving any privacy and security issues arising between you and your users related to your applications, and Huawei shall not be responsible for such issues.\r
|
|
1099
|
+
\r
|
|
1100
|
+
7. Disclaimer\r
|
|
1101
|
+
\r
|
|
1102
|
+
7.1 Huawei, its affiliates, principals, directors, employees, contractors, agents, third-party payment service providers, partners, licensors, and resellers (hereinafter collectively referred to as the Huawei Parties) do not take any responsibility, under any responsibility theory, for any direct, indirect, incidental, special, secondary, or punitive damage (including any loss of data, reputation, or profit) that you may suffer, irrespective of whether the Huawei Parties or their representatives have been informed, or whether the Huawei Parties or their representatives are aware of the possibility of any of the above-mentioned losses.\r
|
|
1103
|
+
\r
|
|
1104
|
+
7.2 HarmonyOS SDKs are provided on an as-is and as available basis without any representation or endorsement of any kind. To the maximum extent permitted by applicable laws, the Huawei Parties do not make any explicit or implicit guarantee, undertaking, representation, or warranty for the following\r
|
|
1105
|
+
\r
|
|
1106
|
+
(a) HarmonyOS SDK marketability, applicability for specific purposes, and non-infringement of any other's rights;\r
|
|
1107
|
+
\r
|
|
1108
|
+
(b) Integrity, accuracy, reliability, and timeliness of any content obtained through HarmonyOS SDKs;\r
|
|
1109
|
+
\r
|
|
1110
|
+
(c) HarmonyOS SDKs or the servers that accommodate HarmonyOS SDKs are free from defects, errors, viruses, bugs, or other harmful elements;\r
|
|
1111
|
+
\r
|
|
1112
|
+
(d) HarmonyOS SDK function defects will be fixed;\r
|
|
1113
|
+
\r
|
|
1114
|
+
(e) Future HarmonyOS SDK versions are fully compatible with applications developed based on previous HarmonyOS SDK versions.\r
|
|
1115
|
+
\r
|
|
1116
|
+
The Huawei Parties are not liable for any loss or damage caused by your full or partial reliance on HarmonyOS SDKs, your use of HarmonyOS SDKs, or any information obtained by your (or anyone else's) use of HarmonyOS SDKs.\r
|
|
1117
|
+
\r
|
|
1118
|
+
7.3 You shall bear full responsibility for any failure to fulfill obligations under this Agreement or any applicable third-party agreements, laws, and regulations, and for any consequences arising thereof, and Huawei does not assume any responsibility for you or any third party.\r
|
|
1119
|
+
\r
|
|
1120
|
+
7.4 The laws of some countries do not allow certain warranties, guarantees, or liabilities to be excluded or limited by a contract. If these laws apply to you, all or part of the above-mentioned exclusions or restrictions may not apply to you, but other content in this Agreement is not affected.\r
|
|
1121
|
+
\r
|
|
1122
|
+
7.5 You agree to select your country or region in the operating system where you use HarmonyOS SDKs according to the actual situation. You shall be solely responsible for the failure to select the factual country/region, and for any consequence arising thereof, such as data leakage. Huawei shall bear no liability.\r
|
|
1123
|
+
\r
|
|
1124
|
+
8. Indemnity\r
|
|
1125
|
+
\r
|
|
1126
|
+
8.1 To the maximum extent permitted by applicable laws, you shall defend, hold harmless, and indemnify the Huawei Parties against and from any and all claims, suits, and actions arising out of or in relation to any of the following events\r
|
|
1127
|
+
\r
|
|
1128
|
+
(a) Your use of HarmonyOS SDKs;\r
|
|
1129
|
+
\r
|
|
1130
|
+
(b) Your breach of any provision of this Agreement;\r
|
|
1131
|
+
\r
|
|
1132
|
+
(c) Your breach of any applicable laws and regulations;\r
|
|
1133
|
+
\r
|
|
1134
|
+
(d) Disputes between you and end users;\r
|
|
1135
|
+
\r
|
|
1136
|
+
(e) Your commitments and warranties to any third party regarding HarmonyOS SDKs under this Agreement;\r
|
|
1137
|
+
\r
|
|
1138
|
+
(f) Any claim that your application infringes upon or embezzles any third party's intellectual property rights or other rights.\r
|
|
1139
|
+
\r
|
|
1140
|
+
8.2 You acknowledge and agree to provide full assistance and cooperation in defending against the aforesaid claims, suits, and actions immediately upon reasonable request of the Huawei Parties.\r
|
|
1141
|
+
\r
|
|
1142
|
+
9. Termination\r
|
|
1143
|
+
\r
|
|
1144
|
+
9.1 This Agreement shall remain in effect unless you or Huawei terminates this Agreement in accordance with the provisions of this Agreement.\r
|
|
1145
|
+
\r
|
|
1146
|
+
9.2 You can terminate this Agreement by stopping using HarmonyOS SDKs.\r
|
|
1147
|
+
\r
|
|
1148
|
+
9.3 Huawei reserves the right to temporarily or permanently suspend, cancel, or restrict your use of part or all HarmonyOS SDKs, and suspend or terminate this Agreement without assuming any responsibility for you or any third party in any of the following circumstances\r
|
|
1149
|
+
\r
|
|
1150
|
+
(a) You violate, or Huawei believes you are about to violate this Agreement, including any agreements, policies, or guidelines incorporated herein;\r
|
|
1151
|
+
\r
|
|
1152
|
+
(b) You, or anyone acting on your behalf, acts illegally, or provides Huawei with any false or misleading information;\r
|
|
1153
|
+
\r
|
|
1154
|
+
(c) In response to requests by law enforcement or other government agencies under a valid legal process;\r
|
|
1155
|
+
\r
|
|
1156
|
+
(d) Unexpected technical, security, or business reasons.\r
|
|
1157
|
+
\r
|
|
1158
|
+
The expiry or termination of this Agreement does not affect the provisions of this Agreement that are expressed or by their nature to operate or have effect after deactivation or termination and is without prejudice to any accrued rights or obligations or any rights or obligations which are intended to survive such deactivation or termination.\r
|
|
1159
|
+
\r
|
|
1160
|
+
10. Amendments\r
|
|
1161
|
+
\r
|
|
1162
|
+
10.1 Huawei has been and will be updating and optimizing HarmonyOS SDKs. Huawei may add or delete functions, set new restrictions, or temporarily or permanently suspend or stop certain functions of HarmonyOS SDKs without any prior notice to you. Huawei may also amend this Agreement at any time based on the changes to the HarmonyOS SDKs.\r
|
|
1163
|
+
\r
|
|
1164
|
+
10.2 If changes to HarmonyOS SDKs or this Agreement severely affect users or restrict the use of HarmonyOS SDKs, Huawei will release a new version notice within a reasonable period after the changes. For the changes to HarmonyOS SDKs that Huawei needs to make to meet security, legal, or regulatory requirements, Huawei may not be able to meet the aforementioned timescales and Huawei will notify you of these changes as soon as possible.\r
|
|
1165
|
+
\r
|
|
1166
|
+
11. Signing Huawei Entities\r
|
|
1167
|
+
11.1. Your signing entity will be determined by the country or region ("Use Area") set in the operating system where you use HarmonyOS SDKs.\r
|
|
1168
|
+
\r
|
|
1169
|
+
11.2 If your Use Area is the Chinese mainland specified in Part I of Exhibit A hereto, you are entering into and concluding this Agreement with Huawei Software Technologies Co., Ltd. which is legally established and incorporated in the People's Republic of China, and you designate Huawei Software Technologies Co., Ltd. as your agent in the Chinese mainland.\r
|
|
1170
|
+
\r
|
|
1171
|
+
11.3 If your Use Area is the country(ies) and/or region(s) listed in Part II of Exhibit A hereto, you are entering into and concluding this Agreement with Aspiegel SE (formerly known as Aspiegel Limited) which is legally established and incorporated in Ireland, and you designate Aspiegel SE as your agent in such countries and regions.\r
|
|
1172
|
+
\r
|
|
1173
|
+
11.4 If your Use Area is the country((ies) and/or region(s) listed in Part III of Exhibit A hereto, you are entering into and concluding this Agreement with Huawei Services (Hong Kong) Co., Limited which is legally established and incorporated in Hong Kong (China), and you designate Huawei Services (Hong Kong) Co., Limited as your agent in such countries and regions.\r
|
|
1174
|
+
\r
|
|
1175
|
+
12. Governing Laws and Dispute Resolution\r
|
|
1176
|
+
\r
|
|
1177
|
+
12.1 If you are concluding this Agreement with Huawei Software Technologies Co., Ltd., you agree that the establishment, jurisdiction, and interpretation of this Agreement shall be governed by the laws of the People's Republic of China. You agree that this Agreement is signed in Longgang District, Shenzhen, P.R. China. Any and all disputes, compensation claims, and causes of action arising out of or in relation to performing this Agreement or receiving HarmonyOS SDKs under this Agreement shall be resolved in the court with jurisdiction over the place where this Agreement is signed.\r
|
|
1178
|
+
\r
|
|
1179
|
+
12.2 If you are concluding this Agreement with Aspiegel SE, you agree that the establishment, jurisdiction, and interpretation of this Agreement shall be governed by the laws of Ireland. You agree that any and all disputes, compensation claims, and causes of action arising out of or in relation to performing this Agreement or receiving HarmonyOS SDKs under this Agreement shall be submitted to the Irish Courts with jurisdiction in Dublin, Ireland, for litigation in the English language, without applying the United Nations Convention on Contracts for the International Sale of Goods.\r
|
|
1180
|
+
\r
|
|
1181
|
+
12.3 If you are concluding this Agreement with Huawei Services (Hong Kong) Co., Limited, you agree that the establishment, jurisdiction, and interpretation of this Agreement shall be governed by the laws of Hong Kong (China), you agree that any and all disputes, compensation claims, and causes of action arising out of or in relation to performing of this Agreement or receiving HarmonyOS SDKs under this Agreement shall be submitted to the courts in Hong Kong (China) for litigation in the English language, without applying the United Nations Convention on contracts for the International Sale of Goods.\r
|
|
1182
|
+
\r
|
|
1183
|
+
13. Miscellaneous\r
|
|
1184
|
+
\r
|
|
1185
|
+
13.1 This Agreement constitutes the entire legal agreement between you and Huawei and governs your use of HarmonyOS SDKs. This Agreement completely replaces any prior agreements between you and Huawei in relation to HarmonyOS SDKs.\r
|
|
1186
|
+
\r
|
|
1187
|
+
13.2 HarmonyOS SDKs may provide links to other websites or resources. You acknowledge and agree that Huawei is not responsible for the availability of such websites or resources, and does not endorse or take responsibility for any content, advertisements, products, or other information on or available from such websites or resources. Huawei is not responsible for any damage or loss caused or alleged to be caused by or in connection with the use of or reliance on any such content, goods, or services available on or through any such websites or resources.\r
|
|
1188
|
+
\r
|
|
1189
|
+
13.3 Nothing in this Agreement shall be construed to create a partnership or agency relationship between you and Huawei, and neither party shall have the right or authority to incur any liability debt or cost or enter into any contracts or other arrangements in the name of or on behalf of the other party.\r
|
|
1190
|
+
\r
|
|
1191
|
+
13.4 Huawei is not liable for any failure or delay in performance of its obligations under this Agreement that is caused or contributed to by matters beyond Huawei's reasonable control.\r
|
|
1192
|
+
\r
|
|
1193
|
+
13.5 If any provision of this Agreement is found by a court of competent jurisdiction or any other competent authority to be void, invalid, or unenforceable, it shall be deemed to be deleted from this Agreement, and all other provisions of this Agreement shall remain in full force and effect.\r
|
|
1194
|
+
\r
|
|
1195
|
+
13.6 Even if Huawei does not exercise any of the rights or remedies mentioned in this Agreement, it shall not be deemed that Huawei waives these rights or remedies. Huawei can still exercise these rights or take these remedies.\r
|
|
1196
|
+
\r
|
|
1197
|
+
13.7 The headings in this Agreement are for reading convenience only and have no legal effect.\r
|
|
1198
|
+
\r
|
|
1199
|
+
13.8 Huawei may assign or sub-contract any of Huawei's rights and obligations under this Agreement.\r
|
|
1200
|
+
\r
|
|
1201
|
+
13.9 You shall not distribute obligations under this Agreement or transfer or sublicense rights under this Agreement.\r
|
|
1202
|
+
\r
|
|
1203
|
+
Exhibit A - List of Countries/Regions\r
|
|
1204
|
+
\r
|
|
1205
|
+
Part I: Chinese mainland.\r
|
|
1206
|
+
\r
|
|
1207
|
+
Part II: Aland Islands, Albania, Andorra, Australia, Austria, Belgium, Bonaire, Bosnia and Herzegovina, Bulgaria, Canada, Croatia, Curacao, Cyprus, Czech Republic, Denmark, Dutch Caribbean, Estonia, Faroe Islands, Finland, France, Germany, Gibraltar, Greece, Greenland, Guernsey, Hungary, Iceland, Israel, Italy, Jersey, Latvia, Liechtenstein, Lithuania, Luxembourg, Malta, Moldova, Monaco, Montenegro, Netherlands, New Zealand, North Macedonia, Norway, Poland, Portugal, Ireland, Romania, Saba, Saint Vincent and the Grenadines, San Marino, Serbia, Sint Eustatius, Sint Maarten, Slovakia, Slovenia, Spain, St. Martin, St. Pierre and Miquelon (France), Sweden, Switzerland, Turkey, Ukraine, United Kingdom, United States, Vatican City.\r
|
|
1208
|
+
\r
|
|
1209
|
+
Part III: Other countries and regions.\r
|
|
1210
|
+
---------------------------------------\r`;var bc=new Set,Wt=new Map,pr="HarmonyOS_Software_Service_Agreement",Vi=["Emulator license agreements are not accepted yet.","","Accept the agreements in an interactive terminal:"," devecocli emulator license accept","","To review the agreement text (read-only):"," devecocli emulator license view"].join(`
|
|
1211
|
+
`),qi=Vi,hr="HarmonyOS_SDK_Agreement";function Yi(r,e){return`${r}\0${e}`}function Sc(){bc.clear(),Wt.clear()}var Pc=Vi,Q=class extends Error{constructor(e=Pc){super(e),this.name="EmulatorLicenseBlockedError"}};function Gi(r,e){return[r??"",e??""].join(`
|
|
1212
|
+
`)}function Ji(r){let e=r.normalize("NFKC"),t=e.match(/(\d+)\.(\d+)\.\d+/);if(t)return`${t[1]}.${t[2]}`;let n=e.match(/(\d+)\.(\d+)\b/);return n?`${n[1]}.${n[2]}`:null}function Ec(r){return`Emulator${r.trim()}`}function Ki(r){let e=Ec(r);if(process.platform==="win32"){let n=process.env.LOCALAPPDATA;if(!n)throw new Error("LOCALAPPDATA is not set; cannot resolve .emu_config path.");return xe.join(n,"Huawei",e,".emu_config")}if(process.platform==="darwin")return xe.join(ur.homedir(),"Library","Caches","Huawei",e,".emu_config");let t=process.env.XDG_CACHE_HOME?.trim()||xe.join(ur.homedir(),".cache");return xe.join(t,"Huawei",e,".emu_config")}async function Dc(r,e,t){let n=Yi(r,e),i=Wt.get(n);if(i!==void 0)return i;let o=await zi(r,["-version"],{stdio:["ignore","pipe","pipe"],env:{...process.env,DEVECO_SDK_HOME:e},reject:!1,maxBuffer:1024*1024}),s=Gi(o.stdout,o.stderr).trim();if(o.exitCode!==0||!s)throw new Q(t);return Wt.set(n,s),s}function Ic(r){let e=r[0],t=r[r.length-1];return(e==='"'||e==="'")&&e===t?r.slice(1,-1):r}function Cc(r){try{let e=JSON.parse(r);if(e&&typeof e=="object"&&!Array.isArray(e)){let t={};for(let[n,i]of Object.entries(e))t[n]={value:typeof i=="string"?i:String(i),delimiter:"json"};return t}}catch{return}}function Ac(r){let e=r.trim();if(!(!e||e.startsWith("#")))for(let t of["=",":"]){let n=e.indexOf(t);if(n<=0)continue;let i=e.slice(0,n).trim();if(!i||t===":"&&i.includes("//"))continue;let o=Ic(e.slice(n+1).trim());return{key:i,entry:{value:o,delimiter:t}}}}function kc(r){let e={};for(let t of r.split(/\r?\n/)){let n=Ac(t);n&&(e[n.key]=n.entry)}return e}function Tc(r){let e=r.trim();if(!e)return{};let t=Cc(e);return t||kc(r)}function Mc(r){return typeof r!="string"?!1:r.normalize("NFKC").trim().toLowerCase()==="agree"}async function Zi(r,e,t,n){let i=await Dc(r,e,n),o=Ji(i);if(!o)throw new Q(n);let s=Ki(o),a;try{a=await Se.readFile(s,"utf8")}catch(u){throw u.code==="ENOENT"?new Q(n):u}let d=Tc(a)[t];if(!d)throw new Q(n);if(d.delimiter==="=")throw new Q(n);if(!Mc(d.value))throw new Q(n)}async function Xi(r,e){await Zi(r,e,pr,qi)}async function Qi(r,e){await Zi(r,e,hr,qi)}async function xc(r,e){let t=await zi(r,["-version"],{stdio:["ignore","pipe","pipe"],env:{...process.env,DEVECO_SDK_HOME:e},reject:!1,maxBuffer:1048576}),n=Gi(t.stdout,t.stderr).trim();if(t.exitCode!==0||!n)throw new Error(`Emulator -version failed (exit ${String(t.exitCode)}); cannot resolve .emu_config path.`);let i=Yi(r,e);return Wt.set(i,n),n}async function Rc(r,e){let t=await xc(r,e),n=Ji(t);if(!n)throw new Error(`Cannot parse Emulator major.minor from:
|
|
1213
|
+
${t}`);return Ki(n)}function Bi(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}async function Oc(r,e,t){if(!t.startsWith("{"))return!1;try{let n=JSON.parse(e);if(n&&typeof n=="object"&&!Array.isArray(n))return n[pr]="agree",n[hr]="agree",await Se.writeFile(r,`${JSON.stringify(n,null,2)}
|
|
1214
|
+
`,"utf8"),!0}catch{}return!1}async function Nc(r,e){let t=pr,n=hr,i=[{k:t,re:new RegExp(`^\\s*${Bi(t)}\\s*[:=]`)},{k:n,re:new RegExp(`^\\s*${Bi(n)}\\s*[:=]`)}],o=e.length===0?[]:e.split(/\r?\n/),s=[],a=new Set;for(let c of o){let d=!1;for(let{k:u,re:b}of i)if(b.test(c)){s.push(`${u}:agree`),a.add(u),d=!0;break}d||s.push(c)}a.has(t)||s.push(`${t}:agree`),a.has(n)||s.push(`${n}:agree`),await Se.writeFile(r,s.join(`
|
|
1215
|
+
`)+(s.length>0?`
|
|
1216
|
+
`:""),"utf8")}async function Lc(r){await Se.mkdir(xe.dirname(r),{recursive:!0});let e="";try{e=await Se.readFile(r,"utf8")}catch(n){if(n.code!=="ENOENT")throw n}let t=e.trim();await Oc(r,e,t)||await Nc(r,e)}async function eo(r,e){return console.log(dr),0}var Hc="Please read carefully and confirm whether agree to the above agreement? (y/N): ";async function to(r,e){if(console.log(dr),!process.stdin.isTTY||!process.stdout.isTTY)return console.error("devecocli emulator license accept requires an interactive terminal."),1;let n=wc.createInterface({input:process.stdin,output:process.stdout}),i;try{i=await n.question(Hc)}finally{n.close()}let o=i.trim().toLowerCase();if(o!=="y"&&o!=="yes")return 1;try{let s=await Rc(r,e);await Lc(s),Sc()}catch(s){return console.error(s.message),1}return 0}var Fc=["ohos.qemu.hvd.name","const.product.name","const.product.model"];function $c(r){let e=r.trim();if(!e||!/^[A-Za-z0-9_ ]+$/.test(e))throw new Error("The virtual device name can only contain letters, spaces, numbers, and underscores (_).")}function _c(r){let e=r.trim();if(!e)throw new Error("--os-version must not be empty.");if(/^\d+$/.test(e))throw new Error(`--os-version "${r}" is invalid: use the full image label, e.g. HarmonyOS 5.1.1(19).`);if(!/^HarmonyOS\s+/i.test(e))throw/^HarmonyOS$/i.test(e)?new Error('--os-version is incomplete (only "HarmonyOS"). On PowerShell/cmd, quote the full label, e.g. --os-version "HarmonyOS 6.0.1(21)"'):new Error(`--os-version must start with "HarmonyOS " (e.g. HarmonyOS 5.1.1(19)). Got: "${r}"`)}function Wc(r,e){let t=i=>i.normalize("NFKC").trim(),n=t(r);if(e.length===0)throw console.error(oe("Could not parse any downloaded images from `emulator -imageList -downloaded true` (JSON array expected).")),console.error(oe("Run `devecocli emulator image download ...` then `devecocli emulator image list` and copy an `osVersion` string exactly.")),new Error("No downloaded osVersion values parsed; cannot validate --os-version.");if(!e.some(i=>t(i)===n)){console.error(V("--os-version does not match any downloaded image (exact string required).")),console.log(oe("Use one of these --os-version values:"));for(let i of e)console.log(` ${i}`);throw new Error(`No downloaded image matches --os-version "${r}".`)}}var Uc=["Name","Status","Serial","Device Type","OS Version"];function Bc(r,e,t){return{cells:[r.name,t?"running":"stopped",e??"-",r.deviceType??"-",r.osVersion??"-"],highlight:t}}async function zc(r,e){let t=await Promise.all(e.map(async n=>{let i=await Be(r,n,Fc);return[n,i]}));return new Map(t)}async function Vc(r){let e=await ir(r),t=await zc(r,e);return{serials:e,params:t}}function qc(r,e,t,n,i){if(e)for(let o of["const.product.name","const.product.model"]){let s=e.get(o);if(!s)continue;let a=t.indexOf(s);if(a===-1)continue;t.splice(a,1),i.set(s,r);let c=n.indexOf(r);c!==-1&&n.splice(c,1);return}}function Yc(r,e,t){let n=new Map,i=new Map,o=[...r],s=[...t];for(let a of r){let c=e.get(a),d=c?.get("ohos.qemu.hvd.name");d&&i.set(d,a),t.length>0&&qc(a,c,s,o,n)}for(let a=0;a<s.length&&a<o.length;a++)n.set(s[a],o[a]);return{productSerialMap:n,hvdSerialMap:i}}function Gc(r,e,t){let n=r.map(i=>({emu:i,serial:e.get(i.name)??t.get(i.name),effectiveRunning:i.isRunning===!0||t.has(i.name)}));return n.sort((i,o)=>i.effectiveRunning!==o.effectiveRunning?i.effectiveRunning?-1:1:i.emu.name.localeCompare(o.emu.name)),n.map(i=>Bc(i.emu,i.serial,i.effectiveRunning))}async function Jc(r,e,t){try{let[n,i]=await Promise.all([r.listEmulators(),Vc(e)]);if(n.length===0){t?.stop(),console.log(oe(" No emulator instances found.")),console.log(Ke(" You can create an emulator in DevEco Studio."));return}let o=n.filter(d=>d.isRunning).map(d=>d.name),{productSerialMap:s,hvdSerialMap:a}=Yc(i.serials,i.params,o);t?.stop();let c=Gc(n,s,a);console.log(ft(Uc,c))}catch(n){_t(t,`Failed to list emulators: ${n.message}`)}}function io(r,e,t){let n=!1;for(let i=0;i<r.length;i++){let o=r[i];if(o.status!=="rejected")continue;n=!0;let s=o.reason;console.error(V(`Failed to ${t} emulator "${e[i]}": ${s.message}`)),s.stdout&&console.error(Ke(s.stdout)),s.stderr&&console.error(Ke(s.stderr))}return n}var Kc=2e3,Zc=6e4;async function Xc(r,e){let t=j(e);return(await or(r)).some(i=>j(i)===t)}async function oo(r,e,t,n=Zc,i=Kc){let o=Date.now()+n;for(;Date.now()<o;){if(await Xc(r,e)===t)return!0;await new Promise(a=>setTimeout(a,i))}return!1}async function Qc(r,e,t){if(await r.startEmulator(t)==="already-running"){console.log(oe(`Emulator "${t}" is already running.`));return}console.log(Je(`Starting emulator "${t}"...`));let i=await oo(e,t,!0);console.log(i?Ut(`Emulator "${t}" started successfully.`):oe(`Emulator "${t}" was launched but did not appear in hdc list targets within the timeout.`))}async function el(r,e,t){let n=await Promise.allSettled(t.map(o=>Qc(r,e,o)));io(n,t,"start")&&process.exit(1)}async function tl(r,e){let t=e.trim();if(!mt(t))return t;let n=await z.withHdcPath(r).getDeviceName(t);if(n===t)throw new Error(`Cannot resolve a running emulator with serial "${t}". Use \`devecocli emulator list\` or pass the emulator name instead.`);return n}async function nl(r,e,t){let n=await tl(e,t);if(console.log(Je(`Stopping emulator "${n}"...`)),await r.stopEmulator(n)==="already-stopped"){console.log(oe(`Emulator "${n}" is already stopped.`));return}let o=await oo(e,n,!1);console.log(o?Ut(`Emulator "${n}" stopped successfully!`):oe(`Emulator "${n}" stop signal was sent but the instance is still visible in hdc list targets within the timeout.`))}async function rl(r,e,t){let n=await Promise.allSettled(t.map(o=>nl(r,e,o)));io(n,t,"stop")&&process.exit(1)}async function se(){try{let r=await N.new();return{manager:Ye.from(r),toolProvider:r}}catch(r){console.error(V(`Failed to initialize emulator: ${r.message}`)),process.exit(1);return}}var Pe=new mr("emulator").description("Manage emulator instances"),il=["phone","foldable","widefold","triplefold","tablet","2in1","2in1 foldable","wearable","tv"];function Bt(r){let e=new ro("--device-type <type>","Emulator device type").choices([...il]);return r?e.makeOptionMandatory():e}function Ge(r,e){for(let t of e)if(t in r)return r[t]}function gt(r){return r==null?"":typeof r=="string"?r.trim():String(r).trim()}function no(r){let e=gt(r).toLowerCase();return e==="true"?"true":e==="false"?"false":e}var ol=["OS Version","Device Type","Software Version","Release Type","Upgradable","Downloaded"],sl="No matching system images found. Try `devecocli emulator image list --all`, then download an image via `devecocli emulator image download ...`.";function so(r){try{let e=JSON.parse(r);return Array.isArray(e)?e:null}catch{return null}}function ao(r,e){let t=[];for(let n of r){if(!n||typeof n!="object")continue;let i=n,o=gt(Ge(i,["osVersion","OsVersion","OSVersion","os_version"])),s=gt(Ge(i,["deviceType","DeviceType","device_type"])),a=no(Ge(i,["downloaded","Downloaded","isDownloaded"])),c=gt(Ge(i,["SoftWareVersion","SoftwareVersion","softwareVersion","software_version","version"])),d=gt(Ge(i,["releaseType","ReleaseType","release_type"])),u=no(Ge(i,["upgradable","Upgradable","isUpgradable"]));t.push({cells:[o,s,c,d,u,a],highlight:e&&a==="true"})}return t}function al(r){let e=r.trim();if(!e)return!0;let t=so(e);return t===null?!1:t.length===0?!0:ao(t,!0).length===0}function cl(r,e){let t=r.trim();if(!t)return"";let n=so(t);if(!n)return r.trimEnd();let i=ao(n,e);return ft(ol,i)}var zt=new mr("image").description("HarmonyOS emulator system images (download, list, remove)");zt.command("download").description("Download a system image").addOption(Bt(!1)).option("--os-version <version>","e.g. HarmonyOS 5.1.1(19) or HarmonyOS 6.0.1(21) (required)").option("--force","Overwrite an existing image").action(async r=>{let{manager:e,toolProvider:t}=await se();try{await Qi(t.emulatorPath,t.sdkPath)}catch(n){throw n instanceof Q&&(console.error(V(n.message)),process.exit(1)),n}r.deviceType?.trim()||(console.error(V("error: required option '--device-type <type>' not specified")),process.exit(1)),r.osVersion?.trim()||(console.error(V("error: required option '--os-version <version>' not specified")),process.exit(1));try{await e.installEmulatorImage({deviceType:r.deviceType.trim(),osVersion:r.osVersion.trim(),force:r.force===!0})}catch(n){console.error(V(`Failed to download system image: ${n.message}`)),process.exit(1)}});zt.command("remove").description("Remove a downloaded system image").addOption(Bt(!0)).requiredOption("--os-version <version>","Supports both image label (HarmonyOS x.y.z(n)) and softwareVersion").action(async r=>{let{manager:e}=await se();try{await e.uninstallEmulatorImage({deviceType:r.deviceType,osVersion:r.osVersion})}catch(t){console.error(V(`Failed to remove system image: ${t.message}`)),process.exit(1)}});zt.command("list").description("List system images").addOption(Bt(!1)).option("--all","List all images (downloaded and not downloaded)").addOption(new ro("--format <format>","Output format").choices(["table","json"]).default("table")).action(async r=>{let{manager:e}=await se();try{let t;r.all?t=void 0:t=!0;let n=await e.listEmulatorImages({deviceType:r.deviceType,downloaded:t});if(al(n)){console.log(oe(sl));return}if(r.format==="json"){console.log(n.trimEnd());return}let i=cl(n,r.all===!0);console.log(i)}catch(t){console.error(V(`Failed to list emulator images: ${t.message}`)),process.exit(1)}});Pe.addCommand(zt);var fr=new mr("license").description("HarmonyOS local emulator license");fr.command("view").description("review the agreement text (read-only)").action(async()=>{let{toolProvider:r}=await se(),e=await eo(r.emulatorPath,r.sdkPath);process.exit(e)});fr.command("accept").description("review and accept the agreements").action(async()=>{let{toolProvider:r}=await se(),e=await to(r.emulatorPath,r.sdkPath);process.exit(e)});Pe.addCommand(fr);Pe.command("list").description("List all emulator instances").action(async()=>{let{manager:r,toolProvider:e}=await se(),t=jc({text:"Listing emulators\u2026",color:"cyan"}).start();await Jc(r,e.hdcPath,t)});Pe.command("start [names...]").description("Start one or more emulator instances").action(async r=>{let{manager:e,toolProvider:t}=await se();try{await Xi(t.emulatorPath,t.sdkPath)}catch(n){throw n instanceof Q&&(console.error(V(n.message)),process.exit(1)),n}r?.length||(console.error(V("error: missing required argument 'names'")),process.exit(1)),await el(e,t.hdcPath,r)});Pe.command("stop <names...>").description("Stop one or more emulator instances (by name or 127.0.0.1:<port> serial)").action(async r=>{let{manager:e,toolProvider:t}=await se();r?.length||(console.error(V("error: missing required argument 'names'")),process.exit(1)),await rl(e,t.hdcPath,r)});var co=Pe.command("create <name>").description("Create a local emulator. Runs emulator -create <name> \u2026; --os-version must match a downloaded image from `emulator image list`.").addOption(Bt(!0)).requiredOption("--os-version <version>",'Exact downloaded image label. Quote in PowerShell (e.g. "HarmonyOS 6.0.1(21)") or use --os-version="\u2026"; see `devecocli emulator image list`').option("--force","Overwrite if the tool supports it");co.configureOutput({outputError:(r,e)=>{e(r),/too many arguments/i.test(r)&&e(`
|
|
1217
|
+
${oe("Tip: ")}${Ke("Unquoted --os-version values with spaces/parentheses are split into multiple arguments. Use:")}
|
|
1218
|
+
${Je('devecocli emulator create 123 --device-type phone --os-version "HarmonyOS 6.0.1(21)"')}
|
|
1219
|
+
${Je('devecocli emulator create 123 --device-type phone --os-version="HarmonyOS 6.0.1(21)"')}
|
|
1220
|
+
`)}});co.action(async(r,e)=>{try{$c(r),_c(e.osVersion);let{manager:t}=await se(),n=await t.listDownloadedImageOsVersions();Wc(e.osVersion,n),console.log(Je(`Creating emulator "${r}"...`)),await t.createVirtualDevice({name:r,deviceType:e.deviceType,osVersion:e.osVersion,force:e.force===!0}),console.log(Ut(`Emulator "${r}" created successfully.`))}catch(t){console.error(V(`${t.message}`)),process.exit(1)}});Pe.command("delete <name>").description("Delete a local emulator instance").action(async r=>{let{manager:e}=await se();console.log(Je(`Deleting emulator "${r}"...`));try{let t=await e.deleteVirtualDevice(r);console.log(Ut(`Emulator "${t}" deleted successfully.`))}catch(t){let n=t;console.error(V(n.message)),n.stdout&&console.error(Ke(n.stdout)),n.stderr&&console.error(Ke(n.stderr)),process.exit(1)}});var lo=Pe;import{Command as El}from"commander";import{green as Dl,red as St,cyan as Lo,yellow as Ho,dim as jo}from"colorette";import Il from"p-limit";import ll from"ora";var Re=class{spinner=null;isRunning=!1;start(e){this.spinner?this.spinner.text=e:this.spinner=ll(e),this.spinner.start(),this.isRunning=!0}stop(){this.spinner&&this.isRunning&&(this.spinner.stop(),this.isRunning=!1)}succeed(e){this.spinner&&(this.spinner.succeed(e),this.isRunning=!1)}fail(e){this.spinner&&(this.spinner.fail(e),this.isRunning=!1)}};import*as mo from"fs";import*as fo from"path";import{homedir as ul}from"os";import dl from"axios";var gr={HTTP_TIMEOUT_MS:2e4},Vt={USER_AGENT:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",ACCEPT_LANGUAGE:"zh-CN"};var yr="https://matrix.openharmony.cn",ee={TAGS_API_URL:`${yr}/api/model_base/model/tags?serviceType=skill`,SKILLS_API_URL:`${yr}/api/registry/skill/skills`,SKILL_API_BASE:`${yr}/api/registry/skill`,DEFAULT_PAGE_SIZE:20,SUCCESS_CODE:"20000"},ue={"trae-cn":{path:".trae-cn/skills",displayName:"trae-cn"},opencode:{path:".config/opencode/skills",displayName:"opencode"},cursor:{path:".cursor/skills",displayName:"cursor"},codebuddy:{path:".codebuddy/skills",displayName:"codebuddy"},qoder:{path:".qoder/skills",displayName:"qoder"},"claude-code":{path:".claude/skills",displayName:"claude-code"},codex:{path:".codex/skills",displayName:"codex"}};import{homedir as pe}from"os";import G from"path";var ae="deveco-mcp";var Ee={opencode:{name:"opencode",displayName:"OpenCode",supportsGlobal:!0,globalConfigPath:G.join(pe(),".config","opencode","opencode.json"),projectConfigPath:".opencode/opencode.json",mcpServersKey:"mcp",format:"opencode"},"trae-cn":{name:"trae-cn",displayName:"Trae-CN",supportsGlobal:!0,globalConfigPath:G.join(process.platform==="win32"?G.join(process.env.APPDATA??G.join(pe(),"AppData","Roaming"),"Trae CN","User"):G.join(pe(),"Library","Application Support","Trae CN","User"),"mcp.json"),projectConfigPath:".trae/mcp.json",mcpServersKey:"mcpServers",format:"standard"},cursor:{name:"cursor",displayName:"Cursor",supportsGlobal:!0,globalConfigPath:G.join(pe(),".cursor","mcp.json"),projectConfigPath:".cursor/mcp.json",mcpServersKey:"mcpServers",format:"standard"},codebuddy:{name:"codebuddy",displayName:"Codebuddy",supportsGlobal:!0,globalConfigPath:G.join(pe(),".codebuddy","mcp.json"),projectConfigPath:".codebuddy/mcp.json",mcpServersKey:"mcpServers",format:"standard"},qoder:{name:"qoder",displayName:"Qoder",supportsGlobal:!0,globalConfigPath:G.join(process.platform==="win32"?G.join(process.env.APPDATA??G.join(pe(),"AppData","Roaming"),"Qoder","SharedClientCache"):G.join(pe(),"Library","Application Support","Qoder","SharedClientCache"),"mcp.json"),projectConfigPath:".mcp.json",mcpServersKey:"mcpServers",format:"standard"},"claude-code":{name:"claude-code",displayName:"Claude Code",supportsGlobal:!0,globalConfigPath:G.join(pe(),".claude.json"),projectConfigPath:".mcp.json",mcpServersKey:"mcpServers",format:"claude-code"},codex:{name:"codex",displayName:"Codex",supportsGlobal:!0,globalConfigPath:G.join(pe(),".codex","config.toml"),projectConfigPath:".codex/config.toml",mcpServersKey:"mcp_servers",format:"codex"}};function po(r){return{type:"local",command:["devecocli","serve","mcp"],environment:{PROJECT_PATH:r??"."},enabled:!0}}function uo(r){return{type:"stdio",command:"devecocli",args:["serve","mcp"],env:{PROJECT_PATH:r??"."},enabled:!0}}function ho(r){return{type:"stdio",command:"devecocli",args:["serve","mcp"],env:{PROJECT_PATH:r??"${workspaceFolder}"}}}function qt(r,e){return r.format==="opencode"?po(e):r.format==="claude-code"||r.format==="codex"?uo(e):ho(e)}var vr=class{client;constructor(){let e={timeout:gr.HTTP_TIMEOUT_MS,headers:{"User-Agent":Vt.USER_AGENT,"accept-language":Vt.ACCEPT_LANGUAGE},transformResponse:[t=>t],proxy:!1};this.client=dl.create(e),this.client.interceptors.response.use(t=>t,t=>{let n=`Network connection failed (${t.code}). Please check your proxy configuration or network settings`;throw new Error(`${t.message}
|
|
1221
|
+
${n}`)})}async get(e,t){let n=await this.client.request({method:"GET",url:e,params:t?.params,headers:t?.headers,timeout:t?.timeout});return this.convertResponse(n)}async post(e,t){let n=await this.client.request({method:"POST",url:e,data:t?.params,headers:t?.headers,timeout:t?.timeout});return this.convertResponse(n)}convertResponse(e){return{data:typeof e.data=="string"?e.data:JSON.stringify(e.data),statusCode:e.status,headers:e.headers}}parseJson(e){return JSON.parse(e.data)}async getBinary(e,t){let n=await this.client.request({method:"GET",url:e,responseType:"arraybuffer",headers:t?.headers,timeout:t?.timeout});if(n.status!==200)throw new Error(`HTTP ${n.status}`);return Buffer.from(n.data)}},De=new vr;async function Yt(){let r=await De.get(ee.TAGS_API_URL),t=Gt(r,"Tags API").data.skill.filter(n=>n.name==="HMOS"||n.name==="DevEco");if(t.length===0)throw new Error("No HMOS or DevEco tags found");return t.map(n=>n.id)}async function pl(r){let e=[],t=ee.DEFAULT_PAGE_SIZE,n=1;for(;;){let i=await De.post(ee.SKILLS_API_URL,{headers:{"Content-Type":"application/json"},params:{pageNum:n,pageSize:t,tagIds:[r]}}),o=Gt(i,"Skills API");if(e.push(...o.data.list),o.data.list.length<t)break;n++}return e}async function wr(r){let e=new Map,t=r.map(i=>pl(i)),n=await Promise.all(t);for(let i of n)for(let o of i)e.has(o.id)||e.set(o.id,o);return Array.from(e.values())}async function hl(r,e){let t=await De.post(ee.SKILLS_API_URL,{headers:{"Content-Type":"application/json"},params:{pageNum:1,pageSize:ee.DEFAULT_PAGE_SIZE,keyword:r,tagIds:[e]}});return Gt(t,"Skills API").data.list}async function br(r,e){let t=new Map,n=e.map(o=>hl(r,o)),i=await Promise.all(n);for(let o of i)for(let s of o)t.has(s.id)||t.set(s.id,s);return Array.from(t.values())}function go(r){let e=[];for(let[,t]of Object.entries(ue)){let n=fo.join(ul(),t.path,r);mo.existsSync(n)&&e.push(t.displayName)}return e.sort()}function Gt(r,e){if(r.statusCode!==200)throw new Error(`${e} Request failed: HTTP ${r.statusCode}`);let t=De.parseJson(r);if(t.code!==ee.SUCCESS_CODE)throw new Error(`${e} Error returned: ${t.code} - ${t.message}`);return t}async function yo(r){let e=`${ee.SKILL_API_BASE}/${r}/checksum`,t=await De.get(e);return Gt(t,"Checksum API").data}import ml from"adm-zip";import fl from"crypto";import wo from"fs";import R from"path";import{fileURLToPath as gl}from"url";import{homedir as bo}from"os";import{red as yl}from"colorette";var he=wo.promises;function Sr(r){if(!/^[A-Za-z0-9._-]+$/.test(r)||r==="."||r==="..")throw new Error(`Unsafe skill name: ${JSON.stringify(r)}`)}function vo(r,e){let t=R.resolve(e),n=R.resolve(r),i=R.relative(n,t);if(i.startsWith("..")||R.isAbsolute(i))throw new Error(`Path escape detected: ${e}`)}function Pr(r){return R.isAbsolute(r)?r:R.resolve(process.cwd(),r)}function vl(r){return fl.createHash("sha256").update(r).digest("hex")}async function wl(r,e){if(r.length!==e.size)throw new Error("Skill zip integrity verification failed: Size mismatch");let n=vl(r),i=e.sha256.toLowerCase();if(n!==i)throw new Error("Skill zip integrity verification failed: SHA256 mismatch")}async function So(r){let e=`${ee.SKILL_API_BASE}/${r}/install?format=zip`,t=await De.getBinary(e),n=await yo(r);return await wl(t,n),t}async function bl(r,e,t){Sr(t);let n=new ml(r),i=n.getEntries();try{await he.stat(e)}catch{await he.mkdir(e,{recursive:!0})}let o=R.join(e,t);vo(e,o);for(let s of i){let a=R.join(o,s.entryName);vo(o,a)}n.extractAllTo(o,!0)}async function Er(r){let e=ue[r];if(!e)throw new Error(`Invalid agent: ${r}, Valid options are: ${Object.keys(ue).join(", ")}`);let t=R.join(bo(),e.path.replace("/skills",""));try{return await he.access(t),!0}catch{return!1}}function Dr(r){let e=ue[r];return R.join(bo(),e.path)}function Ir(r,e){return R.join(r,"."+e,"skills")}async function Sl(r,e,t){Sr(e);let n=R.join(r,e);try{if(await he.access(n),t)await he.rm(n,{recursive:!0,force:!0});else return console.log(`Skill ${e} exists in ${r}`),{skillDir:n,shouldSkip:!0}}catch{}return{skillDir:n,shouldSkip:!1}}async function Cr(r,e,t){await bl(r,e,t),console.log(`Skill ${t} installed to ${R.join(e,t)}`)}async function Ar(r,e,t){let n=R.join(e,t);await he.mkdir(n,{recursive:!0});let i=R.join(n,R.basename(r));await he.copyFile(r,i),console.log(`Skill ${t} installed to ${n}`)}function Po(r,e,t=""){let n=e instanceof Error?e.message:t;return console.log(yl(`Skill ${r} operation failed - ${n}`)),{success:!1,error:n}}async function Ze(r,e,t,n){try{let i=await e(),{shouldSkip:o}=await Sl(i,r,n);return o?{success:!0,skipped:!0}:(await t(i),{success:!0})}catch(i){return Po(r,i,"Installation failed")}}async function kr(r,e){try{Sr(r);let t=await e(),n=R.join(t,r);try{await he.access(n)}catch{return console.log(`Skill ${r} does not exist in ${t}`),{success:!0,skipped:!0}}return await he.rm(n,{recursive:!0,force:!0}),console.log(`Skill ${r} removed from ${n}`),{success:!0}}catch(t){return Po(r,t,"Removal failed")}}async function Eo(r,e,t,n=!1){return Ze(r,()=>Dr(e),i=>Cr(t,i,r),n)}async function Do(r,e,t,n=!1){return Ze(r,()=>t,i=>Cr(e,i,r),n)}async function Io(r,e,t,n,i=!1){return Ze(r,()=>Ir(t,n),o=>Cr(e,o,r),i)}async function Co(r,e,t,n=!1){return Ze(r,()=>Dr(t),i=>Ar(e,i,r),n)}async function Ao(r,e,t,n,i=!1){return Ze(r,()=>Ir(t,n),o=>Ar(e,o,r),i)}async function ko(r,e,t,n=!1){return Ze(r,()=>t,i=>Ar(e,i,r),n)}async function To(r,e){return kr(r,()=>Dr(e))}async function Mo(r,e){return kr(r,()=>e)}async function xo(r,e,t){return kr(r,()=>Ir(e,t))}function Ro(){let e=R.dirname(gl(import.meta.url));for(;;){let t=R.join(e,"SKILL.md");if(wo.existsSync(t))return t;let n=R.dirname(e);if(n===e)break;e=n}throw new Error("SKILL.md not found in deveco-cli package; please reinstall deveco-cli.")}import Oo from"fs";import{cyan as Pl}from"colorette";async function yt(r){if(!r)return[];let e=[],t=r.split(",").map(n=>n.trim());for(let n of t){if(!await Er(n))throw new Error(`Agent ${n} not found`);e.push(n)}return e}async function vt(){let r=[];for(let e of Object.keys(ue))await Er(e)&&r.push(e);return r}function wt(r){let e=r.filter(i=>i.success&&!i.skipped).length,t=r.filter(i=>i.skipped).length,n=r.filter(i=>!i.success).length;console.log(),console.log(Pl("Finished:")),console.log(` Success: ${e}`),console.log(` Skipped: ${t}`),console.log(` Failed: ${n}`),n>0&&(process.exitCode=1)}function Ie(r,e,t){if(!Oo.existsSync(r)){if(t)return;throw new Error(`${e} "${r}" not found`)}if(!Oo.statSync(r).isDirectory())throw new Error(`"${r}" is not a directory`)}function bt(r,e,t){if(r&&(e||t))throw new Error("Cannot use --path with --project or --agent");return{resolvedPath:r?Pr(r):void 0,resolvedProject:e?Pr(e):void 0}}async function Jt(r,e,t){let n=[],i=[],o;if(e?o=e:t&&r.agent?i=(await yt(r.agent)).map(a=>({project:t,agent:a})):t?i=(await vt()).map(a=>({project:t,agent:a})):r.agent?n=await yt(r.agent):n=await vt(),!o&&n.length===0&&i.length===0)throw new Error("No agents found. Please install an AI agent (cursor, opencode, etc.) or use --path for a custom location.");return{agents:n,projectAgents:i,customPath:o}}async function Cl(r){let e=await Yt();if(r.all)return(await wr(e)).map(n=>n.enName);{let n=(await br(r.skill,e)).find(i=>i.enName===r.skill);if(!n)throw new Error(`Skill "${r.skill}" not found`);return[n.enName]}}async function Al(r,e,t,n){let i=[];if(t.customPath){let o=await Do(r,e,t.customPath,n);return i.push(o),i}for(let o of t.agents){let s=await Eo(r,o,e,n);i.push(s)}for(let{project:o,agent:s}of t.projectAgents){let a=await Io(r,e,o,s,n);i.push(a)}return i}function kl(r){if(r.all&&r.skill)throw new Error("--all and --skill cannot be specified together");if(!r.all&&!r.skill)throw new Error("Must specify --all or --skill");let{resolvedPath:e,resolvedProject:t}=bt(r.path,r.project,r.agent);return t&&Ie(t,"Project directory",r.force),e&&Ie(e,"Directory",r.force),{resolvedPath:e,resolvedProject:t}}async function Tl(r,e,t){let n=await Jt(r,e,t);return{skillNames:await Cl(r),targets:n}}async function Ml(r,e,t,n){let i=[],o=r.length,s=Il(5),a=r.map(async c=>s(async()=>{try{let d=await So(c);return{name:c,buffer:d,success:!0}}catch(d){let u=d instanceof Error?d.message:"unknown error";return{name:c,error:u,success:!1}}}));for(let c=0;c<r.length;c++){let d=r[c],u=o>1?` (${c+1}/${o})`:"";n.start(`Installing ${d}${u}...`);let b=await a[c];if(!b.success){n.fail(),console.log(St(`${d}: Download failed - ${b.error}`)),i.push({success:!1});continue}n.stop();let k=await Al(d,b.buffer,e,t);i.push(...k)}return i}async function xl(r){let e=new Re;try{e.start("Installing skill...");let{resolvedPath:t,resolvedProject:n}=kl(r),{skillNames:i,targets:o}=await Tl(r,t,n),s=await Ml(i,o,r.force||!1,e);e.stop(),wt(s)}catch(t){throw e.stop(),t}}function Rl(r){let{resolvedPath:e,resolvedProject:t}=bt(r.path,r.project,r.agent);return t&&Ie(t,"Project directory"),e&&Ie(e,"Directory"),{resolvedPath:e,resolvedProject:t}}async function Ol(r,e){let t=new Re;try{t.start("Removing skill...");let{resolvedPath:n,resolvedProject:i}=Rl(e);t.stop();let o=await Nl(e,r,n,i);t.stop(),wt(o)}catch(n){throw t.stop(),n}}function No(r,e=""){if(r.length===0)throw new Error(`No agents found. Please install an AI agent (cursor, opencode, etc.) ${e}`)}async function Kt(r,e){let t=[];for(let n of e){let i=n.type==="agent"?await To(r,n.agent):await xo(r,n.project,n.agent);t.push(i)}return t}async function Nl(r,e,t,n){if(t)return[await Mo(e,t)];if(n&&r.agent){let a=(await yt(r.agent)).map(c=>({type:"projectAgent",agent:c,project:n}));return Kt(e,a)}if(n){let s=await vt();No(s);let a=s.map(c=>({type:"projectAgent",agent:c,project:n}));return Kt(e,a)}if(r.agent){let a=(await yt(r.agent)).map(c=>({type:"agent",agent:c}));return Kt(e,a)}let i=await vt();No(i,"or use --path for a custom location.");let o=i.map(s=>({type:"agent",agent:s}));return Kt(e,o)}var Pt=new El("skills").description("Manage HarmonyOS skills");Pt.command("list").description("List all available HarmonyOS skills").option("-l, --long","Show detailed information including description and installation status").action(async r=>{let e=new Re;try{e.start("Fetching skills...");let t=await Yt(),n=await wr(t);if(n.length===0){e.stop(),console.log(Ho("No skills available"));return}e.succeed(`Fetched ${n.length} skills`);for(let i of n)if(r.long){console.log(Lo(i.enName)),console.log(jo(i.description));let o=go(i.enName);o.length>0&&console.log(Dl(`Installed for: ${o.join(", ")}`)),console.log()}else console.log(i.enName)}catch(t){e.stop(),console.error(St(t.message)),process.exit(1)}});Pt.command("find <keyword>").description("Search skills by keyword").action(async r=>{let e=new Re;try{e.start("Searching skills...");let t=await Yt(),n=await br(r,t);if(n.length===0){console.log(Ho(`No skills found matching '${r}'`)),e.stop();return}e.succeed(`Found ${n.length} skills`);for(let i of n)console.log(Lo(i.enName)),console.log(jo(i.description)),console.log()}catch(t){e.stop(),console.error(St(t.message)),process.exit(1)}});Pt.command("add").description("Install skills to AI agents").option("--all","Install all available skills").option("--agent <agents>","Target agents, comma-separated; installs to all available agents if omitted").option("--skill <skill-name>","Name of the skill to install").option("-f, --force","Overwrite an existing skill installation").option("--project <path>","Project root directory to install the skill into").option("--path <path>","Path to install the skill directly (cannot be used with --project or --agent)").action(async r=>{try{await xl(r)}catch(e){console.error(St(e.message)),process.exit(1)}});Pt.command("remove").description("Remove an installed skill from AI agents").requiredOption("--skill <skill-name>","Name of the skill to remove").option("--agent <agents>","Target agents, comma-separated; removes from all available agents if omitted").option("--project <path>","Project root directory to remove the skill from").option("--path <path>","Path to remove the skill from").action(async r=>{try{await Ol(r.skill,r)}catch(e){console.error(St(e.message)),process.exit(1)}});var Fo=Pt;import{Command as Hl,InvalidArgumentError as _o}from"commander";import{cyan as Zt}from"colorette";function Oe(r,e){if(r.exitCode===0)return null;let t=r.stderr||r.stdout,n=Ue(t);return n==="transient"?new Error(`${e}: device communication channel is not ready yet. Please retry in a few seconds.`):n==="fatal"?new Error(`${e}: ${t.trim()}`):null}var Tr=[800,1500,2500];function Ll(r){return new Promise(e=>setTimeout(e,r))}var Xt=class{toolProvider;deviceManager;constructor(e){this.toolProvider=e,this.deviceManager=z.from(e)}createFollowLineHandler(e){return(t,n)=>{let i=e.keyword?t.filter(o=>o.includes(e.keyword)):t;if(n!=="stderr")for(let o of i)console.log(o)}}findDeviceByArg(e,t){return e.find(n=>n.serial===t||n.name===t)}formatConnectedDeviceList(e){return e.map(t=>` - ${t.name} (${t.serial})`).join(`
|
|
1222
|
+
`)}async loadConnectedDevicesByName(){let e=await this.getConnectedDevices();if(e)return e}async selectDevice(e){let t=await this.getConnectedDeviceSerials();if(!t)return;if(!e&&t.length===1){let i=t[0];return g(Zt(`Using device serial: ${i}`)),i}if(e&&t.includes(e))return g(Zt(`Using device serial: ${e}`)),e;let n=await this.loadConnectedDevicesByName();if(n){if(e){let i=this.findDeviceByArg(n,e);if(i)return g(Zt(`Using device: ${i.name} (${i.serial})`)),i.serial;let o=this.formatConnectedDeviceList(n);throw new Error(`Device '${e}' not found.
|
|
1223
|
+
Available devices:
|
|
1224
|
+
${o}`)}if(n.length===1){let i=n[0];return g(Zt(`Using device: ${i.name} (${i.serial})`)),i.serial}throw new Error("Multiple devices found. Please specify a target device using `--device <name>` or `--device <serial>`.\nAvailable devices:\n"+this.formatConnectedDeviceList(n))}}async getConnectedDeviceSerials(){let e=await this.deviceManager.listDevices();if(e.length===0)throw new Error("No active devices found. Please start an emulator or connect a physical device.");return e.map(t=>t.serial)}async getConnectedDevices(){let e=await this.deviceManager.listDevicesWithName();if(e.length===0)throw new Error("No active devices found. Please start an emulator or connect a physical device.");return e}async getPidForBundle(e,t,n){g(`Trying to get PID for bundle: ${n}`),E.assertBundleName(n);let i=await be(e,["-t",t,"shell","pidof",n]),o=Oe(i,"Failed to look up PID");if(o)throw o;if(i.exitCode===0&&i.stdout.trim()){let s=i.stdout.trim(),a=s.split(/\s+/)[0]||s;return g(`Found PID for ${n}: ${a}`),a}return g(`No PID found for bundle: ${n}`),null}async resizeHilogBuffer(e,t,n){g(`Setting hilog buffer size to: ${n}`);let i=await be(e,["-t",t,"shell","hilog","-G",n]),o=Oe(i,"Failed to resize hilog buffer");if(o)throw o;i.exitCode!==0&&console.error(`Failed to resize hilog buffer: ${i.stderr||i.stdout}`)}buildHilogCommand(e,t,n,i){let o=this.buildHilogShellCommand(n,i);return[e,["-t",t,"shell",o]]}buildHilogShellCommand(e,t){let n=["hilog"];return e.isFollow||n.push("-x"),e.tag&&(E.assertHilogToken(e.tag,"tag"),n.push("-T",e.tag)),e.level&&(E.assertHilogLevel(e.level),n.push("-L",e.level)),e.domain&&(E.assertHilogToken(e.domain,"domain"),n.push("-D",e.domain)),t&&n.push("-P",t),e.keyword&&(E.assertHilogKeyword(e.keyword),n.push("-e",E.quotePosixShellArg(e.keyword))),n.join(" ")}async followHilog(e,t,n,i,o){let a=await Pi(e,t,{onData:n,onError:i,onClose:o});return{stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode}}async runHilogWithSpawnRetry(e,t,n,i,o){let s=1+Tr.length,a={stdout:"",stderr:"",exitCode:-1};for(let c=0;c<s;c++){a=await this.followHilog(e,t,n,i,o);let d=a.exitCode===0?a.stdout:a.stderr||a.stdout;if(Ue(d)!=="transient"||c>=s-1)return a;g(`hdc transient failure on \`${t.join(" ")}\`: retrying in ${Tr[c]}ms`),await Ll(Tr[c])}return a}async printTailSnapshotIfNeeded(e,t,n,i){if(!n.tail&&!n.fromSeconds&&!n.toSeconds)return;let o={...n,isFollow:!1},[,s]=this.buildHilogCommand(e,t,o,i),a=await be(e,s),c=Oe(a,"Failed to get hilog");if(c)throw c;if(a.exitCode!==0&&a.stderr)throw new Error(`Failed to get hilog: ${a.stderr}`);let d=E.filterLogsByRelativeWindow(a.stdout||a.stderr,n.fromSeconds,n.toSeconds);d=E.getLastLines(d,n.tail),d.trim()&&console.log(d)}async getHilogOnce(e,t,n,i){let[o,s]=this.buildHilogCommand(e,t,n,i);g(`Ready to execute hilog command: ${o} ${s.join(" ")}`);let a=await this.runHilogWithSpawnRetry(o,s,()=>{},b=>{g(`hilog once stream error callback: ${b.message}`)},()=>{}),c=Oe(a,"Failed to get hilog");if(c)throw c;if(a.exitCode!==0&&a.stderr)throw new Error(`Failed to get hilog: ${a.stderr}`);let d=a.stdout||a.stderr,u=E.filterLogsByRelativeWindow(d,n.fromSeconds,n.toSeconds);return u=E.getLastLines(u,n.tail),u}async runHilogFollow(e,t,n,i){await this.printTailSnapshotIfNeeded(e,t,n,i);let[o,s]=this.buildHilogCommand(e,t,n,i);g(`Ready to execute hilog command which contain follow and tail: ${o} ${s.join(" ")}`);let a=await this.runHilogWithSpawnRetry(o,s,this.createFollowLineHandler(n),d=>{console.error(d.message)},()=>{}),c=Oe(a,"Failed to follow hilog");if(c)throw c;if(a.exitCode!==0&&a.stderr)throw new Error(`Failed to follow hilog: ${a.stderr}`);return""}async getHilog(e,t){let n=this.toolProvider.hdcPath,i=t.bundleName?await this.getPidForBundle(n,e,t.bundleName):void 0;if(t.bundleName&&!i)throw new Error(`No running process found for bundle '${t.bundleName}'. Make sure the app is launched on the device before fetching logs.`);return t.logSize&&await this.resizeHilogBuffer(n,e,t.logSize),t.isFollow?await this.runHilogFollow(n,e,t,i||""):await this.getHilogOnce(n,e,t,i||"")}async getCrashLog(e,t){g(`Fetching crash logs from device: ${e}`);let n=this.toolProvider.hdcPath,i=await this.listCrashLogs(n,e,t);if(i.length===0)return t?`No crash logs found for bundle '${t}'.`:"No crash logs found.";let s=[...i].sort((c,d)=>{let u=c.split("-").pop()||"";return(d.split("-").pop()||"").localeCompare(u)})[0],a=await this.fetchCrashLogContent(n,e,s);return`--- Latest Crash Log File: ${s} ---${a}`}async listCrashLogs(e,t,n){let i=["-t",t,"shell","hidumper","-s","1201","-a","-p Faultlogger"];g(`Executing command: ${e} ${i.join(" ")}`);let o=await be(e,i),s=Oe(o,"Failed to list crash logs");if(s)throw s;if(o.exitCode!==0)throw new Error(`Failed to list crash logs: ${o.stderr||o.stdout}`);return g(`Crash logs list output:
|
|
1225
|
+
${o.stdout}`),o.stdout.split(`
|
|
1226
|
+
`).map(c=>c.trim()).filter(c=>c.length>0).filter(c=>{try{return E.assertCrashFilename(c),!0}catch{return!1}}).filter(c=>n?c.toLowerCase().includes(n.toLowerCase()):!0)}async fetchCrashLogContent(e,t,n){g(`Fetching latest crash log file: ${n}`);let i=["-t",t,"shell","hidumper","-s","1201","-a",`-p Faultlogger -f ${n}`];g(`Executing command: ${e} ${i.join(" ")}`);let o=await be(e,i),s=Oe(o,"Failed to fetch crash log content");if(s)throw s;return o.exitCode!==0&&o.stderr&&console.error(`Warning: Failed to fetch crash log content: ${o.stderr}`),o.stdout+o.stderr}};import{cyan as Mr,red as Wo}from"colorette";import jl from"ora";function Fl(r){try{return E.parsePositiveInteger(r,"tail")}catch{throw new _o("tail must be a positive integer")}}function $o(r,e){try{return E.parseDurationToSeconds(r,e)}catch{throw new _o(`${e} must be like 30s, 5m or 2.5m (s/m only; seconds/default must be integers)`)}}function $l(r){if(r.to&&r.follow)throw new Error("--to cannot be used with --follow");E.assertRelativeTimeRange(r.from,r.to)}async function _l(r,e,t,n,i){return t.crash?await r.getCrashLog(e,t.bundleName):await r.getHilog(e,{level:t.level,bundleName:t.bundleName,keyword:t.keyword,isFollow:!!t.follow,tail:t.tail,fromSeconds:n,toSeconds:i})}function Wl(r,e,t,n){let i=E.filterLogsByRelativeWindow(r,t,n);return e.tail?E.getLastLines(i,e.tail):i}var Ul=new Hl("log").description("Obtain device application logs").configureOutput({outputError:(r,e)=>e(Wo(r))}).option("--device <device>","Target device (name or serial)").option("--crash","Only obtain the crash log").option("--level <level>","Log level filter: D, I, W, E, F").option("--bundle-name <bundle-name>","Filter by application bundle name").option("--keyword <keyword>","Keyword filter").option("--tail <num>","Show only the latest N log lines",Fl).option("--from <start>","Start offset from now, e.g. 30s, 5m, 2.5m, or 120",r=>$o(r,"from")).option("--to <end>","End offset from now, e.g. 30s, 5m, 2.5m, or 120",r=>$o(r,"to")).option("--follow","Follow the log stream in real-time.").action(async r=>{await Bl(r)});async function Bl(r){let e=jl({text:"Preparing log request\u2026",color:"cyan"}),t=()=>{e.stop(),e.clear()};try{e.start(),$l(r);let n=r.from,i=r.to,o=await N.new(),s=new Xt(o),a=await s.selectDevice(r.device);a||(t(),process.exit(1)),g(Mr(`deviceId: ${a}`)),g(Mr(`type: ${r.crash?"Crash logs":"Common logs"}`)),g(Mr("Obtaining logs ...")),e.text="Fetching logs\u2026",r.follow&&t();let c=await _l(s,a,r,n,i);t(),r.crash&&c&&(c=Wl(c,r,n,i)),c&&console.log(c)}catch(n){t(),console.error(Wo(n.message)),process.exit(1)}}var Uo=Ul;import Dt from"path";import me from"fs";import Or from"process";import Jo from"os";import{Command as td}from"commander";import{green as qo,red as xr,cyan as nd,yellow as Rr}from"colorette";import F from"fs-extra";import T from"path";import*as Bo from"os";import{fileURLToPath as zl}from"url";var Vl={17:{sdkVersion:"5.0.5(17)",modelVersion:"5.0.5"},18:{sdkVersion:"5.1.0(18)",modelVersion:"5.1.0"},19:{sdkVersion:"5.1.1(19)",modelVersion:"5.1.1"},20:{sdkVersion:"6.0.0(20)",modelVersion:"6.0.0"},21:{sdkVersion:"6.0.1(21)",modelVersion:"6.0.1"},22:{sdkVersion:"6.0.2(22)",modelVersion:"6.0.2"},23:{sdkVersion:"6.1.0(23)",modelVersion:"6.1.0"},24:{sdkVersion:"6.1.1(24)",modelVersion:"6.1.1"}},ql=["build-profile.json5","AppScope/resources/base/media/layered_image.json","entry/src/main/resources/base/media/layered_image.json"];function Yl(){let r=import.meta.url,e=zl(r);if(e.includes("dist")){let o=T.dirname(e),s=T.dirname(o);return T.join(s,"templates","application")}let t=T.dirname(e),n=T.dirname(t),i=T.dirname(n);return T.join(i,"templates","application")}function zo(r,e){F.mkdirSync(e,{recursive:!0});for(let t of F.readdirSync(r,{withFileTypes:!0})){let n=T.join(r,t.name),i=T.join(e,t.name);if(t.isDirectory()){zo(n,i);continue}F.existsSync(i)||(F.mkdirSync(T.dirname(i),{recursive:!0}),F.copyFileSync(n,i))}}function Et(r,e){let t=F.readFileSync(r,"utf-8"),n=t;for(let[i,o]of e)n=n.replaceAll(i,o);n!==t&&F.writeFileSync(r,n,"utf-8")}function Gl(r,e){if(e===22)return;let t=Vl[e];t&&(Et(T.join(r,"build-profile.json5"),[["6.0.2(22)",t.sdkVersion]]),Et(T.join(r,"hvigor","hvigor-config.json5"),[["6.0.2",t.modelVersion]]),Et(T.join(r,"oh-package.json5"),[["6.0.2",t.modelVersion]]))}function Jl(r){return ql.filter(t=>!F.existsSync(T.join(r,t))).length===0}function Kl(){return Buffer.from([137,80,78,71,13,10,26,10,0,0,0,13,73,72,68,82,0,0,0,1,0,0,0,1,8,2,0,0,0,144,119,83,222,0,0,0,12,73,68,65,84,8,215,99,248,255,255,255,0,5,254,2,254,0,0,0,0,73,69,78,68,174,66,96,130])}function Zl(r){return Bo.platform()==="darwin"?T.join(r,"Contents","plugins","codegenie-plugin","previewProjectTemplate"):T.join(r,"plugins","codegenie-plugin","previewProjectTemplate")}function Xl(r,e){let t=Zl(e);if(!F.existsSync(t))return!1;let n=[["AppScope/resources/base/media/background.png","AppScope/resources/base/media/background.png"],["AppScope/resources/base/media/foreground.png","AppScope/resources/base/media/foreground.png"],["entry/src/main/resources/base/media/background.png","entry/src/main/resources/base/media/background.png"],["entry/src/main/resources/base/media/foreground.png","entry/src/main/resources/base/media/foreground.png"],["entry/src/main/resources/base/media/startIcon.png","entry/src/main/resources/base/media/startIcon.png"]];for(let[i,o]of n){let s=T.join(t,i),a=T.join(r,o);F.existsSync(s)&&(F.mkdirSync(T.dirname(a),{recursive:!0}),F.copyFileSync(s,a))}return!0}function Ql(r){let e=Kl(),t=["AppScope/resources/base/media/background.png","AppScope/resources/base/media/foreground.png","entry/src/main/resources/base/media/background.png","entry/src/main/resources/base/media/foreground.png","entry/src/main/resources/base/media/startIcon.png"];for(let n of t){let i=T.join(r,n);F.mkdirSync(T.dirname(i),{recursive:!0}),F.writeFileSync(i,e)}}function ed(r,e){e&&Xl(r,e)||Ql(r)}function Vo(r,e,t,n,i){let o=Yl();if(!F.existsSync(o))throw new Error(`Template directory not found: ${o}`);F.mkdirSync(r,{recursive:!0}),zo(o,r),ed(r,i),Et(T.join(r,"AppScope","resources","base","element","string.json"),[["MyApplication",e]]),Et(T.join(r,"AppScope","app.json5"),[["com.example.myapplication",t]]),Gl(r,n);let s=Jl(r);if(!s)throw new Error("Template integrity check failed");return{projectRoot:r,appName:e,bundleName:t,apiLevel:n,verified:s}}function rd(r){if(r.length<1||r.length>200)throw new Error(`App name length must be 1-200 characters. Current: ${r.length}`);if(!/^[a-zA-Z][a-zA-Z0-9_]*$/.test(r))throw new Error("App name must start with a letter (a-z, A-Z) and contain only letters, digits, and underscores")}function id(r){if(r.length<7||r.length>128)throw new Error(`Bundle name length must be 7-128 characters. Current: ${r.length}`);if(r.includes(".."))throw new Error('Bundle name cannot contain consecutive dots (e.g., "com..example")');let e=r.split(".");if(e.length<3)throw new Error("Bundle name must contain at least 3 segments separated by dots");let t=/^[a-zA-Z0-9_]+$/;for(let n=0;n<e.length;n++){let i=e[n];if(!t.test(i))throw new Error(`Segment "${i}" contains invalid characters. Only letters, digits, and underscores allowed`);if(n===0){if(!/^[a-zA-Z]/.test(i))throw new Error(`First segment "${i}" must start with a letter (a-z, A-Z)`)}else if(!/^[a-zA-Z0-9]/.test(i))throw new Error(`Segment "${i}" must start with a letter or digit`);if(!/[a-zA-Z0-9]$/.test(i))throw new Error(`Segment "${i}" must end with a letter or digit`)}}function Ko(r){if(Jo.platform()==="win32"){let t=r.replace(/\\/g,"/");return t=t.replace(/\/+/g,"/"),t}return r.replace(/\/+/g,"/")}function Yo(r){if(r.length===0)throw new Error("Project path cannot be empty");if(r.length>120)throw new Error(`Project path cannot exceed 120 characters (current: ${r.length})`);let e=Jo.platform();if(!(e==="win32"?/^[a-zA-Z0-9._\-:\\/]+$/:/^[a-zA-Z0-9._\-/]+$/).test(r)){let o=e==="win32"?"letters, digits, dots, underscores, hyphens, colons, slashes (/) or backslashes (\\)":"letters, digits, dots, underscores, hyphens or slashes (/)";throw new Error(`Project path can only contain ${o}`)}let n=Ko(r);if(/[\u4e00-\u9fff]/.test(n))throw new Error("Project path cannot contain Chinese characters");if(n.endsWith("."))throw new Error("Project path cannot end with a dot (.)")}function od(r){let e=r,t=Dt.parse(r).root;for(;e!==t;){if(me.existsSync(e))return e;e=Dt.dirname(e)}return me.existsSync(t)?t:null}function Go(r){let e=od(r);if(!e)throw new Error(`No existing parent directory found for '${r}'. Cannot create project directory.`);try{me.accessSync(e,me.constants.W_OK)}catch{throw new Error(`No write permission for directory '${e}'. Cannot create project here.`)}let t=Dt.join(e,`.deveco_write_test_${Date.now()}`);try{me.writeFileSync(t,"test"),me.unlinkSync(t)}catch{throw new Error(`No write permission for directory '${e}'. Cannot create project here.`)}}function sd(r){return`com.example.${r.toLowerCase()}`}function ad(r,e){if(e){let i=Ko(e),o=Dt.resolve(i);if(me.existsSync(o)){if(me.readdirSync(o).length>0)throw new Error(`Directory '${o}' is not empty. Cannot create project in non-empty directory.`)}else Go(o);return o}let t=Or.cwd(),n=Dt.join(t,r);if(me.existsSync(n))throw new Error(`Directory '${n}' already exists. Cannot create project here.`);return Go(n),n}function cd(r,e){let t=e?.getMaxApiLevel(),n=23;if(r.apiLevel){let i=Number(r.apiLevel);if(!Number.isInteger(i)||i<17)throw new Error(`Invalid API level ${r.apiLevel}. Minimum supported is API 17`);if(t!==void 0){if(i>t)throw new Error(`Invalid API level ${r.apiLevel}. Your SDK supports API 17-${t}`)}else if(i>n){let o=O()?"commandLineTools":"DevEco Studio";throw new Error(`Invalid API level ${r.apiLevel}. Without ${o}, supported range is API 17-${n}`)}return i}return t!==void 0?t:23}async function ld(){try{return await N.new()}catch(r){let e=r,t=O()?"Toolchain not found":"DevEco Studio not found";console.error(Rr(`${t}: ${e.message}`)),O()?console.log(Rr("Please install commandLineTools. Using placeholder API level instead.")):console.log(Rr("Using placeholder API level instead."));return}}var dd=new td("create").description("Scaffold a new HarmonyOS application project").option("--project-path <path>","Project directory path (default: ./<app-name>)").option("--app-name <name>","Application name").option("--bundle-name <bundle>","Bundle name (auto-derived as com.example.<app-name> if omitted)").option("--api-level <level>","API level (auto-detected from SDK if omitted; minimum: 17)").action(async r=>{try{r.appName||(console.error(xr("Error: --app-name is required")),Or.exit(1));let e=r.appName;rd(e);let t=r.bundleName||sd(e);id(t),r.projectPath&&Yo(r.projectPath);let n=ad(e,r.projectPath);Yo(n),console.log(nd("Initializing project...")),console.log(`Project path: ${n}`),console.log(`App name: ${e}`),console.log(`Bundle name: ${t}`);let i=await ld(),o=cd(r,i);console.log(`API level: ${o}`);let s=i?.devecoStudioPath,a=Vo(n,e,t,o,s);console.log(`
|
|
1227
|
+
`+qo("Project created successfully!")),console.log(`Project root: ${a.projectRoot}`),console.log(`App name: ${a.appName}`),console.log(`Bundle name: ${a.bundleName}`),console.log(`API level: ${a.apiLevel}`),console.log(qo("Template integrity check passed"))}catch(e){let t=e;console.error(xr(`
|
|
1228
|
+
Failed to create project`)),console.error(xr(t.message)),Or.exit(1)}}),Zo=dd;import{Command as yd}from"commander";import{red as vd,cyan as is}from"colorette";import ud from"fs";import Qt from"path";import{cyan as pd}from"colorette";import*as en from"smol-toml";var Xe=ud.promises;async function hd(r){try{let e=await Xe.readFile(r,"utf8");return e.trim()===""?{}:JSON.parse(e)}catch(e){if(e.code==="ENOENT")return{};throw new Error(`Failed to read config file ${r}: ${e.message}`,{cause:e})}}async function md(r){try{let e=await Xe.readFile(r,"utf8");return e.trim()===""?{}:en.parse(e)}catch(e){if(e.code==="ENOENT")return{};throw new Error(`Failed to read TOML config file ${r}: ${e.message}`,{cause:e})}}async function fd(r,e){let t=Qt.dirname(r);await Xe.mkdir(t,{recursive:!0});let n=JSON.stringify(e,null,2);await Xe.writeFile(r,n,"utf8")}async function gd(r,e){let t=Qt.dirname(r);await Xe.mkdir(t,{recursive:!0});let n=en.stringify(e);await Xe.writeFile(r,n,"utf8")}function Xo(r,e,t){let n=r[e];return!n||typeof n!="object"?!1:t in n}function Qo(r,e,t,n,i){(!r[e]||typeof r[e]!="object")&&(r[e]={});let o=r[e];return t in o&&!i?!1:(o[t]=n,!0)}async function es(r,e){return r.format==="codex"?md(e):hd(e)}async function ts(r,e,t){return r.format==="codex"?gd(e,t):fd(e,t)}async function ns(r,e,t=!1){let n=Ee[r];if(!n)return{success:!1,error:`Unknown agent: ${r}. Supported agents: ${Object.keys(Ee).join(", ")}`};if(!n.supportsGlobal)return{success:!1,error:`${n.displayName} does not support global MCP configuration. Use --project to configure project-level MCP.`};try{let i=await es(n,n.globalConfigPath);if(Xo(i,n.mcpServersKey,ae)&&!t)return console.log(`MCP server ${ae} already configured in ${n.globalConfigPath}`),{success:!0,skipped:!0,configPath:n.globalConfigPath,agentName:r,installType:"global"};let o=qt(n,void 0);return Qo(i,n.mcpServersKey,ae,o,t),await ts(n,n.globalConfigPath,i),console.log(`MCP server ${ae} configured in ${n.globalConfigPath}`),{success:!0,configPath:n.globalConfigPath,agentName:r,installType:"global"}}catch(i){return{success:!1,error:`Failed to configure MCP for ${n.displayName}: ${i.message}`}}}async function Nr(r,e,t=!1){let n=Ee[r];if(!n)return{success:!1,error:`Unknown agent: ${r}. Supported agents: ${Object.keys(Ee).join(", ")}`};let i=Qt.isAbsolute(n.projectConfigPath)?n.projectConfigPath:Qt.join(e,n.projectConfigPath);try{let o=await es(n,i);if(Xo(o,n.mcpServersKey,ae)&&!t)return console.log(`MCP server ${ae} already configured in ${i}`),{success:!0,skipped:!0,configPath:i,agentName:r,installType:"project"};let s=qt(n,e);return Qo(o,n.mcpServersKey,ae,s,t),await ts(n,i,o),console.log(`MCP server ${ae} configured in ${i}`),{success:!0,configPath:i,agentName:r,installType:"project"}}catch(o){return{success:!1,error:`Failed to configure MCP for ${n.displayName}: ${o.message}`}}}function rs(r){let e=r.filter(i=>i.success&&!i.skipped).length,t=r.filter(i=>i.skipped).length,n=r.filter(i=>!i.success).length;console.log(),console.log(pd("Finished:")),console.log(` Success: ${e}`),console.log(` Skipped: ${t}`),console.log(` Failed: ${n}`);for(let i of r)!i.success&&i.error&&console.error(` - ${i.agentName??"unknown"}: ${i.error}`);n>0&&(process.exitCode=1)}var Lr="deveco-cli";async function wd(r,e,t){let n=[];if(r.customPath){let i=await ko(Lr,e,r.customPath,t.force);return n.push(i),n}for(let{project:i,agent:o}of r.projectAgents){let s=await Ao(Lr,e,i,o,t.force);n.push(s)}for(let i of r.agents){let o=await Co(Lr,e,i,t.force);n.push(o)}return n}async function bd(r,e,t){let n=[];for(let{project:i,agent:o}of r.projectAgents){let s=await Nr(o,i,t);n.push(s)}for(let i of r.agents){let o=await Nr(i,e,t);n.push(o)}return n}async function Sd(r,e){let t=[];for(let n of r){if(!Ee[n])continue;let o=await ns(n,process.cwd(),e);t.push(o)}return t}async function Pd(r,e,t){if(t.agent&&t.agent.split(",").map(d=>d.trim()).includes("qoder"))throw new Error("Qoder does not support MCP configuration via DevEco CLI. Use other supported agents instead.");let n=t.force??!1,i=r.projectAgents.filter(c=>c.agent!=="qoder"),o=r.agents.filter(c=>c!=="qoder"),s={...r,projectAgents:i,agents:o},a=e?await bd(s,e,n):await Sd(s.agents,n);a.length>0&&(console.log(is("MCP Configuration:")),rs(a))}async function Ed(r){if(r.skill&&r.mcp)throw new Error("Cannot use --skill and --mcp together. Use --skill for skill installation only, or --mcp for MCP configuration only.");let{resolvedPath:e,resolvedProject:t}=bt(r.path,r.project,r.agent);t&&Ie(t,"Project directory",r.force),e&&Ie(e,"Directory",r.force);let n=await Jt(r,e,t);if(r.mcp){await Pd(n,t,r);return}let i=Ro(),o=await wd(n,i,r);console.log(),o.length>0&&(console.log(is("Skill Installation:")),wt(o))}var Dd=new yd("init").description("Install the deveco-cli skill or configure the deveco-mcp server into AI agents").option("--agent <agents>","Target agents, comma-separated; installs to all available agents if omitted").option("--project <path>","Project root directory to install the skill or MCP config into").option("--path <path>","Path to install the skill directly (cannot be used with --project or --agent)").option("--skill","Install the deveco-cli skill only (same as default behavior; explicit for symmetry with --mcp)").option("--mcp","Configure the deveco-mcp server (syntax checking for .ets and C/C++) only; no skill installation").option("-f, --force","Overwrite an existing skill / MCP configuration").action(async r=>{try{await Ed(r)}catch(e){console.error(vd(e.message)),process.exit(1)}}),os=Dd;import{Command as _u}from"commander";import{McpServer as ju}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as Fu}from"@modelcontextprotocol/sdk/server/stdio.js";import*as ut from"path";import{z as ei}from"zod";var tn=class{tools=new Map;add(e,t){return this.tools.set(e.name,{definition:e,handler:t}),this}getAll(){return Array.from(this.tools.values())}registerToServer(e){for(let{definition:t,handler:n}of this.getAll())e.registerTool(t.name,{description:t.description,inputSchema:t.inputSchema},(async i=>n(i)))}};function Hr(){return new tn}import*as we from"fs";import*as ne from"path";import{z as Zr}from"zod";import D from"fs";import*as nn from"os";import*as S from"path";import Id from"json5";var jr="Huawei";var Cd=3,ls=3,ss="DevEco Studio",ds={DevEcoStudio:"deveco_studio"};function Fr(r){if(!D.existsSync(r)||!D.statSync(r).isDirectory())return!1;let e=D.existsSync(S.join(r,"build-profile.json5")),t=D.existsSync(S.join(r,"hvigorfile.js"))||D.existsSync(S.join(r,"hvigorfile.ts"));if(!e||!t)return!1;try{let n=D.readFileSync(S.join(r,"build-profile.json5"),"utf-8");return Id.parse(n).app!==void 0}catch{return!1}}function us(r,e,t){if(e>=t)return null;let n=Ad(r),i=kd(n);if(i)return i;for(let o of n){let s=us(o,e+1,t);if(s)return s}return null}function Ad(r){try{let e=D.readdirSync(r,{withFileTypes:!0}),t=[];for(let n of e)n.isDirectory()&&t.push(S.join(r,n.name));return t}catch{return[]}}function kd(r){for(let e of r)if(Fr(e))return e;return null}function fe(r){if(!r||r.trim()==="")return null;let e=S.resolve(r),t;try{t=D.realpathSync(e)}catch{t=e}if(!D.existsSync(t))return null;if(Fr(t))return t;let n=t;for(let i=1;i<=3;i++){let o=S.dirname(n);if(o===n)break;if(Fr(o))return o;n=o}if(D.statSync(t).isDirectory()){let i=us(t,0,Cd);if(i)return i}return null}function ps(r){if(process.platform==="linux")return null;let e=r??Ne();if(!e)return null;let t;if(process.platform==="win32")t=S.join(e,"plugins","openharmony");else if(process.platform==="darwin")t=S.join(e,"contents","plugins","openharmony");else return null;let n=S.join(t,"ace-server","out","index.js");return D.existsSync(n)?t:null}var Td=["sdk","default","openharmony","native","llvm","bin","clangd"],$r=[".idea",".deveco","cxx","compile_commands.json"];function Md(r){return process.platform==="darwin"&&r.endsWith(".app")?S.join(r,"Contents"):r}function as(r){let e=new Set,t=[r,Md(r)];for(let n of t){let i=S.join(n,...Td);e.add(process.platform==="win32"?i+".exe":i)}return[...e]}function hs(r){let e=[],t=process.env.DEVECO_HOME??process.env.DEVECO_PATH;if(t&&t.trim()){for(let i of as(t.trim()))if(e.push(i),D.existsSync(i))return i}let n=r??Ne();if(n){for(let i of as(n))if(e.push(i),D.existsSync(i))return i}return null}function rn(r){return S.join(r,...$r)}function Ne(){if(process.platform==="win32"){let r=[S.join("C:\\Program Files",jr,ss),S.join("C:\\Program Files (x86)",jr,ss)];return cs(r)}if(process.platform==="darwin"){let r=["/Applications/DevEco Studio.app",S.join(process.env.HOME??"","Applications","DevEco Studio.app")];return cs(r)}return null}function cs(r){for(let e of r)if(D.existsSync(e))return e;return null}function ce(r){return process.platform==="darwin"?S.join(r,"Contents"):r}function xd(r){if(!r||!D.existsSync(r)||!ms(r))return!1;let e=ce(r);return[S.join(e,"plugins","openharmony"),S.join(e,"sdk"),S.join(e,"tools")].some(n=>D.existsSync(n))}function ms(r){try{return D.statSync(r).isDirectory()}catch{return!1}}function _r(r,e){return!r||!D.existsSync(r)?!1:e===ds.DevEcoStudio?xd(r):!1}function on(r,e=ds.DevEcoStudio){if(!r)return"";if(_r(r,e))return r;let t=Rd(r,e);if(t)return t;let n=Od(r,e);return n||r}function Rd(r,e){let t=r;for(let n=0;n<ls;n++){let i=S.dirname(t);if(!i||i===t)break;if(_r(i,e))return i;t=i}return null}function Od(r,e){if(!D.existsSync(r)||!ms(r))return null;let t=[{p:r,depth:0}];for(;t.length>0;){let{p:n,depth:i}=t.shift();if(i>=ls)continue;let o=Nd(n,i,e,t);if(o)return o}return null}function Nd(r,e,t,n){let i;try{i=D.readdirSync(r,{withFileTypes:!0})}catch{return null}for(let o of i){if(!o.isDirectory())continue;let s=S.join(r,o.name);if(_r(s,t))return s;n.push({p:s,depth:e+1})}return null}function fs(r){return new Promise(e=>setTimeout(e,r))}var Ld=new Set(["c","cc","cpp","cxx","c++","h","hh","hpp","hxx","h++","ipp","ixx","inl","inc","tpp"]);function sn(r){let e=S.extname(r).replace(/^\./,"").toLowerCase();return e.length>0&&Ld.has(e)}function gs(r){return S.extname(r).replace(/^\./,"").toLowerCase()==="c"?"c":"cpp"}function le(r){let e=r.replace(/\\/g,"/");return process.platform==="win32"&&/^[a-zA-Z]:/.test(e)&&(e=e[0].toUpperCase()+e.slice(1)),e}function Wr(r){return le(r)}function Le(r){let e=Wr(r);return e.startsWith("/")?`file://${e}`:`file:///${e}`}function It(r){try{let e=new URL(r);if(e.protocol==="file:"){let t=decodeURIComponent(e.pathname);return process.platform==="win32"&&/^\/[a-zA-Z]:/.test(t)&&(t=t.slice(1)),Le(t)}}catch{}return r}function ys(r){let e=[],t=r.lastIndexOf("file:/");if(t>=0){let n=r.slice(t).replace(/^file:\/+/,"");if(n){let i=n.startsWith("/")?`file://${n}`:`file:///${n}`,o=It(i);o!==r&&o!==It(r)&&e.push(o)}}return e}function an(){if(process.platform==="win32"){let r=process.env.LOCALAPPDATA??S.join(nn.homedir(),"AppData","Local");return S.join(r,"devecocli-mcp-server","logs")}return process.platform==="darwin"?S.join(nn.homedir(),"Library","Logs","devecocli-mcp-server"):S.join(nn.homedir(),".local","share","devecocli-mcp-server","logs")}function vs(r,e){let t=Hd(e),n=jd(t,r);if(n!==null)return n;let i=Date.now(),s=`${r.replace(/:/g,"\\:")}=${i}`,a=Fd(t,r,s);return $d(e,a),i}function Hd(r){let e;try{e=D.readFileSync(r,"utf8")}catch{e=""}return e.length>0?e.split(/\r?\n/):[]}function jd(r,e){for(let t of r){let n=t.indexOf("=");if(n<=0||t.slice(0,n).replace(/\\:/g,":")!==e)continue;let o=parseInt(t.slice(n+1),10);return Number.isFinite(o)&&o>0?o:null}return null}function Fd(r,e,t){let n=!1,i=r.map(o=>{if(n)return o;let s=o.indexOf("=");return s<=0?o:o.slice(0,s).replace(/\\:/g,":")===e?(n=!0,t):o});return n||i.push(t),i}function $d(r,e){try{D.mkdirSync(S.dirname(r),{recursive:!0})}catch{}try{D.writeFileSync(r,e.join(`
|
|
1229
|
+
`)+`
|
|
1230
|
+
`,"utf8")}catch{}}function Ur(r,e,t="[Cleanup]"){try{let n=S.dirname(r);if(!D.existsSync(n))return;let i=Date.now();for(let o of D.readdirSync(n,{withFileTypes:!0}))o.isDirectory()&&_d(S.join(n,o.name),i,e,t)}catch{}}function _d(r,e,t,n){try{let{mtimeMs:i}=D.statSync(r);if(e-i<=t)return;D.rmSync(r,{recursive:!0,force:!0});let o=Math.floor((e-i)/1e3);console.error(`${n} Removed expired dir (age ${Math.floor(o/86400)}d ${Math.floor(o%86400/3600)}h): ${r}`)}catch(i){console.error(`${n} Failed to remove expired dir ${r}: ${i}`)}}function cn(r){let e=r.replace(/sdk\/?$/i,"tools"),t=process.platform==="win32"?"node.exe":"node",n=S.join(e,"node",t);return D.existsSync(n)||process.platform!=="win32"&&(n=S.join(e,"node","bin","node"),D.existsSync(n))?n:process.execPath??"node"}import*as C from"fs";import*as dn from"path";var ws="mcp-server.log",Wd="mcp-server",Ud={maxSize:10*1024*1024,maxFiles:4},Br=class{fd=null;logDir=null;currentLogFile=null;mode;rotationOptions;currentFileSize=0;currentDate="";isRotating=!1;constructor(e,t){this.rotationOptions={...Ud,...t},e?(this.mode="console",this.logDir=null,this.currentLogFile=null):(this.mode="file",this.logDir=an(),this.currentLogFile=dn.join(this.logDir,ws),C.existsSync(this.logDir)||C.mkdirSync(this.logDir,{recursive:!0}),this.cleanupOrphanLogFiles(),this.openLogFile())}getCurrentDateString(){let e=new Date,t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),i=String(e.getDate()).padStart(2,"0");return`${t}-${n}-${i}`}getRotatedFileName(e,t){return dn.join(this.logDir,`${Wd}-${e}.log.${t}`)}fileExists(e){try{return C.accessSync(e,C.constants.F_OK),!0}catch{return!1}}cleanupOrphanLogFiles(){if(this.logDir)try{let e=C.readdirSync(this.logDir),t=[];for(let i of e)if(i===ws||/^mcp-server-\d{4}-\d{2}-\d{2}\.log\.\d+$/.test(i)){let o=dn.join(this.logDir,i),s=C.statSync(o);t.push({name:i,mtime:s.mtime,path:o})}t.sort((i,o)=>o.mtime.getTime()-i.mtime.getTime());let n=1+this.rotationOptions.maxFiles;for(let i=n;i<t.length;i++)try{C.unlinkSync(t[i].path)}catch{}}catch{}}rotateLog(){if(!(this.isRotating||!this.logDir||!this.currentLogFile)){this.isRotating=!0;try{if(this.closeLogFile(),!this.fileExists(this.currentLogFile)){this.isRotating=!1,this.openLogFile();return}let e=this.getCurrentDateString(),t=this.getRotatedFileName(e,this.rotationOptions.maxFiles);this.fileExists(t)&&C.unlinkSync(t);for(let i=this.rotationOptions.maxFiles-1;i>=1;i--){let o=this.getRotatedFileName(e,i),s=this.getRotatedFileName(e,i+1);this.fileExists(o)&&C.renameSync(o,s)}let n=this.getRotatedFileName(e,1);C.renameSync(this.currentLogFile,n),this.cleanupOrphanLogFiles(),this.openLogFile()}catch{this.openLogFile()}finally{this.isRotating=!1}}}openLogFile(){if(this.currentLogFile){this.currentDate=this.getCurrentDateString();try{if(this.fileExists(this.currentLogFile)){let e=C.statSync(this.currentLogFile);this.currentFileSize=e.size}else this.currentFileSize=0}catch{this.currentFileSize=0}try{this.fd=C.openSync(this.currentLogFile,"a")}catch{this.fd=null}}}closeLogFile(){if(this.fd!==null){try{C.closeSync(this.fd)}catch{}this.fd=null}}checkRotation(e){let t=this.getCurrentDateString();this.currentDate&&this.currentDate!==t&&(this.rotateLog(),this.currentDate=t),this.currentFileSize+=e,this.currentFileSize>=this.rotationOptions.maxSize&&this.rotateLog()}write(e,t,...n){if(this.mode==="silent")return;let i=n.map(c=>typeof c=="object"?JSON.stringify(c,null,2):String(c)).join(" "),o=i?`${t} ${i}`:t,a=`[${new Date().toLocaleString("sv-SE",{timeZone:"Asia/Shanghai",hour12:!1})+"."+String(new Date().getMilliseconds()).padStart(3,"0")}] [MCP/${e.toUpperCase()}] ${o}
|
|
1231
|
+
`;if(this.mode==="file"&&this.currentLogFile){if(this.fd===null&&this.openLogFile(),this.fd!==null)try{let c=Buffer.from(a);C.writeSync(this.fd,c),this.checkRotation(c.byteLength)}catch{this.closeLogFile(),this.openLogFile()}}else this.mode==="console"&&process.stderr.write(a)}debug(e,...t){this.write("debug",e,...t)}info(e,...t){this.write("info",e,...t)}warn(e,...t){this.write("warn",e,...t)}error(e,...t){this.write("error",e,...t)}dispose(){this.closeLogFile()}flush(){if(!(this.mode!=="file"||this.fd===null))try{C.fsyncSync(this.fd)}catch{}}getLogFilePath(){return this.currentLogFile}getLogDirectory(){return this.logDir}},Z=null;function zr(r=!1){Z&&Z.dispose(),Z=new Br(r)}function bs(){Z&&(Z.dispose(),Z=null)}function Ss(){Z&&Z.flush()}function Ps(){return Z?.getLogFilePath()??null}function Es(){return Z?.getLogDirectory()??null}function ln(){return Z||zr(!1),Z}var m={debug:(r,...e)=>ln().debug(r,...e),info:(r,...e)=>ln().info(r,...e),warn:(r,...e)=>ln().warn(r,...e),error:(r,...e)=>ln().error(r,...e)};function Ds(r){return"method"in r&&!("id"in r)}import{spawn as zd}from"child_process";import{EventEmitter as Vd}from"events";import*as et from"fs";import*as Ts from"path";import*as Is from"util";var Vr="";function Cs(r){if(!r||r==="auto"||r==="stdout"||r==="none"){Vr="";return}Vr=r}function As(){return Vr||(Es()??"")}function un(r,...e){if(e.length===0)return r;try{return Is.format(r,...e)}catch{return[r,...e.map(t=>typeof t=="string"?t:JSON.stringify(t))].join(" ")}}var l={info(r,...e){m.info(`[lsp] ${un(r,...e)}`)},warn(r,...e){m.warn(`[lsp] ${un(r,...e)}`)},error(r,...e){m.error(`[lsp] ${un(r,...e)}`)},debug(r,...e){m.debug(`[lsp] ${un(r,...e)}`)}};import*as Ct from"fs";import*as qr from"os";import*as Qe from"path";import Bd from"json5";function J(r){if(!Ct.existsSync(r))return null;try{let e=Ct.readFileSync(r,"utf-8");return e.trim()?Bd.parse(e):null}catch{return null}}function ge(r){try{let e=Qe.resolve(r),t=new URL(`file://${e}`).toString();if(qr.platform()==="win32"){let n=t.match(/^file:\/\/\/([A-Za-z]):/);if(n){let i=n[1].toUpperCase(),o=t.substring(`file:///${n[1]}:`.length);t=`file:///${i}%3A${o}`}}return t}catch{return r}}function pn(r){return r&&r.replace(/\\/g,"/")}function $(r){let e=Qe.normalize(r).replace(/\\/g,"/");if(qr.platform()==="win32"){let t=e.match(/^([A-Za-z]):/);t&&(e=`${t[1].toUpperCase()}:${e.substring(2)}`)}return e}function ks(r){return Qe.join(r,"build-profile.json5")}var hn=class extends Vd{constructor(t){super();this.config=t}config;process=null;buffer=Buffer.alloc(0);isClosing=!1;async start(){let t=Ts.join(this.config.logPath,"lspLog");et.existsSync(t)||et.mkdirSync(t,{recursive:!0}),et.existsSync(this.config.indexingDataLocation)||et.mkdirSync(this.config.indexingDataLocation,{recursive:!0});let n=this.config.nodeMaxOldSpaceSize??8192,i=$(t),o=["--expose-gc",`--max-old-space-size=${n}`,"--report-on-fatalerror","--report-uncaught-exception",`--report-filename=nodejs_error_${Date.now()}.txt`,`--report-dir=${i}`,this.config.serverPath,"--stdio",`--logger-path=${i}`,"--logger-level=TRACE"];l.info(`[LspClient] Starting process: node ${o.join(" ")}`);let s=process.execPath??"node";l.info(`[LspClient] nodePath: ${s}`),this.process=zd(s,o,{cwd:this.config.cwd||process.cwd(),stdio:["pipe","pipe","pipe"],windowsHide:!0}),this.process.stdout?.on("data",a=>{this.handleData(a)}),this.process.stderr?.on("data",a=>{let c=a.toString("utf8").trim();l.error(`[LspClient] stderr: ${c}`),this.isClosing||this.emit("error",new Error(`[LspClient] stderr: ${c}`))}),this.process.on("exit",a=>{l.info(`[LSP EXIT] code=${a}`),this.isClosing||this.emit("error",new Error(`LSP process exited with code ${a}`))}),await new Promise(a=>setTimeout(a,500)),l.info("[LspClient] start lsp process success")}sendRaw(t,n){if(!this.process?.stdin?.writable){l.warn("[LspClient] Cannot send message, stdin not writable");return}l.info(`[LspClient] send message: ${n}`);let i=this.buildLspMessage(t);this.process.stdin.write(i,"utf8")}send(t,n,i){let o={jsonrpc:"2.0",method:t,params:n};i!==void 0&&(o.id=i),this.sendRaw(JSON.stringify(o),t)}buildLspMessage(t){return`Content-Length: ${Buffer.from(t,"utf8").length}\r
|
|
1232
|
+
\r
|
|
1233
|
+
${t}`}handleData(t){for(this.buffer=Buffer.concat([this.buffer,t]);;){let n=this.buffer.indexOf(`\r
|
|
1234
|
+
\r
|
|
1235
|
+
`);if(n===-1)break;let o=this.buffer.slice(0,n).toString("ascii").match(/Content-Length:\s*(\d+)/i);if(!o){l.warn("[LspClient] Invalid LSP header, drop until next packet"),this.buffer=this.buffer.slice(n+4);continue}let s=parseInt(o[1],10),a=n+4,c=a+s;if(this.buffer.length<c)break;let d=this.buffer.slice(a,c).toString("utf8"),u=this.recoverFramedJson(d);if(u&&u.rest.length>0){l.warn(`[LspClient] recovered mixed LSP frame, bodyLen=${d.length}, restLen=${u.rest.length}`),this.emit("message",u.json),this.buffer=Buffer.concat([Buffer.from(u.rest,"utf8"),this.buffer.slice(c)]);continue}this.emit("message",d),this.buffer=this.buffer.slice(c)}}waitForExitOrTimeout(t){let n=this.process;return!n||n.exitCode!==null||n.signalCode!==null?Promise.resolve():new Promise(i=>{let o=!1,s=()=>{o||(o=!0,clearTimeout(c),n.off("exit",a),i())},a=()=>s();n.once("exit",a);let c=setTimeout(s,t)})}recoverFramedJson(t){let n=t.search(/\S/);if(n<0||t[n]!=="{"&&t[n]!=="[")return null;let i=0,o=!1,s=!1;for(let a=n;a<t.length;a++){let c=t[a];if(o){if(s){s=!1;continue}if(c==="\\"){s=!0;continue}c==='"'&&(o=!1);continue}if(c==='"'){o=!0;continue}if(c==="{"||c==="["){i++;continue}if((c==="}"||c==="]")&&(i--,i===0)){let d=t.slice(n,a+1),u=t.slice(a+1);return{json:d,rest:u}}}return null}stop(){this.isClosing=!0;let t=this.process;if(!t)return;if(this.process=null,t.exitCode===null&&t.signalCode===null)try{t.kill()}catch{}}};var mn=class{callbacks=new Map;timeouts=new Map;register(e,t){this.callbacks.set(e,t)}emit(e,t,n){l.info(`[RequestCallbackManager] emit, method: ${t}, key: ${e}`),this.clearTimeout(e);let i=this.callbacks.get(e);i&&(i(t,n),this.callbacks.delete(e))}registerTimeout(e,t,n,i){this.timeouts.has(e)&&clearTimeout(this.timeouts.get(e));let o=setTimeout(()=>{l.info(`[RequestCallbackManager] timeout, key=${e}, method=${t}`),i(),this.timeouts.delete(e)},n);this.timeouts.set(e,o)}clearTimeout(e){let t=this.timeouts.get(e);t&&(clearTimeout(t),this.timeouts.delete(e))}deleteCallback(e){this.callbacks.delete(e)}hasCallback(e){return this.callbacks.has(e)}clear(e){this.clearTimeout(e),this.callbacks.delete(e)}};var fn=class{uri;messages=[];receivedTypes=new Set;uniqueMessages=new Set;isFromEditor=!1;constructor(e){this.uri=e}setReceivedType(e){this.receivedTypes.add(e)}addMessage(e,t){this.receivedTypes.add(e);let n=`${e}:${t}`;if(this.uniqueMessages.has(n)){l.info(`[Diagnostic] addMessage: duplicate message=${n}`);return}this.uniqueMessages.add(n),this.messages.push(new Yr(e,t))}clearMessages(){this.messages=[]}clear(){this.receivedTypes.clear(),this.uniqueMessages.clear(),this.messages=[]}hasReceivedAllTypes(e){for(let t of e)if(!this.receivedTypes.has(t))return!1;return!0}getMessages(){return this.messages.map(e=>e.diagnostics)}},Yr=class{version=-1;diagnostics;constructor(e,t){this.version=e,this.diagnostics=t}};var gn=class{map=new Map;register(e,t){let n=this.map.get(e);n||(n=new Set,this.map.set(e,n)),n.add(t)}unregister(e,t){let n=this.map.get(e);n&&(t!==void 0?n.delete(t):n.clear(),n.size===0&&this.map.delete(e))}invoke(e,...t){let n=this.map.get(e);if(n)for(let i of n)try{i(...t)}catch(o){console.error(`[CallbackRegistry] invoke("${String(e)}") callback error:`,o)}}invokeOnce(e,...t){this.invoke(e,...t),this.unregister(e)}clear(){this.map.clear()}has(e){let t=this.map.get(e);return t!==void 0&&t.size>0}};function f(r){return typeof r=="object"&&r!==null}function Gr(r){return Array.isArray(r)&&r.every(e=>typeof e=="string")}var qd={EXIT:"exit",INITIALIZED:"initialized",ON_DID_CHANGE_PACKAGE_DEPENDENCIES:"aceProject/onDidChangePackageDependencies",ON_ASYNC_DID_OPEN:"aceProject/onAsyncDidOpen",ON_ASYNC_DID_CHANGE:"aceProject/onAsyncDidChange",DID_CLOSE:"textDocument/didClose",ON_ASYNC_HOVER:"aceProject/onAsyncHover",ON_ASYNC_DEFINITION:"aceProject/onAsyncDefinition",ON_ASYNC_FIND_USAGES:"aceProject/onAsyncFindUsages"},yn={MODULE_INIT_FINISH:"aceProject/onModuleInitFinish",INDEXING_PROGRESS_UPDATE:"aceProject/onIndexingProgressUpdate",BROADCAST:"lsp/broadcast",ARKTS_ERROR:"arkts/error",ON_FORCE_OPEN_FILE:"aceProject/onForceOpenFile",ON_PACKAGE_CHANGE_FINISH:"aceProject/onPackageChangeFinish",PUBLISH_DIAGNOSTICS:"textDocument/publishDiagnostics",HOVER:"textDocument/hover",TEXT_DOCUMENT_ON_ASYNC_DEFINITION:"textDocument/onAsyncDefinition",REFERENCES:"textDocument/references",DID_OPEN:"textDocument/didOpen",DID_CHANGE:"textDocument/didChange",DEFINITION:"textDocument/definition",ON_DID_CHANGE_PACKAGE_DEPENDENCIES_CLIENT:"textDocument/onDidChangePackageDependencies",WORKSPACE_DID_CHANGE_CONFIGURATION:"workspace/didChangeConfiguration",ARKTS_INITIALIZED:"arkts/initialized",ARKTS_INITIALIZATION_FAILED:"arkts/initializationFailed",ARKTS_INDEXING_PROGRESS:"arkts/indexingProgress",ARKTS_SYNC_PROJECT:"arkts/syncProject",ARKTS_SYNC_COMPLETED:"arkts/syncCompleted",ARKTS_REINITIALIZING:"arkts/reinitializing",WORKSPACE_DID_CHANGE_WATCHED_FILES:"workspace/didChangeWatchedFiles"},y={...qd,...yn},M="2.0",X={EXIT:"exit",INITIALIZED:"initialized",EMPTY:"empty",ON_DID_CHANGE_PACKAGE_DEPENDENCIES:"onDidChangePackageDependencies",ON_ASYNC_DID_OPEN:"onAsyncDidOpen",ON_ASYNC_DID_CHANGE:"onAsyncDidChange",DID_CLOSE:"didClose",ON_ASYNC_HOVER:"onAsyncHover",ON_ASYNC_DEFINITION:"onAsyncDefinition",ON_ASYNC_FIND_USAGES:"onAsyncFindUsages"};function Yd(r){if(!f(r))return!1;let e=r.textDocument;return f(e)&&typeof e.uri=="string"}function Gd(r){return f(r)?typeof r.uri=="string"&&typeof r.type=="number":!1}var vn=class r{client;isInitialized=!1;stopOnce=null;callbacks=new gn;requestCallbacks=new mn;diagnosticMap=new Map;static DIAGNOSTIC_TIMEOUT_MS=20*1e3;static EXPECTED_DIAGNOSTIC_TYPES=new Set([1e3,2e3,3e3,3001]);constructor(e){this.client=new hn(e),this.client.on("message",t=>this.handleRawMessage(t)),this.client.on("error",t=>this.handleError(t))}async start(){await this.client.start()}stop(){return this.stopOnce||(this.stopOnce=(async()=>{l.info("[ClientMessageHandle] Sending exit notification to LSP"),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.EXIT,params:{}}),X.EXIT),l.info("[ClientMessageHandle] Waiting for LSP process to exit"),await this.client.waitForExitOrTimeout(300),l.info("[ClientMessageHandle] LSP exit wait completed, calling stop"),this.client.stop()})()),this.stopOnce}setBroadcastToClients(e){this.callbacks.unregister(y.BROADCAST),this.callbacks.register(y.BROADCAST,e)}broadcastToClients(e){this.callbacks.invoke(y.BROADCAST,e)}onInitializationCompleted(e){this.isInitialized?e():this.callbacks.register(y.MODULE_INIT_FINISH,e)}onIndexingProgressUpdate(e){this.callbacks.register(y.INDEXING_PROGRESS_UPDATE,e)}registerRequestCallback(e,t){this.requestCallbacks.register(e,t)}sendInitialize(e,t){this.client.send("initialize",e,t)}sendInitialized(e){this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.INITIALIZED,params:{editors:e}}),X.INITIALIZED),this.client.sendRaw(JSON.stringify({jsonrpc:M,id:0,result:{}}),X.EMPTY)}sendAsyncRequest(e,t,n,i){if(!f(t)){l.warn(`[LSP] sendAsyncRequest invalid params, method=${e}`);return}if(!Yd(t)){l.warn(`[LSP] sendAsyncRequest missing textDocument.uri, method=${e}, params=${JSON.stringify(t)}`);return}if(typeof n!="number"){l.warn(`[LSP] sendAsyncRequest invalid requestId, method=${e}, requestId=${String(n)}`);return}let o=t.textDocument.uri,s=ge(o);t.textDocument.uri=s,delete t.requestId;let a=i??e;l.info(`[LSP] sendAsyncRequest ${a}, filePath: ${o}`),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:e,params:{params:t,requestId:n}}),a)}onDidChangeWatchedFiles(e){if(l.info(`[LSP] onDidChangeWatchedFiles, params=${JSON.stringify(e)}`),e.length===0)return;let t=[];for(let n of e){if(!Gd(n)){l.warn(`[LSP] onDidChangeWatchedFiles, param is missing 'uri' or 'type': ${JSON.stringify(n)}`);continue}t.push(n)}this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.WORKSPACE_DID_CHANGE_WATCHED_FILES,params:{changes:t}}),y.WORKSPACE_DID_CHANGE_WATCHED_FILES)}sendModuleDependencyUpdate(e){if(!f(e)||!Array.isArray(e.moduleSet)||e.moduleSet.length===0){l.warn("[LSP] sendModuleDependencyUpdate, moduleSet is empty or null");return}let t=e.moduleSet;l.info(`[LSP] sending module dependency updated, count: ${t.length}`),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.ON_DID_CHANGE_PACKAGE_DEPENDENCIES,params:{params:e}}),X.ON_DID_CHANGE_PACKAGE_DEPENDENCIES)}onAsyncOpenFile(e){let t=e.textDocument.uri,n=t.split(".").pop()||"";if(n!=="ets"&&n!=="ts")return;let i=ge(t);e.textDocument.uri=i,l.info(`[LSP] onAsyncOpenFile, uri: ${i}`);let o=this.diagnosticMap.get(i);o||(o=new fn(i),this.diagnosticMap.set(i,o),this.registerDiagnosticTimeout(i,yn.PUBLISH_DIAGNOSTICS)),e.isFromEditor&&(o.isFromEditor=!0),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.ON_ASYNC_DID_OPEN,params:{params:{editorFiles:e.editorFiles,textDocument:e.textDocument}}}),X.ON_ASYNC_DID_OPEN)}onAsyncDidChange(e){let t=ge(e.uri),n=this.diagnosticMap.get(t);n&&(n.clear(),this.registerDiagnosticTimeout(t,yn.PUBLISH_DIAGNOSTICS)),l.info(`[LSP] onAsyncDidChange, uri: ${t}`),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.ON_ASYNC_DID_CHANGE,params:{editorFiles:[e.uri],params:{textDocument:{uri:t,version:e.version===0?null:e.version},contentChanges:e.contentChanges}}}),X.ON_ASYNC_DID_CHANGE)}closeFile(e,t){let n=ge(e);l.info(`[LSP] didClose, uri: ${n}`);let i=this.diagnosticMap.get(n);if(!t&&(!i||i.isFromEditor)){l.info(`[LSP] closeFile skip, !diagnostic: ${!i}, isFromEditor: ${i?.isFromEditor}`);return}this.cleanupDiagnosticState(n),this.client.sendRaw(JSON.stringify({jsonrpc:M,method:y.DID_CLOSE,params:{textDocument:{uri:n}}}),X.DID_CLOSE)}getDiagnosticMessage(e){let t=ge(e),n=this.diagnosticMap.get(t);return n?n.getMessages():[]}clear(e){this.diagnosticMap.get(e)?.clear()}handleRawMessage(e){try{let t=JSON.parse(e);this.handleLspMessage(t)}catch(t){let n=t instanceof Error?t.message:String(t);l.error(`[LSP] JSON parse error: ${n}, raw: ${e}`)}}handleError(e){let t=this.getPendingDiagnosticUris();if(t.length>0){let n=JSON.stringify({message:e.message,severity:"Error",severityStr:"Error"});for(let i of t)this.finalizeDiagnostic(i,y.PUBLISH_DIAGNOSTICS,[n]);return}this.broadcastToClients({jsonrpc:M,method:y.ARKTS_ERROR,params:{message:e.message}})}handleLspMessage(e){let t=e.method;t!==void 0&&(!this.isInitialized&&this.handlePreInitMessage(t)||this.handlePostInitMessage(t,e))}handlePreInitMessage(e){switch(e){case y.MODULE_INIT_FINISH:return l.info("[LSP] handleLspMessage, receive onModuleInitFinish"),this.isInitialized=!0,this.callbacks.invokeOnce(y.MODULE_INIT_FINISH),this.callbacks.unregister(y.INDEXING_PROGRESS_UPDATE),this.client.emit("initialized_done"),!0;case y.INDEXING_PROGRESS_UPDATE:return l.info("[LSP] handleLspMessage, receive onIndexingProgressUpdate"),this.callbacks.invoke(y.INDEXING_PROGRESS_UPDATE),!0;default:return!1}}handlePostInitMessage(e,t){switch(e){case y.ON_FORCE_OPEN_FILE:this.handleOnForceOpenFile(t);return;case y.ON_PACKAGE_CHANGE_FINISH:l.info("[LSP] handleLspMessage, receive onPackageChangeFinish"),this.handlePackageChangeFinish(t);return;case y.PUBLISH_DIAGNOSTICS:this.handlePublishDiagnostics(t);return;case y.ON_ASYNC_HOVER:this.handleAsyncResponse(t,y.HOVER);return;case y.ON_ASYNC_DEFINITION:this.handleAsyncResponse(t,y.TEXT_DOCUMENT_ON_ASYNC_DEFINITION);return;case y.ON_ASYNC_FIND_USAGES:this.handleAsyncResponse(t,y.REFERENCES);return;default:l.warn(`[LSP] handleLspMessage: no handler for notification, ignoring, method: ${e}, initialized: ${this.isInitialized}`)}}handleOnForceOpenFile(e){l.info("[LSP] handleLspMessage, receive onForceOpenFile");let t=e.params;f(t)&&f(t.result)&&typeof t.result.uri=="string"&&this.handleForceOpenFile(t.result.uri)}handlePublishDiagnostics(e){l.info("[LSP] handleLspMessage, receive publishDiagnostics");let t=e.params;t&&this.parseDiagnostics(t)}handlePackageChangeFinish(e){let t=e.params,n={jsonrpc:M,method:y.ON_PACKAGE_CHANGE_FINISH,params:[!1]};if(!t||!Array.isArray(t)){l.warn("[LSP] aceProject/onPackageChangeFinish params invalid"),this.broadcastToClients(n);return}if(!(t.length>0&&t[0]===!0)){l.warn("[LSP] aceProject/onPackageChangeFinish: package request failed"),this.broadcastToClients(n);return}l.info("[LSP] aceProject/onPackageChangeFinish: success"),this.broadcastToClients(e)}handleAsyncResponse(e,t){l.info(`[LSP] handleAsyncResponse\uFF0C method: ${t}`);let n=e.params;if(!f(n)){l.warn("[LSP] aceProject/onAsyncHover message invalid");return}let i=n.requestId;if(typeof i!="number"){l.warn(`[LSP] ${t} requestId invalid`);return}this.requestCallbacks.emit(i,t,n)}handleForceOpenFile(e){if(!e){l.warn("[LSP] handleForceOpenFile, uri is empty");return}this.requestCallbacks.emit(e,y.DID_OPEN,[]),this.clear(e)}parseDiagnostics(e){let t=e.uri;if(!t){l.info("[LSP] publishDiagnostics uri is null");return}let n=e.version??-1;if(n===-1)return;let i=this.diagnosticMap.get(t);if(!i){l.info(`[LSP] Diagnostic cleared for uri: ${t}`);return}let o=e.diagnostics||[];o.length!==0?o.forEach(s=>{this.normalizeDiagnostic(s),i.addMessage(n,JSON.stringify(s))}):i.setReceivedType(n),i.hasReceivedAllTypes(r.EXPECTED_DIAGNOSTIC_TYPES)&&this.finalizeDiagnostic(t,y.PUBLISH_DIAGNOSTICS,i.getMessages())}normalizeDiagnostic(e){if(delete e.source,e.severity!==void 0){let t=typeof e.severity=="number"?e.severity:parseInt(e.severity),n={1:"Error",2:"Warning",3:"Information",4:"Hint"};e.severityStr=n[t]||"Unknown",e.severity=e.severityStr}e.range&&(this.adjustPositionLine(e.range,"start"),this.adjustPositionLine(e.range,"end"))}adjustPositionLine(e,t){let n=e[t];n&&typeof n.line=="number"&&(n.line=n.line+1)}registerDiagnosticTimeout(e,t){this.requestCallbacks.registerTimeout(e,t,r.DIAGNOSTIC_TIMEOUT_MS,()=>{let n=this.diagnosticMap.get(e),i=n?n.getMessages():[];this.finalizeDiagnostic(e,t,i,i.length>0?void 0:`received no diagnostics within ${r.DIAGNOSTIC_TIMEOUT_MS}ms from LSP, uri: ${e}`)})}finalizeDiagnostic(e,t,n,i){let o={uri:e,diagnostics:n,...i?{errorMessage:i}:{}};this.requestCallbacks.emit(e,t,o),this.diagnosticMap.get(e)?.clear()}getPendingDiagnosticUris(){return Array.from(this.diagnosticMap.keys()).filter(e=>this.requestCallbacks.hasCallback(e))}cleanupDiagnosticState(e){this.requestCallbacks.clear(e),this.diagnosticMap.delete(e)}};import $n from"path";import*as In from"path";var wn=class{enableRecentlyUsed=!1;enableCompletionSortByType=!0;maxValidCompletionItemsCount=50;enableCompletionFunctionParameter=!1;enableIndexModuleRootDirEtsFile=!1};var bn=class{overriddenEnable=!0;overridingEnable=!0;implementedEnable=!0;implementingEnable=!0};var Sn=class{tsVariablesEnable=!1;tsPropertyEnable=!1;tsParameterEnable=!1;tsReturnEnable=!1;etsVariablesEnable=!1;etsPropertyEnable=!1;etsParameterEnable=!1;etsReturnEnable=!1};var Pn=class{etsParameterNameHintKind=null;tsParameterNameHintKind=null};var En=class{typeSetting=new Sn;parameterNames=new Pn};var Dn=class{constructor(e,t,n,i){this.rootUri=e;this.lspServerWorkspacePath=$(In.dirname(t)),this.indexingDataLocation=$(i),this.loggerPath=$(In.join(n,"lspLog"))}rootUri;modules=[];clientType="intellij";indexingDataLocation="";completionSortSetting=new wn;gutterIconsSetting=new bn;inlayHintsSetting=new En;lspMaxOldSpaceSize="8192";projectType="OHOS";loggerPath="";lspServerWorkspacePath};import*as Ms from"path";var At=class{productName="default";buildModeName="debug";targetName="default";arkTSVersion="1.1";resourceDirectories=[];targetESVersion="ES2021";maxFlowDepth=2e3;caseSensitiveCheck=!0;tsImportSendable=!1;compatibleSdkVersionStage="";useNormalizedOHMUrl=!0;reExportCheckMode="noCheck";skipOhModulesLint=!1;byteCodeHar=!0;obfuscationRuleOptionsEnable=!1;enableStrictCheckOHModules=!1;sourceRoots=[];constructor(e){e&&this.resourceDirectories.push($(Ms.join(e,"src","main","resources")))}};var Jd="OS",tt=class{deviceType=[5];aceLoaderPath;modulePath;jsComponentType="declarative";sdkJsPath;compatibleSdkVersion;compatibleSdkLevel;compileSdkLevel;compileSdkVersion="6.0.1.112";compileSdkType="Release";syscap={NDeviceSysCaps:[],addedSysCaps:[]};apiType="stageMode";hosSdkPath;runtimeOs=`Harmony${Jd}`;moduleName;moduleType;compileMode="jsbundle";crossPlatform=!1;ignoreCrossPlatform=!1;packageManagerType="ohpm";permissions=[];testPermissions=[];buildProfileParam;appParam={bundleType:"app"};packageName;projectType="OHOS";projectName;moduleDependencies;moduleJsonParam=null;globalDeclarationFiles=[];constructor(e){e?(this.modulePath=e,this.buildProfileParam=new At(e)):this.buildProfileParam=new At}toString(){return JSON.stringify(this)}};var nt=class{constructor(e=[]){this.pages=e}pages;pagesFileName="main_pages.json";metaDataList=[]};import*as U from"path";import*as ot from"fs";var Cn=class{modulePath;dependencies={};dynamicDependencies={}};var He=class{registryType;resolved;name;version;type;constructor(e){let t=typeof e=="object"&&e!==null?e:{};this.name=typeof t.name=="string"?t.name:"",this.version=typeof t.version=="string"?t.version:"",typeof t.registryType=="string"?this.registryType=t.registryType:this.registryType=typeof t.path=="string"?"local":"ohpm",typeof t.resolved=="string"?this.resolved=t.resolved:typeof t.storePath=="string"?this.resolved=t.storePath:this.resolved="",this.type=typeof t.type=="string"?t.type:void 0}};var rt=class{constructor(e,t,n){this.projectPath=e;this.moduleName=t;this.modulePath=n}projectPath;moduleName;modulePath;dependencies=[];devDependencies=[];dynamicDependencies=[];finalDependencies=[];finalDevDependencies=[];finalDynamicDependencies=[]};import*as ye from"path";import*as An from"fs";var it=class{name="";version="";storePath="";dependencyPath="";path=""};var I={HVIGOR_CACHE:".hvigor",DEPENDENCY:"dependencyMap",JSON5:".json5",KEY_DEPENDENCY:"dependencies",KEY_DYNAMIC_DEPENDENCY:"dynamicDependencies",KEY_DEV_DEPENDENCY:"devDependencies",OH_MODULES_PATH:"oh_modules",OHPM_PATH:".ohpm",LOCK_JSON5_FILE:"lock.json5",OH_PACKAGE_JSON5:"oh-package.json5"},kt=`${I.HVIGOR_CACHE}/${I.DEPENDENCY}`,je=`${I.DEPENDENCY}${I.JSON5}`;var Tt=class r{dependencyPath;modulePath;projectPath;static FILE_DEPENDENCY_PREFIX="file:";static PARAMETER_PREFIX="@param:";fileSpecPattern;fileNameForOhpm=/[.](?:har|tgz|tar.gz|tar)$/;static PACKAGE_JSON_PARSER_MAP=new Map;dependencies=[];devDependencies=[];dynamicDependencies=[];static getInstance(e,t,n){let i=this.PACKAGE_JSON_PARSER_MAP.get(e);return i||(i=new r(e,t,n),this.PACKAGE_JSON_PARSER_MAP.set(e,i)),i}constructor(e,t,n){this.dependencyPath=e,this.modulePath=t,this.projectPath=n,this.fileSpecPattern=r.isWindows()?/^(?:[.]|~[/]|[/\\]|[a-zA-Z]:)/:/^(?:[.]|~[/]|[/]|[a-zA-Z]:)/}static isWindows(){return process.platform==="win32"}parseDependency(e){let t=ye.join(this.dependencyPath,I.OH_PACKAGE_JSON5),n=J(t);n&&(this.dependencies=this.getDependencyList(n,I.KEY_DEPENDENCY),this.devDependencies=this.getDependencyList(n,I.KEY_DEV_DEPENDENCY),this.dynamicDependencies=this.getDependencyList(n,I.KEY_DYNAMIC_DEPENDENCY),e.dependencies=this.dependencies,e.dynamicDependencies=this.devDependencies,e.devDependencies=this.dynamicDependencies)}getDependencyList(e,t){let n=[];if(!f(e))return n;let i=e[t];if(!f(i))return n;for(let[o,s]of Object.entries(i)){if(typeof s!="string"){l.error(`${o} package dependency value is not String ${t}`);continue}let a=new it;a.name=o;let c=s.replace(/\s/g,"");a.version=c,c.startsWith(r.PARAMETER_PREFIX)||this.parseDependencyPath(o,c,a,!1),n.push(a)}return n}parseDependencyPath(e,t,n,i){if(!(!e||!t))try{let o=ye.normalize(ye.join(this.modulePath,I.OH_MODULES_PATH,e));if(!(t.startsWith(r.FILE_DEPENDENCY_PREFIX)||this.fileSpecPattern.test(t))){n.dependencyPath=o;return}if(n.path=t,this.fileNameForOhpm.test(t)){n.dependencyPath=o;return}let s=t;if(t.startsWith(r.FILE_DEPENDENCY_PREFIX)&&(s=t.substring(r.FILE_DEPENDENCY_PREFIX.length)),ye.isAbsolute(s)){n.dependencyPath=o;return}i||(o=ye.normalize(ye.join(this.modulePath,s))),An.existsSync(o)&&An.statSync(o).isDirectory()&&(n.dependencyPath=o)}catch(o){l.error("parser dependency path is invalid",o)}}};import*as Mt from"fs";import*as Ce from"path";import Kd from"json5";var kn=class r{projectPath;static FILE_DEPENDENCY_PREFIX="file:";fileNameForOhpm=/[.](?:har|tgz|tar.gz|tar)$/;finalDependencies=[];finalDevDependencies=[];finalDynamicDependencies=[];storePathMap=new Map;constructor(e=""){this.projectPath=e}parseDependencies(e){let t=this.getLockFilePath(),n=this.readLockFile(t);if(!n)return!1;let i=this.validateLockFile(n);return i.valid?(this.extractDependencies(i.modules,i.packages,e),!0):!1}getLockFilePath(){return Ce.join(this.projectPath,I.OH_MODULES_PATH,I.OHPM_PATH,I.LOCK_JSON5_FILE)}readLockFile(e){if(!Mt.existsSync(e))return l.error("lock file does not exist"),this.clearDependencies(),null;try{let t=Mt.readFileSync(e,"utf8"),n=Kd.parse(t);return n||(l.error("lockFileJsonObject is null"),this.clearDependencies(),null)}catch(t){return l.error("Error parsing lock.json5:",t),this.clearDependencies(),null}}validateLockFile(e){if(!f(e))return l.error("lockFileJsonObject is not a valid object"),this.clearDependencies(),{valid:!1};let t=e.modules;if(!t)return l.error("modulesJsonObject is null"),this.clearDependencies(),{valid:!1};let n=e.packages;return n?{valid:!0,modules:t,packages:n}:(l.error("packagesJsonObject is null"),this.clearDependencies(),{valid:!1})}extractDependencies(e,t,n){this.storePathMap=this.parseStorePathMap(t),this.finalDependencies=this.getDependencyList(e,I.KEY_DEPENDENCY,n),this.finalDevDependencies=this.getDependencyList(e,I.KEY_DEV_DEPENDENCY,n),this.finalDynamicDependencies=this.getDependencyList(e,I.KEY_DYNAMIC_DEPENDENCY,n)}parseStorePathMap(e){let t=new Map;if(!f(e))return t;for(let[n,i]of Object.entries(e)){if(!f(i)){l.error(`${n} value is not json object`);continue}typeof i.storePath=="string"&&t.set(n,i.storePath)}return t}getDependencyList(e,t,n){if(!f(e))return[];for(let[i,o]of Object.entries(e))if(f(o)){let s=typeof o.name=="string"?o.name:"";if(n==="."&&s===""||s===n)return this.getFinalDependencyList(e,t,i)}return[]}getFinalDependencyList(e,t,n){let i=e[n];if(!f(i))return l.error("moduleJsonObject is null"),[];let o=[],s=i[t];if(!f(s))return[];for(let[a,c]of Object.entries(s)){if(!f(c))continue;let d=typeof c.specifier=="string"?c.specifier:"",u=typeof c.version=="string"?c.version:"",b=new it;b.name=a,b.version=u.startsWith(r.FILE_DEPENDENCY_PREFIX)?u.substring(r.FILE_DEPENDENCY_PREFIX.length):u,this.parseDependencyPath(b,n,a,d,u);let k=`${a}@${u}`;this.storePathMap.has(k)&&(b.storePath=this.storePathMap.get(k)||""),o.push(b)}return o}parseDependencyPath(e,t,n,i,o){let s=Ce.normalize(Ce.join(this.projectPath,t,I.OH_MODULES_PATH,n));try{let a=o;o.startsWith(r.FILE_DEPENDENCY_PREFIX)&&(a=o.substring(r.FILE_DEPENDENCY_PREFIX.length));let c=a;if(Ce.isAbsolute(c)||(c=Ce.join(this.projectPath,a)),!Mt.existsSync(c)){e.dependencyPath=s;return}if(e.path=i,this.fileNameForOhpm.test(o)){e.dependencyPath=s;return}e.dependencyPath=c}catch(a){l.error("Invalid dependency path in lock.json5",a)}}clearDependencies(){this.finalDependencies=[],this.finalDevDependencies=[],this.finalDynamicDependencies=[]}};var Fe=class{constructor(e){this.projectRoot=e}projectRoot;getAllModuleInfo(){let e=ks(this.projectRoot);try{let t=J(e);if(typeof t!="object"||t===null)return[];let n=t.modules;return Array.isArray(n)?n.filter(i=>{if(typeof i!="object"||i===null)return!1;let o=i;return typeof o.name=="string"&&typeof o.srcPath=="string"}):[]}catch(t){return l.warn(`[ConfigFileWatcher] Failed to parse build-profile.json5: ${t instanceof Error?t.message:String(t)}`),[]}}};function xs(r){return f(r)?typeof r.name=="string"&&typeof r.srcPath=="string":!1}var xt=class{constructor(e,t){this.projectPath=e;this.sdkPath=t;this.moduleInfoParse=new Fe(this.projectPath)}projectPath;sdkPath;moduleInfoParse;getAllDependencyMap(e){let t=this.projectPath,n=U.join(t,kt),i=U.join(n,je);if(!ot.existsSync(n)||!ot.existsSync(i)){let a="Dependency map or JSON not found";return l.warn(`[Parser] getAllDependencyMap failed: ${a}.`),{status:"ERROR",message:`${a}, please rebuild project`}}let o=new rt(this.projectPath,".",this.projectPath);this.parseProjectDependencies(n,o),this.parseLockJson(o);let s=this.moduleInfoParse.getAllModuleInfo();if(s.length===0){let a="No modules found in build-profile.json5";return l.warn(`[Parser] getAllDependencyMap failed: ${a}.`),{status:"ERROR",message:a}}for(let a of s)xs(a)&&this.parseSingleModule(a,n,o,e);return{status:"OK"}}getDependenciesOnly(e){let t=[],n=this.projectPath,i=U.join(n,kt),o=U.join(i,je);if(!ot.existsSync(i)||!ot.existsSync(o))return l.warn("[Parser] Dependency map or JSON not found."),t;let s=e&&e.length>0?new Set(e.map(d=>d.trim()).filter(Boolean)):null,a=new rt(this.projectPath,".",this.projectPath);this.parseProjectDependencies(i,a),this.parseLockJson(a);let c=this.moduleInfoParse.getAllModuleInfo();if(c.length===0)return l.warn("[Parser] getAllDependencyMap failed: No modules found in build-profile.json5."),t;for(let d of c){if(!xs(d))continue;let u=d.name;if(s&&!s.has(u))continue;let b=d.srcPath,k=U.resolve(this.projectPath,b),de=U.join(i,u),$e=$(k),_e=this.buildModuleDependencies(u,$e,de,a);_e.moduleName=u,t.push(_e)}return t}parseSingleModule(e,t,n,i){let o=e.name,s=e.srcPath,a=U.resolve(this.projectPath,s),c=U.join(t,o),d=$(a),u=new tt(d),b=this.buildModuleDependencies(o,d,c,n);this.parseModuleJson5(d,u);let k=this.parseMainPages(d);this.parseSdkJson(u),this.parseCompatibleSdkVersion(u),u.moduleName=o,u.moduleType=o,u.packageName=o,u.moduleDependencies=b,u.moduleJsonParam=new nt(k),i.push(u)}buildModuleDependencies(e,t,n,i){let o=new rt(this.projectPath,e,t);Tt.getInstance(n,t,this.projectPath).parseDependency(o),this.parseLockJson(o),o.finalDependencies.push(...i.finalDependencies),o.finalDevDependencies.push(...i.finalDevDependencies),o.finalDynamicDependencies.push(...i.finalDynamicDependencies),o.finalDependencies.push(...o.finalDevDependencies);let a=new Cn;return a.modulePath=t,this.toModuleDependencies(o,a),a}toModuleDependencies(e,t){let n={},i={};for(let o of e.finalDependencies)n[o.name]=new He(o);for(let o of e.finalDynamicDependencies)i[o.name]=new He(o);t.dependencies=n,t.dynamicDependencies=i}parseProjectDependencies(e,t){let n=U.join(e,I.OH_PACKAGE_JSON5);if(!ot.existsSync(n))return;Tt.getInstance(e,this.projectPath,this.projectPath).parseDependency(t)}parseLockJson(e){let t=new kn(e.projectPath);t.parseDependencies(e.moduleName)?(e.finalDependencies=t.finalDependencies,e.finalDevDependencies=t.finalDevDependencies,e.finalDynamicDependencies=t.finalDynamicDependencies):(e.finalDependencies=e.dependencies,e.finalDevDependencies=e.devDependencies,e.finalDynamicDependencies=e.dynamicDependencies)}parseModuleJson5(e,t){let n=U.join(e,"src","main","module.json5"),i=J(n);if(!f(i)||!f(i.module))return;let o=i.module;t.permissions=this.parseRequestPermissions(o),t.deviceType=this.parseDeviceTypes(o)}parseRequestPermissions(e){let t=[];if(f(e)&&Array.isArray(e.requestPermissions))for(let n of e.requestPermissions)f(n)&&typeof n.name=="string"&&t.push(n.name);return t}parseMainPages(e){let t=U.join(e,"src","main","resources","base","profile","main_pages.json"),n=J(t);return!f(n)||!Array.isArray(n.src)?[]:n.src.filter(i=>typeof i=="string")}parseSdkJson(e){let t=U.join(this.sdkPath,"default","sdk-pkg.json"),n=J(t);!f(n)||!f(n.data)||(typeof n.data.apiVersion=="string"&&(e.compileSdkLevel=n.data.apiVersion),typeof n.data.releaseType=="string"&&(e.compileSdkType=n.data.releaseType),typeof n.data.version=="string"&&(e.compileSdkVersion=n.data.version))}parseCompatibleSdkVersion(e){let t=U.join(this.projectPath,"build-profile.json5"),n=J(t);if(!f(n)||!f(n.app)||!Array.isArray(n.app.products)||n.app.products.length===0)return;let i=n.app.products[0];if(!f(i)||typeof i.compatibleSdkVersion!="string")return;let[o,s]=this.parseBySplit(i.compatibleSdkVersion);e.compatibleSdkVersion=o,e.compatibleSdkLevel=s}parseBySplit(e){let t=e.indexOf("(");if(t===-1||!e.endsWith(")"))return[e,""];let n=e.substring(0,t),i=e.substring(t+1,e.length-1);return[n,i]}parseDeviceTypes(e){return!f(e)||!Array.isArray(e.deviceTypes)?[]:e.deviceTypes.filter(t=>typeof t=="string").map(t=>this.getDeviceType(t))}getDeviceType(e){return{liteWearable:1,wearable:2,tv:3,car:4,phone:5,default:5,smartVision:6,tablet:7,router:8,pc:9,"2in1":10}[e]||0}};var Tn=class{constructor(e=[]){this.valueSet=e}valueSet};var st=class{refreshSupport=!0;tokenTypes=["namespace","type","class","enum","interface","struct","parameter","variable","property","function","method"];tokenModifiers=["declaration","definition","readonly","static","deprecated"]};var Rs=(v=>(v[v.File=1]="File",v[v.Module=2]="Module",v[v.Namespace=3]="Namespace",v[v.Package=4]="Package",v[v.Class=5]="Class",v[v.Method=6]="Method",v[v.Property=7]="Property",v[v.Field=8]="Field",v[v.Constructor=9]="Constructor",v[v.Enum=10]="Enum",v[v.Interface=11]="Interface",v[v.Function=12]="Function",v[v.Variable=13]="Variable",v[v.Constant=14]="Constant",v[v.String=15]="String",v[v.Number=16]="Number",v[v.Boolean=17]="Boolean",v[v.Array=18]="Array",v[v.Object=19]="Object",v[v.Key=20]="Key",v[v.Null=21]="Null",v[v.EnumMember=22]="EnumMember",v[v.Struct=23]="Struct",v[v.Event=24]="Event",v[v.Operator=25]="Operator",v[v.TypeParameter=26]="TypeParameter",v))(Rs||{}),Os=()=>Object.values(Rs).filter(r=>typeof r=="number");var Mn=class{documentChanges=null;resourceOperations=null;failureHanding=null;normalizesLineEndings=null;changeAnnotationSupport=null};var xn=class{applyEdit=!0;workspaceEdit=new Mn;didChangeConfiguration=null;didChangeWatchedFiles={relativePatternSupport:{},dynamicRegistration:{}};symbol=new Tn(Os());executeCommand={dynamicRegistration:{}};workspaceFolders=!1;configuration=!1;semanticTokens=new st;codeLens=null;fileOperations=null;inlayHint=null;diagnostics=null};var Rn=class{willSave=!0;willSaveWaitUntil=!0;didSave=!0;dynamicRegistration=null};var On=class{constructor(e=[]){this.valueSet=e}valueSet};var Nn=class{snippetSupport=!0;commitCharactersSupport=null;documentationFormat=null;deprecateSupport=null;preselectSupport=null;tagSupport=null;insertReplaceSupport=null;resolveSupport=null;insertTextModeSupport=null;labelDetailsSupport=null};var Ns=(w=>(w[w.Text=1]="Text",w[w.Method=2]="Method",w[w.Function=3]="Function",w[w.Constructor=4]="Constructor",w[w.Field=5]="Field",w[w.Variable=6]="Variable",w[w.Class=7]="Class",w[w.Interface=8]="Interface",w[w.Module=9]="Module",w[w.Property=10]="Property",w[w.Unit=11]="Unit",w[w.Value=12]="Value",w[w.Enum=13]="Enum",w[w.Keyword=14]="Keyword",w[w.Snippet=15]="Snippet",w[w.Color=16]="Color",w[w.File=17]="File",w[w.Reference=18]="Reference",w[w.Folder=19]="Folder",w[w.EnumMember=20]="EnumMember",w[w.Constant=21]="Constant",w[w.Struct=22]="Struct",w[w.Event=23]="Event",w[w.Operator=24]="Operator",w[w.TypeParameter=25]="TypeParameter",w))(Ns||{}),Ls=()=>Object.values(Ns).filter(r=>typeof r=="number");var Ln=class{completionItemKind=new On(Ls());completionItem=new Nn;contextSupport=null;insertTextSupport=null;completionList=null;dynamicRegistration=null};var Hn=class{synchronization=new Rn;completion=new Ln;hover={contentFormat:{},dynamicRegistration:{}};signatureHelp={signatureInformation:{},contextSupport:{},dynamicRegistration:{}};references={dynamicRegistration:{}};documentHighlight={dynamicRegistration:!0};documentSymbol=null;formatting={dynamicRegistration:{}};rangeFormatting={dynamicRegistration:{}};onTypeFormatting={dynamicRegistration:{}};declaration={};definition={linkSupport:{},dynamicRegistration:{}};codeLens=null;documentLink={tooltipSupport:{},dynamicRegistration:{}};colorProvider=null;rename={prepareSupport:!0,prepareSupportDefaultBehavior:null,honorsChangeAnnotations:null,dynamicRegistrationSupport:null};publishDiagnostics=null;foldingRage=null;typeHierarchy=null;callHierarchy={dynamicRegistration:{}};selectionRange=null;semanticTokens=new st;moniker=null;linkedEditingRange=null;inlayHint=null;inlineValue=null;diagnostic=null};var jn=class{workspace=new xn;textDocument=new Hn;notebookDocument=null;window=null;general=null;experimental=null};var Fn=class{constructor(e,t,n){this.rootUri=e;this.initializationOptions=t;this.capabilities=n}rootUri;initializationOptions;capabilities};function at(r){return f(r)?typeof r.line=="number"&&typeof r.character=="number":!1}function Hs(r){return f(r)?typeof r.uri=="string"&&typeof r.text=="string"&&typeof r.languageId=="string"&&typeof r.version=="number":!1}function js(r){if(!f(r)||typeof r.text!="string")return!1;let e=r.range;return f(e)?at(e.start)&&at(e.end):!1}var _n=class{constructor(e,t,n,i,o){this.sdkPath=e;this.rootUri=n;this.nodeMaxOldSpaceSize=o;this.serverPath=$n.resolve(t,"ace-server","out","index.js"),this.logPath=As(),this.indexLogPath=i||this.logPath,this.messageHandle=new vn({serverPath:this.serverPath,logPath:this.logPath,nodeMaxOldSpaceSize:this.nodeMaxOldSpaceSize,indexingDataLocation:this.indexLogPath}),this.messageHandle.setBroadcastToClients(s=>this.onLspMessage(s))}sdkPath;rootUri;nodeMaxOldSpaceSize;messageHandle;serverPath;logPath;lastStartErrorMessage=null;currentParams=null;indexLogPath;lastDepsOnlyForDiff=[];get currentModuleModels(){return this.currentParams?.initializationOptions?.modules??[]}initTimeoutMs=60*1e3;async start(e,t){let n=!1;try{l.info(`serverPath: ${this.serverPath}`),l.info(`rootUri: ${this.rootUri}`),l.info(`sdkPath: ${this.sdkPath}`),l.info(`logPath: ${this.logPath}`),await this.messageHandle.start();let i=ge(this.rootUri),o=new Dn(i,this.serverPath,this.logPath,this.indexLogPath),s=[],c=new xt(this.rootUri,this.sdkPath).getAllDependencyMap(s);if(c.status==="ERROR")throw new Error(`${c.message}`);this.fillModuleModelsPaths(s),o.modules=s,this.currentParams=new Fn(i,o,new jn),this.messageHandle.sendInitialize(this.currentParams,1),this.messageHandle.onIndexingProgressUpdate(()=>{this.onLspMessage({jsonrpc:M,method:y.ARKTS_INDEXING_PROGRESS,params:{}})}),await this.withResettableTimeout((d,u)=>{this.messageHandle.onIndexingProgressUpdate(u),this.messageHandle.onInitializationCompleted(d)},"LSP initialization",this.initTimeoutMs),this.messageHandle.sendInitialized(e),n=!0}catch(i){this.lastStartErrorMessage=i instanceof Error?i.message:String(i),l.error(`[LSP] Initialization failed: ${this.lastStartErrorMessage}`),await this.messageHandle.stop()}t?.(n)}consumeStartErrorMessage(){let e=this.lastStartErrorMessage;return this.lastStartErrorMessage=null,e}onLspMessage=()=>{};setOnMessage(e){this.onLspMessage=e}registerDiagnosticCallback(e){let t=ge(e);this.messageHandle.registerRequestCallback(t,(n,i)=>{let o=f(i)?i:{};l.info(`[LSP] onDiagnosticCompleted called, filePath: ${e}`);let s={jsonrpc:M,method:n,params:{uri:typeof o.uri=="string"?o.uri:t,diagnostics:Array.isArray(o.diagnostics)?o.diagnostics.filter(a=>typeof a=="string"):[],...typeof o.errorMessage=="string"?{errorMessage:o.errorMessage}:{}}};this.onLspMessage(s)})}registerRequestCallback(e,t){this.messageHandle.registerRequestCallback(t,(n,i)=>{l.info(`[LSP] onRequestCompleted called, requestId: ${t}, method: ${n}`);let o={jsonrpc:M,id:e,result:f(i)?i.result:void 0};this.onLspMessage(o)})}reloadDependenciesOnly(e){let t=e?.fullReload??!1,n=new xt(this.rootUri,this.sdkPath),i=this.getModuleModelsByName();if(t){l.info("[LspServerProxy] Project-level oh-package changed, parsing all modules' dependencies");let d=n.getDependenciesOnly();this.markDependencyTypesIncremental(d);let u=this.mergeDepsOnlyIntoModuleList(d,i);return this.applyModuleModelsUpdate(u),l.info(`[LspServerProxy] Dependencies only (all) reloaded, count: ${u.length}`),this.lastDepsOnlyForDiff=d,d}let o=e?.changedModules??[],s=new Set(e?.removedModuleNames??[]);if(o.length===0&&s.size===0)return l.info("[LspServerProxy] No changed/removed modules, skip dependency reload"),[];l.info(`[LspServerProxy] Module-level deps changed, parsing: [${o.join(", ")}]`);let a=n.getDependenciesOnly(o);this.markDependencyTypesIncremental(a);let c=this.mergeIncrementalDeps(this.currentModuleModels,s,a);return this.applyModuleModelsUpdate(c),l.info(`[LspServerProxy] Dependencies only (incremental) reloaded, count: ${c.length}`),this.lastDepsOnlyForDiff=a,a}getModuleModelsByName(){return new Map(this.currentModuleModels.map(e=>[e.moduleName??"",e]))}markDependencyTypesIncremental(e){let t=this.getModuleModelsByName(),n=new Map(this.lastDepsOnlyForDiff.map(i=>[i.moduleName??"",i]));for(let i of e){let o=i.moduleName??"",{oldDeps:s,oldDynamic:a}=this.getOldDepsForModule(o,t,n),c=i.dependencies??{},d=i.dynamicDependencies??{};this.markAddAndDeleteInDeps(s,c,(u,b)=>{(i.dependencies??={})[u]=this.makeDeleteEntry(u,b)}),this.markAddAndDeleteInDeps(a,d,(u,b)=>{(i.dynamicDependencies??={})[u]=this.makeDeleteEntry(u,b)})}}getOldDepsForModule(e,t,n){let i=t.get(e),o=i?.moduleDependencies?.dependencies??{},s=i?.moduleDependencies?.dynamicDependencies??{};if(Object.keys(o).length===0&&Object.keys(s).length===0){let a=n.get(e);a&&(o=a.dependencies??{},s=a.dynamicDependencies??{})}return{oldDeps:o,oldDynamic:s}}markAddAndDeleteInDeps(e,t,n){for(let i of Object.keys(t))i in e||(t[i].type="add");for(let i of Object.keys(e))i in t||n(i,e[i])}makeDeleteEntry(e,t){return new He({name:e,version:t?.version??"",registryType:t?.registryType??"ohpm",resolved:t?.resolved??"",type:"delete"})}createMinimalModelFromDepsItem(e){let t=new tt(e.modulePath);return t.moduleName=e.moduleName,t.moduleType=e.moduleName,t.packageName=e.moduleName,t.moduleJsonParam=new nt([]),t.modulePath=e.modulePath,t.moduleDependencies=e,t}mergeDepsOnlyIntoModuleList(e,t){let n=[];for(let i of e){let o=i.moduleName??"",s=t.get(o);s?(s.modulePath=i.modulePath,s.moduleDependencies=i):s=this.createMinimalModelFromDepsItem(i),n.push(s)}return n}mergeIncrementalDeps(e,t,n){let i=new Map(n.map(s=>[s.moduleName??"",s])),o=[];for(let s of e){let a=s.moduleName??"";if(t.has(a))continue;let c=i.get(a);c&&(s.modulePath=c.modulePath,s.moduleDependencies=c,i.delete(a)),o.push(s)}for(let[,s]of i)o.push(this.createMinimalModelFromDepsItem(s));return o}applyModuleModelsUpdate(e){this.fillModuleModelsPaths(e),this.currentParams&&(this.currentParams.initializationOptions.modules=e)}fillModuleModelsPaths(e){let t=this.sdkPath,n=pn($n.join(t,"default/openharmony/ets/build-tools/ets-loader")),i=pn($n.join(t,"default/openharmony/ets/api")),o=pn($n.join(t,"default/hms"));for(let s of e)s.aceLoaderPath=n,s.sdkJsPath=i,s.hosSdkPath=o}sendRequest(e){switch(e.method){case y.HOVER:this.handleHoverRequest(e);break;case y.DEFINITION:this.handleDefinitionRequest(e);break;case y.REFERENCES:this.handleReferencesRequest(e);break;default:l.warn(`Unhandled LSP request: ${e.method}`)}}handleHoverRequest(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/hover, params missing or not an object");return}let{textDocument:n,position:i,requestId:o}=t;if(!f(n)||typeof n.uri!="string"||!at(i)){l.error("Invalid client textDocument/hover, malformed or missing required parameters");return}if(typeof o!="number"){l.error("Invalid client textDocument/hover, requestId missing or not a number");return}this.registerRequestCallback(e.id,o),this.messageHandle.sendAsyncRequest(y.ON_ASYNC_HOVER,t,o,X.ON_ASYNC_HOVER)}handleDefinitionRequest(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/definition, params missing or not an object");return}let{textDocument:n,position:i}=t;if(!f(n)||typeof n.uri!="string"||!at(i)){l.error("Invalid client textDocument/definition, malformed or missing required parameters");return}let o=this.resolveRequestId(t.requestId,e.id);if(!Number.isFinite(o)){l.error("Invalid client textDocument/definition, requestId missing or not a valid number");return}this.registerRequestCallback(e.id,o),this.messageHandle.sendAsyncRequest(y.ON_ASYNC_DEFINITION,t,o,X.ON_ASYNC_DEFINITION)}handleReferencesRequest(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/references, params missing or not an object");return}let{textDocument:n,position:i}=t;if(!f(n)||typeof n.uri!="string"||!at(i)){l.error("Invalid client textDocument/references, malformed or missing required parameters");return}let o=this.resolveRequestId(t.requestId,e.id);if(!Number.isFinite(o)){l.error("Invalid client textDocument/references, requestId missing or not a valid number");return}this.registerRequestCallback(e.id,o),this.messageHandle.sendAsyncRequest(y.ON_ASYNC_FIND_USAGES,t,o,X.ON_ASYNC_FIND_USAGES)}resolveRequestId(e,t){let n=e??t;return typeof n=="number"?n:Number(n)}sendNotification(e){if(!Ds(e)){l.info("LspServerProxy, msg is not notification request, ignore.");return}switch(e.method){case y.DID_OPEN:this.handleDidOpenNotification(e);break;case y.DID_CHANGE:this.handleDidChangeNotification(e);break;case y.DID_CLOSE:this.handleDidCloseNotification(e);break;case y.ON_DID_CHANGE_PACKAGE_DEPENDENCIES_CLIENT:this.handleDidChangePackageDependencies(e);break;case y.WORKSPACE_DID_CHANGE_WATCHED_FILES:this.handleDidChangeWatchedFiles(e);break;default:l.warn(`Unhandled LSP notification: ${e.method}`)}}handleDidOpenNotification(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/didOpen, params missing or not an object");return}let{textDocument:n,editorFiles:i}=t;if(!Hs(n)||!Gr(i)){l.error("Invalid client textDocument/didOpen, malformed or missing required parameters");return}let s={isFromEditor:typeof t.isFromEditor=="boolean"?t.isFromEditor:!1,editorFiles:i,textDocument:n};this.registerDiagnosticCallback(n.uri),this.messageHandle.onAsyncOpenFile(s)}handleDidChangeNotification(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/didChange, params missing or not an object");return}let{textDocument:n,contentChanges:i}=t;if(!f(n)||typeof n.uri!="string"||typeof n.version!="number"){l.error("Invalid client textDocument/didChange, malformed or missing required parameters");return}if(!Array.isArray(i)||!i.every(js)){l.error("Invalid client textDocument/didChange, contentChanges invalid");return}let o=n.uri,s=n.version;this.registerDiagnosticCallback(o),this.messageHandle.onAsyncDidChange({uri:o,version:s,contentChanges:i})}handleDidCloseNotification(e){let t=e.params;if(!f(t)){l.error("Invalid client textDocument/didClose, params missing or not an object");return}let{textDocument:n}=t;if(!f(n)||typeof n.uri!="string"){l.error("Invalid client textDocument/didClose, malformed or missing required parameters");return}let i=typeof t.isManual=="boolean"?t.isManual:!1;this.messageHandle.closeFile(n.uri,i)}handleDidChangePackageDependencies(e){let t=e.params;if(!f(t)){l.error("Invalid client aceProject/onDidChangePakcageDependencies, params missing or not an object");return}let{moduleSet:n}=t;if(!Array.isArray(n)||n.length===0){l.error("Invalid client aceProject/onDidChangePakcageDependencies, malformed or missing required parameters");return}this.messageHandle.sendModuleDependencyUpdate(t)}handleDidChangeWatchedFiles(e){let t=e.params;if(!f(t)){l.error("Invalid client workspace/didChangeWatchedFiles, params missing or not an object");return}let{changes:n}=t;if(!Array.isArray(n)){l.error("Invalid client workspace/didChangeWatchedFiles, malformed or missing required parameters");return}this.messageHandle.onDidChangeWatchedFiles(n)}withResettableTimeout(e,t,n){return new Promise((i,o)=>{let s,a=()=>{s=setTimeout(()=>{o(new Error(`${t} timeout after ${n}ms`))},n)},c=()=>{clearTimeout(s),a()};a(),e(()=>{clearTimeout(s),i()},c)})}async dispose(){await this.messageHandle.stop()}};import*as ve from"fs";import*as q from"path";import{createHash as Zd}from"crypto";import{EventEmitter as Xd}from"events";var Wn=class extends Xd{constructor(t,n=500){super();this.projectRoot=t;this.debounceMs=n}projectRoot;watchers=new Map;debounceTimers=new Map;contentHashes=new Map;buildProfileWatcher=null;lastModulesSnapshot="";lastModules=[];debounceMs;start(){let t=this.parseModulesFromBuildProfile();this.lastModules=t,this.lastModulesSnapshot=this.computeModulesSnapshot(t),this.refreshWatchTargets(),this.watchBuildProfile()}refreshWatchTargets(){let t=new Set(this.collectWatchTargets()),n=new Set(this.watchers.keys());for(let i of t)n.has(i)||(this.watchFile(i),l.info(`[ConfigFileWatcher] Started watching: ${i}`));for(let i of n)t.has(i)||(this.unwatchFile(i),l.info(`[ConfigFileWatcher] Stopped watching: ${i}`));l.info(`[ConfigFileWatcher] Watching ${this.watchers.size} oh-package.json5 file(s)`)}watchBuildProfile(){let t=this.getBuildProfilePath();if(!ve.existsSync(t)){l.warn(`[ConfigFileWatcher] build-profile.json5 not found at ${t}, cannot watch for module changes`);return}try{this.buildProfileWatcher=ve.watch(t,n=>{n==="change"&&this.onBuildProfileChanged()}),this.buildProfileWatcher.on("error",n=>{l.error(`[ConfigFileWatcher] build-profile.json5 watch error: ${n.message}`)}),l.info(`[ConfigFileWatcher] Watching module registry: ${t}`)}catch(n){l.error(`[ConfigFileWatcher] Failed to watch build-profile.json5: ${n instanceof Error?n.message:String(n)}`)}}emitModuleAddedEvents(t,n){for(let i of t){let o=q.resolve(this.projectRoot,i.srcPath);this.emit("configChanged",{source:"buildProfile",kind:1,filePath:o,relativePath:i.srcPath,timestamp:n,moduleName:i.name})}}emitModuleRemovedEvents(t,n){for(let i of t){let o=q.resolve(this.projectRoot,i.srcPath);this.emit("configChanged",{source:"buildProfile",kind:2,filePath:o,relativePath:i.srcPath,timestamp:n,removedModuleName:i.name})}}emitModuleRenamedEvents(t,n){for(let i of t){let o=q.resolve(this.projectRoot,i.after.srcPath);this.emit("configChanged",{source:"buildProfile",kind:3,filePath:o,relativePath:i.after.srcPath,timestamp:n,moduleName:i.after.name,removedModuleName:i.before.name})}}emitModuleMovedEvents(t,n){for(let i of t){let o=q.resolve(this.projectRoot,i.after.srcPath);this.emit("configChanged",{source:"buildProfile",kind:6,filePath:o,relativePath:i.after.srcPath,timestamp:n,moduleName:i.after.name})}}processBuildProfileDiff(t){this.refreshWatchTargets();let n=Date.now();this.emitModuleAddedEvents(t.added,n),this.emitModuleRemovedEvents(t.removed,n),this.emitModuleRenamedEvents(t.renamed,n),this.emitModuleMovedEvents(t.moved,n)}onBuildProfileChanged(){let t="__build_profile__",n=this.debounceTimers.get(t);n&&clearTimeout(n);let i=setTimeout(()=>{this.debounceTimers.delete(t);let o=this.parseModulesFromBuildProfile(),s=this.computeModulesSnapshot(o);if(s===this.lastModulesSnapshot){l.info("[ConfigFileWatcher] build-profile.json5 changed but modules unchanged, skipping");return}let a=this.diffModules(this.lastModules,o);this.lastModules=o,this.lastModulesSnapshot=s,l.info(`[ConfigFileWatcher] build-profile.json5 modules changed, added=${a.added.length}, removed=${a.removed.length}, renamed=${a.renamed.length}, moved=${a.moved.length}`),this.processBuildProfileDiff(a)},this.debounceMs);this.debounceTimers.set(t,i)}computeModulesSnapshot(t){return t.map(i=>`${i.name}::${i.srcPath}`).sort().join("|")}diffModules(t,n){let i=this.buildModuleMatchState(n),o={added:[],removed:[],renamed:[],moved:[]};return this.matchExactModules(t,i),this.matchRenamedModules(t,i,o),this.matchMovedModules(t,i,o),this.collectRemovedModules(t,i,o),this.collectAddedModules(n,i,o),o}buildModuleMatchState(t){let n=new Map,i=new Map;for(let o of t)n.set(o.srcPath,o),i.set(o.name,o);return{matchedOld:new Set,matchedNew:new Set,newBySrc:n,newByName:i}}matchExactModules(t,n){for(let i of t){let o=n.newBySrc.get(i.srcPath);o&&o.name===i.name&&(n.matchedOld.add(i),n.matchedNew.add(o))}}matchRenamedModules(t,n,i){for(let o of t){if(n.matchedOld.has(o))continue;let s=n.newBySrc.get(o.srcPath);s&&!n.matchedNew.has(s)&&s.name!==o.name&&(i.renamed.push({before:o,after:s}),n.matchedOld.add(o),n.matchedNew.add(s))}}matchMovedModules(t,n,i){for(let o of t){if(n.matchedOld.has(o))continue;let s=n.newByName.get(o.name);s&&!n.matchedNew.has(s)&&s.srcPath!==o.srcPath&&(i.moved.push({before:o,after:s}),n.matchedOld.add(o),n.matchedNew.add(s))}}collectRemovedModules(t,n,i){for(let o of t)n.matchedOld.has(o)||i.removed.push(o)}collectAddedModules(t,n,i){for(let o of t)n.matchedNew.has(o)||i.added.push(o)}parseModulesFromBuildProfile(){let t=this.getBuildProfilePath();try{let n=J(t);if(typeof n!="object"||n===null)return[];let i=n.modules;return Array.isArray(i)?i.filter(o=>{if(typeof o!="object"||o===null)return!1;let s=o;return typeof s.name=="string"&&typeof s.srcPath=="string"}):[]}catch(n){return l.warn(`[ConfigFileWatcher] Failed to parse build-profile.json5: ${n instanceof Error?n.message:String(n)}`),[]}}collectWatchTargets(){let t=[],n=q.join(this.projectRoot,I.OH_PACKAGE_JSON5);ve.existsSync(n)&&t.push(n);let i=this.parseModulesFromBuildProfile();for(let o of i){let s=q.resolve(this.projectRoot,o.srcPath),a=q.join(s,I.OH_PACKAGE_JSON5);ve.existsSync(a)&&t.push(a)}return t}getBuildProfilePath(){return q.join(this.projectRoot,"build-profile.json5")}computeFileHash(t){try{let n=ve.readFileSync(t,"utf-8");return Zd("sha256").update(n).digest("hex")}catch{return null}}watchFile(t){if(!this.watchers.has(t))try{let n=this.computeFileHash(t);n&&this.contentHashes.set(t,n);let i=ve.watch(t,o=>{o==="change"&&this.onFileChanged(t)});i.on("error",o=>{l.error(`[ConfigFileWatcher] Watch error for ${t}: ${o.message}`)}),this.watchers.set(t,i)}catch(n){l.error(`[ConfigFileWatcher] Failed to watch ${t}: ${n instanceof Error?n.message:String(n)}`)}}unwatchFile(t){let n=this.watchers.get(t);n&&(n.close(),this.watchers.delete(t)),this.contentHashes.delete(t);let i=this.debounceTimers.get(t);i&&(clearTimeout(i),this.debounceTimers.delete(t))}onFileChanged(t){let n=this.debounceTimers.get(t);n&&clearTimeout(n);let i=setTimeout(()=>{this.debounceTimers.delete(t);let o=this.computeFileHash(t);if(!o){l.warn(`[ConfigFileWatcher] Could not read file for hash: ${t}`);return}if(this.contentHashes.get(t)===o){l.info(`[ConfigFileWatcher] File touched but content unchanged, skipping: ${t}`);return}this.contentHashes.set(t,o),l.info(`[ConfigFileWatcher] Config file content changed: ${t}`);let a={source:"ohPackage",kind:4,filePath:t,fileName:q.basename(t),relativePath:q.relative(this.projectRoot,t),timestamp:Date.now()};this.emit("configChanged",a)},this.debounceMs);this.debounceTimers.set(t,i)}stop(){for(let[,t]of this.watchers)t.close();this.watchers.clear(),this.buildProfileWatcher&&(this.buildProfileWatcher.close(),this.buildProfileWatcher=null);for(let t of this.debounceTimers.values())clearTimeout(t);this.debounceTimers.clear(),this.contentHashes.clear(),l.info("[ConfigFileWatcher] All watchers stopped")}};import*as Ae from"fs";import*as te from"path";import{createHash as Qd}from"crypto";import{EventEmitter as eu}from"events";var Un=class extends eu{constructor(t,n=500){super();this.projectRoot=t;this.debounceMs=n,this.coalesceMs=n+300,this.depMapDir=te.join(t,kt)}projectRoot;dirWatcher=null;contentHashes=new Map;lastModules=[];debounceMs;depMapDir;pendingTags=[];pendingRenames=[];coalesceTimer=null;coalesceMs;fullScanTimer=null;pollInterval=null;initialScanDone=!1;start(){if(!Ae.existsSync(this.depMapDir)){l.warn(`[DependencyMapWatcher] dependencyMap dir not found: ${this.depMapDir}, skip watching`);return}this.lastModules=this.parseModulesFromDepMap();try{this.dirWatcher=Ae.watch(this.depMapDir,{recursive:!0},(t,n)=>this.onDirEvent(t,n)),this.dirWatcher.on("error",t=>{l.error(`[DependencyMapWatcher] Directory watch error for ${this.depMapDir}: ${t.message}`)})}catch(t){l.error(`[DependencyMapWatcher] Failed to watch directory ${this.depMapDir}: ${t instanceof Error?t.message:String(t)}`);return}this.pollInterval=setInterval(()=>this.scanAllCacheFiles(),2500),l.info(`[DependencyMapWatcher] Started, watching directory (recursive): ${this.depMapDir}, modules: [${this.lastModules.map(t=>t.name).join(", ")}]`)}canonicalPath(t){return $(te.resolve(t))}onDirEvent(t,n){if(!n||typeof n!="string")return;let i=n.replace(/\\/g,"/"),o;if(i===I.OH_PACKAGE_JSON5)o="root-oh-package";else if(i===je)o="dep-map-json";else{let a=i.match(/^([^/]+)\/oh-package\.json5$/);o=a?`module:${a[1]}`:""}if(!o)return;let s=te.join(this.depMapDir,n);Ae.existsSync(s)&&this.scheduleDebouncedFullScan()}stop(){this.dirWatcher&&(this.dirWatcher.close(),this.dirWatcher=null),this.fullScanTimer&&(clearTimeout(this.fullScanTimer),this.fullScanTimer=null),this.pollInterval&&(clearInterval(this.pollInterval),this.pollInterval=null),this.coalesceTimer&&(clearTimeout(this.coalesceTimer),this.coalesceTimer=null),this.pendingTags=[],this.pendingRenames=[],this.contentHashes.clear(),this.initialScanDone=!1,l.info("[DependencyMapWatcher] All watchers stopped")}scheduleDebouncedFullScan(){this.fullScanTimer&&clearTimeout(this.fullScanTimer),this.fullScanTimer=setTimeout(()=>{this.fullScanTimer=null,this.scanAllCacheFiles()},this.debounceMs)}scanAllCacheFiles(){let t=te.join(this.depMapDir,I.OH_PACKAGE_JSON5),n=te.join(this.depMapDir,je),i=this.parseModulesFromDepMap(),o=[{path:t,tag:"root-oh-package"},{path:n,tag:"dep-map-json"},...i.map(s=>({path:te.join(this.depMapDir,s.name,I.OH_PACKAGE_JSON5),tag:`module:${s.name}`}))];for(let{path:s,tag:a}of o){if(!Ae.existsSync(s))continue;let c=this.canonicalPath(s),d=this.computeFileHash(s);if(!d)continue;let u=this.contentHashes.get(c);if(!this.initialScanDone){this.contentHashes.set(c,d);continue}u!==d&&(this.contentHashes.set(c,d),l.info(`[DependencyMapWatcher] Cache file changed: ${s} (tag=${a})`),this.scheduleCoalescedReload(a))}this.initialScanDone||(this.initialScanDone=!0)}parseModulesFromDepMap(){let t=te.join(this.depMapDir,je);try{let n=J(t);if(typeof n!="object"||n===null)return[];let i=n.modules;return Array.isArray(i)?i.filter(o=>{if(typeof o!="object"||o===null)return!1;let s=o;return typeof s.name=="string"&&typeof s.srcPath=="string"}):[]}catch(n){return l.warn(`[DependencyMapWatcher] Failed to parse dependencyMap.json5: ${n instanceof Error?n.message:String(n)}`),[]}}scheduleCoalescedReload(t){this.pendingTags.push(t),t==="dep-map-json"&&this.applyDepMapJsonDiff(),this.coalesceTimer&&clearTimeout(this.coalesceTimer),this.coalesceTimer=setTimeout(()=>{this.coalesceTimer=null,this.flushPendingReload()},this.coalesceMs)}collectPendingState(){let t=this.pendingTags,n=this.pendingRenames;return this.pendingTags=[],this.pendingRenames=[],{tags:t,renameEntries:n}}processTagsIntoSets(t,n,i,o){for(let s of t)s.startsWith("module:")?(i.add(s.substring(7)),n.add("moduleDepsChanged")):s.startsWith("dep-added:")?(i.add(s.substring(10)),n.add("moduleAdded")):s.startsWith("dep-removed:")&&(o.add(s.substring(12)),n.add("moduleRemoved"))}processRenameEntries(t,n,i,o,s){for(let a of t)s.push(a.info),i.add(a.info.newName),o.add(a.info.oldName),n.add(a.kind)}buildAddedNamesSet(t,n){let i=new Set;for(let o of t)o.startsWith("dep-added:")&&i.add(o.substring(10));for(let o of n)i.add(o.info.newName);return i}emitIncrementalReload(t,n,i,o,s){l.info(`[DependencyMapWatcher] Coalesced \u2192 kinds=[${[...t].join(",")}], changed=[${[...n].join(",")}], removed=[${[...i].join(",")}], added=[${[...o].join(",")}], renames=[${s.map(a=>`${a.oldName}\u2192${a.newName}`).join(",")}]`),this.emit("reload",{fullReload:!1,kinds:[...t],changedModules:[...n],removedModuleNames:[...i],addedModuleNames:[...o],renames:s.length>0?s:void 0})}flushPendingReload(){let{tags:t,renameEntries:n}=this.collectPendingState();if(t.length===0&&n.length===0)return;if(l.info(`[DependencyMapWatcher] Flushing coalesced reload, tags=[${t.join(", ")}], renames=${n.length}`),t.includes("root-oh-package")){l.info("[DependencyMapWatcher] Root oh-package.json5 in batch \u2192 full reload"),this.emit("reload",{fullReload:!0,kinds:["projectDepsChanged"]});return}let i=new Set,o=new Set,s=new Set,a=[];this.processTagsIntoSets(t,i,o,s),this.processRenameEntries(n,i,o,s,a);for(let d of o)s.delete(d);if(o.size===0&&s.size===0&&a.length===0){l.info("[DependencyMapWatcher] Coalesced batch has no effective changes, skipping");return}let c=this.buildAddedNamesSet(t,n);this.emitIncrementalReload(i,o,s,c,a)}normalizeSrcPath(t){return $(t).replace(/^\.\//,"").replace(/\/$/,"")}buildModuleLookupMaps(t){let n=new Map(t.map(o=>[o.name,o])),i=new Map(t.map(o=>[this.normalizeSrcPath(o.srcPath),o]));return{byName:n,bySrcPath:i}}detectModuleRenames(t,n,i,o){for(let[s,a]of t){let c=n.get(s);if(!c||c.name===a.name)continue;this.pendingRenames.push({kind:"moduleRenamed",info:{oldName:a.name,newName:c.name,oldSrcPath:a.srcPath,newSrcPath:c.srcPath,kind:"moduleRenamed"}}),i.add(a.name),o.add(c.name);let d=te.join(this.depMapDir,a.name,I.OH_PACKAGE_JSON5);this.contentHashes.delete(this.canonicalPath(d)),l.info(`[DependencyMapWatcher] Module renamed: ${a.name} \u2192 ${c.name} (srcPath=${s})`)}}detectModuleMoves(t,n,i,o){for(let[s,a]of t){if(i.has(s))continue;let c=n.get(s);!c||c.srcPath===a.srcPath||(this.pendingRenames.push({kind:"moduleMoved",info:{oldName:a.name,newName:c.name,oldSrcPath:a.srcPath,newSrcPath:c.srcPath,kind:"moduleMoved"}}),i.add(s),o.add(s),l.info(`[DependencyMapWatcher] Module moved: ${s} srcPath ${a.srcPath} \u2192 ${c.srcPath}`))}}detectAddedModules(t,n,i){for(let[o]of t)i.has(o)||n.has(o)||(this.pendingTags.push(`dep-added:${o}`),i.add(o))}detectRemovedModules(t,n,i){for(let[o]of t)if(!i.has(o)&&!n.has(o)){this.pendingTags.push(`dep-removed:${o}`),i.add(o);let s=te.join(this.depMapDir,o,I.OH_PACKAGE_JSON5);this.contentHashes.delete(this.canonicalPath(s))}}logDepMapDiffResult(){let t=this.pendingTags.filter(i=>i.startsWith("dep-")),n=this.pendingRenames.map(i=>`${i.kind}(${i.info.oldName}\u2192${i.info.newName})`);l.info(`[DependencyMapWatcher] dependencyMap.json5 diff complete, depTags: [${t.join(", ")}], renames: [${n.join(", ")}]`)}applyDepMapJsonDiff(){let t=this.parseModulesFromDepMap(),{byName:n,bySrcPath:i}=this.buildModuleLookupMaps(this.lastModules),{byName:o,bySrcPath:s}=this.buildModuleLookupMaps(t),a=new Set,c=new Set;this.detectModuleRenames(i,s,a,c),this.detectModuleMoves(n,o,a,c),this.detectAddedModules(o,n,c),this.detectRemovedModules(n,o,a),this.lastModules=t,this.logDepMapDiffResult()}computeFileHash(t){try{let n=Ae.readFileSync(t,"utf-8");return Qd("sha256").update(n).digest("hex")}catch{return null}}};import{spawn as tu}from"child_process";import*as Vn from"path";import*as zn from"fs";var nu=600*1e3;function ru(r,e,t){let n=t.split(/\s+/).filter(i=>i.length>0);return[r,[e,...n]]}function iu(r){let e=[],t=[];return r.stdout?.on("data",n=>{e.push(n.toString())}),r.stderr?.on("data",n=>{t.push(n.toString())}),{stdout:e,stderr:t}}function Bn(r){return r.join("")}function ou(r,e,t){if(e)return{success:!1,output:"Build process killed by signal "+e+`.
|
|
1236
|
+
Output so far:
|
|
1237
|
+
`+t,exitCode:-1};let n=r??-1;return{success:n===0,output:t,exitCode:n}}function su(r,e,t){return new Promise(n=>{let i=tu(r[0],r[1],{cwd:e,env:t,windowsHide:!0,stdio:["ignore","pipe","pipe"]}),{stdout:o,stderr:s}=iu(i),a=setTimeout(()=>{i.kill();let c=[Bn(o),Bn(s)].filter(Boolean).join(`
|
|
1238
|
+
`).trim();n({success:!1,output:`Build process timeout after 10 minutes.
|
|
1239
|
+
Output so far:
|
|
1240
|
+
`+c,exitCode:-1})},nu);i.on("close",(c,d)=>{clearTimeout(a);let u=[Bn(o),Bn(s)].filter(Boolean).join(`
|
|
1241
|
+
`).trim()||"";n(ou(c,d,u))}),i.on("error",c=>{clearTimeout(a),n({success:!1,output:`Build execution exception: ${c.message}`,exitCode:-1})})})}async function Jr(r,e,t,n,i){let o={...process.env,DEVECO_SDK_HOME:n},s=ru(e,t,i);return await su(s,r,o)}function au(r){let e=Vn.join(Vn.dirname(r),"tools","hvigor","bin","hvigorw.js");return{node_path:cn(r),hvigor_path:e,sdk_path:r}}function cu(r){return!r.node_path||!zn.existsSync(r.node_path)?`Node path not found or invalid: ${r.node_path}`:!r.hvigor_path||!zn.existsSync(r.hvigor_path)?`Hvigor path not found or invalid: ${r.hvigor_path}`:!r.sdk_path||!zn.existsSync(r.sdk_path)?`SDK path not found or invalid: ${r.sdk_path}`:null}var lu="--sync -p product=default --analyze=normal --parallel --incremental --no-daemon";async function Fs(r,e){try{let t=au(e),n=cu(t);return n!=null?(l.info(`Config validation failed: ${n}`),!1):(await Jr(r,t.node_path,t.hvigor_path,e,lu)).success}catch(t){return l.info(`syncProject failed: ${JSON.stringify(t)}`),!1}}import{spawn as du}from"child_process";import*as Kr from"fs";import*as Rt from"path";var uu=["install","--all"];function pu(r){let e=r.replace(/sdk\/?$/i,"tools"),t=Rt.join(e,"ohpm","bin","pm-cli.js");if(Kr.existsSync(t))return t;let n=r.toLowerCase().endsWith("sdk")?Rt.dirname(r):r;return t=Rt.join(n,"ohpm","bin","pm-cli.js"),Kr.existsSync(t)?t:null}async function hu(r,e,t,n){return new Promise(i=>{let o=du(r,[e,...uu],{cwd:t,env:{...process.env,DEVECO_SDK_HOME:n},windowsHide:!0,stdio:["ignore","pipe","pipe"]}),s="",a="";o.stdout?.on("data",c=>{s+=c.toString()}),o.stderr?.on("data",c=>{a+=c.toString()}),o.on("close",c=>{let d=[s,a].filter(Boolean).join(`
|
|
1242
|
+
`);i({exitCode:c??-1,output:d})}),o.on("error",c=>{let d=[s,a].filter(Boolean).join(`
|
|
1243
|
+
`);i({exitCode:-1,output:d+`
|
|
1244
|
+
`+c.message})})})}function mu(r){r.split(/\r?\n/).filter(Boolean).forEach(e=>l.info("[ohpm] %s",e))}async function $s(r,e){try{let t=cn(e);if(!t)return l.error("node \u8DEF\u5F84\u4E0D\u5B58\u5728"),!1;let n=pu(e);if(!n)return l.error("ohpm (pm-cli.js) \u4E0D\u5B58\u5728"),!1;let{exitCode:i,output:o}=await hu(t,n,r,e);return mu(o),i===0?(l.info("ohpm \u5B89\u88C5\u6210\u529F"),!0):(l.error("ohpm \u5B89\u88C5\u5931\u8D25\uFF0C\u9000\u51FA\u7801: %s",i),l.error("ohpm \u8F93\u51FA: %s",o),!1)}catch(t){return l.error("ohpm \u5B89\u88C5\u5F02\u5E38",t),!1}}var _s={UNINITIALIZED:-32099,UNKNOWN:-32e3},Ot=class r extends Error{code;constructor(e,t){super(e),this.name="ArkTsProxyError",this.code=t}static uninitialized(e){return new r(e,_s.UNINITIALIZED)}static unknown(e="Unknown error"){return new r(e,_s.UNKNOWN)}toJsonRpcErrorParams(){return{code:this.code,message:this.message}}};var ct=class{config;lspProxy=null;configWatcher=null;depMapWatcher=null;isInitialized=!1;lastEditorOpenFiles=[];onMessage=()=>{};disposeOnce=null;constructor(e){this.config=e}setOnMessage(e){this.onMessage=e}async start(e=[]){this.lastEditorOpenFiles=e,this.startConfigWatcher(),this.startLspProxy(e)}sendNotification(e){if(!this.lspProxy){l.warn("[ArktsLspManager] sendNotification before LSP ready, dropped");return}this.lspProxy.sendNotification(e)}sendRequest(e){if(!this.lspProxy){l.warn("[ArktsLspManager] sendRequest before LSP ready, dropped");return}this.lspProxy.sendRequest(e)}static async handleSyncProject(e,t){if(l.info("[ArktsLspManager] Received arkts/syncProject"),!e||!t)return l.error("[ArktsLspManager] handleSyncProject: workspaceRoot or sdkPath is empty"),!1;if(!await $s(e,t))return l.error("[ArktsLspManager] ohpm install failed"),!1;let i=await Fs(e,t);return i?l.info("[ArktsLspManager] syncProject completed successfully"):l.error("[ArktsLspManager] syncProject failed"),i}async dispose(){return this.disposeOnce||(this.disposeOnce=this.performDispose()),this.disposeOnce}async performDispose(){try{this.configWatcher?.stop()}catch(e){l.warn(`[ArktsLspManager] configWatcher stop error: ${e}`)}try{this.depMapWatcher?.stop()}catch(e){l.warn(`[ArktsLspManager] depMapWatcher stop error: ${e}`)}if(this.configWatcher=null,this.depMapWatcher=null,this.lspProxy){try{await this.lspProxy.dispose()}catch(e){l.warn(`[ArktsLspManager] lspProxy dispose error: ${e}`)}this.lspProxy=null}this.isInitialized=!1}startLspProxy(e){let t=new _n(this.config.sdkPath,this.config.arktsLangServerPath,this.config.workspaceRoot,this.config.indexLogPath,this.config.nodeMaxOldSpaceSize);t.setOnMessage(n=>this.handleLspMessage(n)),t.start(e,n=>this.handleLspInitialized(n)),this.lspProxy=t}handleLspInitialized=e=>{if(this.isInitialized=e,e)l.info("[ArktsLspManager] LSP initialized"),this.startDependencyMapWatcher(),this.onMessage({jsonrpc:M,method:y.ARKTS_INITIALIZED,params:{}});else{let t=this.lspProxy?.consumeStartErrorMessage();l.error(`[ArktsLspManager] LSP initialization failed: ${t}`);let n=t?Ot.uninitialized(t):Ot.unknown();this.onMessage({jsonrpc:M,method:y.ARKTS_INITIALIZATION_FAILED,params:n.toJsonRpcErrorParams()}),this.lspProxy=null}};handleLspMessage(e){this.onMessage(e)}maybeRetryLspAfterSuccessfulSync(){this.isInitialized||this.lspProxy!==null||(l.info("[ArktsLspManager] Retrying LSP startup after successful sync"),this.onMessage({jsonrpc:M,method:y.ARKTS_REINITIALIZING,params:{}}),this.startLspProxy(this.lastEditorOpenFiles))}startConfigWatcher(){this.configWatcher||(this.configWatcher=new Wn(this.config.workspaceRoot),this.configWatcher.on("configChanged",e=>this.handleConfigChanged(e)),this.configWatcher.start())}startDependencyMapWatcher(){this.depMapWatcher||(this.depMapWatcher=new Un(this.config.workspaceRoot),this.depMapWatcher.on("reload",e=>{if(!this.lspProxy){l.warn("[ArktsLspManager] LspServerProxy not initialized, skip reload");return}let n=this.lspProxy.reloadDependenciesOnly(e).map(i=>({modulePath:i.modulePath??"",dependencies:i.dependencies??{},dynamicDependencies:i.dynamicDependencies??{}}));this.lspProxy.sendNotification({jsonrpc:M,method:y.ON_DID_CHANGE_PACKAGE_DEPENDENCIES_CLIENT,params:{moduleSet:n}}),this.onMessage({jsonrpc:M,method:y.ARKTS_SYNC_COMPLETED,params:{success:!0}})}),this.depMapWatcher.start())}handleConfigChanged(e){l.info(`[ArktsLspManager] Config file changed: ${e.filePath}`);try{let t=e.kind??4,n={jsonrpc:M,method:y.WORKSPACE_DID_CHANGE_CONFIGURATION,params:{relativePath:e.relativePath,timestamp:e.timestamp,changeSource:e.source,changeSignal:t,...e.filePath&&{filePath:e.filePath},...e.fileName!==void 0&&{fileName:e.fileName},...e.moduleName!==void 0&&{moduleName:e.moduleName},...e.removedModuleName!==void 0&&{removedModuleName:e.removedModuleName}}};this.onMessage(n)}catch(t){l.error(`[ArktsLspManager] Failed to handle config change: ${t instanceof Error?t.message:String(t)}`)}}};var fu=120*1e3,gu=300*1e3,yu=180*1e3,vu=10080*60*1e3,wu=7200*60*1e3,lt=class{manager=null;diagnosticWaiters=new Map;initialized=!1;initializing=!1;initPromise=null;initDeadlineTimer=null;initResolve=null;initReject=null;projectPath;devecoPath;arktsLangServerPath;nodeMaxOldSpaceSize;constructor(e,t,n){this.projectPath=e,this.devecoPath=t??"",this.arktsLangServerPath=null,this.nodeMaxOldSpaceSize=n}static getToolDefinition(){return{name:"check_ets_files",description:"\u5BF9\u4F20\u5165\u7684ets\u6587\u4EF6\u8FDB\u884C\u9759\u6001\u8BED\u6CD5\u68C0\u67E5(ArkTS-Check)\u5E76\u5B9E\u65F6\u8FD4\u56DE\u8BCA\u65AD\u4FE1\u606F\u3002",inputSchema:Zr.object({files:Zr.array(Zr.string()).describe('\u5F85\u68C0\u67E5\u7684 ETS \u6587\u4EF6\u8DEF\u5F84\u5217\u8868\uFF0C\u683C\u5F0F\u4E3A ["file1.ets","file2.ets",...]')})}}isInitializing(){return this.initializing}isInitialized(){return this.initialized}async initialize(){if(!this.initialized){if(this.initPromise){await this.initPromise;return}this.initializing=!0,this.initPromise=this.doInitialize().then(()=>{this.initialized=!0}).finally(()=>{this.initializing=!1}),await this.initPromise}}async doInitialize(){let{harmonyRoot:e,devecoPath:t,arktsLangServerPath:n}=this.resolveProjectAndDeveco(),i=le(e),{logPath:o,indexPath:s}=this.getLogAndIndexPath(i);setImmediate(()=>{Ur(s,vu,"[ArkTS-Check]"),Ur(o,wu,"[ArkTS-Check]")}),Cs(o);let a=this.nodeMaxOldSpaceSize?parseInt(this.nodeMaxOldSpaceSize,10):NaN,c=Number.isNaN(a)?void 0:a,d=ne.join(ce(t),"sdk");m.info(`ArktsCheck devecoPath: ${t}, contentRoot: ${ce(t)}, sdkPath: ${d}`),this.manager=new ct({sdkPath:d,arktsLangServerPath:n,workspaceRoot:$(i),indexLogPath:s,nodeMaxOldSpaceSize:c}),this.manager.setOnMessage(u=>this.handleLspMessage(u)),await new Promise((u,b)=>{this.initResolve=u,this.initReject=b,this.armInitTimer(gu),this.manager.start([]).catch(k=>{let de=k instanceof Error?k:new Error(String(k));this.failInit(de)})})}resolveProjectAndDeveco(){let e=fe(this.projectPath);if(!e)throw new Error(`Failed to find HarmonyOS project from path: ${this.projectPath}`);this.projectPath=e;let t=this.devecoPath??Ne();if(m.debug(`DevEco Studio installation path: ${t}, this.devecoPath: ${this.devecoPath}`),!t)throw new Error("DevEco Studio installation path not found");this.devecoPath=t;let n=ps(t);if(!n)throw new Error("arkts-lang-server path not found");return this.arktsLangServerPath=n,{harmonyRoot:e,devecoPath:t,arktsLangServerPath:n}}armInitTimer(e){this.initDeadlineTimer&&clearTimeout(this.initDeadlineTimer),this.initDeadlineTimer=setTimeout(()=>{let t=this.initReject;this.clearInitHandlers(),t?.(new Error("LSP initialize timeout"))},e)}clearInitHandlers(){this.initDeadlineTimer&&(clearTimeout(this.initDeadlineTimer),this.initDeadlineTimer=null),this.initResolve=null,this.initReject=null}failInit(e){let t=this.initReject;this.clearInitHandlers(),t?.(e)}async checkFile(e){this.initialized||await this.initialize();let t=It(Le(e)),n=Wr(e),i=await we.promises.readFile(e,"utf8"),s=`deveco.apptool.${ne.extname(e).replace(/^\./,"")||"plaintext"}`,a=new Promise((d,u)=>{let b=setTimeout(()=>{this.diagnosticWaiters.delete(t)&&u(new Error("Wait for diagnostics timeout"))},fu);this.diagnosticWaiters.set(t,{resolve:d,reject:u,timer:b})}),c={textDocument:{uri:n,text:i,languageId:s,version:i.length},editorFiles:[n],isFromEditor:!1};m.debug(`textDocument/didOpen uri=${n} content_len=${i.length}`),this.sendNotification("textDocument/didOpen",c);try{return await a}finally{this.sendNotification("textDocument/didClose",{textDocument:{uri:n},isManual:!1})}}async handleCall(e){if(!this.initialized)return this.buildNotReadyResponse();let t=[],n=[],i=this.collectValidFiles(e.files,t);return i.length===0?{content:[{type:"text",text:t.length>0?t.join(`
|
|
1245
|
+
`):"\u6CA1\u6709\u6709\u6548\u7684 .ets \u6587\u4EF6"}],isError:!0}:(await this.runDiagnosticsForFiles(i,t,n),this.formatCallResult(t,n))}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 n=this.projectPath,i=[];for(let o of e){let s=ne.isAbsolute(o)?o:ne.join(n,o);if(!we.existsSync(s)){t.push(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${o}`);continue}if(!we.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,n){for(let i of e){await fs(500);try{let o=await this.checkFile(i);n.push(bu(i,o))}catch(o){t.push(`${i} => wait for diagnostics failed: ${o.message}`)}}}formatCallResult(e,t){let n=[];e.length>0&&n.push(e.join(`
|
|
1246
|
+
`)),t.length>0&&n.push(t.join(`
|
|
1247
|
+
`));let i=n.join(`
|
|
1248
|
+
`).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(){if(this.failAllPending(new Error("LSP shutting down")),this.manager){try{await this.manager.dispose()}catch(e){m.warn(`Failed to dispose ArktsLspManager: ${e}`)}this.manager=null}this.initialized=!1,this.initializing=!1,this.initPromise=null,this.clearInitHandlers()}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,n=t.method;if(n)switch(n){case"textDocument/publishDiagnostics":case"textDocument/didOpen":this.handleDiagnosticsNotification(t.params);break;case"arkts/indexingProgress":this.initResolve&&(this.armInitTimer(yu),m.debug("Received arkts/indexingProgress, reset init timeout"));break;case"arkts/initialized":{m.info("Received arkts/initialized");let i=this.initResolve;this.clearInitHandlers(),i?.();break}case"arkts/initializationFailed":{let o=t.params?.message??"unknown";m.error(`LSP initialization failed: ${o}`);let s=this.initReject;this.clearInitHandlers(),s?.(new Error(`LSP initialize failed: ${o}`));break}default:break}}handleDiagnosticsNotification(e){if(!e)return;let t=e.uri;if(!t)return;let n=this.resolveDiagnosticWaiter(t);if(!n)return;if(typeof e.errorMessage=="string"){m.warn(`diagnostics error uri=${t} message=${e.errorMessage}`),n.resolve({errorMessage:e.errorMessage});return}let i=e.diagnostics,o=Array.isArray(i)?i.length:0;m.debug(`diagnostics received uri=${t} count=${o}`),n.resolve(Array.isArray(i)?i:[])}resolveDiagnosticWaiter(e){let t=It(e),n=this.popDiagnosticWaiter(t);if(n)return n;for(let i of ys(e)){let o=this.popDiagnosticWaiter(i);if(o)return o}}popDiagnosticWaiter(e){let t=this.diagnosticWaiters.get(e);if(t)return this.diagnosticWaiters.delete(e),clearTimeout(t.timer),t}failAllPending(e){for(let[,n]of this.diagnosticWaiters)clearTimeout(n.timer),n.reject(e);this.diagnosticWaiters.clear();let t=this.initReject;this.clearInitHandlers(),t?.(e)}getLogAndIndexPath(e){try{let t=ne.join(an(),"ArkTSCheck"),n=ne.join(t,"mapping-config.properties"),i=vs(e,n),o=`${Date.now()}${process.hrtime.bigint()%1000000n}`,s=ne.join(t,"lsp-log",String(i),o),a=ne.join(t,"lsp-index",String(i));return we.mkdirSync(s,{recursive:!0}),we.mkdirSync(a,{recursive:!0}),{logPath:le(s),indexPath:le(a)}}catch{return{logPath:"auto",indexPath:"auto"}}}};function bu(r,e){if(Array.isArray(e))return e.length===0?`${r} => no diagnostics`:`${r} => Diagnostic: ${JSON.stringify(e)}`;if(e&&typeof e=="object"&&typeof e.errorMessage=="string"){let t=e.errorMessage;return`${r} diagnostic failed, error_message: ${t}`}return`${r} => diagnostic failed, result: ${JSON.stringify(e)}`}import{spawn as Su}from"child_process";import*as A from"fs";import*as L from"path";import{z as Xr}from"zod";var Ws=60*1e3,Pu=30*1e3,Eu=new Set(["textDocument/didOpen","textDocument/didChange","textDocument/didClose","textDocument/didSave"]),Du=1e3,Qr=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=>{m.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 n=le(this.projectPath),i=Le(n),o=L.basename(n)||"workspace",s={processId:null,clientInfo:{name:"devecocli-mcp-server",version:"0.0.1"},rootPath:n,rootUri:i,workspaceFolders:[{uri:i,name:o}],capabilities:{}};await this.sendRequestToClangd("initialize",s,Ws),await this.sendNotificationToClangd("initialized",{}),this.backendReady=!0,this.wrapperState="proxying";for(let a of this.queuedDocumentNotifications)await this.writeToClangd(a);this.queuedDocumentNotifications.length=0,m.info("[CppCheck] clangd backend ready, switched to proxying mode")}async waitForBackendReady(){if(this.backendReady)return;let e=Ws,t=Date.now();for(;!this.backendReady&&!this.closed&&Date.now()-t<e;)await new Promise(n=>setTimeout(n,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=A.realpathSync(e)}catch{t=e}let n=Le(t),i=gs(t),o=await A.promises.readFile(t,"utf8"),s=new Promise((a,c)=>{let d=setTimeout(()=>{this.diagnosticWaiters.delete(n)&&c(new Error(`Timed out waiting for diagnostics: ${e}`))},Pu);this.diagnosticWaiters.set(n,{resolve:a,reject:c,timer:d})});try{await this.sendNotification("textDocument/didOpen",{textDocument:{uri:n,languageId:i,version:1,text:o}})}catch(a){let c=this.diagnosticWaiters.get(n);throw c&&(clearTimeout(c.timer),this.diagnosticWaiters.delete(n)),a}try{return await s}finally{await this.closeFile(n).catch(a=>{m.warn(`[CppCheck] didClose failed for ${n}: ${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){m.warn(`[CppCheck] shutdown request failed: ${e}`)}try{await this.sendNotificationToClangd("exit",null)}catch(e){m.warn(`[CppCheck] exit notification failed: ${e}`)}try{this.clangdStdin.end()}catch(e){m.warn(`[CppCheck] stdin.end() failed: ${e}`)}}}async sendNotification(e,t){let n={jsonrpc:"2.0",method:e,params:t??void 0};if(this.backendReady&&this.clangdStdin){await this.writeToClangd(n);return}Eu.has(e)&&this.queuedDocumentNotifications.push(n)}async closeFile(e){await this.sendNotification("textDocument/didClose",{textDocument:{uri:e}})}async sendRequestToClangd(e,t,n){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`))},n);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,n)=>{let i;try{i=JSON.stringify(e)}catch(u){n(new Error(`Failed to encode LSP message: ${u}`));return}let o=Buffer.from(i,"utf8"),s=Buffer.from(`Content-Length: ${o.length}\r
|
|
1249
|
+
\r
|
|
1250
|
+
`,"ascii"),a=!1,c=u=>{a||(a=!0,u?n(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
|
|
1251
|
+
\r
|
|
1252
|
+
`);if(t<0)return;let n=this.clangdBuffer.slice(0,t).toString("ascii"),i=/content-length:\s*(\d+)/i.exec(n);if(!i){this.clangdBuffer=this.clangdBuffer.slice(t+4);continue}let o=parseInt(i[1],10),s=t+4+o;if(this.clangdBuffer.length<s)return;let a=this.clangdBuffer.slice(t+4,s).toString("utf8");this.clangdBuffer=this.clangdBuffer.slice(s);try{let c=JSON.parse(a);this.dispatchMessage(c)}catch(c){m.error(`[CppCheck] Failed to parse C++ LSP JSON message: ${c}`)}}}dispatchMessage(e){if(typeof e.id=="number"){let t=this.pendingRequests.get(e.id);t&&(this.pendingRequests.delete(e.id),clearTimeout(t.timer),e.error?t.reject(new Error(e.error.message??JSON.stringify(e.error))):t.resolve(e.result??null));return}if(e.method==="textDocument/publishDiagnostics"&&e.params){let t=e.params,n=t.uri;if(!n)return;let i=Iu(n),o=this.diagnosticWaiters.get(i);if(o){this.diagnosticWaiters.delete(i),clearTimeout(o.timer);let s=Array.isArray(t.diagnostics)?t.diagnostics:[];m.info(`[CppCheck] Received C++ diagnostics for ${i} (${s.length} entries)`),o.resolve(s)}}}failAll(e){for(let[,t]of this.pendingRequests)clearTimeout(t.timer),t.reject(e);this.pendingRequests.clear();for(let[,t]of this.diagnosticWaiters)clearTimeout(t.timer),t.reject(e);this.diagnosticWaiters.clear()}async acquireFileCheckLock(){let e=this.fileCheckLock,t;return this.fileCheckLock=new Promise(n=>{t=n}),await e,t}};function Iu(r){try{let e=new URL(r);if(e.protocol==="file:"){let t=decodeURIComponent(e.pathname);return process.platform==="win32"&&/^\/[a-zA-Z]:/.test(t)&&(t=t.slice(1)),Le(t)}}catch{}return r}function Cu(r){let e=L.extname(r).replace(/^\./,"").toLowerCase();return["c","cpp","cxx","cc","h","hpp","hxx","hh","c++","h++"].includes(e)}function Au(r,e){let t=L.join(r,e.name);return e.isDirectory()?e.name===".cxx"||Us(t):Cu(t)}function Us(r){if(!A.existsSync(r))return!1;try{return A.readdirSync(r,{withFileTypes:!0}).some(t=>Au(r,t))}catch{}return!1}function Bs(r){let t=new Fe(r).getAllModuleInfo(),n=[];for(let i of t){let o=i.srcPath.replace(/^\.\//,""),s=L.join(r,o);Us(s)&&n.push(i)}return n}function ku(r){let e=[],n=new Fe(r).getAllModuleInfo();for(let i of n){let o=i.srcPath.replace(/^\.\//,""),s=L.join(r,o,".cxx");A.existsSync(s)&&zs(s,e)}return e}function zs(r,e){try{let t=A.readdirSync(r,{withFileTypes:!0});for(let n of t){let i=L.join(r,n.name);n.isDirectory()?zs(i,e):n.name==="compile_commands.json"&&e.push(i)}}catch{}}function Tu(r){let e=[];for(let t of r)try{let n=A.readFileSync(t,"utf8"),i=JSON.parse(n);e.push(...i)}catch{}return e}function Mu(r,e){let t=L.join(r,...$r.slice(0,-1));A.mkdirSync(t,{recursive:!0});let n=L.join(t,"compile_commands.json");A.writeFileSync(n,JSON.stringify(e,null,2),"utf8")}function xu(r){let e=ku(r);if(e.length>0){let t=Tu(e);Mu(r,t),m.info(`[CppCheck] compile_commands.json \u5DF2\u751F\u6210\uFF0C\u5171 ${t.length} \u6761\u7F16\u8BD1\u547D\u4EE4`)}else m.warn("[CppCheck] \u672A\u627E\u5230\u4EFB\u4F55 compile_commands.json \u6587\u4EF6")}function Ru(r){let e=new Set;for(let t of r)if(t.file)try{e.add(A.realpathSync(t.file))}catch{e.add(t.file)}return e}function Ou(r,e){try{let t=A.realpathSync(r);if(!e.has(t))return m.info(`[CppCheck] File not covered by compile_commands.json: ${r}`),!1}catch{}return!0}function Nu(r,e){if(!A.existsSync(r))return!1;try{let t=A.readFileSync(r,"utf8"),n=JSON.parse(t),i=Ru(n);for(let o of e)if(!Ou(o,i))return!1;return!0}catch(t){return m.warn(`[CppCheck] Failed to read/parse compile_commands.json: ${t}`),!1}}async function Lu(r,e,t){let n=L.join(ce(e),"sdk"),i=process.execPath||"node",o=L.join(ce(e),"tools");m.info(`CppCheck devecoPath: ${e}, contentRoot: ${ce(e)}, sdkPath: ${n}, toolsDir: ${o}`);let s=L.join(o,"hvigor","bin","hvigorw.js");for(let a of t){let c=["--mode","module","-p",`module=${a.name}`,"-p","product=default","compileNative","--analyze=normal","--parallel","--incremental","--no-daemon"].join(" ");m.info(`[CppCheck] Running compileNative for module: ${a.name}`);let d=await Jr(r,i,s,n,c);d.success?m.info(`[CppCheck] compileNative ${a.name} \u6210\u529F`):m.warn(`[CppCheck] compileNative ${a.name} \u5931\u8D25: ${d.output}`)}}async function Hu(r,e){let t=Bs(r);if(t.length===0){m.info("[CppCheck] \u672A\u53D1\u73B0\u542BC++\u7684\u6A21\u5757\uFF0C\u8DF3\u8FC7\u521D\u59CB\u5316");return}m.info(`[CppCheck] \u53D1\u73B0 ${t.length} \u4E2A\u542BC++\u7684\u6A21\u5757: ${t.map(n=>n.name).join(", ")}`),await Lu(r,e,t),xu(r)}var dt=class{projectPath;devecoPath;clangdProcess=null;client=null;initializedProjectPath=null;initializing=!1;initPromise=null;pollHandle=null;backendReady=!1;constructor(e,t){this.projectPath=e,this.devecoPath=on(t??"")??t??null}static getToolDefinition(){return{name:"check_cpp_files",description:"\u5BF9\u4F20\u5165\u7684 C/C++ \u6587\u4EF6\u8FDB\u884C\u9759\u6001\u8BED\u6CD5\u68C0\u67E5\u5E76\u8FD4\u56DE clangd \u8BCA\u65AD\u4FE1\u606F\u3002",inputSchema:Xr.object({files:Xr.array(Xr.string()).describe('\u5F85\u68C0\u67E5\u7684 C/C++ \u6587\u4EF6\u8DEF\u5F84\u5217\u8868\uFF0C\u683C\u5F0F\u4E3A ["file1.cpp","file2.hpp",...]')})}}isInitializing(){return this.initializing}isInitialized(){return this.client!==null&&this.initializedProjectPath!==null}async handleCall(e){let t=[],n=[],i=this.collectValidFiles(e.files,t);if(i.length===0)return{content:[{type:"text",text:t.length>0?t.join(`
|
|
1253
|
+
`):"\u6CA1\u6709\u6709\u6548\u7684 C/C++ \u6587\u4EF6"}],isError:!0};let o;try{o=await this.ensureInitializedWithFiles(i)}catch(a){return t.push(a.message),{content:[{type:"text",text:t.join(`
|
|
1254
|
+
`)}],isError:!0}}return await this.runDiagnosticsForFiles(o,i,t,n)&&this.shutdown().catch(a=>{m.warn(`[CppCheck] shutdown after diagnostic failure: ${a}`)}),this.formatCallResult(t,n)}async runDiagnosticsForFiles(e,t,n,i){let o=!1;for(let s of t)try{let a=await e.checkFile(s);a.length===0?i.push(`${s} => \u65E0\u8BCA\u65AD`):i.push(`${s} => Diagnostic: ${JSON.stringify(a)}`)}catch(a){o=!0,n.push(`${s} => \u83B7\u53D6\u8BCA\u65AD\u5931\u8D25: ${a.message}`)}return o}formatCallResult(e,t){let n=e.length>0;return!n&&t.length===0&&t.push("\u6CA1\u6709\u8FD4\u56DE\u4EFB\u4F55\u8BCA\u65AD\u4FE1\u606F"),{content:[{type:"text",text:[t.join(`
|
|
1255
|
+
`),e.join(`
|
|
1256
|
+
`)].filter(o=>o.trim().length>0).join(`
|
|
1257
|
+
`).trim()}],isError:n}}async ensureInitializedWithFiles(e){let t=le(this.projectPath);if(this.prepareCppCheck(t,e)){this.client&&this.initializedProjectPath&&(m.info("[CppCheck] Re-initializing C++ project due to file changes"),await this.shutdown());let i=this.devecoPath??Ne();if(!i)throw new Error("DevEco Studio installation path not found");this.devecoPath=i,await Hu(t,i)}else if(this.client&&this.initializedProjectPath){let i=le(this.projectPath);if(this.initializedProjectPath===i)return this.client;await this.shutdown()}return this.doEnsureInitialized()}prepareCppCheck(e,t){let n=rn(e);return A.existsSync(n)?Bs(e).length===0?(m.info("[CppCheck] No cpp modules found, no initialization needed"),!1):Nu(n,t)?(m.info("[CppCheck] All files covered, no initialization needed"),!1):(m.info("[CppCheck] Files not fully covered by compile_commands.json, needs initialization"),!0):(m.info("[CppCheck] compile_commands.json not found, needs initialization"),!0)}async doEnsureInitialized(){if(this.initPromise&&(await this.initPromise,this.client))return this.client;if(this.initializing=!0,this.initPromise=this.doInitialize().finally(()=>{this.initializing=!1,this.initPromise=null}),await this.initPromise,!this.client)throw new Error("C++ LSP failed to initialize");return this.client}async doInitialize(){let e=this.resolveProjectRoot();this.client=new Qr,await this.client.initialize(e),this.initializedProjectPath=e,m.info(`[CppCheck] Client initialized in wrapper mode for workspace: ${e}`),this.startPollingForClangd(e)}resolveProjectRoot(){let e=fe(this.projectPath);if(!e)throw new Error(`Failed to find HarmonyOS project from path: ${this.projectPath}`);return this.projectPath=e,le(e)}startPollingForClangd(e){let t=rn(e);if(A.existsSync(t)){m.info("[CppCheck] compile_commands.json found, spawning clangd immediately"),this.spawnAndConnectClangd(e).catch(n=>{m.error(`[CppCheck] Immediate clangd spawn failed: ${n}`)});return}m.info("[CppCheck] compile_commands.json not found, starting poll..."),this.pollHandle=setInterval(()=>{if(!this.client||this.client.isClosed()||this.backendReady){this.stopPolling();return}A.existsSync(t)&&(this.stopPolling(),m.info("[CppCheck] compile_commands.json found via poll, spawning clangd..."),this.spawnAndConnectClangd(e).catch(n=>{m.error(`[CppCheck] Clangd spawn from poll failed: ${n}`)}))},Du)}stopPolling(){this.pollHandle&&(clearInterval(this.pollHandle),this.pollHandle=null)}async spawnAndConnectClangd(e){let{clangdPath:t,compileCommandsDir:n}=this.resolveClangdPaths(e);m.info(`[CppCheck] Starting clangd for workspace: ${e} (clangd=${t})`);let i=this.spawnClangd(t,e,n);this.clangdProcess=i;try{await this.client.connectClangdProcess(i.stdin,i.stdout),this.backendReady=!0,m.info(`[CppCheck] clangd connected for workspace: ${e}`)}catch(o){if(m.error(`[CppCheck] Failed to connect clangd: ${o}`),this.clangdProcess&&!this.clangdProcess.killed){try{this.clangdProcess.kill()}catch{}this.clangdProcess=null}throw o}}resolveClangdPaths(e){let t=this.devecoPath??Ne();if(!t)throw new Error("DevEco Studio installation path not found");this.devecoPath=t;let n=hs(t);if(!n)throw new Error("clangd executable not found inside DevEco Studio SDK");let i=rn(e),o=L.dirname(i);return{clangdPath:n,compileCommandsDir:o}}spawnClangd(e,t,n){let i=Su(e,[`--compile-commands-dir=${n}`],{cwd:t,stdio:["pipe","pipe","pipe"]});if(!i.stdin||!i.stdout||!i.stderr)throw new Error("Failed to start clangd: stdio not available");return i.stderr.on("data",o=>{let s=o.toString("utf8").trimEnd();s&&m.warn(`[CppLsp stderr] ${s}`)}),i.on("exit",(o,s)=>{m.warn(`[CppCheck] clangd exited code=${o} signal=${s??"null"}`),this.clangdProcess===i&&(this.clangdProcess=null,this.backendReady=!1)}),i.on("error",o=>{m.error(`[CppCheck] clangd spawn error: ${o}`)}),i}collectValidFiles(e,t){let n=this.projectPath,i=[];for(let o of e){let s=L.isAbsolute(o)?o:L.join(n,o);if(!A.existsSync(s)){t.push(`\u6587\u4EF6\u4E0D\u5B58\u5728: ${o}`);continue}if(!A.statSync(s).isFile()){t.push(`\u4E0D\u662F\u666E\u901A\u6587\u4EF6: ${o}`);continue}if(!sn(s)){t.push(`\u4E0D\u662F\u53D7\u652F\u6301\u7684 C/C++ \u6587\u4EF6: ${o}`);continue}try{i.push(A.realpathSync(s))}catch{i.push(s)}}return i}async shutdown(){this.stopPolling();let e=this.client,t=this.clangdProcess;if(this.client=null,this.clangdProcess=null,this.initializedProjectPath=null,this.backendReady=!1,e)try{await e.close()}catch(n){m.warn(`[CppCheck] client.close() failed: ${n}`)}if(t&&!t.killed)try{t.kill()}catch(n){m.warn(`[CppCheck] failed to kill clangd: ${n}`)}}};var Vs=(s=>(s[s.IDLE=0]="IDLE",s[s.DISCOVERING=1]="DISCOVERING",s[s.SYNCING=2]="SYNCING",s[s.INITIALIZING=3]="INITIALIZING",s[s.READY=4]="READY",s[s.ERROR=5]="ERROR",s))(Vs||{}),ti=3,qn=class{server;toolRouter;config={};arktsCheckTool=null;cppCheckTool=null;projectState=0;workspaceRoot="";sdkPath="";initPromise=null;needsReinit=!1;initRetryCount=0;originalProjectPath="";constructor(e={}){this.config=e,zr(e.debug??!1);let t,n=e.projectPath?.trim()??"";this.originalProjectPath=n,n==="."?(t=process.cwd(),m.info(`Constructor: configuredPath is '.', startPath: '${t}'`)):n===""?(t="",m.info("Constructor: configuredPath is empty, startPath remains empty")):(t=n,m.info(`Constructor: using configured path as startPath: '${t}'`));let i=fe(t);m.info(`Constructor: findHarmonyProject('${t}') => ${i??"null"}`),this.config.projectPath=i??void 0,this.server=new ju({name:"devecocli-mcp-server",version:"0.0.1"}),this.toolRouter=Hr(),this.registerTools()}registerTools(){this.toolRouter.add({name:"check",description:"\u5BF9\u4F20\u5165\u7684 ArkTS (.ets) \u6216 C/C++ \u6587\u4EF6\u8FDB\u884C\u9759\u6001\u8BED\u6CD5\u68C0\u67E5\u5E76\u8FD4\u56DE\u8BCA\u65AD\u4FE1\u606F\u3002\u5DE5\u5177\u4F1A\u6839\u636E\u6587\u4EF6\u6269\u5C55\u540D\u81EA\u52A8\u9009\u62E9\u68C0\u67E5\u5668\uFF1A.ets \u8D70 ArkTS-Check\uFF0C.c/.cc/.cpp/.cxx/.h/.hh/.hpp/.hxx \u7B49\u8D70 clangd\u3002",inputSchema:ei.object({files:ei.array(ei.string()).describe('\u5F85\u68C0\u67E5\u7684\u6587\u4EF6\u8DEF\u5F84\u5217\u8868\uFF0C\u53EF\u540C\u65F6\u5305\u542B ArkTS (.ets) \u548C C/C++ \u6587\u4EF6\uFF0C\u683C\u5F0F\u4E3A ["src/main.ets","native/foo.cpp",...]')})},async e=>this.handleCheckCall(e))}validateContainment(e){let t=this.config.projectPath;if(t){let i=[];for(let o of e){let s=E.isPathContainedWithSymlink(o,t);s.contained||(m.warn(`Containment check failed: ${s.reason}`),i.push(s.reason))}return i.length>0?{content:[{type:"text",text:i.join(`
|
|
1258
|
+
`)}],isError:!0}:null}let n=e.filter(i=>ut.isAbsolute(i));return n.length>0?(m.warn(`Absolute paths rejected (no project root): ${n.join(", ")}`),{content:[{type:"text",text:n.map(i=>`\u4E0D\u5141\u8BB8\u4F7F\u7528\u7EDD\u5BF9\u8DEF\u5F84: ${i}`).join(`
|
|
1259
|
+
`)}],isError:!0}):null}async handleCheckCall(e){let t=Array.isArray(e.files)?e.files.filter(b=>typeof b=="string"):[];if(t.length===0)return m.warn("check tool called with empty files list"),{content:[{type:"text",text:"\u6CA1\u6709\u4F20\u5165\u4EFB\u4F55\u6587\u4EF6"}],isError:!0};let n=this.validateContainment(t);if(n)return n;let{etsFiles:i,cppFiles:o,unsupported:s}=$u(t);s.length>0&&m.warn(`Unsupported file types in check request: ${s.join(", ")}`);let a=s.map(b=>`\u4E0D\u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B: ${b}\uFF08\u4EC5\u652F\u6301 .ets \u4E0E C/C++ \u6E90/\u5934\u6587\u4EF6\uFF09`),c=[];i.length>0&&this.mergeCheckResult(await this.callArktsCheck(i),a,c),o.length>0&&this.mergeCheckResult(await this.callCppCheck(o),a,c);let d=a.length>0;return{content:[{type:"text",text:[c.join(`
|
|
1260
|
+
`),a.join(`
|
|
1261
|
+
`)].filter(b=>b.trim().length>0).join(`
|
|
1262
|
+
`).trim()||"\u672A\u6536\u96C6\u5230\u8BCA\u65AD\u4FE1\u606F"}],isError:d}}async callArktsCheck(e){switch(this.projectState){case 0:return this.handleIdleCheck();case 1:case 2:return m.warn(`ArkTS check rejected: project is ${Vs[this.projectState]}, files: ${e.join(", ")}`),{content:[{type:"text",text:"\u9879\u76EE\u6B63\u5728\u540C\u6B65\u4E2D\uFF0C\u8BF73\u79D2\u540E\u91CD\u8BD5"}],isError:!0};case 3:return m.warn(`ArkTS check rejected: LSP is initializing, files: ${e.join(", ")}`),{content:[{type:"text",text:"ArkTS LSP \u6B63\u5728\u521D\u59CB\u5316\u4E2D\uFF0C\u8BF73\u79D2\u540E\u91CD\u8BD5"}],isError:!0};case 5:return this.handleErrorCheck();case 4:return this.arktsCheckTool.handleCall({files:e})}}async handleIdleCheck(){return this.ensureProjectReady(),this.config.projectPath?(m.info(`Idle check: project '${this.config.projectPath}' already known, triggering init`),{content:[{type:"text",text:"\u68C0\u6D4B\u5230\u9E3F\u8499\u5DE5\u7A0B\uFF0C\u6B63\u5728\u540C\u6B65\u4E2D\uFF0C\u8BF73\u79D2\u540E\u91CD\u8BD5"}],isError:!0}):this.workspaceRoot||this.originalProjectPath?(m.info(`Idle check: no project path yet, will try from '${this.workspaceRoot}' or '${this.originalProjectPath}'`),{content:[{type:"text",text:"\u6B63\u5728\u521D\u59CB\u5316, \u8BF73\u79D2\u540E\u91CD\u8BD5"}],isError:!0}):(m.warn("Idle check: no search candidates available"),{content:[{type:"text",text:"\u672A\u68C0\u6D4B\u5230\u9E3F\u8499\u5DE5\u7A0B\uFF0C\u8BF7\u786E\u8BA4\u9879\u76EE\u76EE\u5F55\u662F\u5426\u6B63\u786E\uFF0C\u6216\u5728\u9879\u76EE\u4E2D\u521B\u5EFA\u5DE5\u7A0B\u540E\u91CD\u8BD5"}],isError:!0})}async handleErrorCheck(){return this.initRetryCount>=ti?(m.error(`Init retry limit reached (${this.initRetryCount}/${ti}), will not auto-retry`),{content:[{type:"text",text:"\u9879\u76EE\u521D\u59CB\u5316\u591A\u6B21\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u9879\u76EE\u914D\u7F6E\u540E\u91CD\u542F MCP Server"}],isError:!0}):(m.info(`Error check: auto-retrying (${this.initRetryCount}/${ti})`),this.ensureProjectReady(),{content:[{type:"text",text:"\u9879\u76EE\u521D\u59CB\u5316\u5931\u8D25\uFF0C\u6B63\u5728\u81EA\u52A8\u91CD\u8BD5\uFF0C\u8BF75\u79D2\u540E\u91CD\u8BD5"}],isError:!0})}async callCppCheck(e){if(!this.cppCheckTool){let t=this.config.projectPath?"C++ LSP \u672A\u5C31\u7EEA\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5":"\u6CA1\u6709\u914D\u7F6E\u5DE5\u7A0B\u8DEF\u5F84\uFF0C\u8BF7\u914D\u7F6EPROJECT_PATH\u53C2\u6570\u6216\u8005\u5728DevEco Studio\u4E2D\u6253\u5F00\u9879\u76EE";return m.warn(`C++ check rejected: ${t}, files: ${e.join(", ")}`),{content:[{type:"text",text:t}],isError:!0}}return this.cppCheckTool.handleCall({files:e})}mergeCheckResult(e,t,n){let i=e.content.map(o=>o.text).filter(o=>o&&o.trim().length>0).join(`
|
|
1263
|
+
`);i&&(e.isError?t.push(i):n.push(i))}setProjectPath(e){this.config.projectPath=e,this.arktsCheckTool&&(this.arktsCheckTool.shutdown().catch(t=>{m.warn("Failed to shutdown ArktsCheckTool during setProjectPath:",t)}),this.arktsCheckTool=null),this.cppCheckTool&&(this.cppCheckTool.shutdown().catch(t=>{m.warn("Failed to shutdown CppCheckTool during setProjectPath:",t)}),this.cppCheckTool=null),this.initPromise?(this.needsReinit=!0,m.info("Project path changed while init is running, will reinit after current init completes")):(this.projectState=0,this.ensureProjectReady().catch(t=>{m.warn("Failed to re-init project after setProjectPath:",t)}))}async start(){this.toolRouter.registerToServer(this.server);let e=new Fu;if(await this.server.connect(e),m.info("devecocli-mcp-server started"),!this.config.debug){let t=Ps();t&&m.info(`Log file: ${t}`)}if(this.setupStdinCloseHandler(),this.config.projectPath)this.workspaceRoot=this.config.projectPath;else{let t=await this.getProjectRootFromClient();if(t){this.workspaceRoot=t;let n=fe(t);n?(m.info(`Detected project path from client root: ${n}`),this.config.projectPath=n,this.sdkPath=this.computeSdkPath()):m.warn(`Client root '${t}' is not a HarmonyOS project`)}else this.originalProjectPath?m.warn(`PROJECT_PATH '${this.originalProjectPath}' was provided but no HarmonyOS project was found in it`):m.info("project path is empty (no PROJECT_PATH env and client did not provide roots)")}this.ensureProjectReady().catch(t=>{m.warn("Background project init failed:",t)}),this.initializeCppCheck()}async getProjectRootFromClient(){try{let t=(await this.server.server.listRoots()).roots?.[0];if(!t)return m.warn("Client did not provide any roots"),null;let n=t.uri;return this.resolveFileUri(n)}catch(e){return m.warn("Failed to list roots from client:",e),null}}resolveFileUri(e){try{let t=new URL(e);if(t.protocol==="file:"){let n=t.pathname;return process.platform==="win32"&&/^\/[A-Za-z]:/.test(n)?n.substring(1):n}}catch(t){m.warn("Failed to parse URI with URL API, falling back to manual parsing:",t)}if(e.startsWith("file://")){let t=e.substring(7);return t=decodeURIComponent(t),process.platform==="win32"&&t.startsWith("/")&&/^[A-Za-z]:/.test(t.substring(1))&&(t=t.substring(1)),t}return e}setupStdinCloseHandler(){let e=!1,t=()=>{e||(e=!0,m.info("stdin closed (MCP client disconnected), shutting down..."),this.shutdown().then(()=>{m.info("shutdown completed, exiting process"),process.exit(0)}).catch(n=>{m.error("shutdown failed:",n),process.exit(1)}))};process.stdin.on("end",t),process.stdin.on("close",t)}initializeCppCheck(){let e=this.config.projectPath;if(!e){m.warn("C++ LSP initialization skipped: project path is not configured");return}this.cppCheckTool=new dt(e,this.config.devecoPath??null),m.info("CppCheckTool created (lazy initialization)")}async ensureProjectReady(){if(!this.initPromise){this.initPromise=this.doEnsureProjectReady();try{await this.initPromise}finally{this.initPromise=null}this.needsReinit&&(this.needsReinit=!1,this.projectState=0,this.ensureProjectReady().catch(e=>{m.warn("Failed to re-init project after needsReinit:",e)}))}}discoverProject(){if(!((this.projectState===0||this.projectState===5)&&!this.config.projectPath))return!0;this.projectState=1;let t=this.workspaceRoot?fe(this.workspaceRoot):null;return!t&&this.originalProjectPath&&(t=fe(this.originalProjectPath),t&&m.info(`Phase 1 found HarmonyOS project from original config: ${t}`)),t?(this.config.projectPath=t,this.sdkPath=this.computeSdkPath(),this.initRetryCount=0,!0):(this.projectState=0,!1)}async doEnsureProjectReady(){if(!this.discoverProject())return;if(this.sdkPath||(this.sdkPath=this.computeSdkPath()),this.projectState=2,m.info("Starting project sync..."),!await ct.handleSyncProject(this.config.projectPath,this.sdkPath)){m.error("Project sync failed"),this.initRetryCount++,this.projectState=5;return}this.projectState=3,this.arktsCheckTool=new lt(this.config.projectPath,this.config.devecoPath??null,this.config.nodeMaxOldSpaceSize);try{await this.arktsCheckTool.initialize(),this.projectState=4,this.initRetryCount=0,m.info("Project fully initialized, check tool is available")}catch(t){m.error("LSP initialization failed:",t),this.arktsCheckTool=null,this.initRetryCount++,this.projectState=5}}computeSdkPath(){let e=on(this.config.devecoPath??""),t=ce(e);return ut.join(t,"sdk")}async shutdown(){this.arktsCheckTool&&await this.arktsCheckTool.shutdown(),this.cppCheckTool&&await this.cppCheckTool.shutdown();try{await this.server.close()}catch(e){m.warn("Failed to close MCP server connection:",e)}m.info("devecocli-mcp-server stopped"),Ss(),bs()}getToolRouter(){return this.toolRouter}getServer(){return this.server}};function $u(r){let e=[],t=[],n=[];for(let i of r)ut.extname(i).toLowerCase()===".ets"?e.push(i):sn(i)?t.push(i):n.push(i);return{etsFiles:e,cppFiles:t,unsupported:n}}function ni(r={}){return new qn(r)}async function Wu(){let r=process.env.PROJECT_PATH||"",e=process.env.DEVECO_PATH,t=process.env.NODE_MAX_OLD_SPACE_SIZE||"8192",n=process.env.DEBUG==="true"||process.env.DEBUG==="1",i=await N.new(),o=r,s=e??i.devecoStudioPath,a=ni({projectPath:o,devecoPath:s,nodeMaxOldSpaceSize:t,debug:n}),c=async()=>{await a.shutdown(),process.exit(0)};process.once("SIGINT",c),process.once("SIGTERM",c),process.platform==="win32"&&process.once("SIGBREAK",c);try{await a.start()}catch(d){console.error("Failed to start MCP server:",d),process.exit(1)}}var qs=new _u("serve").description("Host bundled auxiliary protocol servers");qs.command("mcp").description("Start a local stdio-based MCP server").action(async()=>{await Wu()});var Ys=qs;import{Command as Ju,InvalidArgumentError as oi}from"commander";import{red as Ht,dim as Ku}from"colorette";import*as K from"path";import*as re from"fs";import{homedir as Uu}from"os";import{ripgrep as Bu}from"ripgrep";import zu from"adm-zip";import{fileURLToPath as Vu}from"url";import qu from"ora";var Nt=["harmonyos-guides","harmonyos-references","best-practices","harmonyos-faqs","harmonyos-releases","harmonyos-roadmap"],Lt={"harmonyos-guides":"\u5F00\u53D1\u6307\u5357","harmonyos-references":"API\u53C2\u8003","best-practices":"\u6700\u4F73\u5B9E\u8DF5","harmonyos-faqs":"FAQ","harmonyos-releases":"\u7248\u672C\u8BF4\u660E","harmonyos-roadmap":"\u53D8\u66F4\u9884\u544A"};var Yu="deveco-cli",Gu="docs",ri=class{docsDir;versionFile;initialized=!1;initPromise=null;constructor(){this.docsDir=K.join(Uu(),".local","share",Yu,Gu),this.versionFile=K.join(this.docsDir,".version")}getDocsDir(){return this.docsDir}async ensureInitialized(){if(!this.initialized){if(this.initPromise){await this.initPromise;return}this.initPromise=this.extractDocsIfNeeded(),await this.initPromise,this.initialized=!0}}async extractDocsIfNeeded(){let e=this.getCurrentVersion();await this.getExistingVersion()!==e&&await this.extractDocs(e)}getCurrentVersion(){return"0.0.1"}async getExistingVersion(){try{return(await re.promises.readFile(this.versionFile,"utf-8")).trim()}catch{return null}}async extractDocs(e){let t=this.findDocsZip();if(!t)throw new Error("docs.zip not found");let n=qu({text:"Extracting documentation\u2026",color:"cyan"}).start();try{let i=K.dirname(this.docsDir);await re.promises.mkdir(i,{recursive:!0}),await this.cleanOldDocs(),await re.promises.mkdir(this.docsDir,{recursive:!0}),new zu(t).extractAllTo(this.docsDir,!0),await re.promises.writeFile(this.versionFile,e,"utf-8"),n.succeed("Documentation extracted successfully.")}catch(i){throw n.fail("Failed to extract documentation."),i}}findDocsZip(){let e=import.meta.url,t=Vu(e),n=K.dirname(t),i=[K.join(n,"..","docs.zip")];for(let o of i)if(re.existsSync(o))return o;return null}async cleanOldDocs(){try{await re.promises.rm(this.docsDir,{recursive:!0,force:!0})}catch{}}async search(e,t){await this.ensureInitialized();let n=t?K.join(this.docsDir,Lt[t]):this.docsDir,i=await this.searchFiles(e,n),o=await this.enrichWithTitleRelevance(i,e),s=this.selectByTiers(o,e.length);return(await Promise.all(s.map(async c=>{let d=this.parseFilePath(c.filePath);if(!d||!c.metadata)return null;let u=await this.readContentPreview(c.filePath);return{title:c.metadata.title,documentId:d,content:u}}))).filter(c=>c!==null)}selectByTiers(e,t){let n=(a,c)=>c.totalMatches-a.totalMatches,i=e.filter(a=>a.titleKeywordCount===t).sort(n),o=e.filter(a=>a.keywordCount===t&&a.titleKeywordCount<t).sort(n),s=e.filter(a=>a.keywordCount<t&&a.titleKeywordCount<t).sort(n);return[...i,...o,...s]}async enrichWithTitleRelevance(e,t){return Promise.all(Array.from(e.entries()).map(async([n,i])=>{let o=await this.readMetadata(n),s=o?t.filter(a=>o.title.toLowerCase().includes(a.toLowerCase())).length:0;return{filePath:n,keywordCount:i.keywordCount,totalMatches:i.totalMatches,titleKeywordCount:s,metadata:o}}))}async searchSingleKeyword(e,t){let i=await Bu(["--type","md","--json","--no-messages","-i","-e",e,t],{buffer:!0});if(i.code===1)return new Map;if(i.code!==0)throw new Error(i.stderr?.trim()||`Search failed with exit code ${i.code}`);return this.parseSearchResults(i.stdout)}async searchFiles(e,t){let n=await Promise.all(e.map(o=>this.searchSingleKeyword(o,t))),i=new Map;for(let o of n)for(let[s,a]of o){let c=i.get(s);c?(c.keywordCount+=1,c.totalMatches+=a):i.set(s,{keywordCount:1,totalMatches:a})}return i}parseSearchResults(e){let t=e.split(`
|
|
1264
|
+
`),n=new Map;for(let i of t){if(!i)continue;let o=this.parseSearchResultLine(i);o&&n.set(o.filePath,o.count)}return n}parseSearchResultLine(e){try{let t=JSON.parse(e);if(t.type==="end"&&t.data?.path?.text){let n=t.data.stats?.matches??0;if(n>0)return{filePath:t.data.path.text,count:n}}}catch{}return null}async readDocument(e){await this.ensureInitialized();let n=[e,`${e}.md`].filter(i=>E.isPathContainedWithSymlink(i,this.docsDir).contained).map(i=>K.join(this.docsDir,i));for(let i of n)try{return await re.promises.readFile(i,"utf-8")}catch{continue}throw new Error(`Document not found: ${e}`)}parseFilePath(e){if(!e.endsWith(".md"))return null;let t=K.relative(this.docsDir,e);if(!t||t.startsWith("..")||K.isAbsolute(t))return null;let n=t.split(/[/\\]/);if(n.length<2)return null;let i=n[n.length-1];return n[n.length-1]=i.replace(/\.md$/,""),n.join("/")}async readMetadata(e){let t=e.replace(/\.md$/,".json");try{let n=await re.promises.readFile(t,"utf-8");return JSON.parse(n)}catch{return null}}async readContentPreview(e){try{let t=await re.promises.readFile(e,"utf-8"),n=t.replace(/\n/g," ").trim().slice(0,200);return n.length<t.replace(/\n/g," ").trim().length?n+"...":n}catch{return""}}},ii=new ri;function Gs(...r){return e=>{if(!r.includes(e))throw new oi(`Allowed values: ${r.join(", ")}`);return e}}function Zu(r){let e=Number(r);if(!Number.isInteger(e)||e<=0)throw new oi("Must be a positive integer");return e}var Xu=Gs("json","default"),Qu=Gs("json","default"),Yn=new Ju("docs").description("Search and read HarmonyOS documentation from local docs directory");Yn.command("search <keywords...>").description("Search documentation by keywords").option("--catalog <name>","Catalog name (all for all catalogs)",ep,"all").option("--format <fmt>","Output format (default, json)",Xu,"default").option("--limit <n>","Max number of results",Zu,20).action(async(r,e)=>{try{let t=r.map(s=>s.trim()).filter(s=>s);t.length===0&&(console.error(Ht("Keywords cannot be empty")),process.exit(1)),t.length>10&&(console.error(Ht("Keywords cannot exceed 10")),process.exit(1));let n=e.catalog&&e.catalog!=="all"?e.catalog:void 0,o=(await ii.search(t,n)).slice(0,e.limit);e.format==="json"?console.log(JSON.stringify(o,null,2)):tp(o)}catch(t){console.error(Ht(t.message)),process.exit(1)}});Yn.command("read <documentId>").description("Read full content of a document by document ID").action(async r=>{try{let e=r.trim();e||(console.error(Ht("Document ID cannot be empty")),process.exit(1));let t=await ii.readDocument(e);console.log(t)}catch(e){console.error(Ht(e.message)),process.exit(1)}});Yn.command("catalog").description("List all available catalogs").option("--format <fmt>","Output format (default, json)",Qu,"default").action(r=>{if(r.format==="json"){let e=Nt.map(t=>({name:t,title:Lt[t]}));console.log(JSON.stringify(e,null,2))}else for(let e of Nt)console.log(` ${e.padEnd(20)} ${Ku(Lt[e])}`)});function ep(r){if(r==="all")return"all";if(!Nt.includes(r))throw new oi(`Invalid catalog "${r}". Allowed: all, ${Nt.join(", ")}`);return r}function tp(r){for(let e=0;e<r.length;e++){let t=r[e];console.log(t.documentId),console.log(` Title: ${t.title}`),t.content&&console.log(` Content: ${t.content}`),e<r.length-1&&console.log()}}var Js=Yn;process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE="";np();B.name("devecocli").description("HarmonyOS application development command line tool").version("0.0.1");B.addCommand(vi);B.addCommand(Ci);B.addCommand(Mi);B.addCommand(Ui);O()||B.addCommand(lo);B.addCommand(Fo);B.addCommand(Uo);B.addCommand(Zo);B.addCommand(os);B.addCommand(Ys);B.addCommand(Js);var si=process.argv.slice(2);si.length>=2&&si[si.length-1]==="help"&&(process.argv=[...process.argv.slice(0,-1),"--help"]);var ip=new Set(["update"]);B.hook("preAction",async(r,e)=>{if(process.env.DEVECO_CLI_SKIP_VERSION_CHECK)return;let t=e;for(;t.parent&&t.parent!==B;)t=t.parent;ip.has(t.name())||await N.checkVersion()});B.parseAsync(process.argv).catch(r=>{let e=r instanceof Error?r.message:String(r??"Unknown error");console.error(rp(`Error: ${e}`)),process.env.DEVECO_CLI_DEBUG==="1"&&r instanceof Error&&r.stack&&console.error(r.stack),process.exit(1)});
|