shellway 0.4.0 → 0.5.0

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 (3) hide show
  1. package/README.md +3 -1
  2. package/package.json +24 -7
  3. package/shellway.js +71 -12
package/README.md CHANGED
@@ -27,8 +27,10 @@ Optional: `--name "Home laptop"` on `pair` sets the computer's name. `--server U
27
27
  | `edit_block` | Replace exact text in a file; changes nothing if the text is missing or ambiguous | yes |
28
28
  | `search_files` | Find files by name, or text inside files (skips node_modules, .git, binary files) | no |
29
29
  | `start_search`, `get_more_search_results`, `stop_search` | Advanced search in the background: by name or text, optional regular expression, file-type filter (`*.js,*.ts`), lines of context, results in pages | no |
30
- | `list_directory`, `get_file_info` | List a folder; show size, dates and permissions | no |
30
+ | `list_directory`, `get_file_info` | List a folder; show size, dates and permissions. Pass `recursive:true` to walk subdirectories (default depth 3, max 2000 entries) | no |
31
31
  | `move_file` | Move or rename; never overwrites an existing file | yes |
32
+ | `download_file` | Download a file from a URL and save it to the computer (max 500 MB) | yes |
33
+ | `open_file` | Open a file or URL with the default application (like double-clicking it) | no |
32
34
  | `create_directory` | Create a folder | yes |
33
35
  | `start_process`, `interact_with_process` | Start a program that keeps running (dev server, Python or Node shell, `ssh`) and type into it | yes |
34
36
  | `read_process_output`, `list_sessions` | See what a background program printed; list the ones Shellway started | no |
