@mearl/native-host 2.8.1 → 2.9.0

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.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * (CLI) or `mode` option (API) to install just one.
11
11
  *
12
12
  * CLI:
13
- * mearl-native-host --init [--mode skills|mcp|both] [--extension-id <id>]
13
+ * mearl-native-host init [--mode skills|mcp|both] [--extension-id <id>]
14
14
  *
15
15
  * API:
16
16
  * import { installNativeHost } from '@mearl/native-host';
@@ -51,4 +51,12 @@ export interface UninstallDependencies {
51
51
  export declare function resolveHostDir(): string;
52
52
  export declare function installNativeHost(options?: InstallOptions): Promise<boolean>;
53
53
  export declare function uninstallNativeHost(options?: UninstallOptions, dependencies?: UninstallDependencies): Promise<boolean>;
54
- export declare function runCli(argv: string[]): Promise<void>;
54
+ export interface ParsedNativeHostInstallArgs {
55
+ showHelp: boolean;
56
+ uninstall: boolean;
57
+ mode: IntegrationMode | 'both';
58
+ extensionId?: string;
59
+ skipIfExists: boolean;
60
+ }
61
+ export declare function parseNativeHostInstallArgs(argv: string[]): Promise<ParsedNativeHostInstallArgs>;
62
+ export declare function runCli(argv: string[]): Promise<number>;
package/dist/install.js CHANGED
@@ -3,23 +3,26 @@ import fs2 from"node:fs";import path2 from"node:path";import{execFileSync as exe
3
3
  "${nodePath}" "${hostPath}" %*\r
4
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
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(`
6
- Permission denied. Try running with sudo.`),!1}}async function uninstallNativeHost(options={},dependencies={}){return uninstallNativeHostArtifacts(options,dependencies)}function parseCliArgs(argv){let mode="both",extensionId,skipIfExists=!1,uninstall=!1;for(let i=0;i<argv.length;i+=1){let arg=argv[i];if(arg==="--help"||arg==="-h")return{showHelp:!0,uninstall,mode,skipIfExists};if(arg==="--mode"||arg.startsWith("--mode=")){let value=arg.includes("=")?arg.slice(7):argv[++i];value!=="skills"&&value!=="mcp"&&value!=="both"&&(console.error(`❌ Invalid mode: ${value}. Expected 'skills', 'mcp', or 'both'.`),process.exit(1)),mode=value;continue}if(arg==="--extension-id"||arg.startsWith("--extension-id=")){extensionId=arg.includes("=")?arg.slice(15):argv[++i];continue}if(arg==="--skip-if-exists"){skipIfExists=!0;continue}if(arg==="--uninstall"){uninstall=!0;continue}}return{showHelp:!1,uninstall,mode,extensionId,skipIfExists}}function printHelp(){console.error(`Usage:
7
- mearl-native-host --init [options]
8
- mearl-native-host --uninstall [options]
6
+ 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
+ mearl-native-host init [options]
8
+ mearl-native-host uninstall [options]
9
9
 
10
10
  Options:
11
11
  --mode <skills|mcp|both> Integration mode (default: both — installs both hosts)
12
12
  --extension-id <id> Chrome extension ID (default: ${DEFAULT_EXTENSION_ID})
13
- --uninstall Remove the selected Native Messaging manifests
13
+ --skip-if-exists Keep existing Native Messaging manifests unchanged
14
14
  -h, --help Show this help message
15
15
 
16
+ Compatibility aliases:
17
+ --init, --uninstall Established flag forms for init and uninstall
18
+
16
19
  Examples:
17
- mearl-native-host --init
18
- mearl-native-host --init --mode mcp
19
- mearl-native-host --uninstall --mode skills
20
- mearl-native-host --init --extension-id abcdefghijklmnopqrstuvwxyzabcdef`)}async function runCli(argv){let parsed=parseCliArgs(argv);if(parsed.showHelp&&(printHelp(),process.exit(0)),parsed.extensionId&&!/^[a-z]{32}$/.test(parsed.extensionId)&&(console.error(`❌ Invalid extension ID: ${parsed.extensionId}`),console.error(" Must be a 32-character lowercase string (see chrome://extensions/)"),process.exit(1)),parsed.uninstall){let success2=await uninstallNativeHost({mode:parsed.mode});success2&&console.error(`
20
+ mearl-native-host init
21
+ mearl-native-host init --mode mcp
22
+ mearl-native-host uninstall --mode skills
23
+ mearl-native-host init --extension-id abcdefghijklmnopqrstuvwxyzabcdef`)}async function runCli(argv){let parsed;try{parsed=await parseNativeHostInstallArgs(argv)}catch(error){return console.error(`❌ ${error instanceof Error?error.message:String(error)}`),printHelp(),2}if(parsed.showHelp)return printHelp(),0;if(parsed.extensionId&&!/^[a-z]{32}$/.test(parsed.extensionId))return console.error(`❌ Invalid extension ID: ${parsed.extensionId}`),console.error(" Must be a 32-character lowercase string (see chrome://extensions/)"),2;if(parsed.uninstall){let success2=await uninstallNativeHost({mode:parsed.mode});return success2&&console.error(`
21
24
  ✅ Uninstall complete!
22
- `),process.exit(success2?0:1)}let success=await installNativeHost({mode:parsed.mode,extensionId:parsed.extensionId,skipIfExists:parsed.skipIfExists});success&&console.error(`
25
+ `),success2?0:1}let success=await installNativeHost({mode:parsed.mode,extensionId:parsed.extensionId,skipIfExists:parsed.skipIfExists});return success&&console.error(`
23
26
  ✅ Installation complete!
24
27
 
25
28
  Next steps:
@@ -28,4 +31,4 @@ Next steps:
28
31
 
29
32
  Verify:
30
33
  mearl get_requests --payload '{"count":1}'
31
- `),process.exit(success?0:1)}export{installNativeHost,resolveHostDir,runCli,uninstallNativeHost};
34
+ `),success?0:1}export{installNativeHost,parseNativeHostInstallArgs,resolveHostDir,runCli,uninstallNativeHost};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@mearl/native-host",
3
- "version": "2.8.1",
3
+ "version": "2.9.0",
4
4
  "description": "Native Messaging Host for Mearl — bridges Chrome Extension and local socket server",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=18"
7
+ "node": ">=22.12.0"
8
8
  },
9
9
  "main": "dist/install.js",
10
10
  "types": "dist/install.d.ts",
@@ -42,9 +42,9 @@
42
42
  "esbuild": "^0.25.2",
43
43
  "typescript": "^5.8.3",
44
44
  "wuying-agentbay-sdk": "0.22.0",
45
- "@mearl/daemon-core": "2.8.1",
46
- "@mearl/browser-core": "2.8.1",
47
- "@mearl/setup": "2.8.1"
45
+ "@mearl/daemon-core": "2.9.0",
46
+ "@mearl/browser-core": "2.9.0",
47
+ "@mearl/setup": "2.9.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rm -rf dist/ && node build.mjs",