shellway 0.8.2 → 0.8.4

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Shellway",
4
- "version": "0.8.2",
4
+ "version": "0.8.4",
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.2",
3
+ "version": "0.8.4",
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.7.7"
32
+ "shellwayStable": "0.8.3"
33
33
  }
package/shellway.js CHANGED
@@ -2,14 +2,15 @@
2
2
  import { spawn } from 'node:child_process';
3
3
  import { homedir, hostname, platform, release } from 'node:os';
4
4
  import { join, resolve, dirname, basename, sep } from 'node:path';
5
- import { mkdirSync, readFileSync, writeFileSync, chmodSync, existsSync, copyFileSync, rmSync, statSync, realpathSync, cpSync } from 'node:fs';
5
+ import { mkdirSync, readFileSync, writeFileSync, chmodSync, existsSync, copyFileSync, rmSync, statSync, realpathSync, cpSync, renameSync } from 'node:fs';
6
+ import { gunzipSync } from 'node:zlib';
6
7
  import { fileURLToPath } from 'node:url';
7
- import { execFileSync, execFile } from 'node:child_process';
8
+ import { execFileSync, execFile, spawnSync } from 'node:child_process';
8
9
  import { readFile, writeFile, appendFile, readdir, stat, lstat, mkdir, rename, cp, rm, open as fsOpen } from 'node:fs/promises';
9
10
  import { createServer as netServer, connect as netConnect } from 'node:net';
10
11
  import { randomBytes, timingSafeEqual, createHash } from 'node:crypto';
11
12
 
12
- const AGENT_VERSION = '0.8.2'; // keep equal to agent/package.json
13
+ const AGENT_VERSION = '0.8.4'; // keep equal to agent/package.json
13
14
  if (Number(process.versions.node.split('.')[0]) < 22) {
14
15
  console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
15
16
  process.exit(1);
@@ -684,12 +685,12 @@ function policyCli() {
684
685
  p.browser = 'extension';
685
686
  const r = installExtensionHost();
686
687
  console.log(`Browser control ON, in YOUR OWN Edge/Chrome through the Shellway extension (your sign-ins are used; banking, trading,
687
- payment and password sites are blocked in the extension).${r.agentFile.includes('_npx') ? '\nNote: run "npx shellway@beta service install" first so the extension can always reach Shellway.' : ''}
688
+ payment and password sites are blocked in the extension).${r.agentFile.includes('_npx') ? '\nNote: run "npx shellway@latest service install" first so the extension can always reach Shellway.' : ''}
688
689
  One-time setup in the browser:
689
- 1. Open edge://extensions (Edge) or chrome://extensions (Chrome)
690
- 2. Turn on "Developer mode"
691
- 3. Click "Load unpacked" and choose the folder: ${r.extDest || '(extension folder missing in this package)'}
692
- 4. Click the Shellway icon in the toolbar (puzzle piece -> pin it) and turn it on.
690
+ Edge: install "Shellway" from the Edge Add-ons store: https://microsoftedge.microsoft.com/addons/detail/jaebfnkgmaopbkikeigclembnhbdlldc
691
+ Chrome: open chrome://extensions, turn on "Developer mode", click "Load unpacked" and choose the folder:
692
+ ${r.extDest || '(extension folder missing in this package)'}
693
+ Then click the Shellway icon in the toolbar (puzzle piece -> pin it) and turn it on.
693
694
  To stop at any time: turn it off in the Shellway icon, press Cancel on the "debugging this browser" bar, or: shellway policy browser off`);
694
695
  }
695
696
  else if (sub === 'browser' && (val === 'on' || val === 'off')) {
@@ -1003,7 +1004,7 @@ const EXT_IDS = [
1003
1004
  'cepfcfgajaghchkamfmnhgcelblihndk', // the unpacked extension (fixed by the key in its manifest)
1004
1005
  'jaebfnkgmaopbkikeigclembnhbdlldc', // 0.7.4: the Edge Add-ons store version (Partner Center CRX ID, 21 Nov 2026)
1005
1006
  ];
1006
- 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@beta policy browser extension, then load the extension as shown.)';
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)';
1007
1008
  const ext = { sock: null, seq: 0, pending: new Map(), version: '' };
