shellway 0.8.0 → 0.8.2

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.0",
4
+ "version": "0.8.2",
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.0",
3
+ "version": "0.8.2",
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": {
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.8.0'; // keep equal to agent/package.json
12
+ const AGENT_VERSION = '0.8.2'; // 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);
@@ -1512,6 +1512,17 @@ Object.assign(handlers, browserHandlers);
1512
1512
  // token. Only the relay asks for it (it is not one of the AI app's tools).
1513
1513
  // 0.7.8: remembers the HTTPS fallback across restarts (see runAgent). Never holds a token.
1514
1514
  const LINK_STATE = join(CONF_DIR, 'link-state.json');
1515
+ // 0.8.2 (customer 10396, 23 Nov: "service status" said "not running" on Windows while the agent ran and worked; the
1516
+ // process-list check misses some setups): the running agent writes a small heartbeat (pid, version, link, time) every
1517
+ // tick, and "shellway service status" reads it on every system. No token, no paths, no commands in it.
1518
+ const ALIVE_FILE = join(CONF_DIR, 'agent-alive.json');
1519
+ export function writeAlive(extra = {}) { try { mkdirSync(CONF_DIR, { recursive: true }); writeFileSync(ALIVE_FILE, JSON.stringify({ pid: process.pid, v: AGENT_VERSION, t: Date.now(), ...extra })); } catch {} }
1520
+ export function readAlive(maxAgeMs = 90_000, t = Date.now()) {
1521
+ let a; try { a = JSON.parse(readFileSync(ALIVE_FILE, 'utf8')); } catch { return null; }
1522
+ if (!a || !a.pid || !(t - a.t <= maxAgeMs)) return null;
1523
+ try { process.kill(a.pid, 0); } catch (e) { if (e.code !== 'EPERM') return null; }
1524
+ return a;
1525
+ }
1515
1526
  function readLinkState() { try { return JSON.parse(readFileSync(LINK_STATE, 'utf8')) || {}; } catch { return {}; } }
1516
1527
  function writeLinkState(st) { try { mkdirSync(CONF_DIR, { recursive: true }); writeFileSync(LINK_STATE, JSON.stringify(st)); } catch {} }
1517
1528
  const linkState = { transport: 'ws', connectedAt: 0, links: 0, lastClose: null, journal: 0, startedAt: Date.now() };
@@ -1559,6 +1570,7 @@ async function tokenValid(conf) {
1559
1570
  // the same conversation with Shellway over plain HTTPS requests (long-poll). It looks like a WebSocket to start(), so
1560
1571
  // keepalives, receipts and reconnects work the same. Messages from Shellway carry a number and are acknowledged on the
1561
1572
  // next poll, so an answer lost on the way is sent again and a repeat is ignored.
1573
+ const POLL_SEND_MS = Number(process.env.SHELLWAY_POLL_SEND_MS) || 10_000;
1562
1574
  export class PollLink {
1563
1575
  constructor(base, token, version) {
1564
1576
  this.base = base; this.h = { authorization: `Bearer ${token}`, 'x-shellway-version': version };
@@ -1610,15 +1622,18 @@ export class PollLink {
1610
1622
  while (this.outq.length && this.readyState === 1) {
1611
1623
  const batch = this.outq.splice(0, 50);
1612
1624
  try {
1613
- const r = await this._req(`/agent/poll/send?sid=${this.sid}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(batch) }, 30_000);
1625
+ // 0.8.1 (customer 10396, 23 Nov): on his network about 1 upload in 10 stalls and never arrives (relay logged
1626
+ // HTTP 408 after 60 s). Answers and keepalives waited 30 s per try, so commands timed out and the link was
1627
+ // reset every 29 s. Now a stalled upload is given up after 10 s and sent again on a new request, up to 6 times.
1628
+ const r = await this._req(`/agent/poll/send?sid=${this.sid}`, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(batch) }, POLL_SEND_MS);
1614
1629
  if (r.status === 410) { this._end(1006, 'closed by Shellway'); break; }
1615
1630
  if (!r.ok) throw new Error(`HTTP ${r.status}`);
1616
1631
  fails = 0;
1617
1632
  } catch (e) {
1618
1633
  if (this.readyState !== 1) break;
1619
1634
  this.outq.unshift(...batch);
1620
- if (++fails >= 3) { this._fail(e); this._end(1006, ''); break; }
1621
- await new Promise((ok) => setTimeout(ok, 1000));
1635
+ if (++fails >= 6) { this._fail(e); this._end(1006, ''); break; }
1636
+ await new Promise((ok) => setTimeout(ok, 300));
1622
1637
  }
1623
1638
  }
1624
1639
  } finally { this.sending = false; }
@@ -1734,8 +1749,10 @@ function start() {
1734
1749
  why = reason; prevCid = cid; cid = null;
1735
1750
  delay = 1000; setTimeout(connect, 500);
1736
1751
  };
1752
+ writeAlive({ link: 'starting' });
1737
1753
  setInterval(() => {
1738
1754
  const t = Date.now(), slept = t - lastTick > Math.max(45_000, TICK * 3); lastTick = t;
1755
+ writeAlive({ link: linkState.transport === 'poll' ? 'https' : 'websocket', up: !!(current && current.readyState === 1) });
1739
1756
  if (connectingSince && t - connectingSince > 30_000) {
1740
1757
  const w = current; current = null; connectingSince = 0;
1741
1758
  if (w) { w.onopen = null; w.onclose = null; w.onmessage = null; try { w.close(); } catch {} }
@@ -1901,11 +1918,14 @@ function service() {
1901
1918
  else if (os === 'darwin') run('launchctl', ['list', 'com.getshellway.agent']);
1902
1919
  else {
1903
1920
  if (!existsSync(winStartup())) throw new Error('not installed');
1904
- let n = 0;
1905
- try { n = Number(run('powershell', ['-NoProfile', '-Command', `(Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*${CONF_DIR.replace(/'/g, "''")}*agent.mjs*' }).Count`], { quiet: true }).trim()) || 0; } catch {}
1921
+ let n = readAlive() ? 1 : 0;
1922
+ if (!n) try { n = Number(run('powershell', ['-NoProfile', '-Command', `(Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -like '*${CONF_DIR.replace(/'/g, "''")}*agent.mjs*' }).Count`], { quiet: true }).trim()) || 0; } catch {}
1906
1923
  console.log(`Auto-start installed (${winStartup()}). Background agent: ${n > 0 ? 'running' : 'not running - log out and in, or run the install again'}. Log: ${join(CONF_DIR, 'agent.log')}`);
1907
1924
  }
1908
1925
  } catch { console.log('Auto-start is not installed (or not running).'); }
1926
+ const a = readAlive();
1927
+ console.log(a ? `Running agent: version ${a.v}, process ${a.pid}, link ${a.link || '?'}${a.up === false ? ' (reconnecting)' : ''}, last heartbeat ${Math.round((Date.now() - a.t) / 1000)} s ago`
1928
+ : 'Running agent: no heartbeat in the last 90 s (the agent is not running, or it is older than 0.8.2)');
1909
1929
  }
1910
1930
  }
1911
1931