supersurf-daemon 1.0.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/LICENSE +225 -0
- package/README.md +40 -0
- package/dist/extension-bridge.d.ts +51 -0
- package/dist/extension-bridge.d.ts.map +1 -0
- package/dist/extension-bridge.js +259 -0
- package/dist/extension-bridge.js.map +1 -0
- package/dist/ipc.d.ts +43 -0
- package/dist/ipc.d.ts.map +1 -0
- package/dist/ipc.js +192 -0
- package/dist/ipc.js.map +1 -0
- package/dist/main.d.ts +31 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +224 -0
- package/dist/main.js.map +1 -0
- package/dist/scheduler.d.ts +48 -0
- package/dist/scheduler.d.ts.map +1 -0
- package/dist/scheduler.js +223 -0
- package/dist/scheduler.js.map +1 -0
- package/dist/session.d.ts +43 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +106 -0
- package/dist/session.js.map +1 -0
- package/dist/shared/index.d.ts +3 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +10 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/logger/logger.d.ts +41 -0
- package/dist/shared/logger/logger.d.ts.map +1 -0
- package/dist/shared/logger/logger.js +110 -0
- package/dist/shared/logger/logger.js.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
The Commons Clause License Condition v1.0
|
|
2
|
+
|
|
3
|
+
The Software is provided to you by the Licensor under the License,
|
|
4
|
+
as defined below, subject to the following condition.
|
|
5
|
+
|
|
6
|
+
Without limiting other conditions in the License, the grant of rights
|
|
7
|
+
under the License will not include, and the License does not grant to
|
|
8
|
+
you, the right to Sell the Software.
|
|
9
|
+
|
|
10
|
+
For purposes of the foregoing, "Sell" means practicing any or all of
|
|
11
|
+
the rights granted to you under the License to provide to third parties,
|
|
12
|
+
for a fee or other consideration (including without limitation fees for
|
|
13
|
+
hosting or consulting/support services related to the Software), a
|
|
14
|
+
product or service whose value derives, entirely or substantially, from
|
|
15
|
+
the functionality of the Software. Any license notice or attribution
|
|
16
|
+
required by the License must also include this Commons Clause License
|
|
17
|
+
Condition notice.
|
|
18
|
+
|
|
19
|
+
Software: SuperSurf
|
|
20
|
+
License: Apache License 2.0
|
|
21
|
+
Licensor: The Media Masons
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Apache License
|
|
26
|
+
Version 2.0, January 2004
|
|
27
|
+
http://www.apache.org/licenses/
|
|
28
|
+
|
|
29
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
30
|
+
|
|
31
|
+
1. Definitions.
|
|
32
|
+
|
|
33
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
34
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
35
|
+
|
|
36
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
37
|
+
the copyright owner that is granting the License.
|
|
38
|
+
|
|
39
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
40
|
+
other entities that control, are controlled by, or are under common
|
|
41
|
+
control with that entity. For the purposes of this definition,
|
|
42
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
43
|
+
direction or management of such entity, whether by contract or
|
|
44
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
45
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
46
|
+
|
|
47
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
48
|
+
exercising permissions granted by this License.
|
|
49
|
+
|
|
50
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
51
|
+
including but not limited to software source code, documentation
|
|
52
|
+
source, and configuration files.
|
|
53
|
+
|
|
54
|
+
"Object" form shall mean any form resulting from mechanical
|
|
55
|
+
transformation or translation of a Source form, including but
|
|
56
|
+
not limited to compiled object code, generated documentation,
|
|
57
|
+
and conversions to other media types.
|
|
58
|
+
|
|
59
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
60
|
+
Object form, made available under the License, as indicated by a
|
|
61
|
+
copyright notice that is included in or attached to the work
|
|
62
|
+
(an example is provided in the Appendix below).
|
|
63
|
+
|
|
64
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
65
|
+
form, that is based on (or derived from) the Work and for which the
|
|
66
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
67
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
68
|
+
of this License, Derivative Works shall not include works that remain
|
|
69
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
70
|
+
the Work and Derivative Works thereof.
|
|
71
|
+
|
|
72
|
+
"Contribution" shall mean any work of authorship, including
|
|
73
|
+
the original version of the Work and any modifications or additions
|
|
74
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
75
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
76
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
77
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
78
|
+
means any form of electronic, verbal, or written communication sent
|
|
79
|
+
to the Licensor or its representatives, including but not limited to
|
|
80
|
+
communication on electronic mailing lists, source code control systems,
|
|
81
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
82
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
83
|
+
excluding communication that is conspicuously marked or otherwise
|
|
84
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
85
|
+
|
|
86
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
87
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
88
|
+
subsequently incorporated within the Work.
|
|
89
|
+
|
|
90
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
91
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
92
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
93
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
94
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
95
|
+
Work and such Derivative Works in Source or Object form.
|
|
96
|
+
|
|
97
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
98
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
99
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
100
|
+
(except as stated in this section) patent license to make, have made,
|
|
101
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
102
|
+
where such license applies only to those patent claims licensable
|
|
103
|
+
by such Contributor that are necessarily infringed by their
|
|
104
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
105
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
106
|
+
institute patent litigation against any entity (including a
|
|
107
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
108
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
109
|
+
or contributory patent infringement, then any patent licenses
|
|
110
|
+
granted to You under this License for that Work shall terminate
|
|
111
|
+
as of the date such litigation is filed.
|
|
112
|
+
|
|
113
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
114
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
115
|
+
modifications, and in Source or Object form, provided that You
|
|
116
|
+
meet the following conditions:
|
|
117
|
+
|
|
118
|
+
(a) You must give any other recipients of the Work or
|
|
119
|
+
Derivative Works a copy of this License; and
|
|
120
|
+
|
|
121
|
+
(b) You must cause any modified files to carry prominent notices
|
|
122
|
+
stating that You changed the files; and
|
|
123
|
+
|
|
124
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
125
|
+
that You distribute, all copyright, patent, trademark, and
|
|
126
|
+
attribution notices from the Source form of the Work,
|
|
127
|
+
excluding those notices that do not pertain to any part of
|
|
128
|
+
the Derivative Works; and
|
|
129
|
+
|
|
130
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
131
|
+
distribution, then any Derivative Works that You distribute must
|
|
132
|
+
include a readable copy of the attribution notices contained
|
|
133
|
+
within such NOTICE file, excluding those notices that do not
|
|
134
|
+
pertain to any part of the Derivative Works, in at least one
|
|
135
|
+
of the following places: within a NOTICE text file distributed
|
|
136
|
+
as part of the Derivative Works; within the Source form or
|
|
137
|
+
documentation, if provided along with the Derivative Works; or,
|
|
138
|
+
within a display generated by the Derivative Works, if and
|
|
139
|
+
wherever such third-party notices normally appear. The contents
|
|
140
|
+
of the NOTICE file are for informational purposes only and
|
|
141
|
+
do not modify the License. You may add Your own attribution
|
|
142
|
+
notices within Derivative Works that You distribute, alongside
|
|
143
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
144
|
+
that such additional attribution notices cannot be construed
|
|
145
|
+
as modifying the License.
|
|
146
|
+
|
|
147
|
+
You may add Your own copyright statement to Your modifications and
|
|
148
|
+
may provide additional or different license terms and conditions
|
|
149
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
150
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
151
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
152
|
+
the conditions stated in this License.
|
|
153
|
+
|
|
154
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
155
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
156
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
157
|
+
this License, without any additional terms or conditions.
|
|
158
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
159
|
+
the terms of any separate license agreement you may have executed
|
|
160
|
+
with Licensor regarding such Contributions.
|
|
161
|
+
|
|
162
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
163
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
164
|
+
except as required for reasonable and customary use in describing the
|
|
165
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
166
|
+
|
|
167
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
168
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
169
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
170
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
171
|
+
implied, including, without limitation, any warranties or conditions
|
|
172
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
173
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
174
|
+
appropriateness of using or redistributing the Work and assume any
|
|
175
|
+
risks associated with Your exercise of permissions under this License.
|
|
176
|
+
|
|
177
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
178
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
179
|
+
unless required by applicable law (such as deliberate and grossly
|
|
180
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
181
|
+
liable to You for damages, including any direct, indirect, special,
|
|
182
|
+
incidental, or consequential damages of any character arising as a
|
|
183
|
+
result of this License or out of the use or inability to use the
|
|
184
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
185
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
186
|
+
other commercial damages or losses), even if such Contributor
|
|
187
|
+
has been advised of the possibility of such damages.
|
|
188
|
+
|
|
189
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
190
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
191
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
192
|
+
or other liability obligations and/or rights consistent with this
|
|
193
|
+
License. However, in accepting such obligations, You may act only
|
|
194
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
195
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
196
|
+
defend, and hold each Contributor harmless for any liability
|
|
197
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
198
|
+
of your accepting any such warranty or additional liability.
|
|
199
|
+
|
|
200
|
+
END OF TERMS AND CONDITIONS
|
|
201
|
+
|
|
202
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
203
|
+
|
|
204
|
+
To apply the Apache License to your work, attach the following
|
|
205
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
206
|
+
replaced with your own identifying information. (Don't include
|
|
207
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
208
|
+
comment syntax for the file format. We also recommend that a
|
|
209
|
+
file or class name and description of purpose be included on the
|
|
210
|
+
same "printed page" as the copyright notice for easier
|
|
211
|
+
identification within third-party archives.
|
|
212
|
+
|
|
213
|
+
Copyright 2026 The Media Masons
|
|
214
|
+
|
|
215
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
216
|
+
you may not use this file except in compliance with the License.
|
|
217
|
+
You may obtain a copy of the License at
|
|
218
|
+
|
|
219
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
220
|
+
|
|
221
|
+
Unless required by applicable law or agreed to in writing, software
|
|
222
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
223
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
224
|
+
See the License for the specific language governing permissions and
|
|
225
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# supersurf-daemon
|
|
2
|
+
|
|
3
|
+
Multiplexer for SuperSurf — coordinates multiple MCP sessions sharing one Chrome extension connection.
|
|
4
|
+
|
|
5
|
+
**You don't install or configure this.** The MCP server ([`supersurf-mcp`](https://www.npmjs.com/package/supersurf-mcp)) automatically spawns the daemon when an agent calls `connect`. If a daemon is already running, it connects to the existing instance instead — no duplicate processes, no wasted memory.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
```mermaid
|
|
10
|
+
graph TD
|
|
11
|
+
A["MCP Server A"] -->|Unix socket| D["supersurf-daemon"]
|
|
12
|
+
B["MCP Server B"] -->|Unix socket| D
|
|
13
|
+
C["MCP Server C"] -->|Unix socket| D
|
|
14
|
+
D -->|WebSocket :5555| E["Chrome Extension"]
|
|
15
|
+
E -->|Content Scripts + CDP| F["Chrome Browser"]
|
|
16
|
+
|
|
17
|
+
style D fill:#1B5E20,stroke:#0D3B14,color:#fff
|
|
18
|
+
style E fill:#4285F4,stroke:#1565C0,color:#fff
|
|
19
|
+
style F fill:#FF6F00,stroke:#E65100,color:#fff
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The daemon owns the single WebSocket connection to the Chrome extension. MCP servers connect to it over a Unix domain socket (`~/.supersurf/daemon.sock`). Tool calls are scheduled round-robin across sessions, with tab ownership enforcement — sessions can't touch each other's tabs.
|
|
23
|
+
|
|
24
|
+
## Lifecycle
|
|
25
|
+
|
|
26
|
+
- **Auto-spawned** by the MCP server on `connect` via `npx supersurf-daemon@latest`
|
|
27
|
+
- **Single instance** — detects an existing daemon via PID file and skips spawning
|
|
28
|
+
- **Stays alive** when sessions disconnect, keeping the extension connection warm
|
|
29
|
+
- **Idle timeout** — exits after 10 minutes with no connected sessions
|
|
30
|
+
|
|
31
|
+
## Protocol
|
|
32
|
+
|
|
33
|
+
1. MCP server connects to `~/.supersurf/daemon.sock`
|
|
34
|
+
2. Sends `{ type: "session_register", sessionId: "..." }\n`
|
|
35
|
+
3. Daemon responds `{ type: "session_ack", browser: "Chrome", buildTimestamp: "..." }\n`
|
|
36
|
+
4. Post-handshake: NDJSON (newline-delimited JSON-RPC 2.0) for tool calls
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
Apache-2.0 with Commons Clause.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSocket bridge to the Chrome extension.
|
|
3
|
+
*
|
|
4
|
+
* Runs an HTTP + WebSocket server on localhost (default port 5555).
|
|
5
|
+
* Communication uses JSON-RPC 2.0 with correlation IDs for request/response matching.
|
|
6
|
+
*
|
|
7
|
+
* Stripped-down copy of server/src/bridge.ts for daemon use:
|
|
8
|
+
* - No onRawConnection hook (daemon handles all routing)
|
|
9
|
+
* - No logger import (uses console.error for debug)
|
|
10
|
+
*
|
|
11
|
+
* @module extension-bridge
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* WebSocket server that bridges the daemon to the Chrome extension.
|
|
15
|
+
* Manages a single active connection, with reconnection support.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ExtensionBridge {
|
|
18
|
+
private port;
|
|
19
|
+
private host;
|
|
20
|
+
private httpServer;
|
|
21
|
+
private wss;
|
|
22
|
+
private socket;
|
|
23
|
+
private inflight;
|
|
24
|
+
private browserType;
|
|
25
|
+
private buildTimestamp;
|
|
26
|
+
private pingInterval;
|
|
27
|
+
onReconnect: (() => void) | null;
|
|
28
|
+
onTabInfoUpdate: ((tabInfo: any) => void) | null;
|
|
29
|
+
constructor(port?: number, host?: string);
|
|
30
|
+
get browser(): string;
|
|
31
|
+
get buildTime(): string | null;
|
|
32
|
+
get connected(): boolean;
|
|
33
|
+
/** Spin up the HTTP + WebSocket server and begin accepting connections. */
|
|
34
|
+
start(): Promise<void>;
|
|
35
|
+
/** Route incoming WebSocket messages: responses, handshakes, or notifications. */
|
|
36
|
+
private handleMessage;
|
|
37
|
+
/**
|
|
38
|
+
* Send a JSON-RPC 2.0 request to the extension and await the response.
|
|
39
|
+
* @param method - Command name
|
|
40
|
+
* @param params - Command parameters
|
|
41
|
+
* @param timeout - Max wait time in ms (default 30s)
|
|
42
|
+
*/
|
|
43
|
+
sendCmd(method: string, params?: Record<string, unknown>, timeout?: number): Promise<any>;
|
|
44
|
+
/** Send an `authenticated` notification to the extension with a session's client ID. */
|
|
45
|
+
notifyClientId(clientId: string): void;
|
|
46
|
+
/** Reject all pending requests with a disconnect error. */
|
|
47
|
+
private drainInflight;
|
|
48
|
+
/** Gracefully shut down: clear ping interval, close socket, close servers. */
|
|
49
|
+
stop(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=extension-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-bridge.d.ts","sourceRoot":"","sources":["../src/extension-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAmB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6
|
+
* Communication uses JSON-RPC 2.0 with correlation IDs for request/response matching.
|
|
7
|
+
*
|
|
8
|
+
* Stripped-down copy of server/src/bridge.ts for daemon use:
|
|
9
|
+
* - No onRawConnection hook (daemon handles all routing)
|
|
10
|
+
* - No logger import (uses console.error for debug)
|
|
11
|
+
*
|
|
12
|
+
* @module extension-bridge
|
|
13
|
+
*/
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ExtensionBridge = void 0;
|
|
19
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
20
|
+
const http_1 = __importDefault(require("http"));
|
|
21
|
+
const ws_1 = require("ws");
|
|
22
|
+
const debugLog = (...args) => {
|
|
23
|
+
const logger = global.DAEMON_LOGGER;
|
|
24
|
+
if (logger)
|
|
25
|
+
logger.log('[WS]', ...args);
|
|
26
|
+
else if (global.DAEMON_DEBUG)
|
|
27
|
+
console.error('[WS]', ...args);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* WebSocket server that bridges the daemon to the Chrome extension.
|
|
31
|
+
* Manages a single active connection, with reconnection support.
|
|
32
|
+
*/
|
|
33
|
+
class ExtensionBridge {
|
|
34
|
+
port;
|
|
35
|
+
host;
|
|
36
|
+
httpServer = null;
|
|
37
|
+
wss = null;
|
|
38
|
+
socket = null;
|
|
39
|
+
inflight = new Map();
|
|
40
|
+
browserType = 'chrome';
|
|
41
|
+
buildTimestamp = null;
|
|
42
|
+
pingInterval = null;
|
|
43
|
+
onReconnect = null;
|
|
44
|
+
onTabInfoUpdate = null;
|
|
45
|
+
constructor(port = 5555, host = '127.0.0.1') {
|
|
46
|
+
this.port = port;
|
|
47
|
+
this.host = host;
|
|
48
|
+
}
|
|
49
|
+
get browser() {
|
|
50
|
+
return this.browserType;
|
|
51
|
+
}
|
|
52
|
+
get buildTime() {
|
|
53
|
+
return this.buildTimestamp;
|
|
54
|
+
}
|
|
55
|
+
get connected() {
|
|
56
|
+
return !!this.socket && this.socket.readyState === ws_1.WebSocket.OPEN;
|
|
57
|
+
}
|
|
58
|
+
/** Spin up the HTTP + WebSocket server and begin accepting connections. */
|
|
59
|
+
async start() {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
this.httpServer = http_1.default.createServer((_req, res) => {
|
|
62
|
+
res.writeHead(200);
|
|
63
|
+
res.end('SuperSurf Daemon');
|
|
64
|
+
});
|
|
65
|
+
this.wss = new ws_1.WebSocketServer({ server: this.httpServer });
|
|
66
|
+
this.wss.on('error', (error) => {
|
|
67
|
+
debugLog('WebSocketServer error:', error);
|
|
68
|
+
reject(error);
|
|
69
|
+
});
|
|
70
|
+
this.wss.on('connection', (ws) => {
|
|
71
|
+
debugLog('Extension connection attempt');
|
|
72
|
+
// Reject if already connected
|
|
73
|
+
if (this.socket && this.socket.readyState === ws_1.WebSocket.OPEN) {
|
|
74
|
+
debugLog('Rejecting new connection — browser already connected');
|
|
75
|
+
const errorMsg = {
|
|
76
|
+
jsonrpc: '2.0',
|
|
77
|
+
error: {
|
|
78
|
+
code: -32001,
|
|
79
|
+
message: 'Another browser is already connected. Only one browser at a time.',
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
ws.send(JSON.stringify(errorMsg));
|
|
83
|
+
setTimeout(() => ws.close(1008, 'Already connected'), 100);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
debugLog('Extension connected');
|
|
87
|
+
const isReconnection = !!this.socket;
|
|
88
|
+
if (this.socket) {
|
|
89
|
+
debugLog('Closing previous connection — reconnection detected');
|
|
90
|
+
this.socket.close();
|
|
91
|
+
}
|
|
92
|
+
this.socket = ws;
|
|
93
|
+
// Clear old ping interval
|
|
94
|
+
if (this.pingInterval) {
|
|
95
|
+
clearInterval(this.pingInterval);
|
|
96
|
+
this.pingInterval = null;
|
|
97
|
+
}
|
|
98
|
+
// Keep-alive ping every 10s
|
|
99
|
+
this.pingInterval = setInterval(() => {
|
|
100
|
+
if (ws.readyState === ws_1.WebSocket.OPEN) {
|
|
101
|
+
ws.ping();
|
|
102
|
+
}
|
|
103
|
+
}, 10000);
|
|
104
|
+
if (isReconnection && this.onReconnect) {
|
|
105
|
+
this.onReconnect();
|
|
106
|
+
}
|
|
107
|
+
ws.on('message', (data) => this.handleMessage(data));
|
|
108
|
+
ws.on('pong', () => debugLog('Pong received'));
|
|
109
|
+
ws.on('close', () => {
|
|
110
|
+
debugLog('Extension disconnected');
|
|
111
|
+
if (this.socket === ws) {
|
|
112
|
+
this.socket = null;
|
|
113
|
+
}
|
|
114
|
+
if (this.pingInterval) {
|
|
115
|
+
clearInterval(this.pingInterval);
|
|
116
|
+
this.pingInterval = null;
|
|
117
|
+
}
|
|
118
|
+
this.drainInflight();
|
|
119
|
+
});
|
|
120
|
+
ws.on('error', (error) => debugLog('WebSocket error:', error));
|
|
121
|
+
});
|
|
122
|
+
this.httpServer.on('error', (error) => {
|
|
123
|
+
debugLog('HTTP Server error:', error);
|
|
124
|
+
reject(error);
|
|
125
|
+
});
|
|
126
|
+
this.httpServer.listen(this.port, this.host, () => {
|
|
127
|
+
debugLog(`Server listening on ${this.host}:${this.port}`);
|
|
128
|
+
resolve();
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** Route incoming WebSocket messages: responses, handshakes, or notifications. */
|
|
133
|
+
handleMessage(data) {
|
|
134
|
+
try {
|
|
135
|
+
const message = JSON.parse(data.toString());
|
|
136
|
+
// JSON-RPC response — correlate with inflight request by id
|
|
137
|
+
if (message.id !== undefined && !message.method) {
|
|
138
|
+
const pending = this.inflight.get(message.id);
|
|
139
|
+
if (pending) {
|
|
140
|
+
this.inflight.delete(message.id);
|
|
141
|
+
// Piggyback: extract tab info from response if present
|
|
142
|
+
const result = message.result;
|
|
143
|
+
if (result && typeof result === 'object' && 'currentTab' in result && this.onTabInfoUpdate) {
|
|
144
|
+
this.onTabInfoUpdate(result.currentTab);
|
|
145
|
+
}
|
|
146
|
+
if (message.error) {
|
|
147
|
+
pending.reject(new Error(message.error.message || JSON.stringify(message.error)));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
pending.resolve(message.result);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
// Handshake
|
|
156
|
+
if (message.type === 'handshake') {
|
|
157
|
+
debugLog('Handshake received:', message);
|
|
158
|
+
this.browserType = message.browser || 'chrome';
|
|
159
|
+
this.buildTimestamp = message.buildTimestamp || null;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
// Notification (has method, no id)
|
|
163
|
+
if (message.method && message.id === undefined) {
|
|
164
|
+
debugLog('Notification:', message.method);
|
|
165
|
+
if (message.method === 'notifications/tab_info_update' &&
|
|
166
|
+
message.params?.currentTab &&
|
|
167
|
+
this.onTabInfoUpdate) {
|
|
168
|
+
this.onTabInfoUpdate(message.params.currentTab);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
debugLog('Error handling message:', error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Send a JSON-RPC 2.0 request to the extension and await the response.
|
|
179
|
+
* @param method - Command name
|
|
180
|
+
* @param params - Command parameters
|
|
181
|
+
* @param timeout - Max wait time in ms (default 30s)
|
|
182
|
+
*/
|
|
183
|
+
async sendCmd(method, params = {}, timeout = 30000) {
|
|
184
|
+
if (!this.socket || this.socket.readyState !== ws_1.WebSocket.OPEN) {
|
|
185
|
+
throw new Error('Extension not connected');
|
|
186
|
+
}
|
|
187
|
+
const id = crypto_1.default.randomUUID().slice(0, 8);
|
|
188
|
+
debugLog(`-> ${method}`, params);
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
const timeoutId = setTimeout(() => {
|
|
191
|
+
this.inflight.delete(id);
|
|
192
|
+
reject(new Error(`Request timeout: ${method}`));
|
|
193
|
+
}, timeout);
|
|
194
|
+
this.inflight.set(id, {
|
|
195
|
+
resolve: (result) => {
|
|
196
|
+
clearTimeout(timeoutId);
|
|
197
|
+
debugLog(`<- ${method}`, result);
|
|
198
|
+
resolve(result);
|
|
199
|
+
},
|
|
200
|
+
reject: (error) => {
|
|
201
|
+
clearTimeout(timeoutId);
|
|
202
|
+
debugLog(`x ${method}:`, error.message);
|
|
203
|
+
reject(error);
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const message = { jsonrpc: '2.0', id, method, params };
|
|
207
|
+
this.socket.send(JSON.stringify(message));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/** Send an `authenticated` notification to the extension with a session's client ID. */
|
|
211
|
+
notifyClientId(clientId) {
|
|
212
|
+
debugLog('Client ID set to:', clientId);
|
|
213
|
+
if (this.connected) {
|
|
214
|
+
const notification = {
|
|
215
|
+
jsonrpc: '2.0',
|
|
216
|
+
method: 'authenticated',
|
|
217
|
+
params: { client_id: clientId },
|
|
218
|
+
};
|
|
219
|
+
this.socket.send(JSON.stringify(notification));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/** Reject all pending requests with a disconnect error. */
|
|
223
|
+
drainInflight() {
|
|
224
|
+
if (this.inflight.size === 0)
|
|
225
|
+
return;
|
|
226
|
+
debugLog(`Draining ${this.inflight.size} inflight request(s)`);
|
|
227
|
+
for (const [_id, pending] of this.inflight) {
|
|
228
|
+
pending.reject(new Error('Extension disconnected'));
|
|
229
|
+
}
|
|
230
|
+
this.inflight.clear();
|
|
231
|
+
}
|
|
232
|
+
/** Gracefully shut down: clear ping interval, close socket, close servers. */
|
|
233
|
+
async stop() {
|
|
234
|
+
debugLog('Stopping server');
|
|
235
|
+
this.drainInflight();
|
|
236
|
+
if (this.pingInterval) {
|
|
237
|
+
clearInterval(this.pingInterval);
|
|
238
|
+
this.pingInterval = null;
|
|
239
|
+
}
|
|
240
|
+
if (this.socket) {
|
|
241
|
+
this.socket.close();
|
|
242
|
+
this.socket = null;
|
|
243
|
+
}
|
|
244
|
+
if (this.wss) {
|
|
245
|
+
this.wss.close();
|
|
246
|
+
this.wss = null;
|
|
247
|
+
}
|
|
248
|
+
if (this.httpServer) {
|
|
249
|
+
return new Promise((resolve) => {
|
|
250
|
+
this.httpServer.close(() => {
|
|
251
|
+
debugLog('Server stopped');
|
|
252
|
+
resolve();
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
exports.ExtensionBridge = ExtensionBridge;
|
|
259
|
+
//# sourceMappingURL=extension-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension-bridge.js","sourceRoot":"","sources":["../src/extension-bridge.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;;;;AAEH,oDAA4B;AAC5B,gDAAwB;AACxB,2BAAgD;AAGhD,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE;IACtC,MAAM,MAAM,GAAI,MAAc,CAAC,aAAuC,CAAC;IACvE,IAAI,MAAM;QAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;SACnC,IAAK,MAAc,CAAC,YAAY;QAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;AACxE,CAAC,CAAC;AAQF;;;GAGG;AACH,MAAa,eAAe;IAClB,IAAI,CAAS;IACb,IAAI,CAAS;IACb,UAAU,GAAuB,IAAI,CAAC;IACtC,GAAG,GAA2B,IAAI,CAAC;IACnC,MAAM,GAAqB,IAAI,CAAC;IAChC,QAAQ,GAAiC,IAAI,GAAG,EAAE,CAAC;IACnD,WAAW,GAAW,QAAQ,CAAC;IAC/B,cAAc,GAAkB,IAAI,CAAC;IACrC,YAAY,GAA0C,IAA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F;AAtQD,0CAsQC"}
|
package/dist/ipc.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IPC Server — Unix socket server for MCP session connections.
|
|
3
|
+
*
|
|
4
|
+
* Accepts connections from MCP servers over a Unix domain socket.
|
|
5
|
+
* Protocol:
|
|
6
|
+
* 1. MCP server sends: { type: "session_register", sessionId: "..." }\n
|
|
7
|
+
* 2. Daemon responds: { type: "session_ack", browser: "...", buildTimestamp: "..." }\n
|
|
8
|
+
* or { type: "session_reject", reason: "..." }\n
|
|
9
|
+
* 3. Post-handshake: NDJSON (newline-delimited JSON-RPC 2.0) for tool calls
|
|
10
|
+
*
|
|
11
|
+
* @module ipc
|
|
12
|
+
*/
|
|
13
|
+
import type { ExtensionBridge } from './extension-bridge';
|
|
14
|
+
import type { SessionRegistry } from './session';
|
|
15
|
+
import type { RequestScheduler } from './scheduler';
|
|
16
|
+
/** Callback invoked when the number of sessions changes (for idle timeout management). */
|
|
17
|
+
export type SessionCountCallback = (count: number) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Unix domain socket server for MCP session connections.
|
|
20
|
+
* Handles session handshake, NDJSON message routing, and cleanup.
|
|
21
|
+
*/
|
|
22
|
+
export declare class IPCServer {
|
|
23
|
+
private server;
|
|
24
|
+
private socketPath;
|
|
25
|
+
private bridge;
|
|
26
|
+
private sessions;
|
|
27
|
+
private scheduler;
|
|
28
|
+
private onSessionCountChange;
|
|
29
|
+
constructor(socketPath: string, bridge: ExtensionBridge, sessions: SessionRegistry, scheduler: RequestScheduler);
|
|
30
|
+
/** Set a callback for session count changes (used by idle timeout). */
|
|
31
|
+
setSessionCountCallback(cb: SessionCountCallback): void;
|
|
32
|
+
/** Start listening on the Unix socket. */
|
|
33
|
+
start(): Promise<void>;
|
|
34
|
+
/** Handle a new connection from an MCP server. */
|
|
35
|
+
private handleConnection;
|
|
36
|
+
/** Route a JSON-RPC 2.0 request into the scheduler. */
|
|
37
|
+
private handleRequest;
|
|
38
|
+
/** Write an NDJSON line to a socket. */
|
|
39
|
+
private sendLine;
|
|
40
|
+
/** Gracefully shut down the IPC server. */
|
|
41
|
+
stop(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=ipc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ipc.d.ts","sourceRoot":"","sources":["../src/ipc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAQpD,0FAA0F;AAC1F,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAE3D;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,SAAS,CAAmB;IACpC,OAAO,CAAC,oBAAoB,CAAqC;gBAG/D,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,eAAe,EACzB,SAAS,EAAE,gBAAgB;IAQ7B,uEAAuE;IACvE,uBAAuB,CAAC,EAAE,EAAE,oBAAoB,GAAG,IAAI;IAIvD,0CAA0C;IACpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B,kDAAkD;IAClD,OAAO,CAAC,gBAAgB;IA8FxB,uDAAuD;YACzC,aAAa;IA2B3B,wCAAwC;IACxC,OAAO,CAAC,QAAQ;IAKhB,2CAA2C;IACrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB5B"}
|