@chrome-in-harness/launcher 0.1.0 → 0.3.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/README.md +75 -0
- package/dist/bin.js +0 -0
- package/dist/cli.js +0 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @chrome-in-harness/launcher
|
|
2
|
+
|
|
3
|
+
[中文](#中文) | [English](#english)
|
|
4
|
+
|
|
5
|
+
`chrome-in-harness` CLI:一条命令完成「启动本地 server + 写 MCP 客户端配置」,并提供可选的常驻服务注册。
|
|
6
|
+
|
|
7
|
+
> npm 包名是 `@chrome-in-harness/launcher`,bin 名是 `chrome-in-harness`,因此用法是 `npx @chrome-in-harness/launcher <command>`。
|
|
8
|
+
|
|
9
|
+
## 中文
|
|
10
|
+
|
|
11
|
+
### 命令
|
|
12
|
+
|
|
13
|
+
| 命令 | 作用 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `start` | 前台启动本地 server(Ctrl-C 退出);已运行则复用;同时向 OpenCode 全局配置写入 MCP 条目 |
|
|
16
|
+
| `doctor` | 环境自检:server 是否运行、扩展是否连通(真发一次 `ping`)、检测常见 MCP 客户端配置文件 |
|
|
17
|
+
| `service install` | 注册常驻服务:macOS launchd / Linux systemd --user(登录自启 + 崩溃自动拉起) |
|
|
18
|
+
| `service status` | 查看服务安装状态与 server 运行状态 |
|
|
19
|
+
| `service uninstall` | 停止并移除常驻服务 |
|
|
20
|
+
| (无参数) | 帮助信息 |
|
|
21
|
+
|
|
22
|
+
### 实现要点
|
|
23
|
+
|
|
24
|
+
- **server 入口解析**:`import.meta.resolve('@chrome-in-harness/server')` 经 npm 依赖解析拿到入口文件,不硬编码路径
|
|
25
|
+
- **MCP 配置写入**(`writeOpencodeConfig`):
|
|
26
|
+
- 已有同名 `chrome-in-harness` 条目 → 原样保留(逐字节不动)
|
|
27
|
+
- 配置文件不存在 → 创建配置目录并写入(文件权限 0600)
|
|
28
|
+
- 配置文件非法(坏 JSON / 非对象 / `mcp` 段非对象)→ **报错退出,不覆盖原文件**
|
|
29
|
+
- **常驻服务**(`src/service.ts`,文件生成是纯函数、系统命令可注入,全程单测覆盖):
|
|
30
|
+
- macOS:`~/Library/LaunchAgents/com.chrome-in-harness.server.plist`(`RunAtLoad` + `KeepAlive`),日志 `~/Library/Logs/chrome-in-harness-server.log`
|
|
31
|
+
- Linux:`~/.config/systemd/user/chrome-in-harness.service`(`Restart=always`),日志走 journalctl
|
|
32
|
+
- 已安装时再次 `install` 拒绝覆盖;`launchctl load` 失败会回滚已写的 plist,不留半安装状态
|
|
33
|
+
- Windows 不支持,明确报错并建议 `start` + 进程守护
|
|
34
|
+
- **CLI 入口拆分**:执行逻辑在 `src/cli.ts`(可被测试 import 且不自动执行),`src/bin.ts` 只做入口引导——通过 symlink 安装、路径含空格也能正确判定入口
|
|
35
|
+
|
|
36
|
+
### 与其他包的关系
|
|
37
|
+
|
|
38
|
+
launcher 只负责生命周期与配置:server 进程来自 `@chrome-in-harness/server`,浏览器操作全部在扩展内完成。launcher 不是源码 watcher,迭代开发请用仓库根的 `npm run dev:server`。
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## English
|
|
43
|
+
|
|
44
|
+
The `chrome-in-harness` CLI: one command to start the local server and register the MCP client config, plus an opt-in persistent-service installer.
|
|
45
|
+
|
|
46
|
+
> The npm package is `@chrome-in-harness/launcher` while the bin is `chrome-in-harness`, so usage is `npx @chrome-in-harness/launcher <command>`.
|
|
47
|
+
|
|
48
|
+
### Commands
|
|
49
|
+
|
|
50
|
+
| Command | What it does |
|
|
51
|
+
| --- | --- |
|
|
52
|
+
| `start` | Start the local server in the foreground (Ctrl-C to stop); reuses an already-running server; also writes the MCP entry into the OpenCode global config |
|
|
53
|
+
| `doctor` | Environment check: is the server running, is the extension connected (performs a real `ping`), and detects common MCP client config files |
|
|
54
|
+
| `service install` | Install a persistent user service: launchd on macOS / systemd --user on Linux (start at login + auto-restart on crash) |
|
|
55
|
+
| `service status` | Show service installation and server running state |
|
|
56
|
+
| `service uninstall` | Stop and remove the persistent service |
|
|
57
|
+
| (no args) | Help |
|
|
58
|
+
|
|
59
|
+
### Implementation notes
|
|
60
|
+
|
|
61
|
+
- **Server entry resolution**: `import.meta.resolve('@chrome-in-harness/server')` resolves the entry via npm dependency resolution — no hardcoded paths
|
|
62
|
+
- **MCP config write** (`writeOpencodeConfig`):
|
|
63
|
+
- An existing `chrome-in-harness` entry is preserved byte for byte
|
|
64
|
+
- Missing config → the directory is created and the file written (mode 0600)
|
|
65
|
+
- Invalid config (broken JSON / non-object / non-object `mcp` section) → **errors out without touching the original file**
|
|
66
|
+
- **Persistent service** (`src/service.ts`; file generation is a pure function and system commands are injectable, fully unit-tested):
|
|
67
|
+
- macOS: `~/Library/LaunchAgents/com.chrome-in-harness.server.plist` (`RunAtLoad` + `KeepAlive`), logs at `~/Library/Logs/chrome-in-harness-server.log`
|
|
68
|
+
- Linux: `~/.config/systemd/user/chrome-in-harness.service` (`Restart=always`), logs via journalctl
|
|
69
|
+
- Re-running `install` while installed refuses to overwrite; a failed `launchctl load` rolls back the written plist, leaving no half-installed state
|
|
70
|
+
- Windows is unsupported and fails with an explicit message suggesting `start` plus a process supervisor
|
|
71
|
+
- **CLI entry split**: the logic lives in `src/cli.ts` (importable by tests without side effects) while `src/bin.ts` is only the bootstrap — installs via symlinks and paths containing spaces are handled correctly
|
|
72
|
+
|
|
73
|
+
### Relation to other packages
|
|
74
|
+
|
|
75
|
+
The launcher only manages lifecycle and configuration: the server process comes from `@chrome-in-harness/server`, and all browser work happens inside the extension. The launcher is not a source watcher — use `npm run dev:server` from the repo root for development.
|
package/dist/bin.js
CHANGED
|
File without changes
|
package/dist/cli.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrome-in-harness/launcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"chrome-in-harness": "./dist/bin.js"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"test": "vitest run"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@chrome-in-harness/server": "^0.
|
|
20
|
+
"@chrome-in-harness/server": "^0.3.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^24.0.0",
|