claude-chrome-android 1.0.0 → 1.2.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/README.md +40 -8
- package/dist/claude-code-bridge.crx +0 -0
- package/dist/cli.js +721 -433
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -36,9 +36,9 @@ var init_import_meta_shim = __esm({
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
//
|
|
39
|
+
// node_modules/ws/lib/constants.js
|
|
40
40
|
var require_constants = __commonJS({
|
|
41
|
-
"
|
|
41
|
+
"node_modules/ws/lib/constants.js"(exports2, module2) {
|
|
42
42
|
"use strict";
|
|
43
43
|
init_import_meta_shim();
|
|
44
44
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
@@ -46,238 +46,23 @@ var require_constants = __commonJS({
|
|
|
46
46
|
if (hasBlob) BINARY_TYPES.push("blob");
|
|
47
47
|
module2.exports = {
|
|
48
48
|
BINARY_TYPES,
|
|
49
|
+
CLOSE_TIMEOUT: 3e4,
|
|
49
50
|
EMPTY_BUFFER: Buffer.alloc(0),
|
|
50
51
|
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
51
52
|
hasBlob,
|
|
52
|
-
kForOnEventAttribute:
|
|
53
|
-
kListener:
|
|
54
|
-
kStatusCode:
|
|
55
|
-
kWebSocket:
|
|
53
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
54
|
+
kListener: Symbol("kListener"),
|
|
55
|
+
kStatusCode: Symbol("status-code"),
|
|
56
|
+
kWebSocket: Symbol("websocket"),
|
|
56
57
|
NOOP: () => {
|
|
57
58
|
}
|
|
58
59
|
};
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
|
|
62
|
-
//
|
|
63
|
-
var require_node_gyp_build = __commonJS({
|
|
64
|
-
"../../../node_modules/node-gyp-build/node-gyp-build.js"(exports2, module2) {
|
|
65
|
-
init_import_meta_shim();
|
|
66
|
-
var fs = require("fs");
|
|
67
|
-
var path = require("path");
|
|
68
|
-
var os = require("os");
|
|
69
|
-
var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
70
|
-
var vars = process.config && process.config.variables || {};
|
|
71
|
-
var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
|
|
72
|
-
var abi = process.versions.modules;
|
|
73
|
-
var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
|
|
74
|
-
var arch = process.env.npm_config_arch || os.arch();
|
|
75
|
-
var platform = process.env.npm_config_platform || os.platform();
|
|
76
|
-
var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
|
|
77
|
-
var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
|
|
78
|
-
var uv = (process.versions.uv || "").split(".")[0];
|
|
79
|
-
module2.exports = load;
|
|
80
|
-
function load(dir) {
|
|
81
|
-
return runtimeRequire(load.resolve(dir));
|
|
82
|
-
}
|
|
83
|
-
load.resolve = load.path = function(dir) {
|
|
84
|
-
dir = path.resolve(dir || ".");
|
|
85
|
-
try {
|
|
86
|
-
var name = runtimeRequire(path.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
|
|
87
|
-
if (process.env[name + "_PREBUILD"]) dir = process.env[name + "_PREBUILD"];
|
|
88
|
-
} catch (err) {
|
|
89
|
-
}
|
|
90
|
-
if (!prebuildsOnly) {
|
|
91
|
-
var release = getFirst(path.join(dir, "build/Release"), matchBuild);
|
|
92
|
-
if (release) return release;
|
|
93
|
-
var debug = getFirst(path.join(dir, "build/Debug"), matchBuild);
|
|
94
|
-
if (debug) return debug;
|
|
95
|
-
}
|
|
96
|
-
var prebuild = resolve3(dir);
|
|
97
|
-
if (prebuild) return prebuild;
|
|
98
|
-
var nearby = resolve3(path.dirname(process.execPath));
|
|
99
|
-
if (nearby) return nearby;
|
|
100
|
-
var target = [
|
|
101
|
-
"platform=" + platform,
|
|
102
|
-
"arch=" + arch,
|
|
103
|
-
"runtime=" + runtime,
|
|
104
|
-
"abi=" + abi,
|
|
105
|
-
"uv=" + uv,
|
|
106
|
-
armv ? "armv=" + armv : "",
|
|
107
|
-
"libc=" + libc,
|
|
108
|
-
"node=" + process.versions.node,
|
|
109
|
-
process.versions.electron ? "electron=" + process.versions.electron : "",
|
|
110
|
-
typeof __webpack_require__ === "function" ? "webpack=true" : ""
|
|
111
|
-
// eslint-disable-line
|
|
112
|
-
].filter(Boolean).join(" ");
|
|
113
|
-
throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
|
|
114
|
-
function resolve3(dir2) {
|
|
115
|
-
var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
|
|
116
|
-
var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
|
|
117
|
-
if (!tuple) return;
|
|
118
|
-
var prebuilds = path.join(dir2, "prebuilds", tuple.name);
|
|
119
|
-
var parsed = readdirSync(prebuilds).map(parseTags);
|
|
120
|
-
var candidates = parsed.filter(matchTags(runtime, abi));
|
|
121
|
-
var winner = candidates.sort(compareTags(runtime))[0];
|
|
122
|
-
if (winner) return path.join(prebuilds, winner.file);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
function readdirSync(dir) {
|
|
126
|
-
try {
|
|
127
|
-
return fs.readdirSync(dir);
|
|
128
|
-
} catch (err) {
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
function getFirst(dir, filter) {
|
|
133
|
-
var files = readdirSync(dir).filter(filter);
|
|
134
|
-
return files[0] && path.join(dir, files[0]);
|
|
135
|
-
}
|
|
136
|
-
function matchBuild(name) {
|
|
137
|
-
return /\.node$/.test(name);
|
|
138
|
-
}
|
|
139
|
-
function parseTuple(name) {
|
|
140
|
-
var arr = name.split("-");
|
|
141
|
-
if (arr.length !== 2) return;
|
|
142
|
-
var platform2 = arr[0];
|
|
143
|
-
var architectures = arr[1].split("+");
|
|
144
|
-
if (!platform2) return;
|
|
145
|
-
if (!architectures.length) return;
|
|
146
|
-
if (!architectures.every(Boolean)) return;
|
|
147
|
-
return { name, platform: platform2, architectures };
|
|
148
|
-
}
|
|
149
|
-
function matchTuple(platform2, arch2) {
|
|
150
|
-
return function(tuple) {
|
|
151
|
-
if (tuple == null) return false;
|
|
152
|
-
if (tuple.platform !== platform2) return false;
|
|
153
|
-
return tuple.architectures.includes(arch2);
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function compareTuples(a, b) {
|
|
157
|
-
return a.architectures.length - b.architectures.length;
|
|
158
|
-
}
|
|
159
|
-
function parseTags(file) {
|
|
160
|
-
var arr = file.split(".");
|
|
161
|
-
var extension = arr.pop();
|
|
162
|
-
var tags = { file, specificity: 0 };
|
|
163
|
-
if (extension !== "node") return;
|
|
164
|
-
for (var i = 0; i < arr.length; i++) {
|
|
165
|
-
var tag = arr[i];
|
|
166
|
-
if (tag === "node" || tag === "electron" || tag === "node-webkit") {
|
|
167
|
-
tags.runtime = tag;
|
|
168
|
-
} else if (tag === "napi") {
|
|
169
|
-
tags.napi = true;
|
|
170
|
-
} else if (tag.slice(0, 3) === "abi") {
|
|
171
|
-
tags.abi = tag.slice(3);
|
|
172
|
-
} else if (tag.slice(0, 2) === "uv") {
|
|
173
|
-
tags.uv = tag.slice(2);
|
|
174
|
-
} else if (tag.slice(0, 4) === "armv") {
|
|
175
|
-
tags.armv = tag.slice(4);
|
|
176
|
-
} else if (tag === "glibc" || tag === "musl") {
|
|
177
|
-
tags.libc = tag;
|
|
178
|
-
} else {
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
tags.specificity++;
|
|
182
|
-
}
|
|
183
|
-
return tags;
|
|
184
|
-
}
|
|
185
|
-
function matchTags(runtime2, abi2) {
|
|
186
|
-
return function(tags) {
|
|
187
|
-
if (tags == null) return false;
|
|
188
|
-
if (tags.runtime && tags.runtime !== runtime2 && !runtimeAgnostic(tags)) return false;
|
|
189
|
-
if (tags.abi && tags.abi !== abi2 && !tags.napi) return false;
|
|
190
|
-
if (tags.uv && tags.uv !== uv) return false;
|
|
191
|
-
if (tags.armv && tags.armv !== armv) return false;
|
|
192
|
-
if (tags.libc && tags.libc !== libc) return false;
|
|
193
|
-
return true;
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
function runtimeAgnostic(tags) {
|
|
197
|
-
return tags.runtime === "node" && tags.napi;
|
|
198
|
-
}
|
|
199
|
-
function compareTags(runtime2) {
|
|
200
|
-
return function(a, b) {
|
|
201
|
-
if (a.runtime !== b.runtime) {
|
|
202
|
-
return a.runtime === runtime2 ? -1 : 1;
|
|
203
|
-
} else if (a.abi !== b.abi) {
|
|
204
|
-
return a.abi ? -1 : 1;
|
|
205
|
-
} else if (a.specificity !== b.specificity) {
|
|
206
|
-
return a.specificity > b.specificity ? -1 : 1;
|
|
207
|
-
} else {
|
|
208
|
-
return 0;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
function isNwjs() {
|
|
213
|
-
return !!(process.versions && process.versions.nw);
|
|
214
|
-
}
|
|
215
|
-
function isElectron() {
|
|
216
|
-
if (process.versions && process.versions.electron) return true;
|
|
217
|
-
if (process.env.ELECTRON_RUN_AS_NODE) return true;
|
|
218
|
-
return typeof window !== "undefined" && window.process && window.process.type === "renderer";
|
|
219
|
-
}
|
|
220
|
-
function isAlpine(platform2) {
|
|
221
|
-
return platform2 === "linux" && fs.existsSync("/etc/alpine-release");
|
|
222
|
-
}
|
|
223
|
-
load.parseTags = parseTags;
|
|
224
|
-
load.matchTags = matchTags;
|
|
225
|
-
load.compareTags = compareTags;
|
|
226
|
-
load.parseTuple = parseTuple;
|
|
227
|
-
load.matchTuple = matchTuple;
|
|
228
|
-
load.compareTuples = compareTuples;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
// ../../../node_modules/node-gyp-build/index.js
|
|
233
|
-
var require_node_gyp_build2 = __commonJS({
|
|
234
|
-
"../../../node_modules/node-gyp-build/index.js"(exports2, module2) {
|
|
235
|
-
init_import_meta_shim();
|
|
236
|
-
var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
|
|
237
|
-
if (typeof runtimeRequire.addon === "function") {
|
|
238
|
-
module2.exports = runtimeRequire.addon.bind(runtimeRequire);
|
|
239
|
-
} else {
|
|
240
|
-
module2.exports = require_node_gyp_build();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
// ../../../node_modules/bufferutil/fallback.js
|
|
246
|
-
var require_fallback = __commonJS({
|
|
247
|
-
"../../../node_modules/bufferutil/fallback.js"(exports2, module2) {
|
|
248
|
-
"use strict";
|
|
249
|
-
init_import_meta_shim();
|
|
250
|
-
var mask = (source, mask2, output, offset, length) => {
|
|
251
|
-
for (var i = 0; i < length; i++) {
|
|
252
|
-
output[offset + i] = source[i] ^ mask2[i & 3];
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var unmask = (buffer, mask2) => {
|
|
256
|
-
const length = buffer.length;
|
|
257
|
-
for (var i = 0; i < length; i++) {
|
|
258
|
-
buffer[i] ^= mask2[i & 3];
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
module2.exports = { mask, unmask };
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// ../../../node_modules/bufferutil/index.js
|
|
266
|
-
var require_bufferutil = __commonJS({
|
|
267
|
-
"../../../node_modules/bufferutil/index.js"(exports2, module2) {
|
|
268
|
-
"use strict";
|
|
269
|
-
init_import_meta_shim();
|
|
270
|
-
try {
|
|
271
|
-
module2.exports = require_node_gyp_build2()(__dirname);
|
|
272
|
-
} catch (e) {
|
|
273
|
-
module2.exports = require_fallback();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
// ../../../node_modules/ws/lib/buffer-util.js
|
|
63
|
+
// node_modules/ws/lib/buffer-util.js
|
|
279
64
|
var require_buffer_util = __commonJS({
|
|
280
|
-
"
|
|
65
|
+
"node_modules/ws/lib/buffer-util.js"(exports2, module2) {
|
|
281
66
|
"use strict";
|
|
282
67
|
init_import_meta_shim();
|
|
283
68
|
var { EMPTY_BUFFER } = require_constants();
|
|
@@ -336,7 +121,7 @@ var require_buffer_util = __commonJS({
|
|
|
336
121
|
};
|
|
337
122
|
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
338
123
|
try {
|
|
339
|
-
const bufferUtil =
|
|
124
|
+
const bufferUtil = require("bufferutil");
|
|
340
125
|
module2.exports.mask = function(source, mask, output, offset, length) {
|
|
341
126
|
if (length < 48) _mask(source, mask, output, offset, length);
|
|
342
127
|
else bufferUtil.mask(source, mask, output, offset, length);
|
|
@@ -351,13 +136,13 @@ var require_buffer_util = __commonJS({
|
|
|
351
136
|
}
|
|
352
137
|
});
|
|
353
138
|
|
|
354
|
-
//
|
|
139
|
+
// node_modules/ws/lib/limiter.js
|
|
355
140
|
var require_limiter = __commonJS({
|
|
356
|
-
"
|
|
141
|
+
"node_modules/ws/lib/limiter.js"(exports2, module2) {
|
|
357
142
|
"use strict";
|
|
358
143
|
init_import_meta_shim();
|
|
359
|
-
var kDone =
|
|
360
|
-
var kRun =
|
|
144
|
+
var kDone = Symbol("kDone");
|
|
145
|
+
var kRun = Symbol("kRun");
|
|
361
146
|
var Limiter = class {
|
|
362
147
|
/**
|
|
363
148
|
* Creates a new `Limiter`.
|
|
@@ -402,9 +187,9 @@ var require_limiter = __commonJS({
|
|
|
402
187
|
}
|
|
403
188
|
});
|
|
404
189
|
|
|
405
|
-
//
|
|
190
|
+
// node_modules/ws/lib/permessage-deflate.js
|
|
406
191
|
var require_permessage_deflate = __commonJS({
|
|
407
|
-
"
|
|
192
|
+
"node_modules/ws/lib/permessage-deflate.js"(exports2, module2) {
|
|
408
193
|
"use strict";
|
|
409
194
|
init_import_meta_shim();
|
|
410
195
|
var zlib = require("zlib");
|
|
@@ -413,11 +198,11 @@ var require_permessage_deflate = __commonJS({
|
|
|
413
198
|
var { kStatusCode } = require_constants();
|
|
414
199
|
var FastBuffer = Buffer[Symbol.species];
|
|
415
200
|
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
416
|
-
var kPerMessageDeflate =
|
|
417
|
-
var kTotalLength =
|
|
418
|
-
var kCallback =
|
|
419
|
-
var kBuffers =
|
|
420
|
-
var kError =
|
|
201
|
+
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
202
|
+
var kTotalLength = Symbol("total-length");
|
|
203
|
+
var kCallback = Symbol("callback");
|
|
204
|
+
var kBuffers = Symbol("buffers");
|
|
205
|
+
var kError = Symbol("error");
|
|
421
206
|
var zlibLimiter;
|
|
422
207
|
var PerMessageDeflate = class {
|
|
423
208
|
/**
|
|
@@ -786,60 +571,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
786
571
|
}
|
|
787
572
|
});
|
|
788
573
|
|
|
789
|
-
//
|
|
790
|
-
var require_fallback2 = __commonJS({
|
|
791
|
-
"../../../node_modules/utf-8-validate/fallback.js"(exports2, module2) {
|
|
792
|
-
"use strict";
|
|
793
|
-
init_import_meta_shim();
|
|
794
|
-
function isValidUTF8(buf) {
|
|
795
|
-
const len = buf.length;
|
|
796
|
-
let i = 0;
|
|
797
|
-
while (i < len) {
|
|
798
|
-
if ((buf[i] & 128) === 0) {
|
|
799
|
-
i++;
|
|
800
|
-
} else if ((buf[i] & 224) === 192) {
|
|
801
|
-
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
802
|
-
return false;
|
|
803
|
-
}
|
|
804
|
-
i += 2;
|
|
805
|
-
} else if ((buf[i] & 240) === 224) {
|
|
806
|
-
if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // overlong
|
|
807
|
-
buf[i] === 237 && (buf[i + 1] & 224) === 160) {
|
|
808
|
-
return false;
|
|
809
|
-
}
|
|
810
|
-
i += 3;
|
|
811
|
-
} else if ((buf[i] & 248) === 240) {
|
|
812
|
-
if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // overlong
|
|
813
|
-
buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
|
|
814
|
-
return false;
|
|
815
|
-
}
|
|
816
|
-
i += 4;
|
|
817
|
-
} else {
|
|
818
|
-
return false;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
return true;
|
|
822
|
-
}
|
|
823
|
-
module2.exports = isValidUTF8;
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
|
|
827
|
-
// ../../../node_modules/utf-8-validate/index.js
|
|
828
|
-
var require_utf_8_validate = __commonJS({
|
|
829
|
-
"../../../node_modules/utf-8-validate/index.js"(exports2, module2) {
|
|
830
|
-
"use strict";
|
|
831
|
-
init_import_meta_shim();
|
|
832
|
-
try {
|
|
833
|
-
module2.exports = require_node_gyp_build2()(__dirname);
|
|
834
|
-
} catch (e) {
|
|
835
|
-
module2.exports = require_fallback2();
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
|
|
840
|
-
// ../../../node_modules/ws/lib/validation.js
|
|
574
|
+
// node_modules/ws/lib/validation.js
|
|
841
575
|
var require_validation = __commonJS({
|
|
842
|
-
"
|
|
576
|
+
"node_modules/ws/lib/validation.js"(exports2, module2) {
|
|
843
577
|
"use strict";
|
|
844
578
|
init_import_meta_shim();
|
|
845
579
|
var { isUtf8 } = require("buffer");
|
|
@@ -1029,7 +763,7 @@ var require_validation = __commonJS({
|
|
|
1029
763
|
};
|
|
1030
764
|
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
1031
765
|
try {
|
|
1032
|
-
const isValidUTF8 =
|
|
766
|
+
const isValidUTF8 = require("utf-8-validate");
|
|
1033
767
|
module2.exports.isValidUTF8 = function(buf) {
|
|
1034
768
|
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
1035
769
|
};
|
|
@@ -1039,9 +773,9 @@ var require_validation = __commonJS({
|
|
|
1039
773
|
}
|
|
1040
774
|
});
|
|
1041
775
|
|
|
1042
|
-
//
|
|
776
|
+
// node_modules/ws/lib/receiver.js
|
|
1043
777
|
var require_receiver = __commonJS({
|
|
1044
|
-
"
|
|
778
|
+
"node_modules/ws/lib/receiver.js"(exports2, module2) {
|
|
1045
779
|
"use strict";
|
|
1046
780
|
init_import_meta_shim();
|
|
1047
781
|
var { Writable } = require("stream");
|
|
@@ -1632,9 +1366,9 @@ var require_receiver = __commonJS({
|
|
|
1632
1366
|
}
|
|
1633
1367
|
});
|
|
1634
1368
|
|
|
1635
|
-
//
|
|
1369
|
+
// node_modules/ws/lib/sender.js
|
|
1636
1370
|
var require_sender = __commonJS({
|
|
1637
|
-
"
|
|
1371
|
+
"node_modules/ws/lib/sender.js"(exports2, module2) {
|
|
1638
1372
|
"use strict";
|
|
1639
1373
|
init_import_meta_shim();
|
|
1640
1374
|
var { Duplex } = require("stream");
|
|
@@ -1643,7 +1377,7 @@ var require_sender = __commonJS({
|
|
|
1643
1377
|
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
1644
1378
|
var { isBlob, isValidStatusCode } = require_validation();
|
|
1645
1379
|
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
1646
|
-
var kByteLength =
|
|
1380
|
+
var kByteLength = Symbol("kByteLength");
|
|
1647
1381
|
var maskBuffer = Buffer.alloc(4);
|
|
1648
1382
|
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
1649
1383
|
var randomPool;
|
|
@@ -2121,20 +1855,20 @@ var require_sender = __commonJS({
|
|
|
2121
1855
|
}
|
|
2122
1856
|
});
|
|
2123
1857
|
|
|
2124
|
-
//
|
|
1858
|
+
// node_modules/ws/lib/event-target.js
|
|
2125
1859
|
var require_event_target = __commonJS({
|
|
2126
|
-
"
|
|
1860
|
+
"node_modules/ws/lib/event-target.js"(exports2, module2) {
|
|
2127
1861
|
"use strict";
|
|
2128
1862
|
init_import_meta_shim();
|
|
2129
1863
|
var { kForOnEventAttribute, kListener } = require_constants();
|
|
2130
|
-
var kCode =
|
|
2131
|
-
var kData =
|
|
2132
|
-
var kError =
|
|
2133
|
-
var kMessage =
|
|
2134
|
-
var kReason =
|
|
2135
|
-
var kTarget =
|
|
2136
|
-
var kType =
|
|
2137
|
-
var kWasClean =
|
|
1864
|
+
var kCode = Symbol("kCode");
|
|
1865
|
+
var kData = Symbol("kData");
|
|
1866
|
+
var kError = Symbol("kError");
|
|
1867
|
+
var kMessage = Symbol("kMessage");
|
|
1868
|
+
var kReason = Symbol("kReason");
|
|
1869
|
+
var kTarget = Symbol("kTarget");
|
|
1870
|
+
var kType = Symbol("kType");
|
|
1871
|
+
var kWasClean = Symbol("kWasClean");
|
|
2138
1872
|
var Event = class {
|
|
2139
1873
|
/**
|
|
2140
1874
|
* Create a new `Event`.
|
|
@@ -2351,9 +2085,9 @@ var require_event_target = __commonJS({
|
|
|
2351
2085
|
}
|
|
2352
2086
|
});
|
|
2353
2087
|
|
|
2354
|
-
//
|
|
2088
|
+
// node_modules/ws/lib/extension.js
|
|
2355
2089
|
var require_extension = __commonJS({
|
|
2356
|
-
"
|
|
2090
|
+
"node_modules/ws/lib/extension.js"(exports2, module2) {
|
|
2357
2091
|
"use strict";
|
|
2358
2092
|
init_import_meta_shim();
|
|
2359
2093
|
var { tokenChars } = require_validation();
|
|
@@ -2505,9 +2239,9 @@ var require_extension = __commonJS({
|
|
|
2505
2239
|
}
|
|
2506
2240
|
});
|
|
2507
2241
|
|
|
2508
|
-
//
|
|
2242
|
+
// node_modules/ws/lib/websocket.js
|
|
2509
2243
|
var require_websocket = __commonJS({
|
|
2510
|
-
"
|
|
2244
|
+
"node_modules/ws/lib/websocket.js"(exports2, module2) {
|
|
2511
2245
|
"use strict";
|
|
2512
2246
|
init_import_meta_shim();
|
|
2513
2247
|
var EventEmitter = require("events");
|
|
@@ -2524,6 +2258,7 @@ var require_websocket = __commonJS({
|
|
|
2524
2258
|
var { isBlob } = require_validation();
|
|
2525
2259
|
var {
|
|
2526
2260
|
BINARY_TYPES,
|
|
2261
|
+
CLOSE_TIMEOUT,
|
|
2527
2262
|
EMPTY_BUFFER,
|
|
2528
2263
|
GUID,
|
|
2529
2264
|
kForOnEventAttribute,
|
|
@@ -2537,8 +2272,7 @@ var require_websocket = __commonJS({
|
|
|
2537
2272
|
} = require_event_target();
|
|
2538
2273
|
var { format, parse } = require_extension();
|
|
2539
2274
|
var { toBuffer } = require_buffer_util();
|
|
2540
|
-
var
|
|
2541
|
-
var kAborted = /* @__PURE__ */ Symbol("kAborted");
|
|
2275
|
+
var kAborted = Symbol("kAborted");
|
|
2542
2276
|
var protocolVersions = [8, 13];
|
|
2543
2277
|
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
2544
2278
|
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
@@ -2583,6 +2317,7 @@ var require_websocket = __commonJS({
|
|
|
2583
2317
|
initAsClient(this, address, protocols, options);
|
|
2584
2318
|
} else {
|
|
2585
2319
|
this._autoPong = options.autoPong;
|
|
2320
|
+
this._closeTimeout = options.closeTimeout;
|
|
2586
2321
|
this._isServer = true;
|
|
2587
2322
|
}
|
|
2588
2323
|
}
|
|
@@ -2984,6 +2719,7 @@ var require_websocket = __commonJS({
|
|
|
2984
2719
|
const opts = {
|
|
2985
2720
|
allowSynchronousEvents: true,
|
|
2986
2721
|
autoPong: true,
|
|
2722
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2987
2723
|
protocolVersion: protocolVersions[1],
|
|
2988
2724
|
maxPayload: 100 * 1024 * 1024,
|
|
2989
2725
|
skipUTF8Validation: false,
|
|
@@ -3001,6 +2737,7 @@ var require_websocket = __commonJS({
|
|
|
3001
2737
|
port: void 0
|
|
3002
2738
|
};
|
|
3003
2739
|
websocket._autoPong = opts.autoPong;
|
|
2740
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
3004
2741
|
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
3005
2742
|
throw new RangeError(
|
|
3006
2743
|
`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
|
|
@@ -3343,7 +3080,7 @@ var require_websocket = __commonJS({
|
|
|
3343
3080
|
function setCloseTimer(websocket) {
|
|
3344
3081
|
websocket._closeTimer = setTimeout(
|
|
3345
3082
|
websocket._socket.destroy.bind(websocket._socket),
|
|
3346
|
-
|
|
3083
|
+
websocket._closeTimeout
|
|
3347
3084
|
);
|
|
3348
3085
|
}
|
|
3349
3086
|
function socketOnClose() {
|
|
@@ -3352,8 +3089,8 @@ var require_websocket = __commonJS({
|
|
|
3352
3089
|
this.removeListener("data", socketOnData);
|
|
3353
3090
|
this.removeListener("end", socketOnEnd);
|
|
3354
3091
|
websocket._readyState = WebSocket3.CLOSING;
|
|
3355
|
-
|
|
3356
|
-
|
|
3092
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
3093
|
+
const chunk = this.read(this._readableState.length);
|
|
3357
3094
|
websocket._receiver.write(chunk);
|
|
3358
3095
|
}
|
|
3359
3096
|
websocket._receiver.end();
|
|
@@ -3389,9 +3126,9 @@ var require_websocket = __commonJS({
|
|
|
3389
3126
|
}
|
|
3390
3127
|
});
|
|
3391
3128
|
|
|
3392
|
-
//
|
|
3129
|
+
// node_modules/ws/lib/stream.js
|
|
3393
3130
|
var require_stream = __commonJS({
|
|
3394
|
-
"
|
|
3131
|
+
"node_modules/ws/lib/stream.js"(exports2, module2) {
|
|
3395
3132
|
"use strict";
|
|
3396
3133
|
init_import_meta_shim();
|
|
3397
3134
|
var WebSocket3 = require_websocket();
|
|
@@ -3488,9 +3225,9 @@ var require_stream = __commonJS({
|
|
|
3488
3225
|
}
|
|
3489
3226
|
});
|
|
3490
3227
|
|
|
3491
|
-
//
|
|
3228
|
+
// node_modules/ws/lib/subprotocol.js
|
|
3492
3229
|
var require_subprotocol = __commonJS({
|
|
3493
|
-
"
|
|
3230
|
+
"node_modules/ws/lib/subprotocol.js"(exports2, module2) {
|
|
3494
3231
|
"use strict";
|
|
3495
3232
|
init_import_meta_shim();
|
|
3496
3233
|
var { tokenChars } = require_validation();
|
|
@@ -3534,9 +3271,9 @@ var require_subprotocol = __commonJS({
|
|
|
3534
3271
|
}
|
|
3535
3272
|
});
|
|
3536
3273
|
|
|
3537
|
-
//
|
|
3274
|
+
// node_modules/ws/lib/websocket-server.js
|
|
3538
3275
|
var require_websocket_server = __commonJS({
|
|
3539
|
-
"
|
|
3276
|
+
"node_modules/ws/lib/websocket-server.js"(exports2, module2) {
|
|
3540
3277
|
"use strict";
|
|
3541
3278
|
init_import_meta_shim();
|
|
3542
3279
|
var EventEmitter = require("events");
|
|
@@ -3547,7 +3284,7 @@ var require_websocket_server = __commonJS({
|
|
|
3547
3284
|
var PerMessageDeflate = require_permessage_deflate();
|
|
3548
3285
|
var subprotocol = require_subprotocol();
|
|
3549
3286
|
var WebSocket3 = require_websocket();
|
|
3550
|
-
var { GUID, kWebSocket } = require_constants();
|
|
3287
|
+
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
3551
3288
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
3552
3289
|
var RUNNING = 0;
|
|
3553
3290
|
var CLOSING = 1;
|
|
@@ -3566,6 +3303,9 @@ var require_websocket_server = __commonJS({
|
|
|
3566
3303
|
* pending connections
|
|
3567
3304
|
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
3568
3305
|
* track clients
|
|
3306
|
+
* @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
|
|
3307
|
+
* wait for the closing handshake to finish after `websocket.close()` is
|
|
3308
|
+
* called
|
|
3569
3309
|
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
3570
3310
|
* @param {String} [options.host] The hostname where to bind the server
|
|
3571
3311
|
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
@@ -3594,6 +3334,7 @@ var require_websocket_server = __commonJS({
|
|
|
3594
3334
|
perMessageDeflate: false,
|
|
3595
3335
|
handleProtocols: null,
|
|
3596
3336
|
clientTracking: true,
|
|
3337
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
3597
3338
|
verifyClient: null,
|
|
3598
3339
|
noServer: false,
|
|
3599
3340
|
backlog: null,
|
|
@@ -3924,10 +3665,10 @@ var require_websocket_server = __commonJS({
|
|
|
3924
3665
|
}
|
|
3925
3666
|
});
|
|
3926
3667
|
|
|
3927
|
-
//
|
|
3668
|
+
// node_modules/ws/wrapper.mjs
|
|
3928
3669
|
var import_stream, import_receiver, import_sender, import_websocket, import_websocket_server;
|
|
3929
3670
|
var init_wrapper = __esm({
|
|
3930
|
-
"
|
|
3671
|
+
"node_modules/ws/wrapper.mjs"() {
|
|
3931
3672
|
init_import_meta_shim();
|
|
3932
3673
|
import_stream = __toESM(require_stream(), 1);
|
|
3933
3674
|
import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -4206,9 +3947,12 @@ var init_compat = __esm({
|
|
|
4206
3947
|
|
|
4207
3948
|
// ../claude-chrome-bridge.ts
|
|
4208
3949
|
var claude_chrome_bridge_exports = {};
|
|
3950
|
+
function adb(...args2) {
|
|
3951
|
+
return ADB_SERIAL ? [ADB_PATH, "-s", ADB_SERIAL, ...args2] : [ADB_PATH, ...args2];
|
|
3952
|
+
}
|
|
4209
3953
|
function adbNotify(tag, title, text) {
|
|
4210
3954
|
try {
|
|
4211
|
-
runDetached(
|
|
3955
|
+
runDetached(adb("shell", "cmd", "notification", "post", "-t", title, tag, text));
|
|
4212
3956
|
} catch {
|
|
4213
3957
|
}
|
|
4214
3958
|
}
|
|
@@ -4549,6 +4293,16 @@ function encodeGIF(frames, delayMs) {
|
|
|
4549
4293
|
}
|
|
4550
4294
|
return result;
|
|
4551
4295
|
}
|
|
4296
|
+
function drainToolQueue() {
|
|
4297
|
+
if (pendingToolQueue.length === 0) return;
|
|
4298
|
+
const next = pendingToolQueue[0];
|
|
4299
|
+
for (const client of wsClients) {
|
|
4300
|
+
try {
|
|
4301
|
+
client.send(next.requestJson);
|
|
4302
|
+
} catch {
|
|
4303
|
+
}
|
|
4304
|
+
}
|
|
4305
|
+
}
|
|
4552
4306
|
function spawnNativeHost() {
|
|
4553
4307
|
if (nativeHost) {
|
|
4554
4308
|
log("warn", "Native host already running, killing first");
|
|
@@ -4837,12 +4591,13 @@ function shutdown() {
|
|
|
4837
4591
|
nativeHost = null;
|
|
4838
4592
|
}
|
|
4839
4593
|
cdpManager.cleanup();
|
|
4594
|
+
cdpManager.stopReconnectForShutdown();
|
|
4840
4595
|
adbNotify("cfc-bridge", "CFC Bridge stopped", "Bridge is no longer running");
|
|
4841
4596
|
server.stop();
|
|
4842
4597
|
log("info", "Bridge stopped");
|
|
4843
4598
|
process.exit(0);
|
|
4844
4599
|
}
|
|
4845
|
-
var import_path, import_node_zlib, SCRIPT_DIR, MANIFEST_PATH, BRIDGE_VERSION, WS_PORT, WS_HOST, BRIDGE_TOKEN, MAX_MESSAGE_SIZE, RECONNECT_DELAY_MS, HEARTBEAT_INTERVAL_MS, TERMUX_PREFIX, TERMUX_BIN, ADB_PATH, REPO_CLI, BUN_GLOBAL_CLI, NPM_GLOBAL_CLI, CLI_PATH, RUNTIME_PATH, LOG_LEVEL, LOG_PRIORITY, NativeMessageDecoder, CDP_PORT, CDP_PID_CHECK_INTERVAL_MS, CDP_TARGET_CACHE_TTL_MS, CDP_TIMEOUT_MS, CdpManager, cdpManager, crc32Table, nativeHost, stdoutDecoder, wsClients, server, TEST_PAGE_HTML;
|
|
4600
|
+
var import_path, import_node_zlib, SCRIPT_DIR, MANIFEST_PATH, BRIDGE_VERSION, WS_PORT, WS_HOST, BRIDGE_TOKEN, MAX_MESSAGE_SIZE, RECONNECT_DELAY_MS, HEARTBEAT_INTERVAL_MS, TERMUX_PREFIX, TERMUX_BIN, ADB_PATH, ADB_SERIAL, REPO_CLI, BUN_GLOBAL_CLI, NPM_GLOBAL_CLI, CLI_PATH, RUNTIME_PATH, LOG_LEVEL, LOG_PRIORITY, NativeMessageDecoder, CDP_PORT, CDP_PID_CHECK_INTERVAL_MS, CDP_TARGET_CACHE_TTL_MS, CDP_TIMEOUT_MS, CdpManager, cdpManager, crc32Table, pendingToolQueue, HTTP_TOOL_TIMEOUT_MS, nativeHost, stdoutDecoder, wsClients, server, TEST_PAGE_HTML;
|
|
4846
4601
|
var init_claude_chrome_bridge = __esm({
|
|
4847
4602
|
"../claude-chrome-bridge.ts"() {
|
|
4848
4603
|
init_import_meta_shim();
|
|
@@ -4869,6 +4624,21 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4869
4624
|
TERMUX_PREFIX = "/data/data/com.termux/files/usr";
|
|
4870
4625
|
TERMUX_BIN = `${TERMUX_PREFIX}/bin`;
|
|
4871
4626
|
ADB_PATH = `${TERMUX_BIN}/adb`;
|
|
4627
|
+
ADB_SERIAL = (() => {
|
|
4628
|
+
try {
|
|
4629
|
+
const result = runSync([ADB_PATH, "devices"]);
|
|
4630
|
+
const lines = result.stdout.toString().trim().split("\n").filter((l) => l.endsWith(" device"));
|
|
4631
|
+
if (lines.length <= 1) return "";
|
|
4632
|
+
for (const line of lines) {
|
|
4633
|
+
const serial = line.split(" ")[0];
|
|
4634
|
+
const check = runSync([ADB_PATH, "-s", serial, "shell", "pidof", "com.microsoft.emmx.canary"]);
|
|
4635
|
+
if (check.exitCode === 0 && check.stdout.toString().trim()) return serial;
|
|
4636
|
+
}
|
|
4637
|
+
return lines[0]?.split(" ")[0] ?? "";
|
|
4638
|
+
} catch {
|
|
4639
|
+
return "";
|
|
4640
|
+
}
|
|
4641
|
+
})();
|
|
4872
4642
|
REPO_CLI = (0, import_path.resolve)(SCRIPT_DIR, "cli.js");
|
|
4873
4643
|
BUN_GLOBAL_CLI = (0, import_path.resolve)(
|
|
4874
4644
|
process.env.HOME ?? "~",
|
|
@@ -4938,8 +4708,10 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4938
4708
|
targetsLastFetched = 0;
|
|
4939
4709
|
/** Cached CDP targets */
|
|
4940
4710
|
cachedTargets = [];
|
|
4941
|
-
/** PID recheck interval handle */
|
|
4711
|
+
/** PID recheck interval handle (active when connected) */
|
|
4942
4712
|
pidCheckTimer = null;
|
|
4713
|
+
/** Reconnect interval handle (active when disconnected) */
|
|
4714
|
+
reconnectTimer = null;
|
|
4943
4715
|
/** Sessions where Network domain has been enabled */
|
|
4944
4716
|
networkEnabledSessions = /* @__PURE__ */ new Set();
|
|
4945
4717
|
/** Network request events per sessionId */
|
|
@@ -4950,16 +4722,9 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4950
4722
|
if (this.state === "connecting") return false;
|
|
4951
4723
|
this.state = "connecting";
|
|
4952
4724
|
try {
|
|
4953
|
-
|
|
4954
|
-
const pidStr = pidResult.stdout.toString().trim().split(/\s+/)[0];
|
|
4955
|
-
if (!pidStr || pidResult.exitCode !== 0) {
|
|
4956
|
-
log("debug", "CDP: Edge not running or ADB unavailable");
|
|
4957
|
-
this.state = "disconnected";
|
|
4958
|
-
return false;
|
|
4959
|
-
}
|
|
4960
|
-
this.edgePid = parseInt(pidStr, 10);
|
|
4725
|
+
this.edgePid = this.getEdgePid();
|
|
4961
4726
|
if (isNaN(this.edgePid)) {
|
|
4962
|
-
log("
|
|
4727
|
+
log("debug", "CDP: Edge not running or ADB unavailable");
|
|
4963
4728
|
this.state = "disconnected";
|
|
4964
4729
|
return false;
|
|
4965
4730
|
}
|
|
@@ -4972,7 +4737,7 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4972
4737
|
let versionData = null;
|
|
4973
4738
|
for (const socketName of socketCandidates) {
|
|
4974
4739
|
const fwdResult = runSync(
|
|
4975
|
-
|
|
4740
|
+
adb("forward", `tcp:${CDP_PORT}`, `localabstract:${socketName}`)
|
|
4976
4741
|
);
|
|
4977
4742
|
if (fwdResult.exitCode !== 0) continue;
|
|
4978
4743
|
try {
|
|
@@ -4981,7 +4746,7 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4981
4746
|
log("info", `CDP: Edge version \u2014 ${versionData["Browser"] ?? "unknown"}, pkg: ${versionData["Android-Package"] ?? "unknown"} (socket: ${socketName})`);
|
|
4982
4747
|
break;
|
|
4983
4748
|
} catch {
|
|
4984
|
-
runSync(
|
|
4749
|
+
runSync(adb("forward", "--remove", `tcp:${CDP_PORT}`));
|
|
4985
4750
|
}
|
|
4986
4751
|
}
|
|
4987
4752
|
if (!versionData) {
|
|
@@ -4991,6 +4756,7 @@ var init_claude_chrome_bridge = __esm({
|
|
|
4991
4756
|
}
|
|
4992
4757
|
const wsUrl = versionData.webSocketDebuggerUrl?.replace(/^ws:\/\/[^/]+/, `ws://127.0.0.1:${CDP_PORT}`) ?? `ws://127.0.0.1:${CDP_PORT}/devtools/browser`;
|
|
4993
4758
|
await this.connectWebSocket(wsUrl);
|
|
4759
|
+
this.stopReconnectTimer();
|
|
4994
4760
|
if (!this.pidCheckTimer) {
|
|
4995
4761
|
this.pidCheckTimer = setInterval(() => this.recheckPid(), CDP_PID_CHECK_INTERVAL_MS);
|
|
4996
4762
|
}
|
|
@@ -5236,9 +5002,9 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5236
5002
|
}
|
|
5237
5003
|
try {
|
|
5238
5004
|
const tmpPath = "/data/data/com.termux/files/usr/tmp/cdp-screencap.png";
|
|
5239
|
-
const cap = runSync(
|
|
5005
|
+
const cap = runSync(adb("shell", "screencap", "-p", "/sdcard/cdp-screencap.png"));
|
|
5240
5006
|
if (cap.exitCode === 0) {
|
|
5241
|
-
const pull = runSync(
|
|
5007
|
+
const pull = runSync(adb("pull", "/sdcard/cdp-screencap.png", tmpPath));
|
|
5242
5008
|
if (pull.exitCode === 0 && await fileExists(tmpPath)) {
|
|
5243
5009
|
const { readFile: rf } = await import("node:fs/promises");
|
|
5244
5010
|
const buf = await rf(tmpPath);
|
|
@@ -5466,28 +5232,65 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5466
5232
|
targets: this.cachedTargets.filter((t) => t.type === "page").length
|
|
5467
5233
|
};
|
|
5468
5234
|
}
|
|
5469
|
-
/**
|
|
5470
|
-
|
|
5235
|
+
/**
|
|
5236
|
+
* Get Edge PID — tries local `pidof` first (works on-device without ADB),
|
|
5237
|
+
* falls back to `adb shell pidof` if local fails.
|
|
5238
|
+
* Returns NaN if Edge is not running or both methods fail.
|
|
5239
|
+
*/
|
|
5240
|
+
getEdgePid() {
|
|
5471
5241
|
try {
|
|
5472
|
-
const
|
|
5473
|
-
const
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5242
|
+
const local = runSync(["pidof", "com.microsoft.emmx.canary"]);
|
|
5243
|
+
const pid = parseInt(local.stdout.toString().trim().split(/\s+/)[0], 10);
|
|
5244
|
+
if (!isNaN(pid)) return pid;
|
|
5245
|
+
} catch {
|
|
5246
|
+
}
|
|
5247
|
+
try {
|
|
5248
|
+
const remote = runSync(adb("shell", "pidof", "com.microsoft.emmx.canary"));
|
|
5249
|
+
const pid = parseInt(remote.stdout.toString().trim().split(/\s+/)[0], 10);
|
|
5250
|
+
if (!isNaN(pid)) return pid;
|
|
5251
|
+
} catch {
|
|
5252
|
+
}
|
|
5253
|
+
return NaN;
|
|
5254
|
+
}
|
|
5255
|
+
/** Re-check Edge PID — reconnect if changed, or attempt connect if disconnected */
|
|
5256
|
+
async recheckPid() {
|
|
5257
|
+
const newPid = this.getEdgePid();
|
|
5258
|
+
if (isNaN(newPid)) {
|
|
5259
|
+
if (this.state === "connected") {
|
|
5260
|
+
log("info", "CDP: Edge no longer running, disconnecting");
|
|
5484
5261
|
this.cleanup();
|
|
5485
|
-
await this.connect();
|
|
5486
5262
|
}
|
|
5487
|
-
|
|
5263
|
+
return;
|
|
5264
|
+
}
|
|
5265
|
+
if (this.state === "disconnected") {
|
|
5266
|
+
log("info", `CDP: Edge running (PID ${newPid}), attempting reconnect`);
|
|
5267
|
+
await this.connect();
|
|
5268
|
+
return;
|
|
5269
|
+
}
|
|
5270
|
+
if (newPid !== this.edgePid && this.state === "connected") {
|
|
5271
|
+
log("info", `CDP: Edge PID changed ${this.edgePid} \u2192 ${newPid}, reconnecting`);
|
|
5272
|
+
this.cleanup();
|
|
5273
|
+
await this.connect();
|
|
5488
5274
|
}
|
|
5489
5275
|
}
|
|
5490
|
-
/**
|
|
5276
|
+
/** Start periodic reconnect timer (runs when disconnected) */
|
|
5277
|
+
startReconnectTimer() {
|
|
5278
|
+
if (this.reconnectTimer) return;
|
|
5279
|
+
this.reconnectTimer = setInterval(() => this.recheckPid(), CDP_PID_CHECK_INTERVAL_MS);
|
|
5280
|
+
log("debug", `CDP: reconnect timer started (every ${CDP_PID_CHECK_INTERVAL_MS / 1e3}s)`);
|
|
5281
|
+
}
|
|
5282
|
+
/** Stop the reconnect timer (called when connection succeeds) */
|
|
5283
|
+
stopReconnectTimer() {
|
|
5284
|
+
if (this.reconnectTimer) {
|
|
5285
|
+
clearInterval(this.reconnectTimer);
|
|
5286
|
+
this.reconnectTimer = null;
|
|
5287
|
+
}
|
|
5288
|
+
}
|
|
5289
|
+
/** Stop reconnect timer for final shutdown (cleanup restarts it, but shutdown shouldn't) */
|
|
5290
|
+
stopReconnectForShutdown() {
|
|
5291
|
+
this.stopReconnectTimer();
|
|
5292
|
+
}
|
|
5293
|
+
/** Clean up CDP connection and ADB forward, restart reconnect timer */
|
|
5491
5294
|
cleanup() {
|
|
5492
5295
|
if (this.pidCheckTimer) {
|
|
5493
5296
|
clearInterval(this.pidCheckTimer);
|
|
@@ -5510,8 +5313,9 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5510
5313
|
p.reject(new Error("CDP cleanup"));
|
|
5511
5314
|
});
|
|
5512
5315
|
this.pending.clear();
|
|
5513
|
-
runSync(
|
|
5316
|
+
runSync(adb("forward", "--remove", `tcp:${CDP_PORT}`));
|
|
5514
5317
|
log("info", "CDP: cleaned up");
|
|
5318
|
+
this.startReconnectTimer();
|
|
5515
5319
|
}
|
|
5516
5320
|
};
|
|
5517
5321
|
cdpManager = new CdpManager();
|
|
@@ -5521,6 +5325,8 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5521
5325
|
for (let j = 0; j < 8; j++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
5522
5326
|
crc32Table[i] = c;
|
|
5523
5327
|
}
|
|
5328
|
+
pendingToolQueue = [];
|
|
5329
|
+
HTTP_TOOL_TIMEOUT_MS = 3e4;
|
|
5524
5330
|
nativeHost = null;
|
|
5525
5331
|
stdoutDecoder = new NativeMessageDecoder();
|
|
5526
5332
|
wsClients = /* @__PURE__ */ new Set();
|
|
@@ -5672,6 +5478,44 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5672
5478
|
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
5673
5479
|
});
|
|
5674
5480
|
}
|
|
5481
|
+
if (url.pathname === "/tool" && req.method === "POST") {
|
|
5482
|
+
if (wsClients.size === 0) {
|
|
5483
|
+
return new Response(
|
|
5484
|
+
JSON.stringify({ error: "No extension connected" }),
|
|
5485
|
+
{ status: 503, headers: { "Content-Type": "application/json" } }
|
|
5486
|
+
);
|
|
5487
|
+
}
|
|
5488
|
+
try {
|
|
5489
|
+
const body = await req.json();
|
|
5490
|
+
const toolRequest = JSON.stringify({
|
|
5491
|
+
type: "tool_request",
|
|
5492
|
+
method: body.method,
|
|
5493
|
+
params: body.params ?? {}
|
|
5494
|
+
});
|
|
5495
|
+
const queuePos = pendingToolQueue.length;
|
|
5496
|
+
log("info", `HTTP /tool: ${body.method} (queue pos ${queuePos})`);
|
|
5497
|
+
const result = await new Promise((resolve3) => {
|
|
5498
|
+
const timeout = setTimeout(() => {
|
|
5499
|
+
const idx = pendingToolQueue.findIndex((e) => e.resolve === resolve3);
|
|
5500
|
+
const wasHead = idx === 0;
|
|
5501
|
+
if (idx !== -1) pendingToolQueue.splice(idx, 1);
|
|
5502
|
+
resolve3({ type: "tool_response", error: "Tool call timed out (30s)" });
|
|
5503
|
+
if (wasHead) drainToolQueue();
|
|
5504
|
+
}, HTTP_TOOL_TIMEOUT_MS);
|
|
5505
|
+
pendingToolQueue.push({ requestJson: toolRequest, resolve: resolve3, timeout });
|
|
5506
|
+
if (pendingToolQueue.length === 1) drainToolQueue();
|
|
5507
|
+
});
|
|
5508
|
+
return new Response(
|
|
5509
|
+
JSON.stringify(result),
|
|
5510
|
+
{ headers: { "Content-Type": "application/json" } }
|
|
5511
|
+
);
|
|
5512
|
+
} catch (err) {
|
|
5513
|
+
return new Response(
|
|
5514
|
+
JSON.stringify({ error: err.message }),
|
|
5515
|
+
{ status: 500, headers: { "Content-Type": "application/json" } }
|
|
5516
|
+
);
|
|
5517
|
+
}
|
|
5518
|
+
}
|
|
5675
5519
|
if (url.pathname === "/ws" || url.pathname === "/") {
|
|
5676
5520
|
if (BRIDGE_TOKEN) {
|
|
5677
5521
|
const token = url.searchParams.get("token") ?? req.headers.get("x-bridge-token") ?? "";
|
|
@@ -5714,6 +5558,15 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5714
5558
|
}
|
|
5715
5559
|
}
|
|
5716
5560
|
}
|
|
5561
|
+
if (parsed.type === "tool_response" && pendingToolQueue.length > 0) {
|
|
5562
|
+
const { resolve: resolve3, timeout } = pendingToolQueue.shift();
|
|
5563
|
+
clearTimeout(timeout);
|
|
5564
|
+
if ("method" in parsed) delete parsed.method;
|
|
5565
|
+
log("debug", `HTTP /tool response (${pendingToolQueue.length} queued): ${json.slice(0, 200)}`);
|
|
5566
|
+
resolve3(parsed);
|
|
5567
|
+
drainToolQueue();
|
|
5568
|
+
return;
|
|
5569
|
+
}
|
|
5717
5570
|
if (parsed.type === "tool_response" && "method" in parsed) {
|
|
5718
5571
|
delete parsed.method;
|
|
5719
5572
|
const fixed = JSON.stringify(parsed);
|
|
@@ -5774,8 +5627,12 @@ var init_claude_chrome_bridge = __esm({
|
|
|
5774
5627
|
log("info", `CLI path: ${CLI_PATH}`);
|
|
5775
5628
|
log("info", `Auth: ${BRIDGE_TOKEN ? "token required" : "open (localhost only)"}`);
|
|
5776
5629
|
cdpManager.connect().then((ok) => {
|
|
5777
|
-
if (ok)
|
|
5778
|
-
|
|
5630
|
+
if (ok) {
|
|
5631
|
+
log("info", `CDP: ready (${JSON.stringify(cdpManager.getStatus())})`);
|
|
5632
|
+
} else {
|
|
5633
|
+
log("info", "CDP: not available at startup \u2014 reconnect timer will retry periodically");
|
|
5634
|
+
cdpManager.startReconnectTimer();
|
|
5635
|
+
}
|
|
5779
5636
|
});
|
|
5780
5637
|
log("info", "Waiting for WebSocket connections...");
|
|
5781
5638
|
adbNotify("cfc-bridge", `CFC Bridge v${BRIDGE_VERSION}`, `Running on :${WS_PORT} (PID ${process.pid})`);
|
|
@@ -5906,8 +5763,11 @@ var PKG_VERSION = (() => {
|
|
|
5906
5763
|
})();
|
|
5907
5764
|
var WS_PORT2 = parseInt(process.env.BRIDGE_PORT ?? "18963", 10);
|
|
5908
5765
|
var WS_HOST2 = "127.0.0.1";
|
|
5909
|
-
var
|
|
5910
|
-
var
|
|
5766
|
+
var BRIDGE_URL = process.env.BRIDGE_URL ?? `http://${WS_HOST2}:${WS_PORT2}`;
|
|
5767
|
+
var HEALTH_URL = `${BRIDGE_URL}/health`;
|
|
5768
|
+
var SHUTDOWN_URL = `${BRIDGE_URL}/shutdown`;
|
|
5769
|
+
var TOOL_URL = `${BRIDGE_URL}/tool`;
|
|
5770
|
+
var TOOL_TIMEOUT_MS = 3e4;
|
|
5911
5771
|
async function fetchWithTimeout(url, opts = {}) {
|
|
5912
5772
|
const { timeout = 3e3, ...fetchOpts } = opts;
|
|
5913
5773
|
const controller = new AbortController();
|
|
@@ -5936,8 +5796,9 @@ CFC Bridge \u2014 connects Claude Code CLI to Chrome/Edge on Android via WebSock
|
|
|
5936
5796
|
|
|
5937
5797
|
Usage:
|
|
5938
5798
|
claude-chrome-android Start the bridge server
|
|
5799
|
+
claude-chrome-android --mcp MCP server mode (spawned by Claude Code)
|
|
5939
5800
|
claude-chrome-android --stop Stop a running bridge
|
|
5940
|
-
claude-chrome-android --setup
|
|
5801
|
+
claude-chrome-android --setup Register MCP server in Claude Code + create url-opener
|
|
5941
5802
|
claude-chrome-android --version Print version
|
|
5942
5803
|
claude-chrome-android --help Show this help
|
|
5943
5804
|
|
|
@@ -5951,18 +5812,14 @@ async function cmdStop() {
|
|
|
5951
5812
|
console.log("Stopping bridge...");
|
|
5952
5813
|
try {
|
|
5953
5814
|
const res = await fetchWithTimeout(SHUTDOWN_URL, { method: "POST", timeout: 3e3 });
|
|
5954
|
-
if (res.ok)
|
|
5955
|
-
console.log("Shutdown request accepted");
|
|
5956
|
-
}
|
|
5815
|
+
if (res.ok) console.log("Shutdown request accepted");
|
|
5957
5816
|
} catch {
|
|
5958
5817
|
}
|
|
5959
5818
|
await new Promise((r) => setTimeout(r, 800));
|
|
5960
5819
|
if (await isBridgeAlive()) {
|
|
5961
5820
|
console.log("Bridge didn't stop gracefully, attempting pkill...");
|
|
5962
5821
|
const { spawnSync: spawnSync2 } = await import("child_process");
|
|
5963
|
-
|
|
5964
|
-
stdio: "ignore"
|
|
5965
|
-
});
|
|
5822
|
+
spawnSync2("pkill", ["-f", "(bun|node).*claude-chrome"], { stdio: "ignore" });
|
|
5966
5823
|
await new Promise((r) => setTimeout(r, 500));
|
|
5967
5824
|
if (await isBridgeAlive()) {
|
|
5968
5825
|
console.error("Bridge is still running. Kill manually: pkill -f claude-chrome-bridge");
|
|
@@ -5984,15 +5841,43 @@ async function cmdSetup() {
|
|
|
5984
5841
|
const { spawnSync: spawnSync2 } = await import("child_process");
|
|
5985
5842
|
const bunCheck = spawnSync2("bun", ["--version"], { stdio: "pipe", encoding: "utf-8" });
|
|
5986
5843
|
if (bunCheck.status === 0) {
|
|
5987
|
-
console.log(`Bun: ${bunCheck.stdout.trim()}
|
|
5988
|
-
} else {
|
|
5989
|
-
console.log("Bun: not found (will use Node.js)");
|
|
5844
|
+
console.log(`Bun: ${bunCheck.stdout.trim()}`);
|
|
5990
5845
|
}
|
|
5991
|
-
const
|
|
5992
|
-
|
|
5993
|
-
|
|
5846
|
+
const claudeDir = (0, import_path2.resolve)(process.env.HOME ?? "~", ".claude");
|
|
5847
|
+
const settingsPath = (0, import_path2.resolve)(claudeDir, "settings.json");
|
|
5848
|
+
const cliPath = typeof __filename !== "undefined" ? __filename : "";
|
|
5849
|
+
let mcpCommand;
|
|
5850
|
+
let mcpArgs;
|
|
5851
|
+
if (cliPath && (0, import_fs.existsSync)(cliPath)) {
|
|
5852
|
+
mcpCommand = "node";
|
|
5853
|
+
mcpArgs = [cliPath, "--mcp"];
|
|
5994
5854
|
} else {
|
|
5995
|
-
|
|
5855
|
+
mcpCommand = "npx";
|
|
5856
|
+
mcpArgs = ["claude-chrome-android", "--mcp"];
|
|
5857
|
+
}
|
|
5858
|
+
try {
|
|
5859
|
+
if (!(0, import_fs.existsSync)(claudeDir)) {
|
|
5860
|
+
(0, import_fs.mkdirSync)(claudeDir, { recursive: true });
|
|
5861
|
+
}
|
|
5862
|
+
let settings = {};
|
|
5863
|
+
if ((0, import_fs.existsSync)(settingsPath)) {
|
|
5864
|
+
settings = JSON.parse((0, import_fs.readFileSync)(settingsPath, "utf-8"));
|
|
5865
|
+
}
|
|
5866
|
+
const mcpServers = settings.mcpServers ?? {};
|
|
5867
|
+
const existing = mcpServers["cfc-bridge"];
|
|
5868
|
+
const desired = { command: mcpCommand, args: mcpArgs };
|
|
5869
|
+
const changed = !existing || existing.command !== desired.command || JSON.stringify(existing.args) !== JSON.stringify(desired.args);
|
|
5870
|
+
if (changed) {
|
|
5871
|
+
mcpServers["cfc-bridge"] = desired;
|
|
5872
|
+
settings.mcpServers = mcpServers;
|
|
5873
|
+
(0, import_fs.writeFileSync)(settingsPath, JSON.stringify(settings, null, 2) + "\n");
|
|
5874
|
+
console.log(`Registered MCP server "cfc-bridge" in ${settingsPath}`);
|
|
5875
|
+
console.log(` command: ${mcpCommand} ${mcpArgs.join(" ")}`);
|
|
5876
|
+
} else {
|
|
5877
|
+
console.log(`MCP server already registered in ${settingsPath}`);
|
|
5878
|
+
}
|
|
5879
|
+
} catch (err) {
|
|
5880
|
+
console.error(`Failed to register MCP server: ${err.message}`);
|
|
5996
5881
|
}
|
|
5997
5882
|
const binDir = (0, import_path2.resolve)(process.env.HOME ?? "/data/data/com.termux/files/home", "bin");
|
|
5998
5883
|
if (!(0, import_fs.existsSync)(binDir)) {
|
|
@@ -6004,105 +5889,171 @@ Created ${binDir}/`);
|
|
|
6004
5889
|
const urlOpenerExists = (0, import_fs.existsSync)(urlOpenerPath);
|
|
6005
5890
|
const urlOpenerScript = `#!/data/data/com.termux/files/usr/bin/bash
|
|
6006
5891
|
# termux-url-opener \u2014 handles URLs shared to Termux via Android share menu
|
|
6007
|
-
# Called by TermuxFileReceiverActivity with the shared URL as $1
|
|
6008
|
-
#
|
|
6009
5892
|
# Generated by: claude-chrome-android --setup v${PKG_VERSION}
|
|
6010
|
-
# NOTE: TermuxFileReceiverActivity runs this in a terminal session managed by
|
|
6011
|
-
# TermuxService. When the script exits, the session closes and SIGHUP is sent
|
|
6012
|
-
# to the process group. We use setsid to escape the process group.
|
|
6013
5893
|
|
|
6014
5894
|
set -euo pipefail
|
|
6015
|
-
|
|
6016
5895
|
url="\${1:-}"
|
|
6017
|
-
|
|
6018
|
-
# Debug log
|
|
6019
5896
|
echo "[$(date +%H:%M:%S)] termux-url-opener: $url" >> "$PREFIX/tmp/url-opener.log"
|
|
6020
5897
|
|
|
6021
5898
|
case "$url" in
|
|
6022
5899
|
*cfcbridge*/start*)
|
|
6023
|
-
# CFC bridge deep-link from the Chrome/Edge extension
|
|
6024
5900
|
BRIDGE_LOG="$PREFIX/tmp/bridge.log"
|
|
6025
|
-
|
|
6026
5901
|
if pgrep -f "(bun|node).*claude-chrome" > /dev/null 2>&1; then
|
|
6027
5902
|
echo "[$(date +%H:%M:%S)] bridge already running" >> "$PREFIX/tmp/url-opener.log"
|
|
6028
5903
|
exit 0
|
|
6029
5904
|
fi
|
|
6030
|
-
|
|
6031
|
-
# Prefer bun (faster startup), fallback to node
|
|
6032
5905
|
RUNTIME=""
|
|
6033
|
-
if [[ -x "$HOME/.bun/bin/bun" ]]; then
|
|
6034
|
-
|
|
6035
|
-
elif command -v
|
|
6036
|
-
RUNTIME="$(command -v bun)"
|
|
6037
|
-
elif command -v node > /dev/null 2>&1; then
|
|
6038
|
-
RUNTIME="$(command -v node)"
|
|
6039
|
-
fi
|
|
6040
|
-
|
|
6041
|
-
if [[ -z "$RUNTIME" ]]; then
|
|
6042
|
-
echo "[$(date +%H:%M:%S)] ERROR: neither bun nor node found" >> "$PREFIX/tmp/url-opener.log"
|
|
6043
|
-
exit 1
|
|
5906
|
+
if [[ -x "$HOME/.bun/bin/bun" ]]; then RUNTIME="$HOME/.bun/bin/bun"
|
|
5907
|
+
elif command -v bun > /dev/null 2>&1; then RUNTIME="$(command -v bun)"
|
|
5908
|
+
elif command -v node > /dev/null 2>&1; then RUNTIME="$(command -v node)"
|
|
6044
5909
|
fi
|
|
6045
|
-
|
|
6046
|
-
# Find the bridge script \u2014 check npx cache, repo checkout, or run via npx
|
|
5910
|
+
if [[ -z "$RUNTIME" ]]; then exit 1; fi
|
|
6047
5911
|
BRIDGE_SCRIPT=""
|
|
6048
|
-
# 1. Local repo checkout
|
|
6049
5912
|
if [[ -f "$HOME/git/termux-tools/claude-chrome-bridge.ts" ]]; then
|
|
6050
5913
|
BRIDGE_SCRIPT="$HOME/git/termux-tools/claude-chrome-bridge.ts"
|
|
6051
5914
|
fi
|
|
6052
|
-
# 2. npm global install (bunx or npx)
|
|
6053
5915
|
NPM_GLOBAL="$HOME/.npm/lib/node_modules/claude-chrome-android/dist/cli.js"
|
|
6054
5916
|
BUN_GLOBAL="$HOME/.bun/install/global/node_modules/claude-chrome-android/dist/cli.js"
|
|
6055
|
-
if [[ -z "$BRIDGE_SCRIPT" && -f "$NPM_GLOBAL" ]]; then
|
|
6056
|
-
|
|
6057
|
-
elif [[ -z "$BRIDGE_SCRIPT" && -f "$BUN_GLOBAL" ]]; then
|
|
6058
|
-
BRIDGE_SCRIPT="$BUN_GLOBAL"
|
|
5917
|
+
if [[ -z "$BRIDGE_SCRIPT" && -f "$NPM_GLOBAL" ]]; then BRIDGE_SCRIPT="$NPM_GLOBAL"
|
|
5918
|
+
elif [[ -z "$BRIDGE_SCRIPT" && -f "$BUN_GLOBAL" ]]; then BRIDGE_SCRIPT="$BUN_GLOBAL"
|
|
6059
5919
|
fi
|
|
6060
|
-
|
|
6061
5920
|
if [[ -n "$BRIDGE_SCRIPT" ]]; then
|
|
6062
|
-
# setsid creates a new session leader \u2014 the child process survives when
|
|
6063
|
-
# TermuxService kills this session's process group on script exit
|
|
6064
5921
|
setsid nohup "$RUNTIME" "$BRIDGE_SCRIPT" > "$BRIDGE_LOG" 2>&1 &
|
|
6065
|
-
echo "[$(date +%H:%M:%S)] bridge started PID=$!" >> "$PREFIX/tmp/url-opener.log"
|
|
6066
5922
|
else
|
|
6067
|
-
# Fallback: use npx to download and run on the fly
|
|
6068
5923
|
setsid nohup npx claude-chrome-android > "$BRIDGE_LOG" 2>&1 &
|
|
6069
|
-
echo "[$(date +%H:%M:%S)] bridge started via npx PID=$!" >> "$PREFIX/tmp/url-opener.log"
|
|
6070
5924
|
fi
|
|
6071
|
-
exit 0
|
|
6072
|
-
;;
|
|
6073
|
-
|
|
5925
|
+
exit 0 ;;
|
|
6074
5926
|
*)
|
|
6075
|
-
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
elif command -v xdg-open > /dev/null 2>&1; then
|
|
6079
|
-
xdg-open "$url"
|
|
6080
|
-
fi
|
|
6081
|
-
;;
|
|
5927
|
+
if command -v termux-open-url > /dev/null 2>&1; then termux-open-url "$url"
|
|
5928
|
+
elif command -v xdg-open > /dev/null 2>&1; then xdg-open "$url"
|
|
5929
|
+
fi ;;
|
|
6082
5930
|
esac
|
|
6083
5931
|
`;
|
|
6084
5932
|
if (urlOpenerExists) {
|
|
6085
5933
|
const existing = (0, import_fs.readFileSync)(urlOpenerPath, "utf-8");
|
|
6086
5934
|
if (existing.includes("cfcbridge")) {
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
console.log(`
|
|
6090
|
-
Backed up existing url-opener to ${backupPath}`);
|
|
5935
|
+
(0, import_fs.writeFileSync)(`${urlOpenerPath}.bak`, existing);
|
|
5936
|
+
console.log(`Backed up existing url-opener to ${urlOpenerPath}.bak`);
|
|
6091
5937
|
}
|
|
6092
5938
|
}
|
|
6093
5939
|
(0, import_fs.writeFileSync)(urlOpenerPath, urlOpenerScript);
|
|
6094
5940
|
(0, import_fs.chmodSync)(urlOpenerPath, 493);
|
|
6095
5941
|
console.log(`${urlOpenerExists ? "Updated" : "Created"} ${urlOpenerPath}`);
|
|
5942
|
+
const dir = typeof __dirname !== "undefined" ? __dirname : (0, import_path2.dirname)(new URL(import_meta_url).pathname);
|
|
5943
|
+
const extVersion = (() => {
|
|
5944
|
+
const manifestCandidates = [
|
|
5945
|
+
(0, import_path2.resolve)(dir, "../../edge-claude-ext/manifest.json")
|
|
5946
|
+
// source repo
|
|
5947
|
+
];
|
|
5948
|
+
for (const p of manifestCandidates) {
|
|
5949
|
+
try {
|
|
5950
|
+
return JSON.parse((0, import_fs.readFileSync)(p, "utf-8")).version;
|
|
5951
|
+
} catch {
|
|
5952
|
+
}
|
|
5953
|
+
}
|
|
5954
|
+
return PKG_VERSION;
|
|
5955
|
+
})();
|
|
5956
|
+
const crxCandidates = [
|
|
5957
|
+
(0, import_path2.resolve)(dir, "claude-code-bridge.crx"),
|
|
5958
|
+
// npm package (bridge/dist/)
|
|
5959
|
+
(0, import_path2.resolve)(dir, `../../dist/claude-code-bridge-v${extVersion}.crx`),
|
|
5960
|
+
// source repo
|
|
5961
|
+
(0, import_path2.resolve)(dir, "../../dist/claude-code-bridge-latest.crx")
|
|
5962
|
+
// source repo -latest
|
|
5963
|
+
];
|
|
5964
|
+
let crxPath = crxCandidates.find((p) => (0, import_fs.existsSync)(p));
|
|
5965
|
+
if (!crxPath) {
|
|
5966
|
+
const buildScript = (0, import_path2.resolve)(dir, "../../scripts/build-crx.js");
|
|
5967
|
+
if ((0, import_fs.existsSync)(buildScript)) {
|
|
5968
|
+
console.log("\nBuilding CRX extension...");
|
|
5969
|
+
spawnSync2("node", [buildScript], { stdio: "inherit" });
|
|
5970
|
+
crxPath = crxCandidates.find((p) => (0, import_fs.existsSync)(p));
|
|
5971
|
+
}
|
|
5972
|
+
}
|
|
5973
|
+
if (!crxPath) {
|
|
5974
|
+
console.log("\nCRX not found. To install the extension manually:");
|
|
5975
|
+
console.log(" 1. Start the bridge: npx claude-chrome-android");
|
|
5976
|
+
console.log(" 2. Open http://127.0.0.1:18963/ext/crx in Edge");
|
|
5977
|
+
} else {
|
|
5978
|
+
const adbCheck = spawnSync2("adb", ["devices"], { stdio: "pipe", encoding: "utf-8" });
|
|
5979
|
+
const hasAdb = adbCheck.status === 0 && adbCheck.stdout.includes(" device");
|
|
5980
|
+
if (!hasAdb) {
|
|
5981
|
+
console.log(`
|
|
5982
|
+
CRX found at ${crxPath}`);
|
|
5983
|
+
console.log("ADB not available. To install the extension:");
|
|
5984
|
+
console.log(" 1. Start the bridge: npx claude-chrome-android");
|
|
5985
|
+
console.log(" 2. Open http://127.0.0.1:18963/ext/crx in Edge");
|
|
5986
|
+
} else {
|
|
5987
|
+
const http2 = await import("http");
|
|
5988
|
+
const crxBuf = (0, import_fs.readFileSync)(crxPath);
|
|
5989
|
+
const INSTALL_PORT = 18964;
|
|
5990
|
+
const crxServer = http2.createServer((_req, res) => {
|
|
5991
|
+
res.writeHead(200, {
|
|
5992
|
+
"Content-Type": "application/x-chrome-extension",
|
|
5993
|
+
"Content-Disposition": 'attachment; filename="claude-code-bridge.crx"',
|
|
5994
|
+
"Content-Length": String(crxBuf.length)
|
|
5995
|
+
});
|
|
5996
|
+
res.end(crxBuf);
|
|
5997
|
+
});
|
|
5998
|
+
await new Promise((resolve3) => {
|
|
5999
|
+
crxServer.listen(INSTALL_PORT, "127.0.0.1", resolve3);
|
|
6000
|
+
});
|
|
6001
|
+
console.log(`
|
|
6002
|
+
Serving CRX at http://127.0.0.1:${INSTALL_PORT}/ext.crx`);
|
|
6003
|
+
const edgePackages = [
|
|
6004
|
+
"com.microsoft.emmx.canary",
|
|
6005
|
+
"com.microsoft.emmx.dev",
|
|
6006
|
+
"com.microsoft.emmx.beta",
|
|
6007
|
+
"com.microsoft.emmx"
|
|
6008
|
+
];
|
|
6009
|
+
let opened = false;
|
|
6010
|
+
for (const pkg of edgePackages) {
|
|
6011
|
+
const result = spawnSync2("adb", [
|
|
6012
|
+
"shell",
|
|
6013
|
+
"am",
|
|
6014
|
+
"start",
|
|
6015
|
+
"-a",
|
|
6016
|
+
"android.intent.action.VIEW",
|
|
6017
|
+
"-d",
|
|
6018
|
+
`http://127.0.0.1:${INSTALL_PORT}/ext.crx`,
|
|
6019
|
+
"-n",
|
|
6020
|
+
`${pkg}/com.microsoft.ruby.Main`
|
|
6021
|
+
], { stdio: "pipe", encoding: "utf-8" });
|
|
6022
|
+
if (result.status === 0 && !result.stderr.includes("Error")) {
|
|
6023
|
+
console.log(`Opened CRX download in ${pkg}`);
|
|
6024
|
+
opened = true;
|
|
6025
|
+
break;
|
|
6026
|
+
}
|
|
6027
|
+
}
|
|
6028
|
+
if (!opened) {
|
|
6029
|
+
console.log("Could not open Edge automatically.");
|
|
6030
|
+
console.log(`Open this URL in Edge: http://127.0.0.1:${INSTALL_PORT}/ext.crx`);
|
|
6031
|
+
}
|
|
6032
|
+
console.log("Waiting 15s for download...");
|
|
6033
|
+
await new Promise((r) => setTimeout(r, 15e3));
|
|
6034
|
+
crxServer.close();
|
|
6035
|
+
spawnSync2("adb", [
|
|
6036
|
+
"shell",
|
|
6037
|
+
"am",
|
|
6038
|
+
"start",
|
|
6039
|
+
"-a",
|
|
6040
|
+
"android.intent.action.VIEW",
|
|
6041
|
+
"-d",
|
|
6042
|
+
"edge://extensions",
|
|
6043
|
+
"-n",
|
|
6044
|
+
"com.microsoft.emmx.canary/com.google.android.apps.chrome.IntentDispatcher"
|
|
6045
|
+
], { stdio: "ignore" });
|
|
6046
|
+
console.log("Opened edge://extensions \u2014 verify the extension is listed.");
|
|
6047
|
+
console.log("Note: if prompted, tap 'Add extension' in the download notification.");
|
|
6048
|
+
}
|
|
6049
|
+
}
|
|
6096
6050
|
console.log(`
|
|
6097
6051
|
Setup complete!
|
|
6098
6052
|
|
|
6099
6053
|
Next steps:
|
|
6100
|
-
1.
|
|
6101
|
-
2.
|
|
6102
|
-
3.
|
|
6103
|
-
|
|
6104
|
-
The bridge runs on ws://${WS_HOST2}:${WS_PORT2} and connects
|
|
6105
|
-
Claude Code CLI to your browser via the Chrome extension.
|
|
6054
|
+
1. Start the bridge: npx claude-chrome-android
|
|
6055
|
+
2. Open a new Claude Code session \u2014 browser tools (mcp__cfc-bridge__*) will be available
|
|
6056
|
+
3. Use ToolSearch to find and load cfc-bridge tools
|
|
6106
6057
|
`);
|
|
6107
6058
|
}
|
|
6108
6059
|
async function cmdStart() {
|
|
@@ -6117,10 +6068,344 @@ async function cmdStart() {
|
|
|
6117
6068
|
} catch (err) {
|
|
6118
6069
|
console.error("Failed to start bridge:", err.message);
|
|
6119
6070
|
console.error("\nIf you installed via npm, the bridge should be bundled in this file.");
|
|
6120
|
-
console.error("Try rebuilding: cd bridge && node build.
|
|
6071
|
+
console.error("Try rebuilding: cd bridge && node build.cjs");
|
|
6121
6072
|
process.exit(1);
|
|
6122
6073
|
}
|
|
6123
6074
|
}
|
|
6075
|
+
var MCP_TOOLS = [
|
|
6076
|
+
{
|
|
6077
|
+
name: "tabs_context_mcp",
|
|
6078
|
+
description: "Get context information about the current MCP tab group. Returns all tab IDs inside the group if it exists. CRITICAL: You must get the context at least once before using other browser automation tools so you know what tabs exist.",
|
|
6079
|
+
inputSchema: {
|
|
6080
|
+
type: "object",
|
|
6081
|
+
properties: { createIfEmpty: { type: "boolean", description: "Creates a new MCP tab group if none exists." } },
|
|
6082
|
+
required: []
|
|
6083
|
+
}
|
|
6084
|
+
},
|
|
6085
|
+
{
|
|
6086
|
+
name: "tabs_create_mcp",
|
|
6087
|
+
description: "Creates a new empty tab in the MCP tab group.",
|
|
6088
|
+
inputSchema: { type: "object", properties: {}, required: [] }
|
|
6089
|
+
},
|
|
6090
|
+
{
|
|
6091
|
+
name: "navigate",
|
|
6092
|
+
description: "Navigate to a URL, or go forward/back in browser history.",
|
|
6093
|
+
inputSchema: {
|
|
6094
|
+
type: "object",
|
|
6095
|
+
properties: {
|
|
6096
|
+
url: { type: "string", description: 'URL to navigate to. Use "forward" or "back" for history.' },
|
|
6097
|
+
tabId: { type: "number", description: "Tab ID to navigate." }
|
|
6098
|
+
},
|
|
6099
|
+
required: ["url", "tabId"]
|
|
6100
|
+
}
|
|
6101
|
+
},
|
|
6102
|
+
{
|
|
6103
|
+
name: "computer",
|
|
6104
|
+
description: "Use a mouse and keyboard to interact with a web browser, and take screenshots.\n* Consult a screenshot to determine coordinates before clicking.\n* Click buttons/icons in the center of the element.",
|
|
6105
|
+
inputSchema: {
|
|
6106
|
+
type: "object",
|
|
6107
|
+
properties: {
|
|
6108
|
+
action: {
|
|
6109
|
+
type: "string",
|
|
6110
|
+
enum: ["left_click", "right_click", "type", "screenshot", "wait", "scroll", "key", "left_click_drag", "double_click", "triple_click", "zoom", "scroll_to", "hover"],
|
|
6111
|
+
description: "The action to perform."
|
|
6112
|
+
},
|
|
6113
|
+
coordinate: { type: "array", items: { type: "number" }, minItems: 2, maxItems: 2, description: "(x, y) pixel coordinates." },
|
|
6114
|
+
text: { type: "string", description: "Text to type or key(s) to press." },
|
|
6115
|
+
duration: { type: "number", minimum: 0, maximum: 30, description: "Seconds to wait." },
|
|
6116
|
+
scroll_direction: { type: "string", enum: ["up", "down", "left", "right"], description: "Scroll direction." },
|
|
6117
|
+
scroll_amount: { type: "number", minimum: 1, maximum: 10, description: "Scroll ticks (default: 3)." },
|
|
6118
|
+
start_coordinate: { type: "array", items: { type: "number" }, minItems: 2, maxItems: 2, description: "Start coords for drag." },
|
|
6119
|
+
region: { type: "array", items: { type: "number" }, minItems: 4, maxItems: 4, description: "(x0,y0,x1,y1) for zoom." },
|
|
6120
|
+
repeat: { type: "number", minimum: 1, maximum: 100, description: "Key repeat count." },
|
|
6121
|
+
ref: { type: "string", description: "Element ref ID for scroll_to." },
|
|
6122
|
+
modifiers: { type: "string", description: 'Modifier keys: "ctrl", "shift", "alt", "cmd".' },
|
|
6123
|
+
tabId: { type: "number", description: "Tab ID." }
|
|
6124
|
+
},
|
|
6125
|
+
required: ["action", "tabId"]
|
|
6126
|
+
}
|
|
6127
|
+
},
|
|
6128
|
+
{
|
|
6129
|
+
name: "javascript_tool",
|
|
6130
|
+
description: "Execute JavaScript in the page context. Returns the last expression result.",
|
|
6131
|
+
inputSchema: {
|
|
6132
|
+
type: "object",
|
|
6133
|
+
properties: {
|
|
6134
|
+
action: { type: "string", description: "Must be 'javascript_exec'" },
|
|
6135
|
+
text: { type: "string", description: "JavaScript code. Don't use 'return'." },
|
|
6136
|
+
tabId: { type: "number", description: "Tab ID." }
|
|
6137
|
+
},
|
|
6138
|
+
required: ["action", "text", "tabId"]
|
|
6139
|
+
}
|
|
6140
|
+
},
|
|
6141
|
+
{
|
|
6142
|
+
name: "read_page",
|
|
6143
|
+
description: "Get accessibility tree of page elements. Filter for interactive elements or get all.",
|
|
6144
|
+
inputSchema: {
|
|
6145
|
+
type: "object",
|
|
6146
|
+
properties: {
|
|
6147
|
+
filter: { type: "string", enum: ["interactive", "all"], description: "Element filter." },
|
|
6148
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6149
|
+
depth: { type: "number", description: "Max tree depth (default: 15)." },
|
|
6150
|
+
ref_id: { type: "string", description: "Parent element ref to focus on." },
|
|
6151
|
+
max_chars: { type: "number", description: "Max output chars (default: 50000)." }
|
|
6152
|
+
},
|
|
6153
|
+
required: ["tabId"]
|
|
6154
|
+
}
|
|
6155
|
+
},
|
|
6156
|
+
{
|
|
6157
|
+
name: "find",
|
|
6158
|
+
description: 'Find elements by natural language (e.g., "search bar", "login button").',
|
|
6159
|
+
inputSchema: {
|
|
6160
|
+
type: "object",
|
|
6161
|
+
properties: {
|
|
6162
|
+
query: { type: "string", description: "What to find." },
|
|
6163
|
+
tabId: { type: "number", description: "Tab ID." }
|
|
6164
|
+
},
|
|
6165
|
+
required: ["query", "tabId"]
|
|
6166
|
+
}
|
|
6167
|
+
},
|
|
6168
|
+
{
|
|
6169
|
+
name: "form_input",
|
|
6170
|
+
description: "Set form element values using ref ID from read_page.",
|
|
6171
|
+
inputSchema: {
|
|
6172
|
+
type: "object",
|
|
6173
|
+
properties: {
|
|
6174
|
+
ref: { type: "string", description: "Element ref ID." },
|
|
6175
|
+
value: { type: ["string", "boolean", "number"], description: "Value to set." },
|
|
6176
|
+
tabId: { type: "number", description: "Tab ID." }
|
|
6177
|
+
},
|
|
6178
|
+
required: ["ref", "value", "tabId"]
|
|
6179
|
+
}
|
|
6180
|
+
},
|
|
6181
|
+
{
|
|
6182
|
+
name: "get_page_text",
|
|
6183
|
+
description: "Extract raw text content from the page.",
|
|
6184
|
+
inputSchema: {
|
|
6185
|
+
type: "object",
|
|
6186
|
+
properties: { tabId: { type: "number", description: "Tab ID." } },
|
|
6187
|
+
required: ["tabId"]
|
|
6188
|
+
}
|
|
6189
|
+
},
|
|
6190
|
+
{
|
|
6191
|
+
name: "read_console_messages",
|
|
6192
|
+
description: "Read browser console messages. Always provide a pattern to filter.",
|
|
6193
|
+
inputSchema: {
|
|
6194
|
+
type: "object",
|
|
6195
|
+
properties: {
|
|
6196
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6197
|
+
onlyErrors: { type: "boolean", description: "Errors only." },
|
|
6198
|
+
clear: { type: "boolean", description: "Clear after reading." },
|
|
6199
|
+
pattern: { type: "string", description: "Regex filter pattern." },
|
|
6200
|
+
limit: { type: "number", description: "Max messages (default: 100)." }
|
|
6201
|
+
},
|
|
6202
|
+
required: ["tabId"]
|
|
6203
|
+
}
|
|
6204
|
+
},
|
|
6205
|
+
{
|
|
6206
|
+
name: "read_network_requests",
|
|
6207
|
+
description: "Read HTTP network requests from a tab.",
|
|
6208
|
+
inputSchema: {
|
|
6209
|
+
type: "object",
|
|
6210
|
+
properties: {
|
|
6211
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6212
|
+
urlPattern: { type: "string", description: "URL substring filter." },
|
|
6213
|
+
clear: { type: "boolean", description: "Clear after reading." },
|
|
6214
|
+
limit: { type: "number", description: "Max requests (default: 100)." }
|
|
6215
|
+
},
|
|
6216
|
+
required: ["tabId"]
|
|
6217
|
+
}
|
|
6218
|
+
},
|
|
6219
|
+
{
|
|
6220
|
+
name: "resize_window",
|
|
6221
|
+
description: "Resize browser window.",
|
|
6222
|
+
inputSchema: {
|
|
6223
|
+
type: "object",
|
|
6224
|
+
properties: {
|
|
6225
|
+
width: { type: "number", description: "Width in pixels." },
|
|
6226
|
+
height: { type: "number", description: "Height in pixels." },
|
|
6227
|
+
tabId: { type: "number", description: "Tab ID." }
|
|
6228
|
+
},
|
|
6229
|
+
required: ["width", "height", "tabId"]
|
|
6230
|
+
}
|
|
6231
|
+
},
|
|
6232
|
+
{
|
|
6233
|
+
name: "gif_creator",
|
|
6234
|
+
description: "Record and export browser session GIFs.",
|
|
6235
|
+
inputSchema: {
|
|
6236
|
+
type: "object",
|
|
6237
|
+
properties: {
|
|
6238
|
+
action: { type: "string", enum: ["start_recording", "stop_recording", "export", "clear"], description: "Action." },
|
|
6239
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6240
|
+
download: { type: "boolean", description: "Download GIF on export." },
|
|
6241
|
+
filename: { type: "string", description: "GIF filename." },
|
|
6242
|
+
options: { type: "object", description: "GIF options." }
|
|
6243
|
+
},
|
|
6244
|
+
required: ["action", "tabId"]
|
|
6245
|
+
}
|
|
6246
|
+
},
|
|
6247
|
+
{
|
|
6248
|
+
name: "upload_image",
|
|
6249
|
+
description: "Upload a screenshot to a file input or drag & drop target.",
|
|
6250
|
+
inputSchema: {
|
|
6251
|
+
type: "object",
|
|
6252
|
+
properties: {
|
|
6253
|
+
imageId: { type: "string", description: "Screenshot ID." },
|
|
6254
|
+
ref: { type: "string", description: "Element ref ID." },
|
|
6255
|
+
coordinate: { type: "array", items: { type: "number" }, description: "Drop coords [x,y]." },
|
|
6256
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6257
|
+
filename: { type: "string", description: "Filename." }
|
|
6258
|
+
},
|
|
6259
|
+
required: ["imageId", "tabId"]
|
|
6260
|
+
}
|
|
6261
|
+
},
|
|
6262
|
+
{
|
|
6263
|
+
name: "update_plan",
|
|
6264
|
+
description: "Present a plan to the user for approval.",
|
|
6265
|
+
inputSchema: {
|
|
6266
|
+
type: "object",
|
|
6267
|
+
properties: {
|
|
6268
|
+
domains: { type: "array", items: { type: "string" }, description: "Domains to visit." },
|
|
6269
|
+
approach: { type: "array", items: { type: "string" }, description: "Steps to take." }
|
|
6270
|
+
},
|
|
6271
|
+
required: ["domains", "approach"]
|
|
6272
|
+
}
|
|
6273
|
+
},
|
|
6274
|
+
{
|
|
6275
|
+
name: "shortcuts_list",
|
|
6276
|
+
description: "List available shortcuts and workflows.",
|
|
6277
|
+
inputSchema: {
|
|
6278
|
+
type: "object",
|
|
6279
|
+
properties: { tabId: { type: "number", description: "Tab ID." } },
|
|
6280
|
+
required: ["tabId"]
|
|
6281
|
+
}
|
|
6282
|
+
},
|
|
6283
|
+
{
|
|
6284
|
+
name: "shortcuts_execute",
|
|
6285
|
+
description: "Execute a shortcut or workflow.",
|
|
6286
|
+
inputSchema: {
|
|
6287
|
+
type: "object",
|
|
6288
|
+
properties: {
|
|
6289
|
+
tabId: { type: "number", description: "Tab ID." },
|
|
6290
|
+
shortcutId: { type: "string", description: "Shortcut ID." },
|
|
6291
|
+
command: { type: "string", description: "Command name." }
|
|
6292
|
+
},
|
|
6293
|
+
required: ["tabId"]
|
|
6294
|
+
}
|
|
6295
|
+
},
|
|
6296
|
+
{
|
|
6297
|
+
name: "switch_browser",
|
|
6298
|
+
description: "Switch which Chrome browser is used for automation.",
|
|
6299
|
+
inputSchema: { type: "object", properties: {}, required: [] }
|
|
6300
|
+
}
|
|
6301
|
+
];
|
|
6302
|
+
function mcpResult(id, result) {
|
|
6303
|
+
return { jsonrpc: "2.0", id, result };
|
|
6304
|
+
}
|
|
6305
|
+
function mcpError(id, code, message) {
|
|
6306
|
+
return { jsonrpc: "2.0", id, error: { code, message } };
|
|
6307
|
+
}
|
|
6308
|
+
function mcpSend(response) {
|
|
6309
|
+
process.stdout.write(JSON.stringify(response) + "\n");
|
|
6310
|
+
}
|
|
6311
|
+
async function callBridgeTool(method, params) {
|
|
6312
|
+
try {
|
|
6313
|
+
const resp = await fetch(TOOL_URL, {
|
|
6314
|
+
method: "POST",
|
|
6315
|
+
headers: { "Content-Type": "application/json" },
|
|
6316
|
+
body: JSON.stringify({ method, params }),
|
|
6317
|
+
signal: AbortSignal.timeout(TOOL_TIMEOUT_MS)
|
|
6318
|
+
});
|
|
6319
|
+
if (!resp.ok) {
|
|
6320
|
+
const body = await resp.text();
|
|
6321
|
+
return { error: `Bridge HTTP ${resp.status}: ${body}` };
|
|
6322
|
+
}
|
|
6323
|
+
const data = await resp.json();
|
|
6324
|
+
if (data.error) return { error: String(data.error) };
|
|
6325
|
+
return { result: data.result ?? data };
|
|
6326
|
+
} catch (err) {
|
|
6327
|
+
return { error: `Bridge unreachable: ${err.message}` };
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
function formatToolResult(result) {
|
|
6331
|
+
if (!result || typeof result !== "object") {
|
|
6332
|
+
return [{ type: "text", text: JSON.stringify(result) }];
|
|
6333
|
+
}
|
|
6334
|
+
const r = result;
|
|
6335
|
+
if (Array.isArray(r.content)) return r.content;
|
|
6336
|
+
if (r.data && typeof r.data === "string" && r.media_type) {
|
|
6337
|
+
return [{ type: "image", source: { type: "base64", media_type: r.media_type, data: r.data } }];
|
|
6338
|
+
}
|
|
6339
|
+
if (r.result !== void 0) return formatToolResult(r.result);
|
|
6340
|
+
return [{ type: "text", text: JSON.stringify(result, null, 2) }];
|
|
6341
|
+
}
|
|
6342
|
+
async function handleMcpRequest(req) {
|
|
6343
|
+
if (req.id === void 0 || req.id === null) return;
|
|
6344
|
+
switch (req.method) {
|
|
6345
|
+
case "initialize":
|
|
6346
|
+
mcpSend(mcpResult(req.id, {
|
|
6347
|
+
protocolVersion: "2024-11-05",
|
|
6348
|
+
capabilities: { tools: {} },
|
|
6349
|
+
serverInfo: { name: "Claude in Chrome (Bridge)", version: PKG_VERSION }
|
|
6350
|
+
}));
|
|
6351
|
+
break;
|
|
6352
|
+
case "tools/list":
|
|
6353
|
+
mcpSend(mcpResult(req.id, { tools: MCP_TOOLS }));
|
|
6354
|
+
break;
|
|
6355
|
+
case "tools/call": {
|
|
6356
|
+
const toolName = req.params?.name ?? "";
|
|
6357
|
+
const toolArgs = req.params?.arguments ?? {};
|
|
6358
|
+
const tool = MCP_TOOLS.find((t) => t.name === toolName);
|
|
6359
|
+
if (!tool) {
|
|
6360
|
+
mcpSend(mcpResult(req.id, { content: [{ type: "text", text: `Unknown tool: ${toolName}` }], isError: true }));
|
|
6361
|
+
break;
|
|
6362
|
+
}
|
|
6363
|
+
const { result, error } = await callBridgeTool(toolName, toolArgs);
|
|
6364
|
+
if (error) {
|
|
6365
|
+
mcpSend(mcpResult(req.id, { content: [{ type: "text", text: error }], isError: true }));
|
|
6366
|
+
} else {
|
|
6367
|
+
mcpSend(mcpResult(req.id, { content: formatToolResult(result) }));
|
|
6368
|
+
}
|
|
6369
|
+
break;
|
|
6370
|
+
}
|
|
6371
|
+
default:
|
|
6372
|
+
mcpSend(mcpError(req.id, -32601, `Method not found: ${req.method}`));
|
|
6373
|
+
}
|
|
6374
|
+
}
|
|
6375
|
+
async function cmdMcp() {
|
|
6376
|
+
const log2 = (msg) => process.stderr.write(`[cfc-mcp] ${msg}
|
|
6377
|
+
`);
|
|
6378
|
+
log2(`MCP server v${PKG_VERSION} \u2014 bridge at ${BRIDGE_URL}`);
|
|
6379
|
+
try {
|
|
6380
|
+
const h = await fetch(HEALTH_URL, { signal: AbortSignal.timeout(2e3) });
|
|
6381
|
+
const d = await h.json();
|
|
6382
|
+
log2(`Bridge OK: clients=${d.clients}, v${d.version}`);
|
|
6383
|
+
} catch {
|
|
6384
|
+
log2("Bridge not reachable \u2014 tool calls will fail until bridge starts");
|
|
6385
|
+
}
|
|
6386
|
+
const decoder = new TextDecoder();
|
|
6387
|
+
let buffer = "";
|
|
6388
|
+
for await (const chunk of process.stdin) {
|
|
6389
|
+
buffer += typeof chunk === "string" ? chunk : decoder.decode(chunk);
|
|
6390
|
+
let idx;
|
|
6391
|
+
while ((idx = buffer.indexOf("\n")) !== -1) {
|
|
6392
|
+
const line = buffer.slice(0, idx).trim();
|
|
6393
|
+
buffer = buffer.slice(idx + 1);
|
|
6394
|
+
if (!line) continue;
|
|
6395
|
+
try {
|
|
6396
|
+
const req = JSON.parse(line);
|
|
6397
|
+
handleMcpRequest(req).catch((err) => {
|
|
6398
|
+
log2(`Error: ${req.method}: ${err.message}`);
|
|
6399
|
+
if (req.id != null) mcpSend(mcpError(req.id, -32603, err.message));
|
|
6400
|
+
});
|
|
6401
|
+
} catch (err) {
|
|
6402
|
+
log2(`Bad JSON-RPC: ${err.message}`);
|
|
6403
|
+
}
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
log2("stdin closed");
|
|
6407
|
+
process.exit(0);
|
|
6408
|
+
}
|
|
6124
6409
|
var args = process.argv.slice(2);
|
|
6125
6410
|
var command = args[0] ?? "";
|
|
6126
6411
|
switch (command) {
|
|
@@ -6138,6 +6423,9 @@ switch (command) {
|
|
|
6138
6423
|
case "--setup":
|
|
6139
6424
|
cmdSetup();
|
|
6140
6425
|
break;
|
|
6426
|
+
case "--mcp":
|
|
6427
|
+
cmdMcp();
|
|
6428
|
+
break;
|
|
6141
6429
|
case "":
|
|
6142
6430
|
cmdStart();
|
|
6143
6431
|
break;
|