shellway 0.6.2 → 0.6.3

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 +30 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellway",
3
- "version": "0.6.2",
3
+ "version": "0.6.3",
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, execFile } 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.2'; // keep equal to agent/package.json
10
+ const AGENT_VERSION = '0.6.3'; // 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);
@@ -563,7 +563,35 @@ function blockedBy(text, pol) {
563
563
  return pol.blocked_commands.find((b) => new RegExp(`(^|[^\\w-])${escRe(b.trim()).replace(/\s+/g, '\\s+')}($|[^\\w-])`, 'i').test(text));
564
564
  }
565
565
  // Throws when the owner's rules forbid this call. May fill in a default cwd inside an allowed folder.
566
+ // Always on (with or without rules): the AI cannot read or change Shellway's own folder (pairing token, safety
567
+ // rules, the agent itself) with file tools, and cannot run "shellway policy" or touch that folder with commands.
568
+ const PROTECT_MSG = "Shellway's own settings (the .shellway folder and \"shellway policy\") can only be changed by the owner directly on the computer, not through the AI. Nothing was done.";
569
+ function protectSelf(method, params) {
570
+ if (PATH_PARAMS[method]) {
571
+ const root = normCase(realLocation(CONF_DIR));
572
+ for (const k of PATH_PARAMS[method]) {
573
+ if (k === 'cwd') continue;
574
+ const vals = k === 'paths' ? (Array.isArray(params[k]) ? params[k] : []) : (params[k] === undefined ? [] : [params[k]]);
575
+ for (const v of vals) {
576
+ if (method === 'open_file' && /^https?:\/\//.test(String(v))) continue;
577
+ const real = normCase(realLocation(String(v)));
578
+ if (real === root || real.startsWith(root + sep)) {
579
+ // backups stay readable so the AI can help restore an older copy of a file
580
+ const backups = root + sep + 'backups';
581
+ const readOnly = ['read_file', 'read_multiple_files', 'list_directory', 'get_file_info', 'search_files', 'start_search'].includes(method);
582
+ if (!(readOnly && (real === backups || real.startsWith(backups + sep)))) throw new Error(PROTECT_MSG);
583
+ }
584
+ }
585
+ }
586
+ }
587
+ if (COMMAND_METHODS.has(method)) {
588
+ const text = method === 'interact_with_process' ? String(params.input ?? '') : String(params.command ?? '');
589
+ if (/[\\/]\.shellway\b|%USERPROFILE%[\\/]\.shellway|~[\\/]\.shellway|\$HOME[\\/]\.shellway|\$env:USERPROFILE[\\/]\.shellway/i.test(text) || /\bshellway(?:@\S+)?(?:\.(?:js|mjs))?["']?\s+policy\b/i.test(text)) throw new Error(PROTECT_MSG);
590
+ }
591
+ }
592
+ export { protectSelf };
566
593
  function checkPolicy(method, params) {
594
+ protectSelf(method, params);
567
595
  const pol = loadPolicy();
568
596
  if (!pol) return params;
569
597
  const fix = 'The owner of this computer set this rule; it can only be changed on the computer (shellway policy).';
@@ -613,7 +641,7 @@ function policyCli() {
613
641
  console.log(`Blocked commands: ${q.blocked_commands.length ? q.blocked_commands.join(', ') : 'none'}`);
614
642
  console.log(`Backups before a file is changed: ${q.backups ? `on (${join(CONF_DIR, 'backups')})` : 'off'}`);
615
643
  console.log(`Keep awake while Shellway runs: ${q.keep_awake ? 'on' : 'off'}`);
616
- console.log(`Screen, apps, mouse and keyboard: ${q.desktop ? 'ON (the AI can see the screen and click/type)' : 'off'}`);
644
+ console.log(`Screen, apps, mouse and keyboard: ${q.desktop ? (platform() === 'win32' ? 'ON (the AI can open, switch and close apps, click and type; no screenshots on Windows yet)' : 'ON (the AI can see the screen; apps, mouse and keyboard on Windows)') : 'off'}`);
617
645
  if (q.allowed_folders.length && q.commands) console.log('Note: commands start inside an allowed folder, but a command can still reach other folders. For a strict lock, also run: shellway policy commands off');
618
646
  console.log('Rules apply right away; no restart needed.');
619
647
  };