package/package.json CHANGED
@@ -1,14 +1,31 @@
1
1
  {
2
2
  "name": "shellway",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Shellway agent: lets ChatGPT, Claude and Cursor work on this computer through the Shellway relay.",
5
5
  "type": "module",
6
- "bin": { "shellway": "./shellway.js" },
7
- "files": ["shellway.js", "README.md"],
8
- "engines": { "node": ">=22" },
9
- "keywords": ["mcp", "remote-mcp", "chatgpt", "claude", "cursor", "ai-agent", "shellway"],
6
+ "bin": {
7
+ "shellway": "./shellway.js"
8
+ },
9
+ "files": [
10
+ "shellway.js",
11
+ "README.md"
12
+ ],
13
+ "engines": {
14
+ "node": ">=22"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "remote-mcp",
19
+ "chatgpt",
20
+ "claude",
21
+ "cursor",
22
+ "ai-agent",
23
+ "shellway"
24
+ ],
10
25
  "homepage": "https://getshellway.com",
11
- "bugs": { "email": "support@getshellway.com" },
26
+ "bugs": {
27
+ "email": "support@getshellway.com"
28
+ },
12
29
  "author": "Sandeep Kumar Saini",
13
30
  "license": "UNLICENSED"
14
- }
31
+ }
package/shellway.js CHANGED
@@ -7,6 +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.5.0'; // keep equal to agent/package.json
10
11
  if (Number(process.versions.node.split('.')[0]) < 22) {
11
12
  console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
12
13
  process.exit(1);
@@ -238,11 +239,26 @@ const handlers = {
238
239
  if (st.size > MAX_EDIT_BYTES) throw new Error(`File is too large to edit (${st.size} bytes, limit ${MAX_EDIT_BYTES})`);
239
240
  const buf = await readFile(p);
240
241
  if (buf.subarray(0, 8000).includes(0)) throw new Error('This looks like a binary file; edit_block only edits text files');
241
- const parts = buf.toString('utf8').split(old_string);
242
+ const text = buf.toString('utf8');
243
+ let oldS = old_string, newS = new_string;
244
+ let parts = text.split(oldS);
245
+ // Windows files often use CRLF line endings while the AI sends plain LF: retry with the file's own line endings.
246
+ if (parts.length === 1 && text.includes('\r\n') && /\n/.test(oldS)) {
247
+ const crlf = (x) => x.replace(/\r?\n/g, '\r\n');
248
+ const retry = text.split(crlf(oldS));
249
+ if (retry.length > 1) { parts = retry; oldS = crlf(oldS); newS = crlf(newS); }
250
+ }
242
251
  const found = parts.length - 1;
243
- if (found === 0) throw new Error('old_string was not found in the file. Nothing changed.');
252
+ if (found === 0) {
253
+ const first = old_string.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
254
+ const lines = text.split(/\r?\n/);
255
+ const at = first ? lines.findIndex((l) => l.includes(first)) : -1;
256
+ throw new Error(`old_string was not found in the file. Nothing changed. ${at >= 0
257
+ ? `Its first line does appear at line ${at + 1}, so the difference is further down: check spaces, tabs and blank lines. Read that part of the file again and copy the text exactly.`
258
+ : 'No line contains the start of it. The file may have changed: read it again and copy the text exactly.'}`);
259
+ }
244
260
  if (found !== exp) throw new Error(`old_string appears ${found} time(s) but expected_replacements is ${exp}. Nothing changed. Add more surrounding text to make it unique, or set expected_replacements to ${found}.`);
245
- await writeFile(p, parts.join(new_string));
261
+ await writeFile(p, parts.join(newS));
246
262
  return `Replaced ${found} occurrence${found === 1 ? '' : 's'} in ${p}`;
247
263
  },
248
264
  async search_files({ path, pattern, mode, max_results, ignore_case }) {
@@ -436,18 +452,61 @@ const handlers = {
436
452
  if (!s.done) { s.stop = true; s.stopped = true; }
437
453
  return `Search ${s.id}: ${s.done && !s.stopped ? 'was already ' + searchStatus(s) : 'stopped'}, ${s.results.length} results found, ${s.results.length - s.cursor} unread.`;
438
454
  },
439
- async list_directory({ path }) {
455
+ async download_file({ url, path }) {
456
+ if (!url || !/^https?:\/\//.test(url)) throw new Error('url must start with http:// or https://');
457
+ const dest = resolve(path);
458
+ const { createWriteStream } = await import('node:fs');
459
+ const res = await fetch(url);
460
+ if (!res.ok) throw new Error(`HTTP ${res.status} from ${url}`);
461
+ const { dirname } = await import('node:path');
462
+ await mkdir(dirname(dest), { recursive: true });
463
+ const stream = createWriteStream(dest);
464
+ const reader = res.body.getReader();
465
+ let bytes = 0;
466
+ const MAX_DL = 500_000_000;
467
+ while (true) {
468
+ const { done, value } = await reader.read();
469
+ if (done) break;
470
+ if (bytes + value.length > MAX_DL) throw new Error('File exceeds 500 MB limit');
471
+ stream.write(Buffer.from(value));
472
+ bytes += value.length;
473
+ }
474
+ await new Promise((res, rej) => stream.end((e) => e ? rej(e) : res()));
475
+ return `Downloaded ${bytes.toLocaleString()} bytes → ${dest}`;
476
+ },
477
+ async open_file({ path: p }) {
478
+ const target = p.startsWith('http') ? p : resolve(p);
479
+ const pl = platform();
480
+ const cmd = pl === 'darwin' ? 'open' : pl === 'win32' ? 'start' : 'xdg-open';
481
+ const c = spawn(cmd, pl === 'win32' ? ['""', target] : [target], { shell: pl === 'win32', detached: true, stdio: 'ignore' });
482
+ c.unref();
483
+ await new Promise((res, rej) => { c.on('error', rej); setTimeout(res, 500); });
484
+ return `Opened: ${target}`;
485
+ },
486
+ async list_directory({ path, recursive, max_depth }) {
440
487
  const p = resolve(path);
441
- const names = await readdir(p);
488
+ const depth = Math.min(Math.max(Number(max_depth) || (recursive ? 3 : 0), 0), 10);
442
489
  const out = [];
443
- for (const n of names.slice(0, 1000)) {
444
- try { const s = await stat(join(p, n)); out.push(`${s.isDirectory() ? 'd' : '-'} ${String(s.size).padStart(10)} ${n}`); }
445
- catch { out.push(`? ${n}`); }
446
- }
447
- return out.join('\n') + (names.length > 1000 ? `\n…[${names.length - 1000} more]` : '');
490
+ let total = 0;
491
+ const walk = async (dir, rel, d) => {
492
+ let names; try { names = await readdir(dir); } catch { return; }
493
+ for (const n of names) {
494
+ if (total >= 2000) { out.push('…[limit 2000 reached]'); return; }
495
+ const full = join(dir, n);
496
+ const r = rel ? rel + '/' + n : n;
497
+ try {
498
+ const s = await stat(full);
499
+ out.push(`${s.isDirectory() ? 'd' : '-'} ${String(s.size).padStart(10)} ${r}`);
500
+ total++;
501
+ if (s.isDirectory() && d > 0 && !SKIP_DIRS.has(n)) await walk(full, r, d - 1);
502
+ } catch { out.push(`? ${r}`); total++; }
503
+ }
504
+ };
505
+ await walk(p, '', depth);
506
+ return out.join('\n') || '(empty)';
448
507
  },
449
508
  };
450
- const writeMethods = new Set(['run_command', 'write_file', 'edit_block', 'move_file', 'create_directory', 'start_process', 'interact_with_process', 'force_terminate']);
509
+ const writeMethods = new Set(['run_command', 'write_file', 'edit_block', 'move_file', 'create_directory', 'start_process', 'interact_with_process', 'force_terminate', 'download_file']);
451
510
 
452
511
  // One entry point for every request from the relay, so it can be tested without a network.
453
512
  async function dispatch(method, params) {
@@ -471,7 +530,7 @@ function start() {
471
530
  let delay = 1000;
472
531
  const connect = async () => {
473
532
  if (!(await tokenValid(conf))) { console.error('This device was removed or its token is invalid. Pair again.'); process.exit(78); }
474
- const ws = new WebSocket(wsUrl, { headers: { authorization: `Bearer ${conf.device_token}` } });
533
+ const ws = new WebSocket(wsUrl, { headers: { authorization: `Bearer ${conf.device_token}`, 'x-shellway-version': AGENT_VERSION } });
475
534
  ws.onopen = () => { delay = 1000; console.log(`Connected as "${conf.device_name}"${readonly ? ' (read-only)' : ''}. Leave this running.`); };
476
535
  ws.onmessage = async (ev) => {
477
536
  let m; try { m = JSON.parse(String(ev.data)); } catch { return; }