1008
1009
  const extMode = () => { const p = loadPolicy(); return !!p && p.browser === 'extension'; };
1009
1010
  function extAttach(sock, rest) {
@@ -1526,6 +1527,96 @@ export function readAlive(maxAgeMs = 90_000, t = Date.now()) {
1526
1527
  function readLinkState() { try { return JSON.parse(readFileSync(LINK_STATE, 'utf8')) || {}; } catch { return {}; } }
1527
1528
  function writeLinkState(st) { try { mkdirSync(CONF_DIR, { recursive: true }); writeFileSync(LINK_STATE, JSON.stringify(st)); } catch {} }
1528
1529
  const linkState = { transport: 'ws', connectedAt: 0, links: 0, lastClose: null, journal: 0, startedAt: Date.now() };
1530
+ // ---- 0.8.3: automatic updates (owner 24 Nov 2026) ----
1531
+ // Only the background copy (~/.shellway/agent.mjs, made by "shellway service install") updates itself. Every 6 hours it
1532
+ // asks the npm registry which version is "latest" (the stable channel Shellway sets). If it is newer, it downloads the
1533
+ // package, checks npm's sha512 integrity, takes shellway.js out of it, checks that it parses, keeps the current file as
1534
+ // agent.prev.mjs and restarts (the service starts the new file). It never updates while a command or a background
1535
+ // process is running. After the restart the new version must connect within 3 minutes, or the old file comes back and
1536
+ // that version is skipped. Turn it off: "shellway auto-update off" (or SHELLWAY_NO_AUTO_UPDATE=1).
1537
+ const AU_PENDING = () => join(CONF_DIR, 'update-pending.json'), AU_SKIP = () => join(CONF_DIR, 'update-skip.json'), AU_OFF = () => join(CONF_DIR, 'auto-update-off');
1538
+ export function newerVersion(a, b) { // true when version a is newer than b
1539
+ const p = (v) => String(v || '').split('.').map((n) => parseInt(n, 10) || 0);
1540
+ const x = p(a), y = p(b);
1541
+ for (let i = 0; i < 3; i++) if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) > (y[i] || 0);
1542
+ return false;
1543
+ }
1544
+ export function tarExtract(buf, want) { // one file out of an (uncompressed) tar archive
1545
+ const str = (b) => b.toString('utf8').replace(/\0[\s\S]*$/, '');
1546
+ for (let o = 0; o + 512 <= buf.length;) {
1547
+ const h = buf.subarray(o, o + 512);
1548
+ if (h.every((b) => b === 0)) break;
1549
+ const name = str(h.subarray(0, 100)), pre = str(h.subarray(345, 500)), full = pre ? `${pre}/${name}` : name;
1550
+ const size = parseInt(str(h.subarray(124, 136)).trim() || '0', 8) || 0;
1551
+ if (full === want) return buf.subarray(o + 512, o + 512 + size);
1552
+ o += 512 + Math.ceil(size / 512) * 512;
1553
+ }
1554
+ return null;
1555
+ }
1556
+ export const autoUpdateOff = () => !!process.env.SHELLWAY_NO_AUTO_UPDATE || existsSync(AU_OFF());
1557
+ const runningAsService = () => { try { return fileURLToPath(import.meta.url) === join(CONF_DIR, 'agent.mjs'); } catch { return false; } };
1558
+ export async function fetchUpdate(current, { registry = 'https://registry.npmjs.org/shellway/latest', fetchImpl = fetch } = {}) {
1559
+ const meta = await (await fetchImpl(registry, { signal: AbortSignal.timeout(20_000) })).json();
1560
+ const v = String((meta && meta.version) || '');
1561
+ if (!/^\d+\.\d+\.\d+$/.test(v) || !newerVersion(v, current)) return null;
1562
+ let skip = {}; try { skip = JSON.parse(readFileSync(AU_SKIP(), 'utf8')); } catch {}
1563
+ if (skip.version === v) return null;
1564
+ const tb = meta.dist && meta.dist.tarball, integ = meta.dist && meta.dist.integrity;
1565
+ if (!tb || !String(tb).startsWith('https://registry.npmjs.org/shellway/-/') || !/^sha512-/.test(String(integ || ''))) throw new Error('registry data looks wrong');
1566
+ const tgz = Buffer.from(await (await fetchImpl(tb, { signal: AbortSignal.timeout(120_000) })).arrayBuffer());
1567
+ if ('sha512-' + createHash('sha512').update(tgz).digest('base64') !== integ) throw new Error('integrity check failed');
1568
+ const file = tarExtract(gunzipSync(tgz), 'package/shellway.js');
1569
+ if (!file) throw new Error('shellway.js missing in the package');
1570
+ if (!file.toString('utf8').includes(`const AGENT_VERSION = '${v}'`)) throw new Error('version inside the package does not match');
1571
+ return { version: v, file };
1572
+ }
1573
+ export function applyUpdate(u, from, dir = CONF_DIR) {
1574
+ const dest = join(dir, 'agent.mjs'), tmp = join(dir, 'agent.new.mjs'), prev = join(dir, 'agent.prev.mjs');
1575
+ writeFileSync(tmp, u.file);
1576
+ if (spawnSync(process.execPath, ['--check', tmp], { stdio: 'ignore' }).status !== 0) { rmSync(tmp, { force: true }); throw new Error('the new file does not parse'); }
1577
+ copyFileSync(dest, prev);
1578
+ renameSync(tmp, dest);
1579
+ writeFileSync(join(dir, 'update-pending.json'), JSON.stringify({ from, to: u.version, t: Date.now() }));
1580
+ }
1581
+ function autoUpdateLoop(isBusy) {
1582
+ if (!runningAsService()) return;
1583
+ // after an update: the new version must connect within 3 minutes, otherwise put the old file back
1584
+ let pend = null; try { pend = JSON.parse(readFileSync(AU_PENDING(), 'utf8')); } catch {}
1585
+ if (pend) {
1586
+ if (pend.to !== AGENT_VERSION) { try { rmSync(AU_PENDING(), { force: true }); } catch {} }
1587
+ else setTimeout(() => {
1588
+ if (linkState.connectedAt) { try { rmSync(AU_PENDING(), { force: true }); } catch {} console.log(`Updated automatically from ${pend.from} to ${AGENT_VERSION}.`); return; }
1589
+ try {
1590
+ copyFileSync(join(CONF_DIR, 'agent.prev.mjs'), join(CONF_DIR, 'agent.mjs'));
1591
+ writeFileSync(AU_SKIP(), JSON.stringify({ version: AGENT_VERSION, t: Date.now() }));
1592
+ rmSync(AU_PENDING(), { force: true });
1593
+ console.error(`Version ${AGENT_VERSION} could not connect within 3 minutes; going back to ${pend.from}.`);
1594
+ process.exit(0);
1595
+ } catch (e) { console.error(`Could not go back to the previous version: ${e.message}`); }
1596
+ }, 180_000).unref();
1597
+ }
1598
+ const check = async () => {
1599
+ if (autoUpdateOff()) return;
1600
+ if (isBusy()) { setTimeout(check, 10 * 60_000).unref(); return; } // try again in 10 minutes
1601
+ try {
1602
+ const u = await fetchUpdate(AGENT_VERSION);
1603
+ if (!u || isBusy()) return;
1604
+ applyUpdate(u, AGENT_VERSION);
1605
+ console.log(`Shellway ${u.version} is available; updating from ${AGENT_VERSION} and restarting.`);
1606
+ setTimeout(() => process.exit(0), 500);
1607
+ } catch (e) { console.error(`Automatic update check failed: ${e.message}`); }
1608
+ };
1609
+ setTimeout(check, (15 + Math.floor(Math.random() * 30)) * 60_000).unref(); // first check 15-45 min after start
1610
+ setInterval(check, 6 * 3600_000).unref();
1611
+ }
1612
+ function autoUpdateCli() {
1613
+ const sub = process.argv[3];
1614
+ mkdirSync(CONF_DIR, { recursive: true });
1615
+ if (sub === 'off') { writeFileSync(AU_OFF(), 'off\n'); console.log('Automatic updates are off. Update by hand with: npx shellway@latest service install'); }
1616
+ else if (sub === 'on') { rmSync(AU_OFF(), { force: true }); console.log('Automatic updates are on (only for the background service).'); }
1617
+ else console.log(`Automatic updates: ${autoUpdateOff() ? 'off' : 'on'} (version ${AGENT_VERSION}).\nshellway auto-update on|off`);
1618
+ }
1619
+
1529
1620
  const STATUS_LINE = /Connected as|Disconnected|reconnecting…|Switching to the HTTPS fallback|Trying the WebSocket link again|Connection error|answers are not reaching|Connecting took too long|token is invalid/;
1530
1621
  handlers.shellway_diagnostics = async () => {
1531
1622
  const out = [`Shellway app ${AGENT_VERSION} · Node.js ${process.versions.node} · ${platform()} ${release()}`,
@@ -1571,6 +1662,7 @@ async function tokenValid(conf) {
1571
1662
  // keepalives, receipts and reconnects work the same. Messages from Shellway carry a number and are acknowledged on the
1572
1663
  // next poll, so an answer lost on the way is sent again and a repeat is ignored.
1573
1664
  const POLL_SEND_MS = Number(process.env.SHELLWAY_POLL_SEND_MS) || 10_000;
1665
+ const POLL_GRACE_MS = Number(process.env.SHELLWAY_POLL_GRACE_MS) || 5_000;
1574
1666
  export class PollLink {
1575
1667
  constructor(base, token, version) {
1576
1668
  this.base = base; this.h = { authorization: `Bearer ${token}`, 'x-shellway-version': version };
@@ -1601,7 +1693,9 @@ export class PollLink {
1601
1693
  let fails = 0;
1602
1694
  while (this.readyState === 1) {
1603
1695
  try {
1604
- const r = await this._req(`/agent/poll?sid=${this.sid}&ack=${this.ack}`, { method: 'GET' }, this.wait + 15_000);
1696
+ // 0.8.4 (26 Nov 2026): on networks that need this fallback about 1 request in 20 stalls on the way (relay nginx 499).
1697
+ // A poll held by Shellway for `wait` ms is given up 5 s after that (was 15 s), so a stalled one is re-sent ~10 s sooner.
1698
+ const r = await this._req(`/agent/poll?sid=${this.sid}&ack=${this.ack}`, { method: 'GET' }, this.wait + POLL_GRACE_MS);
1605
1699
  if (r.status === 410) return this._end(1006, 'closed by Shellway');
1606
1700
  if (!r.ok) throw new Error(`HTTP ${r.status}`);
1607
1701
  const j = await r.json(); fails = 0;
@@ -1730,6 +1824,7 @@ function start() {
1730
1824
  // request gets its stored answer, a running one answers when it finishes, and nothing ever runs twice.
1731
1825
  const BOOT = randomBytes(6).toString('hex');
1732
1826
  const journal = new Map(); // id -> { done, reply, at }
1827
+ autoUpdateLoop(() => [...sessions.values()].some((x) => !x.exited) || [...journal.values()].some((r) => !r.done));
1733
1828
  const remember = (id) => {
1734
1829
  const rec = { done: false, reply: null, at: Date.now() };
1735
1830
  journal.set(id, rec);
@@ -2044,5 +2139,6 @@ else if (cmd === 'start') start();
2044
2139
  else if (cmd === 'service') service();
2045
2140
  else if (cmd === 'policy') policyCli();
2046
2141
  else if (cmd === 'doctor') await doctorCli();
2142
+ else if (cmd === 'auto-update') autoUpdateCli();
2047
2143
  else if (cmd === 'native-host' || String(cmd || '').startsWith('chrome-extension://')) nativeHost();
2048
2144
  else console.log('shellway pair <CODE> [--server URL] [--name NAME]\nshellway start [--readonly]\nshellway doctor check the connection to Shellway and print a report\nshellway service install|uninstall|status [--readonly]\nshellway policy safety rules: allowed folders, blocked commands, backups (shellway policy help)');