@sovovs/bycli 2.0.0 → 2.1.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/clis/twitter/search.js +3 -3
- package/dist/src/browser/cdp.js +3 -0
- package/dist/src/browser/daemon-client.d.ts +2 -0
- package/dist/src/browser/daemon-client.js +1 -1
- package/dist/src/browser/extension-capabilities.d.ts +13 -0
- package/dist/src/browser/extension-capabilities.js +22 -0
- package/dist/src/browser/extension-capabilities.test.d.ts +1 -0
- package/dist/src/browser/extension-version-metadata.test.d.ts +1 -0
- package/dist/src/browser/page.d.ts +1 -0
- package/dist/src/browser/page.js +20 -1
- package/dist/src/build-manifest.js +4 -2
- package/dist/src/capabilityRouting.d.ts +3 -2
- package/dist/src/capabilityRouting.js +10 -2
- package/dist/src/cli.js +1 -1
- package/dist/src/commanderAdapter.js +5 -5
- package/dist/src/daemon.js +16 -0
- package/dist/src/discovery.d.ts +5 -0
- package/dist/src/discovery.js +12 -4
- package/dist/src/discovery.test.d.ts +1 -0
- package/dist/src/execution.d.ts +5 -0
- package/dist/src/execution.js +269 -50
- package/dist/src/help.js +8 -8
- package/dist/src/manifest-schema.d.ts +9 -0
- package/dist/src/manifest-schema.js +162 -0
- package/dist/src/manifest-schema.test.d.ts +1 -0
- package/dist/src/manifest-types.d.ts +1 -1
- package/dist/src/observation/redaction.js +10 -4
- package/dist/src/recorder/runner/verify-runner-main.d.ts +6 -5
- package/dist/src/recorder/runner/verify-runner-main.js +22 -5
- package/dist/src/registry-api.d.ts +1 -1
- package/dist/src/registry-api.types.test.d.ts +1 -0
- package/dist/src/registry-transaction.d.ts +42 -0
- package/dist/src/registry-transaction.js +194 -0
- package/dist/src/registry-transaction.test.d.ts +1 -0
- package/dist/src/registry.d.ts +58 -16
- package/dist/src/registry.js +131 -15
- package/dist/src/serialization.d.ts +1 -1
- package/dist/src/serialization.js +3 -3
- package/dist/src/types.d.ts +2 -0
- package/package.json +1 -1
- package/scripts/recorder.sh +0 -186
package/dist/src/registry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core registry: Strategy enum, Arg/CliCommand interfaces, cli() registration.
|
|
3
3
|
*/
|
|
4
|
+
import { pruneRegistryMutationKey, recordRegistryMutation, registryMutationKeys, withRegistryMutationGroup, } from './registry-transaction.js';
|
|
4
5
|
export var Strategy;
|
|
5
6
|
(function (Strategy) {
|
|
6
7
|
Strategy["PUBLIC"] = "public";
|
|
@@ -9,9 +10,77 @@ export var Strategy;
|
|
|
9
10
|
Strategy["INTERCEPT"] = "intercept";
|
|
10
11
|
Strategy["UI"] = "ui";
|
|
11
12
|
})(Strategy || (Strategy = {}));
|
|
12
|
-
const
|
|
13
|
+
const TRACKED_REGISTRY_MARKER = Symbol.for('@sovovs/bycli/tracked-registry');
|
|
14
|
+
function isTrackedRegistry(registry) {
|
|
15
|
+
return registry !== undefined
|
|
16
|
+
&& registry[TRACKED_REGISTRY_MARKER] === true;
|
|
17
|
+
}
|
|
18
|
+
function instrumentRegistry(registry) {
|
|
19
|
+
if (isTrackedRegistry(registry))
|
|
20
|
+
return registry;
|
|
21
|
+
Object.defineProperties(registry, {
|
|
22
|
+
set: {
|
|
23
|
+
value(key, value) {
|
|
24
|
+
const before = { present: this.has(key), value: this.get(key) };
|
|
25
|
+
recordRegistryMutation(key, before, { present: true, value });
|
|
26
|
+
return Map.prototype.set.call(this, key, value);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
delete: {
|
|
30
|
+
value(key) {
|
|
31
|
+
const before = { present: this.has(key), value: this.get(key) };
|
|
32
|
+
recordRegistryMutation(key, before, { present: false, value: undefined });
|
|
33
|
+
const deleted = Map.prototype.delete.call(this, key);
|
|
34
|
+
pruneRegistryMutationKey(key, this);
|
|
35
|
+
return deleted;
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
clear: {
|
|
39
|
+
value() {
|
|
40
|
+
const keys = new Set([...this.keys(), ...registryMutationKeys()]);
|
|
41
|
+
if (keys.size === 0)
|
|
42
|
+
return;
|
|
43
|
+
withRegistryMutationGroup(() => {
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
const present = this.has(key);
|
|
46
|
+
recordRegistryMutation(key, { present, value: present ? this.get(key) : undefined }, { present: false, value: undefined });
|
|
47
|
+
}
|
|
48
|
+
Map.prototype.clear.call(this);
|
|
49
|
+
for (const key of keys)
|
|
50
|
+
pruneRegistryMutationKey(key, this);
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
[TRACKED_REGISTRY_MARKER]: { value: true },
|
|
55
|
+
});
|
|
56
|
+
return registry;
|
|
57
|
+
}
|
|
58
|
+
const existingRegistry = globalThis.__bycli_registry__ ?? new Map();
|
|
59
|
+
const _registry = instrumentRegistry(existingRegistry);
|
|
60
|
+
globalThis.__bycli_registry__ = _registry;
|
|
13
61
|
export function cli(opts) {
|
|
14
|
-
const
|
|
62
|
+
const base = rawCommandBase(opts);
|
|
63
|
+
let cmd;
|
|
64
|
+
if (typeof opts.browser === 'function') {
|
|
65
|
+
cmd = { ...base, strategy: opts.strategy, browser: opts.browser, func: opts.func };
|
|
66
|
+
}
|
|
67
|
+
else if (opts.browser === false) {
|
|
68
|
+
cmd = { ...base, strategy: opts.strategy, browser: false, func: opts.func };
|
|
69
|
+
}
|
|
70
|
+
else if (opts.browser === true) {
|
|
71
|
+
cmd = { ...base, strategy: opts.strategy, browser: true, func: opts.func };
|
|
72
|
+
}
|
|
73
|
+
else if (isImplicitNonBrowserOptions(opts)) {
|
|
74
|
+
cmd = { ...base, strategy: opts.strategy, browser: opts.browser, func: opts.func };
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
cmd = { ...base, strategy: opts.strategy, browser: opts.browser, func: opts.func };
|
|
78
|
+
}
|
|
79
|
+
registerCommandInput(cmd);
|
|
80
|
+
return _registry.get(fullName(cmd));
|
|
81
|
+
}
|
|
82
|
+
function rawCommandBase(opts) {
|
|
83
|
+
return {
|
|
15
84
|
site: opts.site,
|
|
16
85
|
name: opts.name,
|
|
17
86
|
aliases: opts.aliases,
|
|
@@ -19,11 +88,8 @@ export function cli(opts) {
|
|
|
19
88
|
access: opts.access,
|
|
20
89
|
example: opts.example,
|
|
21
90
|
domain: opts.domain,
|
|
22
|
-
strategy: opts.strategy,
|
|
23
|
-
browser: opts.browser,
|
|
24
91
|
args: opts.args ?? [],
|
|
25
92
|
columns: opts.columns,
|
|
26
|
-
func: opts.func,
|
|
27
93
|
pipeline: opts.pipeline,
|
|
28
94
|
footerExtra: opts.footerExtra,
|
|
29
95
|
validateArgs: opts.validateArgs,
|
|
@@ -31,8 +97,10 @@ export function cli(opts) {
|
|
|
31
97
|
siteSession: opts.siteSession,
|
|
32
98
|
defaultFormat: opts.defaultFormat,
|
|
33
99
|
};
|
|
34
|
-
|
|
35
|
-
|
|
100
|
+
}
|
|
101
|
+
function isImplicitNonBrowserOptions(opts) {
|
|
102
|
+
return opts.browser === undefined
|
|
103
|
+
&& (opts.strategy === Strategy.PUBLIC || opts.strategy === Strategy.LOCAL);
|
|
36
104
|
}
|
|
37
105
|
export function getRegistry() {
|
|
38
106
|
return _registry;
|
|
@@ -43,6 +111,14 @@ export function fullName(cmd) {
|
|
|
43
111
|
export function strategyLabel(cmd) {
|
|
44
112
|
return cmd.strategy ?? Strategy.PUBLIC;
|
|
45
113
|
}
|
|
114
|
+
/** Whether a command may use browser-backed execution for some invocation. */
|
|
115
|
+
export function hasBrowserCapability(cmd) {
|
|
116
|
+
return cmd.browser !== false;
|
|
117
|
+
}
|
|
118
|
+
/** Stable human-readable label for the normalized browser requirement. */
|
|
119
|
+
export function browserRequirementLabel(cmd) {
|
|
120
|
+
return cmd.browser === 'conditional' ? 'conditional' : cmd.browser ? 'yes' : 'no';
|
|
121
|
+
}
|
|
46
122
|
/**
|
|
47
123
|
* Normalize a command's runtime fields. This is the single place where
|
|
48
124
|
* `strategy` is decoded into the concrete fields that the execution path
|
|
@@ -57,10 +133,8 @@ export function strategyLabel(cmd) {
|
|
|
57
133
|
* 2. Derived from strategy + domain (the defaults below)
|
|
58
134
|
*/
|
|
59
135
|
function normalizeCommand(cmd) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const strategy = cmd.strategy ?? (cmd.browser === false ? Strategy.PUBLIC : Strategy.COOKIE);
|
|
63
|
-
const browser = cmd.browser ?? (strategy !== Strategy.PUBLIC && strategy !== Strategy.LOCAL);
|
|
136
|
+
const declaredBrowser = cmd.browser;
|
|
137
|
+
const strategy = cmd.strategy ?? (declaredBrowser === false ? Strategy.PUBLIC : Strategy.COOKIE);
|
|
64
138
|
let navigateBefore = cmd.navigateBefore;
|
|
65
139
|
if (navigateBefore === undefined) {
|
|
66
140
|
if (strategy === Strategy.COOKIE && cmd.domain) {
|
|
@@ -73,9 +147,34 @@ function normalizeCommand(cmd) {
|
|
|
73
147
|
navigateBefore = true;
|
|
74
148
|
}
|
|
75
149
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
150
|
+
if (typeof cmd.browser === 'function') {
|
|
151
|
+
const normalized = {
|
|
152
|
+
...cmd,
|
|
153
|
+
strategy,
|
|
154
|
+
browser: 'conditional',
|
|
155
|
+
requiresBrowser: cmd.browser,
|
|
156
|
+
navigateBefore,
|
|
157
|
+
};
|
|
158
|
+
return normalized;
|
|
159
|
+
}
|
|
160
|
+
if (cmd.browser === false) {
|
|
161
|
+
const normalized = { ...cmd, strategy, browser: false, navigateBefore };
|
|
162
|
+
return normalized;
|
|
163
|
+
}
|
|
164
|
+
if (cmd.browser === true) {
|
|
165
|
+
const normalized = { ...cmd, strategy, browser: true, navigateBefore };
|
|
166
|
+
return normalized;
|
|
167
|
+
}
|
|
168
|
+
if (isImplicitNonBrowserCommand(cmd)) {
|
|
169
|
+
const normalized = { ...cmd, strategy, browser: false, navigateBefore };
|
|
170
|
+
return normalized;
|
|
171
|
+
}
|
|
172
|
+
const normalized = { ...cmd, strategy, browser: true, navigateBefore };
|
|
173
|
+
return normalized;
|
|
174
|
+
}
|
|
175
|
+
function isImplicitNonBrowserCommand(cmd) {
|
|
176
|
+
return cmd.browser === undefined
|
|
177
|
+
&& (cmd.strategy === Strategy.PUBLIC || cmd.strategy === Strategy.LOCAL);
|
|
79
178
|
}
|
|
80
179
|
function assertCommandAccess(cmd) {
|
|
81
180
|
if (cmd.access === 'read' || cmd.access === 'write')
|
|
@@ -92,7 +191,24 @@ function assertSiteSession(cmd) {
|
|
|
92
191
|
}
|
|
93
192
|
}
|
|
94
193
|
export function registerCommand(cmd) {
|
|
95
|
-
|
|
194
|
+
registerCommandInput(cmd);
|
|
195
|
+
}
|
|
196
|
+
function registerCommandInput(cmd) {
|
|
197
|
+
withRegistryMutationGroup(() => {
|
|
198
|
+
assertCommandAccess(cmd);
|
|
199
|
+
assertSiteSession(cmd);
|
|
200
|
+
if (cmd.browser === 'conditional') {
|
|
201
|
+
if (typeof cmd.requiresBrowser !== 'function') {
|
|
202
|
+
const key = `${cmd.site}/${cmd.name}`;
|
|
203
|
+
throw new Error(`Command ${key} requiresBrowser must be a function`);
|
|
204
|
+
}
|
|
205
|
+
insertNormalizedCommand(cmd);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
insertNormalizedCommand(normalizeCommand(cmd));
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
function insertNormalizedCommand(normalized) {
|
|
96
212
|
const canonicalKey = fullName(normalized);
|
|
97
213
|
const existing = _registry.get(canonicalKey);
|
|
98
214
|
if (existing?.aliases) {
|
|
@@ -26,7 +26,7 @@ export declare function serializeCommand(cmd: CliCommand): {
|
|
|
26
26
|
description: string;
|
|
27
27
|
access: import("./registry.js").CommandAccess;
|
|
28
28
|
strategy: string;
|
|
29
|
-
browser: boolean;
|
|
29
|
+
browser: boolean | "conditional";
|
|
30
30
|
args: SerializedArg[];
|
|
31
31
|
columns: string[];
|
|
32
32
|
domain: string | null;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Used by the `list` command, Commander --help, and build-manifest.
|
|
5
5
|
* Separated from registry.ts to keep the registry focused on types + registration.
|
|
6
6
|
*/
|
|
7
|
-
import { fullName, strategyLabel } from './registry.js';
|
|
7
|
+
import { browserRequirementLabel, fullName, strategyLabel } from './registry.js';
|
|
8
8
|
/** Stable arg schema — every field is always present (no sparse objects). */
|
|
9
9
|
export function serializeArg(a) {
|
|
10
10
|
return {
|
|
@@ -28,7 +28,7 @@ export function serializeCommand(cmd) {
|
|
|
28
28
|
description: cmd.description,
|
|
29
29
|
access: cmd.access,
|
|
30
30
|
strategy: strategyLabel(cmd),
|
|
31
|
-
browser:
|
|
31
|
+
browser: cmd.browser,
|
|
32
32
|
args: cmd.args.map(serializeArg),
|
|
33
33
|
columns: cmd.columns ?? [],
|
|
34
34
|
domain: cmd.domain ?? null,
|
|
@@ -87,7 +87,7 @@ export function formatRegistryHelpText(cmd) {
|
|
|
87
87
|
}
|
|
88
88
|
const meta = [];
|
|
89
89
|
meta.push(`Access: ${cmd.access}`);
|
|
90
|
-
meta.push(`Browser: ${cmd
|
|
90
|
+
meta.push(`Browser: ${browserRequirementLabel(cmd)}`);
|
|
91
91
|
if (cmd.domain)
|
|
92
92
|
meta.push(`Domain: ${cmd.domain}`);
|
|
93
93
|
if (cmd.defaultFormat)
|
package/dist/src/types.d.ts
CHANGED
|
@@ -207,6 +207,8 @@ export interface IPage {
|
|
|
207
207
|
* Useful for rich editors that ignore synthetic DOM value/text mutations.
|
|
208
208
|
*/
|
|
209
209
|
insertText?(text: string): Promise<void>;
|
|
210
|
+
/** Focus the browser window containing the active page for interactive login. */
|
|
211
|
+
focusWindow?(): Promise<void>;
|
|
210
212
|
closeWindow?(): Promise<void>;
|
|
211
213
|
/** Returns the current page URL, or null if unavailable. */
|
|
212
214
|
getCurrentUrl?(): Promise<string | null>;
|
package/package.json
CHANGED
package/scripts/recorder.sh
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
# 录制三端管理脚本
|
|
3
|
-
# daemon : 浏览器底座(19825),由 bycli 管理;扩展连这口
|
|
4
|
-
# be : Recorder Local Service(19826),同源托管真实工作台 UI(dashboard/dist)
|
|
5
|
-
# web : Umi dev server(8000),mock 模式,仅前端开发用(无真实录制)
|
|
6
|
-
#
|
|
7
|
-
# 用法:
|
|
8
|
-
# scripts/recorder.sh start [daemon|be|all] # 默认=真实录制环境(daemon+be,自动停 mock)
|
|
9
|
-
# scripts/recorder.sh start --mock # 仅此参数才起 mock 前端(web :8000,假数据)
|
|
10
|
-
# scripts/recorder.sh stop [daemon|be|web|all]
|
|
11
|
-
# scripts/recorder.sh restart [daemon|be|vnc|all] # restart all=daemon+be(不含 mock);改了 .env/dist 后用;vnc=删旧容器换新镜像
|
|
12
|
-
# scripts/recorder.sh status # 看三端
|
|
13
|
-
# scripts/recorder.sh build [core|be|ui|ext|all] # 重建 dist(改源码后;all 含扩展,需手动重载)
|
|
14
|
-
#
|
|
15
|
-
# 真实录制(带 LLM)启动:scripts/recorder.sh start → 打开 http://127.0.0.1:19826/workbench
|
|
16
|
-
#
|
|
17
|
-
# embedded_iframe 录制模式(P2,公开站页内嵌入;**本机默认开**):起 be 默认带 flag——
|
|
18
|
-
# EMBEDDED=0 scripts/recorder.sh start # 显式关闭页内嵌入模式
|
|
19
|
-
# IFRAME_FRAME_SRC=https://juejin.cn scripts/recorder.sh restart be # 只放该 origin(hardened)
|
|
20
|
-
# inline env 经 `env VAR=…` 注入,优先级高于 --env-file(.env 不覆盖已存在的 process env)。
|
|
21
|
-
#
|
|
22
|
-
# vnc 录制模式(容器内 Chromium+扩展+daemon,noVNC 投画面;**本机默认开**,需 podman + 镜像):
|
|
23
|
-
# scripts/recorder.sh build vnc # 构建容器镜像 bycli-verify:latest(需先 build ext + npm run build)
|
|
24
|
-
# scripts/recorder.sh restart vnc # 重启镜像:删旧容器(bycli-vnc),be 下次 bind 用新镜像重建(改镜像后用)
|
|
25
|
-
# VNC=0 scripts/recorder.sh restart be # 显式关闭 vnc 模式
|
|
26
|
-
# 选 VNC 模式后 be 自动 podman run 起容器、前端 iframe 投 noVNC 画面;录的数据走容器网关→be→合成链。
|
|
27
|
-
set -uo pipefail
|
|
28
|
-
|
|
29
|
-
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
30
|
-
RUN="$ROOT/.recorder-run"; mkdir -p "$RUN"
|
|
31
|
-
DAEMON_PORT=19825; BE_PORT=19826; WEB_PORT=8000
|
|
32
|
-
|
|
33
|
-
port_pid() { lsof -ti "tcp:$1" -sTCP:LISTEN 2>/dev/null | head -1; }
|
|
34
|
-
alive() { [ -n "${1:-}" ] && kill -0 "$1" 2>/dev/null; }
|
|
35
|
-
|
|
36
|
-
# ───────────────────────── daemon(交给 bycli 管) ─────────────────────────
|
|
37
|
-
need_bycli() { command -v bycli >/dev/null || { echo "✗ bycli 不在 PATH(在仓库根 npm link)"; return 1; }; }
|
|
38
|
-
daemon_start() { need_bycli || return 1; bycli daemon start 2>&1 | tail -1; }
|
|
39
|
-
daemon_stop() { need_bycli && { bycli daemon stop 2>&1 | tail -1; } || true; }
|
|
40
|
-
daemon_restart() { need_bycli || return 1; bycli daemon restart 2>&1 | tail -1; }
|
|
41
|
-
daemon_status() { local p; p="$(port_pid $DAEMON_PORT)"; [ -n "$p" ] && echo "● daemon RUNNING :$DAEMON_PORT pid=$p" || echo "○ daemon stopped :$DAEMON_PORT"; }
|
|
42
|
-
|
|
43
|
-
# ───────────────────────── vnc(podman 容器,be 自动编排) ────────────────
|
|
44
|
-
# 容器名与 vncOrchestrator.ts 保持一致(BYCLI_VNC_CONTAINER 覆盖,默认 bycli-vnc)。
|
|
45
|
-
VNC_CONTAINER="${BYCLI_VNC_CONTAINER:-bycli-vnc}"
|
|
46
|
-
VNC_IMAGE="${BYCLI_VNC_IMAGE:-bycli-verify:latest}"
|
|
47
|
-
need_podman() { command -v podman >/dev/null || { echo "✗ podman 不在 PATH(VNC 模式需 podman)"; return 1; }; }
|
|
48
|
-
# 重启镜像:删旧容器,be 下次 bind 时用当前镜像重建(build vnc 换镜像后调用)。
|
|
49
|
-
vnc_restart() {
|
|
50
|
-
need_podman || return 1
|
|
51
|
-
[ -n "$(podman images -q "$VNC_IMAGE" 2>/dev/null)" ] || { echo "✗ 镜像 $VNC_IMAGE 不存在 → scripts/recorder.sh build vnc"; return 1; }
|
|
52
|
-
if [ -n "$(podman ps -aq -f "name=^${VNC_CONTAINER}$" 2>/dev/null)" ]; then
|
|
53
|
-
podman rm -f "$VNC_CONTAINER" >/dev/null 2>&1 && echo "✓ 已删旧容器 $VNC_CONTAINER(be 下次 bind 用新镜像 $VNC_IMAGE 重建)"
|
|
54
|
-
else
|
|
55
|
-
echo "○ 容器 $VNC_CONTAINER 未运行(be 下次 bind 会用新镜像 $VNC_IMAGE 新建)"
|
|
56
|
-
fi
|
|
57
|
-
}
|
|
58
|
-
vnc_stop() {
|
|
59
|
-
need_podman || return 1
|
|
60
|
-
if [ -n "$(podman ps -aq -f "name=^${VNC_CONTAINER}$" 2>/dev/null)" ]; then
|
|
61
|
-
podman rm -f "$VNC_CONTAINER" >/dev/null 2>&1 && echo "✓ vnc 容器 $VNC_CONTAINER 已删"
|
|
62
|
-
else echo "○ vnc 容器未运行"; fi
|
|
63
|
-
}
|
|
64
|
-
vnc_status() {
|
|
65
|
-
command -v podman >/dev/null || { echo "○ vnc (podman 未装)"; return; }
|
|
66
|
-
local st; st="$(podman inspect "$VNC_CONTAINER" --format '{{.State.Status}}' 2>/dev/null)"
|
|
67
|
-
[ -n "$st" ] && echo "● vnc $st container=$VNC_CONTAINER image=$VNC_IMAGE" || echo "○ vnc no container ($VNC_CONTAINER)"
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
# ───────────────────────── be(node 进程,PID 文件) ──────────────────────
|
|
71
|
-
be_start() {
|
|
72
|
-
[ -f "$ROOT/dashboard-be/dist/server.js" ] || { echo "✗ be 未构建 → scripts/recorder.sh build be"; return 1; }
|
|
73
|
-
[ -f "$ROOT/dashboard-be/.env" ] || { echo "✗ 缺 dashboard-be/.env → cp dashboard-be/.env.example dashboard-be/.env 并填值"; return 1; }
|
|
74
|
-
[ -d "$ROOT/dashboard/dist" ] || echo "⚠ dashboard/dist 不存在,be 将 API-only(无 UI)→ scripts/recorder.sh build ui"
|
|
75
|
-
if [ -n "$(port_pid $BE_PORT)" ]; then echo "● be 已在 :$BE_PORT(先 stop/restart)"; return 0; fi
|
|
76
|
-
# embedded_iframe 模式(P2):EMBEDDED=1 → 注入 flag 开 frame-src + 前端模式选项。
|
|
77
|
-
# 经 `env VAR=…` 内联注入,优先级高于 --env-file(.env 不覆盖已存在的 process env)。
|
|
78
|
-
# 三种录制模式默认全开(本机录制工作台);显式 EMBEDDED=0 / VNC=0 可单独关。
|
|
79
|
-
# 注:只在本机 be 启动注入,不动 recorder-core 的 fail-closed 发布默认(全局 CSP 安全底线不变)。
|
|
80
|
-
local envv=()
|
|
81
|
-
if [ "${EMBEDDED:-1}" = 1 ]; then
|
|
82
|
-
envv+=(FEATURE_EMBEDDED_IFRAME_RECORDING=1)
|
|
83
|
-
[ -n "${IFRAME_FRAME_SRC:-}" ] && envv+=("RECORDER_IFRAME_FRAME_SRC=$IFRAME_FRAME_SRC")
|
|
84
|
-
echo " ⚙ embedded_iframe 模式 ON${IFRAME_FRAME_SRC:+(frame-src=$IFRAME_FRAME_SRC)}"
|
|
85
|
-
fi
|
|
86
|
-
if [ "${VNC:-1}" = 1 ]; then
|
|
87
|
-
envv+=(FEATURE_VNC_RECORDING=1)
|
|
88
|
-
echo " ⚙ vnc 容器模式 ON(be 自动 podman run bycli-verify:latest;需先 build vnc)"
|
|
89
|
-
fi
|
|
90
|
-
( cd "$ROOT" && nohup env ${envv[@]+"${envv[@]}"} node --env-file=dashboard-be/.env dashboard-be/dist/server.js >"$RUN/be.log" 2>&1 & echo $! >"$RUN/be.pid" )
|
|
91
|
-
sleep 1; be_status; echo " 日志: $RUN/be.log"
|
|
92
|
-
}
|
|
93
|
-
be_stop() {
|
|
94
|
-
# 端口权威:pid 文件 + 实际占 19826 的进程都杀(防重复实例残留)
|
|
95
|
-
local stopped=0 pf; pf="$(cat "$RUN/be.pid" 2>/dev/null)"
|
|
96
|
-
for pid in "$pf" "$(port_pid $BE_PORT)"; do
|
|
97
|
-
if alive "$pid"; then kill "$pid" 2>/dev/null; echo "✓ be 已停(pid=$pid)"; stopped=1; fi
|
|
98
|
-
done
|
|
99
|
-
[ "$stopped" = 0 ] && echo "○ be 未运行"
|
|
100
|
-
rm -f "$RUN/be.pid"
|
|
101
|
-
}
|
|
102
|
-
be_restart() { be_stop; sleep 1; be_start; }
|
|
103
|
-
be_status() { local p; p="$(port_pid $BE_PORT)"; [ -n "$p" ] && echo "● be RUNNING http://127.0.0.1:$BE_PORT/workbench pid=$p" || echo "○ be stopped :$BE_PORT"; }
|
|
104
|
-
|
|
105
|
-
# ───────────────────────── web(Umi dev,mock) ───────────────────────────
|
|
106
|
-
web_start() {
|
|
107
|
-
if [ -n "$(port_pid $WEB_PORT)" ]; then echo "● web 已在 :$WEB_PORT"; return 0; fi
|
|
108
|
-
( cd "$ROOT/dashboard" && nohup npm run dev >"$RUN/web.log" 2>&1 & echo $! >"$RUN/web.pid" )
|
|
109
|
-
echo "✓ web 启动中(mock,http://127.0.0.1:$WEB_PORT) 日志: $RUN/web.log"
|
|
110
|
-
}
|
|
111
|
-
web_stop() {
|
|
112
|
-
local pid; pid="$(cat "$RUN/web.pid" 2>/dev/null)"; [ -z "$pid" ] && pid="$(port_pid $WEB_PORT)"
|
|
113
|
-
if alive "$pid"; then pkill -P "$pid" 2>/dev/null; kill "$pid" 2>/dev/null; echo "✓ web 已停"; else echo "○ web 未运行"; fi
|
|
114
|
-
rm -f "$RUN/web.pid"
|
|
115
|
-
}
|
|
116
|
-
web_restart() { web_stop; sleep 1; web_start; }
|
|
117
|
-
web_status() { local p; p="$(port_pid $WEB_PORT)"; [ -n "$p" ] && echo "● web RUNNING http://127.0.0.1:$WEB_PORT (mock) pid=$p" || echo "○ web stopped :$WEB_PORT (mock dev)"; }
|
|
118
|
-
|
|
119
|
-
# ───────────────────────── build ────────────────────────────────────────
|
|
120
|
-
do_build() {
|
|
121
|
-
case "${1:-all}" in
|
|
122
|
-
core) npm --prefix "$ROOT/packages/recorder-core" run build ;;
|
|
123
|
-
be) npm --prefix "$ROOT/dashboard-be" run build ;;
|
|
124
|
-
ui) ( cd "$ROOT/dashboard" && npm run build ) ;;
|
|
125
|
-
ext) ( cd "$ROOT/extension" && npm run build ) ;;
|
|
126
|
-
vnc) # VNC 录制模式容器镜像(Chromium+扩展+daemon+x11vnc+websockify+网关);be 起容器时复用 bycli-verify:latest。
|
|
127
|
-
command -v podman >/dev/null || { echo "✗ podman 不在 PATH(VNC 模式需 podman)"; return 1; }
|
|
128
|
-
[ -f "$ROOT/extension/dist/background.js" ] || { echo "✗ 扩展未构建 → scripts/recorder.sh build ext"; return 1; }
|
|
129
|
-
[ -f "$ROOT/dist/src/daemon.js" ] || { echo "✗ dist 未构建 → npm run build"; return 1; }
|
|
130
|
-
echo "▶ 构建 VNC 容器镜像 bycli-verify:latest(首次装 chromium 较慢)…"
|
|
131
|
-
( cd "$ROOT" && podman build -f podman-verify/Dockerfile -t bycli-verify:latest . ) ;;
|
|
132
|
-
all) npm --prefix "$ROOT/packages/recorder-core" run build \
|
|
133
|
-
&& npm --prefix "$ROOT/dashboard-be" run build \
|
|
134
|
-
&& ( cd "$ROOT/dashboard" && npm run build ) \
|
|
135
|
-
&& ( cd "$ROOT/extension" && npm run build ) \
|
|
136
|
-
&& echo "↻ 扩展已重建 → chrome://extensions 重载 byCLI(确认版本号刷新)" ;;
|
|
137
|
-
*) echo "build: core|be|ui|ext|vnc|all"; return 1 ;;
|
|
138
|
-
esac
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
# ───────────────────────── dispatch ─────────────────────────────────────
|
|
142
|
-
action="${1:-}"; shift || true
|
|
143
|
-
case "$action" in
|
|
144
|
-
start)
|
|
145
|
-
# mock 仅在显式 --mock 时启动;其余参数视作服务名
|
|
146
|
-
mock=0; svcs=()
|
|
147
|
-
for a in "$@"; do if [ "$a" = "--mock" ]; then mock=1; else svcs+=("$a"); fi; done
|
|
148
|
-
if [ "$mock" = 1 ]; then
|
|
149
|
-
echo "▶ 启动【mock 前端】(web :$WEB_PORT,假数据,无真实录制)"
|
|
150
|
-
web_start
|
|
151
|
-
elif [ ${#svcs[@]} -eq 0 ]; then
|
|
152
|
-
# 默认 = 真实录制环境:停掉 mock web(防 :8000 误测)→ 起 daemon + be
|
|
153
|
-
echo "▶ 启动【真实录制环境】(daemon + be);mock web 若在跑将被停掉以免混淆"
|
|
154
|
-
[ -n "$(port_pid $WEB_PORT)" ] && web_stop
|
|
155
|
-
daemon_start; be_start
|
|
156
|
-
echo; echo "✅ 真实录制 → http://127.0.0.1:$BE_PORT/workbench(mock 需 start --mock)"
|
|
157
|
-
else
|
|
158
|
-
[ "${svcs[0]}" = "all" ] && svcs=(daemon be)
|
|
159
|
-
for t in "${svcs[@]}"; do
|
|
160
|
-
case "$t" in
|
|
161
|
-
daemon|be) "${t}_start" ;;
|
|
162
|
-
web) echo "✗ web 是 mock,请用:scripts/recorder.sh start --mock" ;;
|
|
163
|
-
*) echo "未知服务: $t(daemon|be|all,mock 用 --mock)" ;;
|
|
164
|
-
esac
|
|
165
|
-
done
|
|
166
|
-
fi ;;
|
|
167
|
-
stop|restart)
|
|
168
|
-
# all 语义:restart 只起真实环境(daemon+be,不复活 mock,与 start 默认一致);
|
|
169
|
-
# stop 则全停(含 mock web,teardown)。mock 启停一律显式 web/--mock。
|
|
170
|
-
if [ $# -eq 0 ]; then targets=(daemon be)
|
|
171
|
-
elif [ "${1:-}" = all ]; then
|
|
172
|
-
[ "$action" = stop ] && targets=(daemon be web) || targets=(daemon be)
|
|
173
|
-
else targets=("$@"); fi
|
|
174
|
-
[ "$action" = stop ] && targets=($(printf '%s\n' "${targets[@]}" | tail -r 2>/dev/null || printf '%s\n' "${targets[@]}"))
|
|
175
|
-
for t in "${targets[@]}"; do
|
|
176
|
-
case "$t" in daemon|be|web|vnc) "${t}_${action}" ;; *) echo "未知服务: $t(daemon|be|web|vnc|all)";; esac
|
|
177
|
-
done ;;
|
|
178
|
-
status)
|
|
179
|
-
daemon_status; be_status; web_status; vnc_status ;;
|
|
180
|
-
build)
|
|
181
|
-
do_build "${1:-all}" ;;
|
|
182
|
-
""|-h|--help|help)
|
|
183
|
-
awk 'NR>1 && /^#/{sub(/^# ?/,"");print;next} NR>1{exit}' "${BASH_SOURCE[0]}" ;;
|
|
184
|
-
*)
|
|
185
|
-
echo "未知命令: $action(start|stop|restart|status|build)"; exit 1 ;;
|
|
186
|
-
esac
|