ghost-bridge 0.2.0 → 0.2.2
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/dist/cli.js +1 -9
- package/extension/background.js +16 -14
- package/extension/offscreen.js +9 -0
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -5454,16 +5454,8 @@ var require_lib = __commonJS({
|
|
|
5454
5454
|
import path from "path";
|
|
5455
5455
|
import os2 from "os";
|
|
5456
5456
|
function getClaudeConfigPath() {
|
|
5457
|
-
const platform = os2.platform();
|
|
5458
5457
|
const homeDir = os2.homedir();
|
|
5459
|
-
|
|
5460
|
-
return path.join(process.env.APPDATA, "Claude", "claude.json");
|
|
5461
|
-
} else if (platform === "darwin") {
|
|
5462
|
-
const appSupportPath = path.join(homeDir, "Library", "Application Support", "Claude", "claude.json");
|
|
5463
|
-
return path.join(homeDir, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
5464
|
-
} else {
|
|
5465
|
-
return path.join(homeDir, ".config", "Claude", "claude_desktop_config.json");
|
|
5466
|
-
}
|
|
5458
|
+
return path.join(homeDir, ".claude.json");
|
|
5467
5459
|
}
|
|
5468
5460
|
function getExtensionPath() {
|
|
5469
5461
|
const __filename2 = new URL(import.meta.url).pathname;
|
package/extension/background.js
CHANGED
|
@@ -801,20 +801,9 @@ function sendToServer(data) {
|
|
|
801
801
|
chrome.runtime.sendMessage({ type: 'send', data }).catch(() => {})
|
|
802
802
|
}
|
|
803
803
|
|
|
804
|
-
// ==========
|
|
805
|
-
|
|
806
|
-
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
807
|
-
// 判断消息来源
|
|
808
|
-
const senderUrl = sender.url || ''
|
|
809
|
-
const isFromOffscreen = senderUrl.includes('offscreen.html')
|
|
810
|
-
const isFromBackground = !sender.url // background 发的消息没有 url
|
|
804
|
+
// ========== 状态广播 ==========
|
|
811
805
|
|
|
812
|
-
|
|
813
|
-
if (isFromBackground) {
|
|
814
|
-
return
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
// 主动推送状态给 popup
|
|
806
|
+
// 主动推送状态给 popup
|
|
818
807
|
function broadcastStatus() {
|
|
819
808
|
let status
|
|
820
809
|
if (!state.enabled) {
|
|
@@ -839,7 +828,20 @@ function broadcastStatus() {
|
|
|
839
828
|
}).catch(() => {}) // popup 可能未打开,忽略错误
|
|
840
829
|
}
|
|
841
830
|
|
|
842
|
-
//
|
|
831
|
+
// ========== 消息监听 ==========
|
|
832
|
+
|
|
833
|
+
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
834
|
+
// 判断消息来源
|
|
835
|
+
const senderUrl = sender.url || ''
|
|
836
|
+
const isFromOffscreen = senderUrl.includes('offscreen.html')
|
|
837
|
+
const isFromBackground = !sender.url // background 发的消息没有 url
|
|
838
|
+
|
|
839
|
+
// background 自己发出的消息不处理(避免循环)
|
|
840
|
+
if (isFromBackground) {
|
|
841
|
+
return
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// 来自 offscreen 的状态更新
|
|
843
845
|
if (message.type === 'status' && isFromOffscreen) {
|
|
844
846
|
if (message.status === 'connected') {
|
|
845
847
|
state.connected = true
|
package/extension/offscreen.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
let ws = null
|
|
5
5
|
let reconnectTimer = null
|
|
6
|
+
let manualDisconnect = false // 用户主动断开标志,防止 onclose 触发重连
|
|
6
7
|
let config = {
|
|
7
8
|
basePort: 33333,
|
|
8
9
|
token: '',
|
|
@@ -23,6 +24,9 @@ function getMonthlyToken() {
|
|
|
23
24
|
|
|
24
25
|
// 连接到服务器
|
|
25
26
|
function connect(portIndex = 0, isNewRound = false) {
|
|
27
|
+
// 如果已手动断开,不再尝试连接
|
|
28
|
+
if (manualDisconnect) return
|
|
29
|
+
|
|
26
30
|
if (portIndex >= config.maxPortRetries) {
|
|
27
31
|
log(`扫描完毕,未找到服务,2秒后重试...`)
|
|
28
32
|
reconnectTimer = setTimeout(() => connect(0, true), 2000)
|
|
@@ -99,6 +103,9 @@ function connect(portIndex = 0, isNewRound = false) {
|
|
|
99
103
|
ws.onclose = (event) => {
|
|
100
104
|
clearTimeout(connectionTimeout)
|
|
101
105
|
|
|
106
|
+
// 用户主动断开,不重连
|
|
107
|
+
if (manualDisconnect) return
|
|
108
|
+
|
|
102
109
|
if (!identityVerified) {
|
|
103
110
|
// 连接失败,尝试下一个端口
|
|
104
111
|
setTimeout(() => connect(portIndex + 1), 50)
|
|
@@ -127,6 +134,7 @@ function sendToServer(data) {
|
|
|
127
134
|
|
|
128
135
|
// 断开连接
|
|
129
136
|
function disconnect() {
|
|
137
|
+
manualDisconnect = true // 标记为手动断开,阻止 onclose 重连
|
|
130
138
|
if (reconnectTimer) {
|
|
131
139
|
clearTimeout(reconnectTimer)
|
|
132
140
|
reconnectTimer = null
|
|
@@ -145,6 +153,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
|
145
153
|
config.token = message.token || getMonthlyToken()
|
|
146
154
|
config.maxPortRetries = message.maxPortRetries || 10
|
|
147
155
|
disconnect()
|
|
156
|
+
manualDisconnect = false // 用户重新连接,清除断开标志
|
|
148
157
|
connect(0, true)
|
|
149
158
|
sendResponse({ ok: true })
|
|
150
159
|
return true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ghost-bridge",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Ghost Bridge: Zero-restart Chrome debugger bridge for Claude MCP. Includes CLI for easy setup.",
|
|
@@ -26,4 +26,4 @@
|
|
|
26
26
|
"js-beautify": "^1.14.11",
|
|
27
27
|
"ws": "^8.14.2"
|
|
28
28
|
}
|
|
29
|
-
}
|
|
29
|
+
}
|