shellway 0.7.5 → 0.7.6
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/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/shellway.js +41 -9
package/extension/manifest.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "Shellway",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.6",
|
|
5
5
|
"description": "Lets your AI (ChatGPT, Claude) use this browser through the Shellway app on your computer. Off until you turn it on.",
|
|
6
6
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnZWALJr6dwkQu7eX3reFbtgMAErsCyODHKnwz97XMKpR9bAz4+irBlJ2KEXD6ERZFjuKYqNZ2HLe0eQp5y9fWscyWeTUXNTstsFaymsb5C0aRcpW/dXRl2Dy9vQ7y7+ATH4SCxcckncfmEXt4GFQ6TtyPsctuQfYez6o9MHmwGaKwpCPaWmqfYqomy0yjzMCbCg2b0aP2+hDmOhc0KARhGVnzlZBIBSybtkpAmzXfUxMJHDD5ly3g6ScCcR+3Zf7SKyCfLMGSkwYwiJvvS4sNCtBzwKdDdbEh865T7H5NCS8GOhSt0hxkPPxpbTlXrWXINDiSkF00/b7ZToBRTmK4QIDAQAB",
|
|
7
7
|
"minimum_chrome_version": "116",
|
package/package.json
CHANGED
package/shellway.js
CHANGED
|
@@ -9,7 +9,7 @@ import { readFile, writeFile, appendFile, readdir, stat, lstat, mkdir, rename, c
|
|
|
9
9
|
import { createServer as netServer, connect as netConnect } from 'node:net';
|
|
10
10
|
import { randomBytes, timingSafeEqual, createHash } from 'node:crypto';
|
|
11
11
|
|
|
12
|
-
const AGENT_VERSION = '0.7.
|
|
12
|
+
const AGENT_VERSION = '0.7.6'; // keep equal to agent/package.json
|
|
13
13
|
if (Number(process.versions.node.split('.')[0]) < 22) {
|
|
14
14
|
console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
|
|
15
15
|
process.exit(1);
|
|
@@ -1527,13 +1527,26 @@ function start() {
|
|
|
1527
1527
|
// (send-buffer size, timer gaps) are only a fallback for an old relay that never answers. After each new connection the
|
|
1528
1528
|
// agent reports its Node.js version, the reason, and the connection id it left, so the relay drops that one at once.
|
|
1529
1529
|
const TICK = Number(process.env.SHELLWAY_TICK_MS) || 15_000, KA_TIMEOUT = Number(process.env.SHELLWAY_KA_TIMEOUT_MS) || 75_000;
|
|
1530
|
+
// 0.7.6 (customer report 21 Nov: ~2,980 connect/disconnect cycles on Windows, no way to tell why): every log line gets a
|
|
1531
|
+
// UTC time; each closed link logs its close code, reason, wasClean, lifetime and what came back from Shellway, and the
|
|
1532
|
+
// next connection reports that summary to the relay. A link that never gets an answer from Shellway within
|
|
1533
|
+
// NO_REPLY_MS is treated as blocked (antivirus web protection / VPN / proxy) and replaced at once.
|
|
1534
|
+
const NO_REPLY_MS = Number(process.env.SHELLWAY_NO_REPLY_MS) || 20_000;
|
|
1535
|
+
if (!console.__swStamped) {
|
|
1536
|
+
const stamp = (fn) => (...a) => fn(new Date().toISOString().slice(0, 19) + 'Z', ...a);
|
|
1537
|
+
console.log = stamp(console.log.bind(console)); console.error = stamp(console.error.bind(console)); console.__swStamped = true;
|
|
1538
|
+
}
|
|
1530
1539
|
let current = null, lastTick = Date.now(), gen = 0, connectingSince = 0;
|
|
1531
1540
|
let lastMsg = Date.now(), kaSeen = false, cid = null, prevCid = null, why = 'start';
|
|
1541
|
+
let conn = null, lastClose = null, blockedRuns = 0;
|
|
1542
|
+
const clean = (x) => String(x || '').replace(/Bearer\s+\S+/gi, 'Bearer ***').replace(/[\r\n]+/g, ' ').slice(0, 120);
|
|
1543
|
+
const summary = (c, extra = {}) => c ? { secs: Math.round((Date.now() - c.openedAt) / 1000), rx: c.rx, ka: c.ka, tx: c.tx, quiet: Math.round((Date.now() - (c.lastRx || c.openedAt)) / 1000), ...extra } : extra;
|
|
1532
1544
|
const reconnectNow = (reason) => {
|
|
1533
1545
|
const w = current; if (!w) return;
|
|
1534
1546
|
current = null; w.onclose = null; w.onmessage = null;
|
|
1547
|
+
lastClose = summary(conn, { by: 'agent', reason });
|
|
1535
1548
|
try { w.close(); } catch {}
|
|
1536
|
-
console.log(`${reason} — reconnecting
|
|
1549
|
+
console.log(`${reason} — reconnecting… (link lived ${lastClose.secs}s, ${lastClose.rx} messages from Shellway, ${lastClose.ka} keepalive answers)`);
|
|
1537
1550
|
why = reason; prevCid = cid; cid = null;
|
|
1538
1551
|
delay = 1000; setTimeout(connect, 500);
|
|
1539
1552
|
};
|
|
@@ -1548,11 +1561,17 @@ function start() {
|
|
|
1548
1561
|
}
|
|
1549
1562
|
const w = current; if (!w || w.readyState !== 1) return;
|
|
1550
1563
|
const quiet = t - lastMsg;
|
|
1564
|
+
// 0.7.6: keepalives went out but Shellway's answers never arrived on this link -> something between is holding them.
|
|
1565
|
+
if (conn && conn.ka === 0 && conn.tx >= 1 && t - conn.openedAt > NO_REPLY_MS) {
|
|
1566
|
+
blockedRuns++;
|
|
1567
|
+
if (blockedRuns === 3) console.error('Shellway\'s answers are not reaching this computer. An antivirus "web protection / HTTPS scanning", VPN or proxy is probably holding them: add mcp.getshellway.com to its exceptions (or pause it) and Shellway will stay connected.');
|
|
1568
|
+
return reconnectNow('No answers from Shellway on this link');
|
|
1569
|
+
}
|
|
1551
1570
|
if (slept && quiet > 30_000) return reconnectNow('Computer woke up');
|
|
1552
1571
|
if (kaSeen) { if (quiet > KA_TIMEOUT) return reconnectNow('No answer from Shellway'); }
|
|
1553
1572
|
// fallback for a relay without keepalive answers. 0.6.5: check the buffer BEFORE sending (right after send() it always holds the new frame)
|
|
1554
1573
|
else if (w.bufferedAmount > 0) { w._stuck = (w._stuck || 0) + 1; if (w._stuck >= 8) return reconnectNow('Connection stuck'); } else w._stuck = 0;
|
|
1555
|
-
try { w.send('{"type":"keepalive"}'); } catch { return reconnectNow('Connection lost'); }
|
|
1574
|
+
try { w.send('{"type":"keepalive"}'); if (conn) conn.tx++; } catch { return reconnectNow('Connection lost'); }
|
|
1556
1575
|
}, TICK);
|
|
1557
1576
|
const connect = async () => {
|
|
1558
1577
|
const my = ++gen; connectingSince = Date.now();
|
|
@@ -1560,13 +1579,16 @@ function start() {
|
|
|
1560
1579
|
if (my !== gen) return; // a newer attempt took over while the check was running
|
|
1561
1580
|
const ws = new WebSocket(wsUrl, { headers: { authorization: `Bearer ${conf.device_token}`, 'x-shellway-version': AGENT_VERSION } });
|
|
1562
1581
|
current = ws;
|
|
1563
|
-
ws.onopen = () => { if (my !== gen) { try { ws.close(); } catch {} return; } connectingSince = 0;
|
|
1564
|
-
|
|
1565
|
-
|
|
1582
|
+
ws.onopen = () => { if (my !== gen) { try { ws.close(); } catch {} return; } connectingSince = 0; lastMsg = Date.now();
|
|
1583
|
+
// 0.7.6: the retry delay is reset only after a link has really worked for a minute (see onclose), not on every open.
|
|
1584
|
+
conn = { openedAt: Date.now(), rx: 0, ka: 0, tx: 0, lastRx: 0, err: '' };
|
|
1585
|
+
try { ws.send(JSON.stringify({ type: 'info', v: AGENT_VERSION, node: process.versions.node, os: platform(), reason: why, ...(machineHash() ? { mid: machineHash() } : {}), ...(prevCid ? { replaced: prevCid } : {}), ...(lastClose ? { last: lastClose } : {}) })); } catch {}
|
|
1586
|
+
why = 'network'; prevCid = null; lastClose = null; console.log(`Connected as "${conf.device_name}"${readonly ? ' (read-only)' : ''}. Leave this running.`); };
|
|
1566
1587
|
ws.onmessage = async (ev) => {
|
|
1567
1588
|
lastMsg = Date.now();
|
|
1589
|
+
if (conn && current === ws) { conn.rx++; conn.lastRx = lastMsg; }
|
|
1568
1590
|
let m; try { m = JSON.parse(String(ev.data)); } catch { return; }
|
|
1569
|
-
if (m.type === 'ka') { kaSeen = true; return; }
|
|
1591
|
+
if (m.type === 'ka') { kaSeen = true; if (conn && current === ws) { conn.ka++; blockedRuns = 0; } return; }
|
|
1570
1592
|
if (m.type === 'hello') { if (typeof m.cid === 'string') cid = m.cid; return; }
|
|
1571
1593
|
if (!m.id) return;
|
|
1572
1594
|
try {
|
|
@@ -1575,8 +1597,18 @@ function start() {
|
|
|
1575
1597
|
ws.send(JSON.stringify({ id: m.id, error: e.message }));
|
|
1576
1598
|
}
|
|
1577
1599
|
};
|
|
1578
|
-
ws.onclose = () => {
|
|
1579
|
-
|
|
1600
|
+
ws.onclose = (ev) => {
|
|
1601
|
+
if (my !== gen) return;
|
|
1602
|
+
if (current === ws) current = null; connectingSince = 0; prevCid = cid; cid = null;
|
|
1603
|
+
const opened = !!(conn && conn.openedAt);
|
|
1604
|
+
lastClose = summary(opened ? conn : null, { by: 'close', code: Number(ev && ev.code) || 0, why: clean(ev && ev.reason), clean: !!(ev && ev.wasClean), err: conn ? conn.err : '' });
|
|
1605
|
+
if (opened && lastClose.secs >= 60) delay = 1000; // the link worked: start again quickly
|
|
1606
|
+
const wait = Math.round(delay * (1 + Math.random() * 0.3));
|
|
1607
|
+
console.log(`Disconnected (code ${lastClose.code}${lastClose.why ? ' "' + lastClose.why + '"' : ''}, ${lastClose.clean ? 'clean' : 'not clean'}${opened ? `, lived ${lastClose.secs}s, ${lastClose.rx} messages / ${lastClose.ka} keepalive answers from Shellway, last one ${lastClose.quiet}s ago` : ', never opened'}${lastClose.err ? ', error: ' + lastClose.err : ''}). Retrying in ${Math.round(wait / 1000)}s…`);
|
|
1608
|
+
conn = null;
|
|
1609
|
+
setTimeout(connect, wait); delay = Math.min(delay * 2, 30_000);
|
|
1610
|
+
};
|
|
1611
|
+
ws.onerror = (ev) => { const e = clean((ev && (ev.message || (ev.error && (ev.error.code || ev.error.message)))) || 'error'); if (conn && current === ws) conn.err = e; else console.error(`Connection error: ${e}`); };
|
|
1580
1612
|
};
|
|
1581
1613
|
connect();
|
|
1582
1614
|
}
|