@mearl/cloud-connector 3.0.0-beta.1 → 3.0.0-beta.10

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/README.md CHANGED
@@ -1,94 +1,93 @@
1
1
  # @mearl/cloud-connector
2
2
 
3
- 本地连接器,用于把云端 Agent 的操作转发到本地 native-host。普通云模式使用 WebSocket;
4
- Qoder Cloud Agent 使用官方 Session API、SSE 事件流和 Client-Side 自定义工具。
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
5
4
 
6
- ## 安装
5
+ A local connector forwarding cloud Agent operations to local native-host. WebSocket is built in; other protocols load from installed capability packages. Qoder credentials, pairing, and SSE are provided by the optional [`@mearl/plugin-qoder`](../../plugin-qoder/README.md).
6
+
7
+ ## Installation
7
8
 
8
9
  ```bash
9
10
  npm install -g @mearl/cloud-connector
10
- # 或
11
+ # Or
11
12
  pnpm add -g @mearl/cloud-connector
12
13
  ```
13
14
 
14
- ## 两种管理模式
15
+ ## Two management modes
15
16
 
16
- 连接器同时支持两种生命周期管理方式,二者通过同一份共享注册表互通(见[运行时文件](#运行时文件)),不会对同一个 `server-url` 重复建连:
17
+ The connector supports two lifecycle modes sharing the same registry (see [runtime files](#runtime-files)), preventing duplicate connections to the same `server-url`:
17
18
 
18
- 1. **被 native-host 托管** —— 在浏览器插件面板里点击连接时,native-host 会自动以**前台进程**方式拉起连接器并监听其状态。无需手动操作。
19
- 2. **自管理(守护进程)** —— 在终端用 `start` / `stop` 等子命令把连接器作为后台守护进程管理,拥有独立日志文件,便于在无插件面板的场景(如远程机器、排查问题)下使用。
19
+ 1. **Managed by native-host** — Clicking Connect in the extension panel automatically launches the connector as a **foreground process** and monitors its status. No manual operation is needed.
20
+ 2. **Self-managed daemon** — Use terminal subcommands such as `start` / `stop` to manage a background daemon with its own log file, useful without the extension panel, such as on remote machines or during troubleshooting.
20
21
 
21
- ## 使用
22
+ ## Usage
22
23
 
23
24
  ```bash
24
- mearl-cloud-connector <server-url> [options] # 前台运行
25
- mearl-cloud-connector <command> [server-url|pid] [options] # 管理后台守护进程
25
+ mearl-cloud-connector <server-url> [options] # Run in foreground
26
+ mearl-cloud-connector <command> [server-url|pid] [options] # Manage background daemons
26
27
  ```
27
28
 
28
- **参数:**
29
+ **Arguments:**
29
30
 
30
- - `server-url` —— 连接端点,支持原有 `ws://`、`wss://`,以及 setup 生成的
31
- `qoder://pair/<code>?created=<timestamp>`。`qoder://` 是不含凭证的配对标识,不是网络
32
- 地址,也不会被转换成 WebSocket URL。
31
+ - `server-url` — `ws://` / `wss://`, or a URI declared by an installed capability. The core does not interpret pairing parameters in plugin URIs.
33
32
 
34
- **子命令:**
33
+ **Subcommands:**
35
34
 
36
- - `start <server-url>` —— 后台启动守护进程(幂等:已有存活连接器则复用)
37
- - `stop <server-url|pid>` —— 按端点或 `list` / `status` 展示的 PID 停止后台连接器;
38
- PID 必须与当前连接器注册记录匹配,实例已被替换时不会停止新实例
39
- - `stop --all` —— 停止所有后台连接器
40
- - `restart <server-url>` —— 重启指定连接器
41
- - `status [server-url]` —— 查看连接器健康状态、最近心跳及重试信息;省略
42
- `server-url` 时汇总全部
43
- - `list` —— 列出所有正在运行的连接器
44
- - `logs <server-url>` —— 打印某连接器日志末尾
35
+ - `start <server-url>` — Start a daemon in the background (idempotent: reuse an existing live connector).
36
+ - `stop <server-url|pid>` — Stop a background connector by endpoint or a PID shown by `list` / `status`;
37
+ the PID must match its current registration record, so a replaced instance is not stopped.
38
+ - `stop --all` — Stop all background connectors.
39
+ - `restart <server-url>` — Restart a connector.
40
+ - `status [server-url]` — Show connector health, recent heartbeats, and retry information;
41
+ omit `server-url` to summarize all connectors.
42
+ - `list` — List running connectors.
43
+ - `logs <server-url>` — Print the end of a connector's log.
45
44
 
46
- **选项:**
45
+ **Options:**
47
46
 
48
- - `--foreground` / `-f` —— 前台运行(不守护化)
49
- - `--heartbeat <seconds>` —— 心跳间隔(默认 30 秒)
50
- - `--reconnect <ms>` —— 重连间隔(默认 5000 毫秒)
51
- - `--max-reconnect <n>` —— 最大重连次数,-1 表示无限(默认 -1)
52
- - `--connector-id <id>` —— 覆盖本机稳定的 connector ID
53
- - `--name <name>` —— 设置便于识别的 connector 名称(默认主机名)
54
- - `--fail-fast` —— 首次连接失败即退出(供 native-host 探测启动结果)
47
+ - `--foreground` / `-f` — Run in foreground without daemonizing.
48
+ - `--heartbeat <seconds>` — Heartbeat interval (default 30 seconds).
49
+ - `--reconnect <ms>` — Reconnection interval (default 5000 milliseconds).
50
+ - `--max-reconnect <n>` — Maximum reconnect attempts; -1 means unlimited (default -1).
51
+ - `--connector-id <id>` — Override the machine's stable connector ID.
52
+ - `--name <name>` — Set a recognizable connector name (default: hostname).
53
+ - `--fail-fast` — Exit on the first connection failure (used by native-host to detect startup results).
55
54
 
56
- **示例:**
55
+ **Examples:**
57
56
 
58
57
  ```bash
59
- # 后台启动一个自管理连接器,拥有独立日志文件(推荐)
58
+ # Start a self-managed background connector with its own log file (recommended)
60
59
  mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx" --name work-mac
61
60
 
62
- # Qoder 配对模式;地址由 npx @mearl/setup --qoder-cloud --yes 生成
61
+ # Optional protocol: install @mearl/plugin-qoder and generate a URL as described in its README
63
62
  mearl-cloud-connector start "qoder://pair/pairing-code-1234?created=1786723200000"
64
63
 
65
- # 前台运行,仅用于排障或交给 systemd / PM2 等外部进程管理器
64
+ # Foreground mode for troubleshooting or external managers such as systemd / PM2
66
65
  mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
67
66
 
68
- # 查看状态 / 列表 / 日志
67
+ # Status / list / logs
69
68
  mearl-cloud-connector status
70
69
  mearl-cloud-connector list
71
70
  mearl-cloud-connector logs "wss://cloud.example.com/ws?token=xxx"
72
71
 
73
- # 停止
72
+ # Stop
74
73
  mearl-cloud-connector stop "wss://cloud.example.com/ws?token=xxx"
75
74
  mearl-cloud-connector stop 12345
76
75
  mearl-cloud-connector stop --all
77
76
 
78
- # 自定义心跳和重连配置
77
+ # Custom heartbeat and reconnect settings
79
78
  mearl-cloud-connector start "ws://localhost:8080/ws?token=xxx" --heartbeat 60 --max-reconnect 10
80
79
  ```
81
80
 
82
- `status` 将连接器标记为 `starting`、`healthy`、`reconnecting`、`degraded`、`failed`
83
- 或 `unknown`。其中 `healthy` 表示进程存活、传输已连接且 WebSocket 最近收到过有效心跳;
84
- 旧版本创建、尚未包含连接状态字段的运行记录显示为 `unknown`,重启该连接器后即可补齐。
85
- 输出中的 token 会被隐藏。
81
+ `status` reports `starting`, `healthy`, `reconnecting`, `degraded`, `failed`,
82
+ or `unknown`. `healthy` means the process is alive, the transport is connected, and WebSocket has recently received a valid heartbeat.
83
+ Records without connection-state fields report `unknown`; restarting the connector fills in those fields.
84
+ Tokens are hidden in output.
86
85
 
87
- `start` 会在连接成功后返回,后台进程继续运行。Qoder 配对时请紧接着提交 setup 输出的
88
- `pair` 工具调用;如果配对工具调用已经结束、取消或过期,需要重新生成配对 URL,旧 URL
89
- 不能重复使用。
86
+ `start` returns after connecting; the background process continues running. For optional pairing protocols, follow the plugin instructions to submit the generated
87
+ `pair` tool call. If the pairing tool call has ended, been cancelled, or expired, generate a new pairing URL;
88
+ old URLs cannot be reused.
90
89
 
91
- ### 编程方式
90
+ ### Programmatic usage
92
91
 
93
92
  ```typescript
94
93
  import { CloudConnector } from '@mearl/cloud-connector';
@@ -104,101 +103,76 @@ const connector = new CloudConnector({
104
103
 
105
104
  connector.connect();
106
105
 
107
- // 优雅关闭
106
+ // Graceful shutdown
108
107
  process.on('SIGINT', () => {
109
108
  connector.disconnect();
110
109
  process.exit(0);
111
110
  });
112
111
  ```
113
112
 
114
- ## 运行时文件
115
-
116
- 连接器首次运行时会生成稳定的 connector ID,并保存到
117
- `~/.mearl/cloud-connector-identity.json`。名称默认取主机名,可通过 `--name` 或
118
- `MEARL_CONNECTOR_NAME` 设置;ID 可通过 `--connector-id` 或
119
- `MEARL_CONNECTOR_ID` 设置。相同 ID 的新连接会替换旧连接,适合进程重启和网络重连。
113
+ ## Runtime files
120
114
 
121
- 每个连接器实例在 `~/.mearl/connectors/` 下按 `server-url` 哈希生成一对文件:
115
+ The first run generates a stable connector ID and stores it in
116
+ `~/.mearl/cloud-connector-identity.json`. The name defaults to the hostname and can be set with `--name` or
117
+ `MEARL_CONNECTOR_NAME`; set the ID with `--connector-id` or
118
+ `MEARL_CONNECTOR_ID`. A new connection with the same ID replaces the old one, supporting process restarts and network reconnections.
122
119
 
123
- - `<hash>.json` —— 连接记录(含身份、进程、连接状态、最近心跳和重试信息)。daemon
124
- manager 在拉起子进程后立即写入 `starting` 占位,连接器进程随后持续更新自己的状态;
125
- 删除记录时会核对 pid,避免退出中的旧进程删除新实例记录。崩溃残留会被读取方按 pid
126
- 存活性自动清理。
127
- - `<hash>.log` —— 守护进程日志(`logs` 子命令读取,或 `tail -f` 跟踪);超过 5MB 会在下次启动时滚动为 `<hash>.log.1`。
120
+ Each connector instance creates two files under `~/.mearl/connectors/`, keyed by a hash of `server-url`:
128
121
 
129
- native-host 与守护进程 CLI 都通过这套共享路径(由 [`@mearl/daemon-core`](../../daemon-core) 派生)读取注册表,因此一方启动的连接器另一方也能发现、复用或停止。
122
+ - `<hash>.json` — Registration record containing identity, process, connection state, recent heartbeats, and retries. The daemon
123
+ manager writes a `starting` placeholder immediately after spawning the child, which then updates its own status.
124
+ Removal checks the PID so an exiting process cannot delete a replacement's record. Readers automatically clean up crash remnants
125
+ by checking PID liveness.
126
+ - `<hash>.log` — Daemon log, read with `logs` or followed with `tail -f`. Logs over 5MB rotate to `<hash>.log.1` on the next start.
130
127
 
131
- > 前台运行(含 native-host 托管)时日志输出到 stdout/stderr,不写独立日志文件;只有守护进程模式才落盘到 `<hash>.log`。
128
+ native-host and the daemon CLI read this registry through shared paths derived by [`@mearl/daemon-core`](../../daemon-core/README.md). Each can discover, reuse, or stop connectors started by the other.
132
129
 
133
- Qoder 配对还要求在本地提供 `QODER_PERSONAL_ACCESS_TOKEN`。连接器依次读取当前进程环境、
134
- `MEARL_ENV_FILE`、`~/.mearl/.env`;macOS 还会读取当前用户钥匙串中 service 为
135
- `ai.mearl.qoder.pat` 的通用密码。PAT 只用于访问 Qoder Cloud Session API,连接器不会把它
136
- 写入 `qoder://` URL、进程参数、注册表或日志。配对完成后,连接器
137
- 保持 SSE 连接,收到 `agent.custom_tool_use` 后调用现有本地 Mearl action,并以
138
- `user.custom_tool_result` 回传。截图会优先作为 base64 图片内容块回传;若 Cloud API 拒绝
139
- 图片块,则退回完整 JSON 文本,避免丢失数据。
130
+ > Foreground execution, including native-host management, logs to stdout/stderr without a separate log file. Only daemon mode writes `<hash>.log`.
140
131
 
141
- macOS 可在本地终端交互式写入钥匙串,PAT 不会进入 shell 历史:
132
+ See the corresponding capability package documentation for optional protocol authentication and pairing. The core does not read their credentials.
142
133
 
143
- ```bash
144
- security add-generic-password -U -a "$USER" -s ai.mearl.qoder.pat -w
145
- ```
134
+ ## Prerequisites
146
135
 
147
- ## 前置条件
148
-
149
- 1. **安装并初始化本地 Mearl 环境**
136
+ 1. **Install and initialize the local Mearl environment**
150
137
 
151
138
  ```bash
152
139
  npx @mearl/setup
153
140
  ```
154
141
 
155
- setup 会同步安装 `@mearl/native-host` 与 `@mearl/client`,并完成 Native Messaging 初始化。
142
+ setup installs `@mearl/native-host` and `@mearl/client` together and initializes Native Messaging.
156
143
 
157
- 使用本项目的 monorepo 构建产物时,仍需手动初始化:
144
+ Monorepo build outputs still require manual initialization:
158
145
 
159
146
  ```bash
160
147
  mearl-native-host --init
161
148
  ```
162
149
 
163
- 2. **确保 Chrome 浏览器正在运行**,且:
164
- - 已安装 Mearl 浏览器插件,或
165
- - 已在 `chrome://inspect/#remote-debugging` 启用远程调试(Chrome 145+)
150
+ 2. **Keep Chrome running**, with either:
151
+ - The Mearl browser extension installed, or
152
+ - Remote debugging enabled at `chrome://inspect/#remote-debugging` (Chrome 145+).
166
153
 
167
- ## 架构
154
+ ## Architecture
168
155
 
169
156
  ```
170
- 云端 Agent
157
+ Cloud Agent
171
158
  ↓
172
159
  @mearl/client
173
160
  ↓
174
161
  @mearl/cloud-server
175
162
  ↓ (WebSocket)
176
- @mearl/cloud-connector (本进程)
163
+ @mearl/cloud-connector (this process)
177
164
  ↓ (Unix Socket)
178
165
  @mearl/native-host
179
166
  ↓
180
167
  Chrome Extension / CDP
181
168
  ```
182
169
 
183
- Qoder 配对信息由 `mearl-cloud-server start` 统一生成;配对后的运行时转发不经过常驻
184
- cloud-server 服务:
185
-
186
- ```
187
- Qoder Cloud Agent(mearl Client-Side 自定义工具)
188
- ↓ agent.custom_tool_use / user.custom_tool_result
189
- Qoder Cloud Session API + SSE
190
- ↓
191
- @mearl/cloud-connector(本进程)
192
- ↓ (Unix Socket)
193
- @mearl/native-host
194
- ↓
195
- Chrome Extension / CDP
196
- ```
170
+ Installed connection protocols share the same lifecycle and status callbacks; their plugins describe the specific topology.
197
171
 
198
- ## 注意事项
172
+ ## Notes
199
173
 
200
- - 连接器需要保持运行才能转发云端请求。被 native-host 托管时,连接器以 `detached` 方式启动,会**在插件重载/更新后继续存活**;自管理时由 `start`/`stop` 子命令掌控生命周期。
201
- - 前台模式若想交给外部进程管理器(systemd / PM2)托管,加 `--foreground` 让其在前台运行并由管理器负责守护重启。
202
- - 支持断线自动重连(可在配置中调整);瞬时断连期间连接记录会保留,仅在进程退出时清除。
203
- - 云端响应超过单条消息上限时会返回结构化错误并保持连接。截图过大时可指定元素范围,
204
- 或使用 `format: "jpeg"` 和较低的 `quality` 重试。
174
+ - The connector must stay running to forward cloud requests. native-host launches it with `detached`, so it **survives extension reloads and updates**. Self-managed lifecycles use `start`/`stop`.
175
+ - When using an external process manager such as systemd / PM2, add `--foreground` and let the manager handle supervision and restarts.
176
+ - Automatic reconnection is configurable. Records persist across transient disconnects and are removed only when the process exits.
177
+ - Oversized cloud responses return a structured error while keeping the connection open. For large screenshots, select an element region
178
+ or retry with `format: "jpeg"` and a lower `quality`.
@@ -0,0 +1,178 @@
1
+ # @mearl/cloud-connector
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ 本地连接器,用于把云端 Agent 的操作转发到本地 native-host。内置传输为 WebSocket;其他协议通过已安装的能力包加载。Qoder 的凭据、配对和 SSE 实现在可选的 [`@mearl/plugin-qoder`](../../plugin-qoder/README.zh-CN.md) 中。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install -g @mearl/cloud-connector
11
+ # 或
12
+ pnpm add -g @mearl/cloud-connector
13
+ ```
14
+
15
+ ## 两种管理模式
16
+
17
+ 连接器同时支持两种生命周期管理方式,二者通过同一份共享注册表互通(见[运行时文件](#运行时文件)),不会对同一个 `server-url` 重复建连:
18
+
19
+ 1. **被 native-host 托管** —— 在浏览器插件面板里点击连接时,native-host 会自动以**前台进程**方式拉起连接器并监听其状态。无需手动操作。
20
+ 2. **自管理(守护进程)** —— 在终端用 `start` / `stop` 等子命令把连接器作为后台守护进程管理,拥有独立日志文件,便于在无插件面板的场景(如远程机器、排查问题)下使用。
21
+
22
+ ## 使用
23
+
24
+ ```bash
25
+ mearl-cloud-connector <server-url> [options] # 前台运行
26
+ mearl-cloud-connector <command> [server-url|pid] [options] # 管理后台守护进程
27
+ ```
28
+
29
+ **参数:**
30
+
31
+ - `server-url` —— `ws://` / `wss://`,或已安装能力声明的 URI。核心不解释插件 URI 的配对参数。
32
+
33
+ **子命令:**
34
+
35
+ - `start <server-url>` —— 后台启动守护进程(幂等:已有存活连接器则复用)
36
+ - `stop <server-url|pid>` —— 按端点或 `list` / `status` 展示的 PID 停止后台连接器;
37
+ PID 必须与当前连接器注册记录匹配,实例已被替换时不会停止新实例
38
+ - `stop --all` —— 停止所有后台连接器
39
+ - `restart <server-url>` —— 重启指定连接器
40
+ - `status [server-url]` —— 查看连接器健康状态、最近心跳及重试信息;省略
41
+ `server-url` 时汇总全部
42
+ - `list` —— 列出所有正在运行的连接器
43
+ - `logs <server-url>` —— 打印某连接器日志末尾
44
+
45
+ **选项:**
46
+
47
+ - `--foreground` / `-f` —— 前台运行(不守护化)
48
+ - `--heartbeat <seconds>` —— 心跳间隔(默认 30 秒)
49
+ - `--reconnect <ms>` —— 重连间隔(默认 5000 毫秒)
50
+ - `--max-reconnect <n>` —— 最大重连次数,-1 表示无限(默认 -1)
51
+ - `--connector-id <id>` —— 覆盖本机稳定的 connector ID
52
+ - `--name <name>` —— 设置便于识别的 connector 名称(默认主机名)
53
+ - `--fail-fast` —— 首次连接失败即退出(供 native-host 探测启动结果)
54
+
55
+ **示例:**
56
+
57
+ ```bash
58
+ # 后台启动一个自管理连接器,拥有独立日志文件(推荐)
59
+ mearl-cloud-connector start "wss://cloud.example.com/ws?token=xxx" --name work-mac
60
+
61
+ # 可选协议示例;须先安装 @mearl/plugin-qoder,按其 README 生成地址
62
+ mearl-cloud-connector start "qoder://pair/pairing-code-1234?created=1786723200000"
63
+
64
+ # 前台运行,仅用于排障或交给 systemd / PM2 等外部进程管理器
65
+ mearl-cloud-connector "ws://localhost:8080/ws?token=xxx"
66
+
67
+ # 查看状态 / 列表 / 日志
68
+ mearl-cloud-connector status
69
+ mearl-cloud-connector list
70
+ mearl-cloud-connector logs "wss://cloud.example.com/ws?token=xxx"
71
+
72
+ # 停止
73
+ mearl-cloud-connector stop "wss://cloud.example.com/ws?token=xxx"
74
+ mearl-cloud-connector stop 12345
75
+ mearl-cloud-connector stop --all
76
+
77
+ # 自定义心跳和重连配置
78
+ mearl-cloud-connector start "ws://localhost:8080/ws?token=xxx" --heartbeat 60 --max-reconnect 10
79
+ ```
80
+
81
+ `status` 将连接器标记为 `starting`、`healthy`、`reconnecting`、`degraded`、`failed`
82
+ 或 `unknown`。其中 `healthy` 表示进程存活、传输已连接且 WebSocket 最近收到过有效心跳;
83
+ 旧版本创建、尚未包含连接状态字段的运行记录显示为 `unknown`,重启该连接器后即可补齐。
84
+ 输出中的 token 会被隐藏。
85
+
86
+ `start` 会在连接成功后返回,后台进程继续运行。可选配对协议请按对应插件指引提交输出的
87
+ `pair` 工具调用;如果配对工具调用已经结束、取消或过期,需要重新生成配对 URL,旧 URL
88
+ 不能重复使用。
89
+
90
+ ### 编程方式
91
+
92
+ ```typescript
93
+ import { CloudConnector } from '@mearl/cloud-connector';
94
+
95
+ const connector = new CloudConnector({
96
+ serverUrl: 'wss://cloud.example.com/ws?token=xxx',
97
+ connectorName: 'work-mac',
98
+ heartbeatInterval: 30,
99
+ reconnectInterval: 5000,
100
+ maxReconnectAttempts: -1,
101
+ onConnected: url => console.log('connected to', url),
102
+ });
103
+
104
+ connector.connect();
105
+
106
+ // 优雅关闭
107
+ process.on('SIGINT', () => {
108
+ connector.disconnect();
109
+ process.exit(0);
110
+ });
111
+ ```
112
+
113
+ ## 运行时文件
114
+
115
+ 连接器首次运行时会生成稳定的 connector ID,并保存到
116
+ `~/.mearl/cloud-connector-identity.json`。名称默认取主机名,可通过 `--name` 或
117
+ `MEARL_CONNECTOR_NAME` 设置;ID 可通过 `--connector-id` 或
118
+ `MEARL_CONNECTOR_ID` 设置。相同 ID 的新连接会替换旧连接,适合进程重启和网络重连。
119
+
120
+ 每个连接器实例在 `~/.mearl/connectors/` 下按 `server-url` 哈希生成一对文件:
121
+
122
+ - `<hash>.json` —— 连接记录(含身份、进程、连接状态、最近心跳和重试信息)。daemon
123
+ manager 在拉起子进程后立即写入 `starting` 占位,连接器进程随后持续更新自己的状态;
124
+ 删除记录时会核对 pid,避免退出中的旧进程删除新实例记录。崩溃残留会被读取方按 pid
125
+ 存活性自动清理。
126
+ - `<hash>.log` —— 守护进程日志(`logs` 子命令读取,或 `tail -f` 跟踪);超过 5MB 会在下次启动时滚动为 `<hash>.log.1`。
127
+
128
+ native-host 与守护进程 CLI 都通过这套共享路径(由 [`@mearl/daemon-core`](../../daemon-core/README.zh-CN.md) 派生)读取注册表,因此一方启动的连接器另一方也能发现、复用或停止。
129
+
130
+ > 前台运行(含 native-host 托管)时日志输出到 stdout/stderr,不写独立日志文件;只有守护进程模式才落盘到 `<hash>.log`。
131
+
132
+ 可选协议的认证与配对方式见对应能力包文档;核心不读取其凭据。
133
+
134
+ ## 前置条件
135
+
136
+ 1. **安装并初始化本地 Mearl 环境**
137
+
138
+ ```bash
139
+ npx @mearl/setup
140
+ ```
141
+
142
+ setup 会同步安装 `@mearl/native-host` 与 `@mearl/client`,并完成 Native Messaging 初始化。
143
+
144
+ 使用本项目的 monorepo 构建产物时,仍需手动初始化:
145
+
146
+ ```bash
147
+ mearl-native-host --init
148
+ ```
149
+
150
+ 2. **确保 Chrome 浏览器正在运行**,且:
151
+ - 已安装 Mearl 浏览器插件,或
152
+ - 已在 `chrome://inspect/#remote-debugging` 启用远程调试(Chrome 145+)
153
+
154
+ ## 架构
155
+
156
+ ```
157
+ 云端 Agent
158
+ ↓
159
+ @mearl/client
160
+ ↓
161
+ @mearl/cloud-server
162
+ ↓ (WebSocket)
163
+ @mearl/cloud-connector (本进程)
164
+ ↓ (Unix Socket)
165
+ @mearl/native-host
166
+ ↓
167
+ Chrome Extension / CDP
168
+ ```
169
+
170
+ 已安装的连接协议使用同一生命周期和状态回调;具体拓扑由插件说明。
171
+
172
+ ## 注意事项
173
+
174
+ - 连接器需要保持运行才能转发云端请求。被 native-host 托管时,连接器以 `detached` 方式启动,会**在插件重载/更新后继续存活**;自管理时由 `start`/`stop` 子命令掌控生命周期。
175
+ - 前台模式若想交给外部进程管理器(systemd / PM2)托管,加 `--foreground` 让其在前台运行并由管理器负责守护重启。
176
+ - 支持断线自动重连(可在配置中调整);瞬时断连期间连接记录会保留,仅在进程退出时清除。
177
+ - 云端响应超过单条消息上限时会返回结构化错误并保持连接。截图过大时可指定元素范围,
178
+ 或使用 `format: "jpeg"` 和较低的 `quality` 重试。