terminal-bridge-setup 2.4.0 → 2.6.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/bin/setup.mjs +29 -2
- package/files/extension/background.js +1 -1
- package/files/extension/content.js +4 -4
- package/files/native/host.js +1 -1
- package/files/proxy/package.json +2 -2
- package/files/proxy/server.js +1 -1
- package/files/skill/SKILL.md +5 -5
- package/files/skill/references/protocol.md +1 -1
- package/package.json +1 -1
package/bin/setup.mjs
CHANGED
|
@@ -88,14 +88,41 @@ function installProxyDeps() {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const proxyDir = join(INSTALL_DIR, "proxy");
|
|
91
|
+
|
|
92
|
+
// 支持 --registry 透传(国内网络/公司内网常用)
|
|
93
|
+
// 用法:npx terminal-bridge-setup --registry=https://registry.npmmirror.com
|
|
94
|
+
const registryArg = process.argv.find(a => a.startsWith("--registry="));
|
|
95
|
+
const npmArgs = ["install", "--no-audit", "--no-fund"];
|
|
96
|
+
if (registryArg) {
|
|
97
|
+
npmArgs.push(registryArg);
|
|
98
|
+
console.log(c.dim(` 使用 registry: ${registryArg.split("=")[1]}`));
|
|
99
|
+
} else {
|
|
100
|
+
npmArgs.push("--silent");
|
|
101
|
+
}
|
|
102
|
+
|
|
91
103
|
console.log(c.dim(" 运行 npm install ..."));
|
|
92
|
-
const result = spawnSync("npm",
|
|
104
|
+
const result = spawnSync("npm", npmArgs, {
|
|
93
105
|
cwd: proxyDir,
|
|
94
106
|
stdio: "inherit",
|
|
95
107
|
});
|
|
96
108
|
|
|
97
109
|
if (result.status !== 0) {
|
|
98
|
-
|
|
110
|
+
// 失败时给出明确的排查建议
|
|
111
|
+
console.error("");
|
|
112
|
+
console.error(c.red(" ✗ npm install 失败"));
|
|
113
|
+
console.error(c.yellow(" 常见原因和解决方法:"));
|
|
114
|
+
console.error("");
|
|
115
|
+
console.error(" 1. 网络不通/防火墙拦截:");
|
|
116
|
+
console.error(" 检查:curl -I https://registry.npmjs.org/ws");
|
|
117
|
+
console.error("");
|
|
118
|
+
console.error(" 2. 公司内网/国内网络慢:换国内镜像重试");
|
|
119
|
+
console.error(" 命令:npx terminal-bridge-setup --registry=https://registry.npmmirror.com");
|
|
120
|
+
console.error("");
|
|
121
|
+
console.error(" 3. 需要代理:");
|
|
122
|
+
console.error(" 命令:npm config set proxy http://your-proxy:port");
|
|
123
|
+
console.error(" 然后重跑 npx terminal-bridge-setup");
|
|
124
|
+
console.error("");
|
|
125
|
+
fail("npm install 失败(见上方排查建议)");
|
|
99
126
|
}
|
|
100
127
|
ok("依赖安装完成");
|
|
101
128
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Terminal Bridge - content script (ISOLATED world).
|
|
2
2
|
//
|
|
3
3
|
// 注:manifest 用 matches: <all_urls> + all_frames:true + run_at:document_start
|
|
4
4
|
// 注入,是为了确保能进终端 frame(koko connect iframe / Arthas console 顶层文档等)。
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
// observer 只监听 documentElement 的 childList,开销可忽略。
|
|
14
14
|
|
|
15
15
|
(function () {
|
|
16
|
-
const TAG = "[
|
|
16
|
+
const TAG = "[terminal-bridge-cs]";
|
|
17
17
|
|
|
18
|
-
if (window.
|
|
19
|
-
window.
|
|
18
|
+
if (window.__terminalBridgeContentLoaded) return;
|
|
19
|
+
window.__terminalBridgeContentLoaded = true;
|
|
20
20
|
|
|
21
21
|
// ---------- xterm 定位 ----------
|
|
22
22
|
function findXtermTextarea() {
|
package/files/native/host.js
CHANGED
package/files/proxy/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "terminal-bridge-proxy",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "Terminal Bridge 代理:Agent <-> Chrome 插件,请求-响应配对",
|
|
7
7
|
"main": "server.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"start": "node server.js",
|
package/files/proxy/server.js
CHANGED
|
@@ -120,7 +120,7 @@ function maybeRunNext() {
|
|
|
120
120
|
// kitty 终端逐字符注入会重绘,把任何标记字符串(BEGIN/END/哨兵)打散,
|
|
121
121
|
// 标记方案不可靠。改用 shell prompt 作为命令完成的锚点(expect/pexpect 经典做法)。
|
|
122
122
|
//
|
|
123
|
-
//
|
|
123
|
+
// 典型 shell prompt: [root@host /path]# 或 [user@host ~]$
|
|
124
124
|
// 关键:prompt 是服务端 shell 在命令完成后输出的,不受 kitty 输入重绘影响。
|
|
125
125
|
//
|
|
126
126
|
// 流程:
|
package/files/skill/SKILL.md
CHANGED
|
@@ -91,17 +91,17 @@ Arthas 的能力不止于读,以下命令/用法一律禁止通过桥接执行
|
|
|
91
91
|
lsof -i:8787 | grep LISTEN
|
|
92
92
|
|
|
93
93
|
# 2. 没跑就启动(也可从插件 popup 的"启动代理"按钮启动)
|
|
94
|
-
cd
|
|
94
|
+
cd ~/.terminal-bridge/proxy && node server.js &
|
|
95
95
|
```
|
|
96
96
|
|
|
97
97
|
浏览器侧(任选其一或都开):
|
|
98
|
-
- **JumpServer**:
|
|
99
|
-
- **Arthas**:
|
|
98
|
+
- **JumpServer**:Terminal Bridge 插件已加载 + JumpServer 终端页面已打开 + 已连上一个资产(终端可见、能敲字)
|
|
99
|
+
- **Arthas**:Terminal Bridge 插件已加载 + Arthas Console 页面已打开 + 已 Connect 上目标 JVM
|
|
100
100
|
|
|
101
101
|
多终端场景:如果同时开了 JumpServer 和 Arthas 两个 tab,代理命令只会发给 popup 里"当前选中"的那个 tab。切换用 popup 的 tab 选择器,或让用户在 popup 点选。
|
|
102
102
|
|
|
103
103
|
如果用户说"命令没反应"或"inject-failed":
|
|
104
|
-
1. `chrome://extensions/` 刷新
|
|
104
|
+
1. `chrome://extensions/` 刷新 Terminal Bridge 插件 ↻
|
|
105
105
|
2. 让用户在终端页面按 F5 刷新(让 content script 重新识别 xterm)
|
|
106
106
|
3. 让用户在 popup 点"捕捉 xterm"按钮(手动扫描,免刷新)
|
|
107
107
|
4. 确认终端 tab 顶部有黄色调试条(说明 CDP 已 attach)
|
|
@@ -113,7 +113,7 @@ cd ~/Code/testwork/ws-sniffer/proxy && node server.js &
|
|
|
113
113
|
最简方式(用示例客户端):
|
|
114
114
|
|
|
115
115
|
```bash
|
|
116
|
-
cd
|
|
116
|
+
cd ~/.terminal-bridge/proxy
|
|
117
117
|
|
|
118
118
|
# JumpServer 场景
|
|
119
119
|
node client-example.mjs "uname -a"
|
|
@@ -129,7 +129,7 @@ const PROMPT_RE = /\]\s*[#$]\s*$|>\s*$/;
|
|
|
129
129
|
|
|
130
130
|
| 终端 | prompt 样式 | 匹配部分 |
|
|
131
131
|
|------|------------|---------|
|
|
132
|
-
| JumpServer (shell) | `[root@
|
|
132
|
+
| JumpServer (shell) | `[root@host /path]#` 或 `]$` | `]\s*[#$]\s*$` |
|
|
133
133
|
| Arthas | `arthas@pid>` 或 `[arthas@...]` | `>\s*$` |
|
|
134
134
|
|
|
135
135
|
注意:单独的 `>` 较宽(命令输出里 `>` 偶尔出现),但配合"行尾 + ANSI 清理后 + 注入命令后才出现"三个条件,误判率可接受。
|
package/package.json
CHANGED