fix(cli): 自动拉起 daemon 走 boot.js(带 BrowserManager),修复 open/list/get 全 not found;daemon 增 visionl-daemon bin + start 指向 boot;docs 同步当前 CLI(无 daemon/page 子命令,Bing 易反爬请用百度等国内源)

This commit is contained in:
AskaEth committed 2026-09-06 11:11:56 +08:00
1 parent 36780493a5
commit c3a7f74b1f
4 files changed
+50 -14

No files matched your search

+15 -12
View File
@@ -206,26 +206,29 @@ visionl profiles
## Daemon 管理 ## Daemon 管理
### `visionl daemon start` > 当前 CLI **没有 `daemon start/stop` 子命令**。首条页面命令会自动拉起**带反检测浏览器**的 daemon(`boot.js`);手动启动可选如下方式。
手动启动 daemon。 ### 手动启动浏览器 daemon
```bash ```bash
visionl daemon start [--port <n>] # 方式一:daemon 包 start 脚本(= node ./dist/boot.js)
cd packages/daemon && npm run start
# 默认端口 9527 # 方式二:直接节点
visionl daemon start node packages/daemon/dist/boot.js
# 指定端口
visionl daemon start --port 8080 # 方式三:全局 bin(构建后安装)
visionl-daemon
# 指定端口:VISIONL_PORT 环境变量,默认 9527
VISIONL_PORT=8080 node packages/daemon/dist/boot.js
``` ```
### `visionl daemon stop` > 注意:必须走 `boot.js`(它初始化 `BrowserManager` 并把它传给 `startServer`)。若直接 `node packages/daemon/dist/server.js`,daemon 会**没有浏览器**,页面路由不注册,`open/list/...` 一律 `not found`(这是已修复的坑)。
优雅关闭 daemon(不杀死已打开的页面)。 ### 重启 / 停止 daemon
```bash 没有 `daemon stop` 子命令;结束方式为 `kill <daemon的pid>`(含浏览器常驻进程)即可。
visionl daemon stop
```
### `visionl daemon status` ### `visionl daemon status`
+4 -1
View File
@@ -20,7 +20,10 @@ export async function ensureDaemonRunning(port: number): Promise<VisionLClient>
} }
} }
const daemonEntryPath = path.resolve(__dirname, '../../daemon/dist/server.js'); // Spawn the browser-enabled daemon entry (boot.js) so that page/content/
// action routes are registered. Spawning server.js directly would start a
// browser-less daemon that only serves /health.
const daemonEntryPath = path.resolve(__dirname, '../../daemon/dist/boot.js');
spawn('node', [daemonEntryPath], { spawn('node', [daemonEntryPath], {
env: { ...process.env, VISIONL_PORT: String(port) }, env: { ...process.env, VISIONL_PORT: String(port) },
stdio: 'ignore', stdio: 'ignore',
+4 -1
View File
@@ -3,10 +3,13 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"main": "./dist/index.js", "main": "./dist/index.js",
"bin": {
"visionl-daemon": "./dist/boot.js"
},
"scripts": { "scripts": {
"typecheck": "tsc -b", "typecheck": "tsc -b",
"build": "tsc -b", "build": "tsc -b",
"start": "node ./dist/index.js" "start": "node ./dist/boot.js"
}, },
"dependencies": { "dependencies": {
"@visionl/core": "*", "@visionl/core": "*",
+27
View File
@@ -0,0 +1,27 @@
import { startServer } from './server.js';
import { BrowserManager } from './browser-manager.js';
/**
* boot is the browser-enabled daemon entry: it initializes a persistent
* BrowserManager (anti-detection Chromium) and starts the HTTP+WS server with
* it. Startup via the CLI must go through this entry so page/content/action
* routes are actually registered (spawning server.js alone skips them).
*/
export async function boot(port: number, profile = 'desktop-chrome') {
const bm = new BrowserManager(profile);
await bm.init();
console.log('[daemon] Browser initialized');
const server = await startServer(port, bm);
console.log('[daemon] Ready on port', port);
return { bm, server };
}
// Direct start when run as a script — the correct browser-enabled daemon entry.
if (process.argv[1] && (process.argv[1].endsWith('boot.js') || process.argv[1].endsWith('boot.ts'))) {
const port = parseInt(process.env.VISIONL_PORT || '9527', 10);
const profile = process.env.VISIONL_PROFILE || 'desktop-chrome';
boot(port, profile).catch((err) => {
console.error('[daemon] Fatal:', err);
process.exit(1);
});
}