@mearl/native-host 2.20.3 → 2.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/install.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { createRequire as __mearlCreateRequire } from 'node:module'; const require = __mearlCreateRequire(import.meta.url);
2
- import fs2 from"node:fs";import path2 from"node:path";import{execFileSync as execFileSync2}from"node:child_process";import{createRequire}from"node:module";import{fileURLToPath}from"node:url";import fs from"node:fs";import os from"node:os";import path from"node:path";import{execFileSync}from"node:child_process";var MEARL_NATIVE_HOST_NAMES={skills:"com.alibaba.mearl.skills",mcp:"com.alibaba.mearl.mcp"};function resolveNativeHostDirectory(options={}){let env=options.env??process.env,home=(options.homedir??os.homedir)();switch(options.platform??process.platform){case"darwin":return path.join(home,"Library/Application Support/Google/Chrome/NativeMessagingHosts");case"linux":return path.join(home,".config/google-chrome/NativeMessagingHosts");case"win32":return path.join(env.PROGRAMDATA||"C:\\ProgramData","Google\\Chrome\\NativeMessagingHosts");default:throw new Error(`Unsupported platform: ${String(options.platform??process.platform)}`)}}function unregisterWindowsNativeHost(hostName){let registryKey=`HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\${hostName}`;try{execFileSync("reg",["delete",registryKey,"/f"],{stdio:"pipe"})}catch{}}function uninstallNativeHostArtifacts(options={},dependencies={}){let{mode="both",silent=!1}=options;if(mode==="both")return["skills","mcp"].map(integrationMode=>uninstallNativeHostArtifacts({...options,mode:integrationMode},dependencies)).every(Boolean);let writeLine=dependencies.writeLine??(line=>console.error(line)),log=line=>{silent||writeLine(line)};try{let existsSync=dependencies.existsSync??fs.existsSync,platform=dependencies.platform??process.platform,hostDir=dependencies.hostDir??resolveNativeHostDirectory({env:dependencies.env,homedir:dependencies.homedir,platform}),unlinkSync=dependencies.unlinkSync??fs.unlinkSync,unregister=dependencies.unregisterWindowsNativeHost??unregisterWindowsNativeHost,hostName=MEARL_NATIVE_HOST_NAMES[mode],launcherExtension=platform==="win32"?"cmd":"sh",artifacts=[path.join(hostDir,`${hostName}.json`),path.join(hostDir,`${hostName}-launcher.${launcherExtension}`)];for(let artifact of artifacts)existsSync(artifact)&&(unlinkSync(artifact),log(`✅ Removed: ${artifact}`));return platform==="win32"&&unregister(hostName),!0}catch(error){return log(`❌ Uninstall failed: ${error instanceof Error?error.message:String(error)}`),!1}}var DEFAULT_EXTENSION_ID="aoehhjnofngknnjefamjbplchbolghkm",__filename=fileURLToPath(import.meta.url),__dirname=path2.dirname(__filename),ALL_MODES=["skills","mcp"];function resolveHostDir(){return resolveNativeHostDirectory()}function resolveNativeHostPath(){let siblingPath=path2.join(__dirname,"index.js");if(fs2.existsSync(siblingPath))return siblingPath;try{return createRequire(import.meta.url).resolve("@mearl/native-host/runtime")}catch{throw new Error("Cannot locate native-host runtime entry point. Ensure @mearl/native-host is installed correctly.")}}function registerWindowsNativeHost(hostName,manifestPath){let regKey=`HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\${hostName}`;execFileSync2("reg",["add",regKey,"/ve","/t","REG_SZ","/d",manifestPath,"/f"],{stdio:"pipe"})}function createLauncherScript(hostDir,hostPath,hostName){let nodePath=path2.resolve(process.execPath);if(process.platform==="win32"){let launcherPath2=path2.join(hostDir,`${hostName}-launcher.cmd`),content2=`@echo off\r
3
- "${nodePath}" "${hostPath}" %*\r
4
- `;return fs2.writeFileSync(launcherPath2,content2,"utf-8"),launcherPath2}let launcherPath=path2.join(hostDir,`${hostName}-launcher.sh`),content=["#!/bin/sh",`NODE_BIN=${JSON.stringify(nodePath)}`,`HOST_SCRIPT=${JSON.stringify(hostPath)}`,'exec "$NODE_BIN" "$HOST_SCRIPT" "$@"',""].join(`
5
- `);return fs2.writeFileSync(launcherPath,content,"utf-8"),fs2.chmodSync(launcherPath,493),launcherPath}async function installNativeHost(options={}){let{mode="both",extensionId=DEFAULT_EXTENSION_ID,silent=!1,skipIfExists=!1}=options;if(mode==="both")return(await Promise.all(ALL_MODES.map(m=>installNativeHost({...options,mode:m})))).every(Boolean);let hostName=MEARL_NATIVE_HOST_NAMES[mode];if(!hostName)throw new Error(`Unknown mode: ${mode}. Expected 'skills' or 'mcp'.`);let log=(...args)=>{silent||console.error(...args)};try{let hostDir=resolveHostDir();if(skipIfExists){let manifestPath2=path2.join(hostDir,`${hostName}.json`);if(fs2.existsSync(manifestPath2))return log(`✅ Already installed: ${manifestPath2}`),!0}fs2.existsSync(hostDir)||(fs2.mkdirSync(hostDir,{recursive:!0}),log(`✅ Created directory: ${hostDir}`));let resolvedHostPath=resolveNativeHostPath();log(`✅ Native host path: ${resolvedHostPath}`);let launcherPath=createLauncherScript(hostDir,resolvedHostPath,hostName);log(`✅ Launcher script: ${launcherPath}`);let manifest={name:hostName,description:"Mearl Native Messaging Bridge",path:launcherPath,type:"stdio",allowed_origins:[`chrome-extension://${extensionId}/`]},manifestPath=path2.join(hostDir,`${hostName}.json`);return fs2.writeFileSync(manifestPath,JSON.stringify(manifest,null,2)),process.platform==="win32"?(registerWindowsNativeHost(hostName,manifestPath),log(`✅ Windows registry key created for: ${hostName}`)):fs2.chmodSync(manifestPath,420),log(`✅ Manifest installed: ${manifestPath}`),log(`✅ Extension ID: ${extensionId}`),log(`✅ Host name: ${hostName}`),!0}catch(error){return log(`❌ Installation failed: ${error instanceof Error?error.message:String(error)}`),error instanceof Error&&"code"in error&&error.code==="EACCES"&&log(`
2
+ import fs4 from"node:fs";import path4 from"node:path";import{execFileSync as execFileSync2}from"node:child_process";import{createRequire}from"node:module";import{fileURLToPath}from"node:url";import fs from"node:fs";import path from"node:path";function resolveLauncherNodePaths(execPath){let nodePath=path.resolve(execPath),homebrewNode=nodePath.match(/^(.*)\/Cellar\/(node(?:@\d+(?:\.\d+)*)?)\/[^/]+\/bin\/node$/);if(!homebrewNode)return[nodePath];let[,prefix,formula]=homebrewNode,stablePath=path.join(prefix,"opt",formula,"bin","node");try{if(fs.accessSync(stablePath,fs.constants.X_OK),fs.statSync(stablePath).isFile()&&fs.realpathSync(stablePath)===fs.realpathSync(nodePath))return[stablePath,nodePath]}catch{}return[nodePath,stablePath]}function shellQuote(value){return`'${value.replaceAll("'","'\\''")}'`}function createLauncherScript(hostDir,hostPath,hostName,execPath=process.execPath){let nodePaths=process.platform==="win32"?[path.resolve(execPath)]:resolveLauncherNodePaths(execPath),metadataLine=`mearl-native-host-launcher: ${JSON.stringify({version:1,nodePaths,hostPath})}`;if(process.platform==="win32"){let launcherPath2=path.join(hostDir,`${hostName}-launcher.cmd`),content2=`@echo off\r
3
+ rem ${metadataLine}\r
4
+ "${nodePaths[0]}" "${hostPath}" %*\r
5
+ `;return fs.writeFileSync(launcherPath2,content2,"utf-8"),launcherPath2}let launcherPath=path.join(hostDir,`${hostName}-launcher.sh`),content=["#!/bin/sh",`# ${metadataLine}`,`HOST_SCRIPT=${shellQuote(hostPath)}`,'if [ ! -f "$HOST_SCRIPT" ] || [ ! -r "$HOST_SCRIPT" ]; then',` printf '%s\\n' "Mearl native host: runtime script is missing or unreadable: $HOST_SCRIPT" >&2`," printf '%s\\n' 'Run npx @mearl/setup update --local to repair the installation.' >&2"," exit 1","fi",`for NODE_BIN in ${nodePaths.map(shellQuote).join(" ")}; do`,' if [ -f "$NODE_BIN" ] && [ -x "$NODE_BIN" ]; then',' PATH="${NODE_BIN%/*}${PATH:+:$PATH}"'," export PATH",' exec "$NODE_BIN" "$HOST_SCRIPT" "$@"'," fi","done",`printf '%s\\n' ${shellQuote(`Mearl native host: no executable Node.js found. Tried: ${nodePaths.join(", ")}`)} >&2`,"printf '%s\\n' 'Run mearl-native-host init with a working Node.js, then reopen the extension.' >&2","exit 127",""].join(`
6
+ `);return fs.writeFileSync(launcherPath,content,"utf-8"),fs.chmodSync(launcherPath,493),launcherPath}import fs3 from"node:fs";import path3 from"node:path";import{execFileSync}from"node:child_process";import fs2 from"node:fs";import os from"node:os";import path2 from"node:path";var MEARL_NATIVE_HOST_NAMES={skills:"com.alibaba.mearl.skills",mcp:"com.alibaba.mearl.mcp"};function resolveNativeHostDirectory(options={}){let env=options.env??process.env,home=(options.homedir??os.homedir)();switch(options.platform??process.platform){case"darwin":return path2.join(home,"Library/Application Support/Google/Chrome/NativeMessagingHosts");case"linux":return path2.join(home,".config/google-chrome/NativeMessagingHosts");case"win32":return path2.join(env.PROGRAMDATA||"C:\\ProgramData","Google\\Chrome\\NativeMessagingHosts");default:throw new Error(`Unsupported platform: ${String(options.platform??process.platform)}`)}}function unregisterWindowsNativeHost(hostName){let registryKey=`HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\${hostName}`;try{execFileSync("reg",["delete",registryKey,"/f"],{stdio:"pipe"})}catch{}}function uninstallNativeHostArtifacts(options={},dependencies={}){let{mode="both",silent=!1}=options;if(mode==="both")return["skills","mcp"].map(integrationMode=>uninstallNativeHostArtifacts({...options,mode:integrationMode},dependencies)).every(Boolean);let writeLine=dependencies.writeLine??(line=>console.error(line)),log=line=>{silent||writeLine(line)};try{let existsSync=dependencies.existsSync??fs3.existsSync,platform=dependencies.platform??process.platform,hostDir=dependencies.hostDir??resolveNativeHostDirectory({env:dependencies.env,homedir:dependencies.homedir,platform}),unlinkSync=dependencies.unlinkSync??fs3.unlinkSync,unregister=dependencies.unregisterWindowsNativeHost??unregisterWindowsNativeHost,hostName=MEARL_NATIVE_HOST_NAMES[mode],launcherExtension=platform==="win32"?"cmd":"sh",artifacts=[path3.join(hostDir,`${hostName}.json`),path3.join(hostDir,`${hostName}-launcher.${launcherExtension}`)];for(let artifact of artifacts)existsSync(artifact)&&(unlinkSync(artifact),log(`✅ Removed: ${artifact}`));return platform==="win32"&&unregister(hostName),!0}catch(error){return log(`❌ Uninstall failed: ${error instanceof Error?error.message:String(error)}`),!1}}var DEFAULT_EXTENSION_ID="aoehhjnofngknnjefamjbplchbolghkm",__filename=fileURLToPath(import.meta.url),__dirname=path4.dirname(__filename),ALL_MODES=["skills","mcp"];function resolveHostDir(){return resolveNativeHostDirectory()}function resolveNativeHostPath(){let siblingPath=path4.join(__dirname,"index.js");if(fs4.existsSync(siblingPath))return siblingPath;try{return createRequire(import.meta.url).resolve("@mearl/native-host/runtime")}catch{throw new Error("Cannot locate native-host runtime entry point. Ensure @mearl/native-host is installed correctly.")}}function registerWindowsNativeHost(hostName,manifestPath){let regKey=`HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\${hostName}`;execFileSync2("reg",["add",regKey,"/ve","/t","REG_SZ","/d",manifestPath,"/f"],{stdio:"pipe"})}async function installNativeHost(options={}){let{mode="both",extensionId=DEFAULT_EXTENSION_ID,silent=!1,skipIfExists=!1}=options;if(mode==="both")return(await Promise.all(ALL_MODES.map(m=>installNativeHost({...options,mode:m})))).every(Boolean);let hostName=MEARL_NATIVE_HOST_NAMES[mode];if(!hostName)throw new Error(`Unknown mode: ${mode}. Expected 'skills' or 'mcp'.`);let log=(...args)=>{silent||console.error(...args)};try{let hostDir=resolveHostDir();if(skipIfExists){let manifestPath2=path4.join(hostDir,`${hostName}.json`);if(fs4.existsSync(manifestPath2))return log(`✅ Already installed: ${manifestPath2}`),!0}fs4.existsSync(hostDir)||(fs4.mkdirSync(hostDir,{recursive:!0}),log(`✅ Created directory: ${hostDir}`));let resolvedHostPath=resolveNativeHostPath();log(`✅ Native host path: ${resolvedHostPath}`);let launcherPath=createLauncherScript(hostDir,resolvedHostPath,hostName);log(`✅ Launcher script: ${launcherPath}`);let manifest={name:hostName,description:"Mearl Native Messaging Bridge",path:launcherPath,type:"stdio",allowed_origins:[`chrome-extension://${extensionId}/`]},manifestPath=path4.join(hostDir,`${hostName}.json`);return fs4.writeFileSync(manifestPath,JSON.stringify(manifest,null,2)),process.platform==="win32"?(registerWindowsNativeHost(hostName,manifestPath),log(`✅ Windows registry key created for: ${hostName}`)):fs4.chmodSync(manifestPath,420),log(`✅ Manifest installed: ${manifestPath}`),log(`✅ Extension ID: ${extensionId}`),log(`✅ Host name: ${hostName}`),!0}catch(error){return log(`❌ Installation failed: ${error instanceof Error?error.message:String(error)}`),error instanceof Error&&"code"in error&&error.code==="EACCES"&&log(`
6
7
  Permission denied. Try running with sudo.`),!1}}async function uninstallNativeHost(options={},dependencies={}){return uninstallNativeHostArtifacts(options,dependencies)}async function parseNativeHostInstallArgs(argv){let normalizedArgv=argv[0]==="--init"?["init",...argv.slice(1)]:argv[0]==="--uninstall"?["uninstall",...argv.slice(1)]:argv,operation="init",mode="both",extensionId,showHelp=!1,skipIfExists=!1,index=0;if(normalizedArgv[0]==="init"||normalizedArgv[0]==="uninstall")operation=normalizedArgv[0],index=1;else if(normalizedArgv[0]&&!normalizedArgv[0].startsWith("-"))throw new Error(`Unknown command: ${normalizedArgv[0]}`);let readValue=name=>{let argument=normalizedArgv[index];if(argument===name){let value=normalizedArgv[index+1];if(value===void 0||value.startsWith("-"))throw new Error(`argument missing for option '${name}'`);return index+=1,value}return argument?.startsWith(`${name}=`)?argument.slice(name.length+1):null};for(;index<normalizedArgv.length;index+=1){let argument=normalizedArgv[index];if(argument==="--help"||argument==="-h"){showHelp=!0;continue}if(argument==="--skip-if-exists"){skipIfExists=!0;continue}let parsedMode=readValue("--mode");if(parsedMode!==null){if(parsedMode!=="skills"&&parsedMode!=="mcp"&&parsedMode!=="both")throw new Error(`Invalid --mode: ${parsedMode}. Allowed choices are skills, mcp, and both`);mode=parsedMode;continue}let parsedExtensionId=readValue("--extension-id");if(parsedExtensionId!==null){extensionId=parsedExtensionId;continue}throw new Error(argument?.startsWith("-")?`unknown option '${argument}'`:`unexpected argument '${argument}'`)}if(operation==="uninstall"&&extensionId)throw new Error("--extension-id is only available for init");if(operation==="uninstall"&&skipIfExists)throw new Error("--skip-if-exists is only available for init");return{showHelp,uninstall:operation==="uninstall",mode,...extensionId?{extensionId}:{},skipIfExists}}function printHelp(){console.error(`Usage:
7
8
  mearl-native-host init [options]
8
9
  mearl-native-host uninstall [options]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearl/native-host",
3
- "version": "2.20.3",
3
+ "version": "2.20.5",
4
4
  "description": "Native Messaging Host for Mearl — bridges Chrome Extension and local socket server",
5
5
  "type": "module",
6
6
  "engines": {
@@ -42,12 +42,12 @@
42
42
  "@types/ws": "^8.18.1",
43
43
  "esbuild": "^0.25.2",
44
44
  "typescript": "^5.8.3",
45
- "@mearl/app-profiles": "2.20.3",
46
- "@mearl/client": "2.20.3",
47
- "@mearl/daemon-core": "2.20.3",
48
- "@mearl/browser-core": "2.20.3",
49
- "@mearl/provider": "2.20.3",
50
- "@mearl/setup": "2.20.3"
45
+ "@mearl/app-profiles": "2.20.5",
46
+ "@mearl/browser-core": "2.20.5",
47
+ "@mearl/daemon-core": "2.20.5",
48
+ "@mearl/provider": "2.20.5",
49
+ "@mearl/client": "2.20.5",
50
+ "@mearl/setup": "2.20.5"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "rm -rf dist/ && node build.mjs",