shellway 0.8.5 → 0.8.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.
@@ -92,13 +92,22 @@ function disconnect() {
92
92
  port = null; connected = false; badge(); detachAll();
93
93
  }
94
94
 
95
+ // 0.8.6: lets the Shellway app tell Edge and Chrome apart when the extension runs in both at once.
96
+ function browserName() {
97
+ const ua = (self.navigator && navigator.userAgent) || '';
98
+ if (/Edg\//.test(ua)) return 'edge';
99
+ if (/OPR\//.test(ua)) return 'opera';
100
+ if (self.navigator && navigator.brave) return 'brave';
101
+ if (/Chrome\//.test(ua)) return 'chrome';
102
+ return 'browser';
103
+ }
95
104
  async function onMessage(m) {
96
105
  if (!m || typeof m !== 'object') return;
97
106
  if (m.type === 'hello') {
98
107
  connected = true; agentVersion = m.version || ''; lastError = ''; badge();
99
108
  // 0.7.2: the Shellway app refreshed this extension's folder (a newer version): reload once to use the new files.
100
109
  const mine = chrome.runtime.getManifest().version;
101
- if (port) port.postMessage({ type: 'ext', version: mine }); // 0.7.3: tell the Shellway app which version runs here
110
+ if (port) port.postMessage({ type: 'ext', version: mine, browser: browserName() }); // 0.7.3: version; 0.8.6: and which browser
102
111
  if (m.extVersion && m.extVersion !== mine) {
103
112
  const { reloadedFor } = await chrome.storage.local.get({ reloadedFor: '' });
104
113
  if (reloadedFor !== m.extVersion) { await chrome.storage.local.set({ reloadedFor: m.extVersion }); chrome.runtime.reload(); }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Shellway",
4
- "version": "0.8.5",
4
+ "version": "0.8.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellway",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "Shellway agent: lets ChatGPT, Claude and Cursor work on this computer through the Shellway relay.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -29,5 +29,5 @@
29
29
  },
30
30
  "author": "Sandeep Kumar Saini",
31
31
  "license": "UNLICENSED",
32
- "shellwayStable": "0.8.4"
32
+ "shellwayStable": "0.8.5"
33
33
  }
package/shellway.js CHANGED
@@ -10,7 +10,7 @@ import { readFile, writeFile, appendFile, readdir, stat, lstat, mkdir, rename, c
10
10
  import { createServer as netServer, connect as netConnect } from 'node:net';
11
11
  import { randomBytes, timingSafeEqual, createHash } from 'node:crypto';
12
12
 
13
- const AGENT_VERSION = '0.8.5'; // keep equal to agent/package.json
13
+ const AGENT_VERSION = '0.8.6'; // keep equal to agent/package.json
14
14
  if (Number(process.versions.node.split('.')[0]) < 22) {
15
15
  console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
16
16
  process.exit(1);
@@ -1005,43 +1005,73 @@ const EXT_IDS = [
1005
1005
  'jaebfnkgmaopbkikeigclembnhbdlldc', // 0.7.4: the Edge Add-ons store version (Partner Center CRX ID, 21 Nov 2026)
1006
1006
  ];
1007
1007
  const EXT_OFF = 'The Shellway extension is not connected. On that computer: open Edge or Chrome, click the Shellway extension icon and turn it on. (First time: npx shellway@latest policy browser extension; on Edge install Shellway from the Edge Add-ons store: https://microsoftedge.microsoft.com/addons/detail/jaebfnkgmaopbkikeigclembnhbdlldc)';
1008
- const ext = { sock: null, seq: 0, pending: new Map(), version: '' };
1008
+ // 0.8.6 (27 Nov 2026, beta): one link per browser (e.g. Edge and Chrome at the same time). The browser tools use the
1009
+ // current one: the browser the AI chose with browser_use, otherwise the one that connected last (as before).
1010
+ const STORE_EDGE = 'jaebfnkgmaopbkikeigclembnhbdlldc';
1011
+ const NO_PENDING = new Map();
1012
+ const ext = { seq: 0, links: new Map(), cur: null, pinned: '',
1013
+ get sock() { return this.cur ? this.cur.sock : null; },
1014
+ get version() { return this.cur ? this.cur.version : ''; },
1015
+ get pending() { return this.cur ? this.cur.pending : NO_PENDING; } };
1009
1016
  const extMode = () => { const p = loadPolicy(); return !!p && p.browser === 'extension'; };
1010
- function extAttach(sock, rest) {
1011
- if (ext.sock && ext.sock !== sock) { try { ext.sock.destroy(); } catch {} }
1012
- ext.sock = sock;
1017
+ const browserLabel = (b) => ({ edge: 'Edge', chrome: 'Chrome', brave: 'Brave', opera: 'Opera', chromium: 'Chromium' }[b] || b);
1018
+ function extUse(L) { if (ext.cur !== L) { ext.cur = L; try { activeTarget = null; } catch {} } }
1019
+ function extAttach(sock, rest, hello = {}) {
1020
+ let name = String(hello.browser || '').toLowerCase().replace(/[^a-z0-9-]/g, '').slice(0, 20);
1021
+ if (!name) name = String(hello.origin || '').includes(STORE_EDGE) ? 'edge' : 'browser';
1022
+ const old = ext.links.get(name);
1023
+ if (old && old.sock !== sock) { try { old.sock.destroy(); } catch {} }
1024
+ const L = { sock, browser: name, version: '', pending: new Map(), since: Date.now() };
1025
+ ext.links.set(name, L);
1026
+ if (!ext.pinned || ext.pinned === name || !ext.links.has(ext.pinned)) extUse(L);
1013
1027
  let buf = rest || '';
1014
1028
  const take = () => {
1015
1029
  let i;
1016
1030
  while ((i = buf.indexOf('\n')) >= 0) {
1017
1031
  const line = buf.slice(0, i); buf = buf.slice(i + 1);
1018
1032
  let m; try { m = JSON.parse(line); } catch { continue; }
1019
- if (m && m.type === 'ext') { ext.version = String(m.version || '').slice(0, 20); continue; } // 0.7.3: version running in the browser
1020
- const p = m && m.id !== undefined && ext.pending.get(m.id);
1033
+ if (m && m.type === 'ext') { // 0.7.3: version running in the browser; 0.8.6: and which browser it is
1034
+ L.version = String(m.version || '').slice(0, 20);
1035
+ const b = String(m.browser || '').toLowerCase().replace(/[^a-z0-9-]/g, '').slice(0, 20);
1036
+ if (b && b !== L.browser) {
1037
+ if (ext.links.get(L.browser) === L) ext.links.delete(L.browser);
1038
+ const other = ext.links.get(b); if (other && other !== L) { try { other.sock.destroy(); } catch {} }
1039
+ L.browser = b; ext.links.set(b, L);
1040
+ if (ext.pinned === b) extUse(L);
1041
+ }
1042
+ continue;
1043
+ }
1044
+ const p = m && m.id !== undefined && L.pending.get(m.id);
1021
1045
  if (!p) continue;
1022
- ext.pending.delete(m.id); clearTimeout(p.timer);
1046
+ L.pending.delete(m.id); clearTimeout(p.timer);
1023
1047
  m.ok ? p.ok(m.result) : p.no(new Error(m.error || 'The browser extension reported an error'));
1024
1048
  }
1025
1049
  };
1026
1050
  sock.on('data', (d) => { buf += d.toString('utf8'); take(); });
1051
+ let done = false;
1027
1052
  const gone = () => {
1028
- if (ext.sock !== sock) return;
1029
- ext.sock = null; ext.version = '';
1030
- for (const p of ext.pending.values()) { clearTimeout(p.timer); p.no(new Error('The browser extension disconnected (the browser was closed or Shellway was turned off there).')); }
1031
- ext.pending.clear();
1053
+ if (done) return; done = true;
1054
+ if (ext.links.get(L.browser) === L) ext.links.delete(L.browser);
1055
+ for (const p of L.pending.values()) { clearTimeout(p.timer); p.no(new Error('The browser extension disconnected (the browser was closed or Shellway was turned off there).')); }
1056
+ L.pending.clear();
1057
+ if (ext.cur === L) { const next = (ext.pinned && ext.links.get(ext.pinned)) || [...ext.links.values()].sort((a, b) => b.since - a.since)[0] || null; ext.cur = null; if (next) extUse(next); else { try { activeTarget = null; } catch {} } }
1032
1058
  };
1033
1059
  sock.on('close', gone); sock.on('error', gone);
1034
1060
  take();
1035
1061
  }
1036
1062
  function extCall(op, args = {}, ms = 30_000) {
1037
- if (!ext.sock) return Promise.reject(new Error(EXT_OFF));
1063
+ const L = ext.cur;
1064
+ if (!L || !L.sock) return Promise.reject(new Error(EXT_OFF));
1038
1065
  return new Promise((ok, no) => {
1039
1066
  const id = ++ext.seq;
1040
- const timer = setTimeout(() => { if (ext.pending.delete(id)) no(new Error(`The browser did not answer (${op}${args.method ? ' ' + args.method : ''})`)); }, ms);
1041
- ext.pending.set(id, { ok, no, timer });
1042
- ext.sock.write(JSON.stringify({ id, op, args }) + '\n');
1067
+ const timer = setTimeout(() => { if (L.pending.delete(id)) no(new Error(`The browser did not answer (${op}${args.method ? ' ' + args.method : ''})`)); }, ms);
1068
+ L.pending.set(id, { ok, no, timer });
1069
+ L.sock.write(JSON.stringify({ id, op, args }) + '\n');
1043
1070
  });
1044
1071
  }
1072
+ function extBrowsers() {
1073
+ return [...ext.links.values()].sort((a, b) => a.since - b.since).map((L) => ({ browser: L.browser, name: browserLabel(L.browser), extension_version: L.version || null, in_use: L === ext.cur, connected_since: new Date(L.since).toISOString() }));
1074
+ }
1045
1075
  async function extJson(path) {
1046
1076
  if (path === '/json/version') return { ok: true };
1047
1077
  if (path === '/json/list') return (await extCall('list')).map((t) => ({ ...t, webSocketDebuggerUrl: 'ext:' + t.id }));
@@ -1063,11 +1093,11 @@ function startExtBridge() {
1063
1093
  const i = head.indexOf('\n');
1064
1094
  if (i < 0) { if (head.length > 4096) sock.destroy(); return; }
1065
1095
  sock.off('data', onHead); clearTimeout(t);
1066
- let given = '';
1067
- try { given = String(JSON.parse(head.slice(0, i)).token || ''); } catch {}
1096
+ let given = '', hello = {};
1097
+ try { hello = JSON.parse(head.slice(0, i)) || {}; given = String(hello.token || ''); } catch {}
1068
1098
  const a = Buffer.from(given), b = Buffer.from(token);
1069
1099
  if (a.length !== b.length || !timingSafeEqual(a, b)) { sock.destroy(); return; }
1070
- extAttach(sock, head.slice(i + 1));
1100
+ extAttach(sock, head.slice(i + 1), { browser: hello.browser, origin: hello.origin });
1071
1101
  };
1072
1102
  sock.on('data', onHead);
1073
1103
  sock.on('error', () => {});
@@ -1092,7 +1122,8 @@ function nativeHost() {
1092
1122
  if (!info || !info.port) { frame({ type: 'error', message: 'The Shellway app is not running on this computer.' }); setTimeout(() => process.exit(0), 200); return; }
1093
1123
  const sock = netConnect(info.port, '127.0.0.1');
1094
1124
  let up = false;
1095
- sock.on('connect', () => { up = true; sock.write(JSON.stringify({ token: info.token }) + '\n'); frame({ type: 'hello', version: AGENT_VERSION, extVersion: extFolderVersion() }); });
1125
+ const origin = process.argv.find((a) => String(a).startsWith('chrome-extension://')) || '';
1126
+ sock.on('connect', () => { up = true; sock.write(JSON.stringify({ token: info.token, origin }) + '\n'); frame({ type: 'hello', version: AGENT_VERSION, extVersion: extFolderVersion() }); });
1096
1127
  const bye = (msg) => { if (msg) try { frame({ type: 'error', message: msg }); } catch {} setTimeout(() => process.exit(0), 200); };
1097
1128
  sock.on('error', () => bye(up ? '' : 'The Shellway app is not running on this computer.'));
1098
1129
  sock.on('close', () => bye(''));
@@ -1155,7 +1186,7 @@ function installExtensionHost() {
1155
1186
  }
1156
1187
  const extConnected = () => !!ext.sock;
1157
1188
  const extVersion = () => ext.version;
1158
- export { nativeHostManifest, nativeHostTargets, extJson, extCall, startExtBridge, extConnected, extVersion, installExtensionHost, SNAPSHOT_JS };
1189
+ export { nativeHostManifest, nativeHostTargets, extJson, extCall, startExtBridge, extConnected, extVersion, extBrowsers, installExtensionHost, SNAPSHOT_JS };
1159
1190
  // 0.7.5: one free trial per computer (owner 21 Nov 2026). The computer's own built-in ID (Windows MachineGuid, Mac
1160
1191
  // hardware UUID, Linux machine-id) does not change when the computer or the account is renamed. Only a one-way code
1161
1192
  // made from it is sent; the ID itself never leaves the computer.
@@ -1487,7 +1518,7 @@ const browserHandlers = {
1487
1518
  }
1488
1519
  const list = await browserPages();
1489
1520
  if (!list.length) return extMode() ? `No Shellway AI tabs are open${ext.version ? ` (Shellway extension v${ext.version})` : ''}. (In the user's own browser the AI sees only the tabs it opened, unless the owner allows "my other tabs" in the Shellway extension.) Open one with browser_open.` : 'No tabs are open.';
1490
- if (a === 'list' && extMode()) return `(The user's own browser, Shellway extension${ext.version ? ' v' + ext.version : ''})\n` + list.map((t, i) => `${i + 1}. ${t.id === activeTarget ? '(active) ' : ''}${redactTitle(t.title, t.url) || '(no title)'} — ${redactUrl(t.url)}`).join('\n');
1521
+ if (a === 'list' && extMode()) return `(The user's own browser${ext.links.size > 1 && ext.cur ? ` — ${browserLabel(ext.cur.browser)}, one of ${ext.links.size} connected (browser_select)` : ''}, Shellway extension${ext.version ? ' v' + ext.version : ''})\n` + list.map((t, i) => `${i + 1}. ${t.id === activeTarget ? '(active) ' : ''}${redactTitle(t.title, t.url) || '(no title)'} — ${redactUrl(t.url)}`).join('\n');
1491
1522
  if (a === 'list') return list.map((t, i) => `${i + 1}. ${t.id === activeTarget ? '(active) ' : ''}${redactTitle(t.title, t.url) || '(no title)'} — ${redactUrl(t.url)}`).join('\n');
1492
1523
  const t = list[(Number(index) | 0) - 1];
1493
1524
  if (!t) throw new Error(`No tab number ${index}. Use action "list" to see the tabs.`);
@@ -1495,6 +1526,22 @@ const browserHandlers = {
1495
1526
  if (a === 'close') { if (readonly) throw new Error('This computer is in read-only mode'); await cdpJson(`/json/close/${t.id}`); if (activeTarget === t.id) activeTarget = null; return `Closed tab ${index}.`; }
1496
1527
  throw new Error('action must be list, switch, new, close, back, forward or reload');
1497
1528
  },
1529
+ // 0.8.6 (beta): which browsers have the Shellway extension connected, and which one the browser tools use
1530
+ async browser_browsers() {
1531
+ if (!extMode()) return 'Browser control uses Shellway\'s own browser window on this computer (not the extension), so there is nothing to choose.';
1532
+ const list = extBrowsers();
1533
+ if (!list.length) throw new Error(EXT_OFF);
1534
+ return list.map((b) => `${b.in_use ? '(in use) ' : ''}${b.browser} — ${b.name}${b.extension_version ? `, Shellway extension v${b.extension_version}` : ''}`).join('\n')
1535
+ + (list.length > 1 ? '\nChoose one with browser_select and browser "<name>".' : '');
1536
+ },
1537
+ async browser_use({ browser }) {
1538
+ if (!extMode()) throw new Error('Choosing the browser works only with the Shellway extension (npx shellway policy browser extension).');
1539
+ const want = String(browser || '').toLowerCase().trim();
1540
+ const L = ext.links.get(want) || [...ext.links.values()].find((x) => browserLabel(x.browser).toLowerCase() === want);
1541
+ if (!L) throw new Error(`"${browser}" is not connected. Connected: ${extBrowsers().map((b) => b.browser).join(', ') || 'none'}.`);
1542
+ ext.pinned = L.browser; extUse(L);
1543
+ return `Browser tools now use ${browserLabel(L.browser)}${L.version ? ` (Shellway extension v${L.version})` : ''}. Open a page with browser_open (tabs from the other browser are not used).`;
1544
+ },
1498
1545
  };
1499
1546
  const BROWSER_METHODS = new Set(Object.keys(browserHandlers));
1500
1547
  function checkBrowser(method, params) {