shellway 0.6.0 → 0.6.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/shellway.js +41 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellway",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
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
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'node:url';
7
7
  import { execFileSync } from 'node:child_process';
8
8
  import { readFile, writeFile, appendFile, readdir, stat, lstat, mkdir, rename, cp, rm } from 'node:fs/promises';
9
9
 
10
- const AGENT_VERSION = '0.6.0'; // keep equal to agent/package.json
10
+ const AGENT_VERSION = '0.6.1'; // keep equal to agent/package.json
11
11
  if (Number(process.versions.node.split('.')[0]) < 22) {
12
12
  console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
13
13
  process.exit(1);
@@ -683,7 +683,7 @@ function start() {
683
683
  connect();
684
684
  }
685
685
 
686
- // ---- auto-start service (systemd user unit / launchd agent / Windows scheduled task) ----
686
+ // ---- auto-start service (systemd user unit / launchd agent / Windows Startup-folder launcher) ----
687
687
  const xml = (v) => String(v).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
688
688
  function serviceSpec() {
689
689
  // Copy ourselves to a stable path so the service survives npx cache cleanup.
@@ -693,6 +693,27 @@ function serviceSpec() {
693
693
  }
694
694
  const run = (c, a, opts = {}) => execFileSync(c, a, { stdio: opts.quiet ? 'pipe' : 'inherit', encoding: 'utf8' });
695
695
 
696
+ // Windows auto-start without admin rights: a hidden launcher in the user's Startup folder runs a small
697
+ // loop that restarts the agent after a crash (exit 78 = device removed: stop).
698
+ const winStartup = () => join(process.env.APPDATA || join(homedir(), 'AppData', 'Roaming'), 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', 'Shellway.vbs');
699
+ const winLoop = () => join(CONF_DIR, 'shellway-agent.cmd');
700
+ function renderWinLoop(argv, home = process.env.SHELLWAY_HOME) {
701
+ const q = (a) => `"${a}"`;
702
+ return ['@echo off', 'rem Shellway agent, kept running in the background. Remove Shellway.vbs from the Startup folder to stop it.',
703
+ ...(home ? [`set "SHELLWAY_HOME=${home}"`] : []),
704
+ ':loop', `${argv.map(q).join(' ')} >> ${q(join(CONF_DIR, 'agent.log'))} 2>&1`,
705
+ 'if %errorlevel%==78 exit /b 78', 'ping -n 11 127.0.0.1 >nul', 'goto loop', ''].join('\r\n');
706
+ }
707
+ function renderWinVbs(loopPath) {
708
+ return `' Starts the Shellway agent hidden at login. Delete this file to stop auto-start.\r\nCreateObject("WScript.Shell").Run """${loopPath}""", 0, False\r\n`;
709
+ }
710
+ const winStopAgents = () => {
711
+ // stop running background agents started from ~/.shellway (not this process)
712
+ const ps = `Get-CimInstance Win32_Process | Where-Object { ($_.Name -eq 'node.exe' -or $_.Name -eq 'cmd.exe') -and $_.CommandLine -like '*${CONF_DIR.replace(/'/g, "''")}*' -and $_.ProcessId -ne ${process.pid} } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }`;
713
+ try { run('powershell', ['-NoProfile', '-Command', ps], { quiet: true }); } catch {}
714
+ };
715
+ export { renderWinLoop, renderWinVbs };
716
+
696
717
  function renderService(os, argv) {
697
718
  const home = process.env.SHELLWAY_HOME ? `Environment=SHELLWAY_HOME=${process.env.SHELLWAY_HOME}\n` : '';
698
719
  if (os === 'linux') return `[Unit]\nDescription=Shellway agent\nAfter=network-online.target\nWants=network-online.target\n\n[Service]\n${home}ExecStart=${argv.map((a) => (/\s/.test(a) ? `"${a}"` : a)).join(' ')}\nRestart=always\nRestartSec=5\nRestartPreventExitStatus=78\n\n[Install]\nWantedBy=default.target\n`;
@@ -709,7 +730,7 @@ function service() {
709
730
  if (!['install', 'uninstall', 'status', 'print'].includes(sub)) {
710
731
  console.log('shellway service install [--readonly] start Shellway automatically at login / boot\nshellway service uninstall\nshellway service status'); return;
711
732
  }
712
- if (sub === 'print') { console.log(renderService(os, argv) ?? '(Windows uses a scheduled task)'); return; }
733
+ if (sub === 'print') { console.log(os === 'win32' ? renderWinLoop(argv) : renderService(os, argv)); return; }
713
734
  if (!['linux', 'darwin', 'win32'].includes(os)) { console.error(`Auto-start is not supported on ${os}. Use: shellway start`); process.exit(1); }
714
735
  if (sub === 'install') {
715
736
  loadConf();
@@ -728,16 +749,23 @@ function service() {
728
749
  try { run('launchctl', ['unload', unitPath], { quiet: true }); } catch {}
729
750
  run('launchctl', ['load', '-w', unitPath]);
730
751
  } else {
731
- const tr = argv.map((a) => `"${a}"`).join(' ');
732
- run('schtasks', ['/Create', '/F', '/SC', 'ONLOGON', '/RL', 'LIMITED', '/TN', 'Shellway', '/TR', tr]);
733
- run('schtasks', ['/Run', '/TN', 'Shellway']);
752
+ try { run('schtasks', ['/Delete', '/F', '/TN', 'Shellway'], { quiet: true }); } catch {} // older versions used a task
753
+ winStopAgents();
754
+ writeFileSync(winLoop(), renderWinLoop(argv));
755
+ mkdirSync(dirname(winStartup()), { recursive: true });
756
+ writeFileSync(winStartup(), renderWinVbs(winLoop()));
757
+ spawn('wscript', [winStartup()], { detached: true, stdio: 'ignore', windowsHide: true }).unref();
758
+ console.log(`Auto-start file: ${winStartup()}`);
734
759
  }
735
760
  console.log(`Done. Shellway now starts automatically${has('readonly') ? ' (read-only)' : ''}. Check: shellway service status`);
736
761
  } else if (sub === 'uninstall') {
737
762
  try {
738
763
  if (os === 'linux') { try { run('systemctl', ['--user', 'disable', '--now', 'shellway.service']); } catch {} rmSync(unitPath, { force: true }); try { run('systemctl', ['--user', 'daemon-reload'], { quiet: true }); } catch {} }
739
764
  else if (os === 'darwin') { try { run('launchctl', ['unload', '-w', unitPath], { quiet: true }); } catch {} rmSync(unitPath, { force: true }); }
740
- else { try { run('schtasks', ['/End', '/TN', 'Shellway'], { quiet: true }); } catch {} run('schtasks', ['/Delete', '/F', '/TN', 'Shellway']); }
765
+ else {
766
+ try { run('schtasks', ['/End', '/TN', 'Shellway'], { quiet: true }); run('schtasks', ['/Delete', '/F', '/TN', 'Shellway'], { quiet: true }); } catch {}
767
+ rmSync(winStartup(), { force: true }); rmSync(winLoop(), { force: true }); winStopAgents();
768
+ }
741
769
  } catch (e) { console.error(e.message); process.exit(1); }
742
770
  rmSync(dest, { force: true });
743
771
  console.log('Auto-start removed. (Your pairing is kept; run "shellway start" to run manually.)');
@@ -745,7 +773,12 @@ function service() {
745
773
  try {
746
774
  if (os === 'linux') run('systemctl', ['--user', 'status', 'shellway.service', '--no-pager', '-n', '5']);
747
775
  else if (os === 'darwin') run('launchctl', ['list', 'com.getshellway.agent']);
748
- else run('schtasks', ['/Query', '/TN', 'Shellway']);
776
+ else {
777
+ if (!existsSync(winStartup())) throw new Error('not installed');
778
+ let n = 0;
779
+ 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 {}
780
+ 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')}`);
781
+ }
749
782
  } catch { console.log('Auto-start is not installed (or not running).'); }
750
783
  }
751
784
  }