shellway 0.0.0-stage → 0.1.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 +23 -2
  2. package/package.json +12 -4
  3. package/shellway.js +123 -0
package/README.md CHANGED
@@ -1,3 +1,24 @@
1
- # Temporary Holding Version
1
+ # Shellway agent
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Lets ChatGPT, Claude and Cursor work on your own computer through [Shellway](https://getshellway.com).
4
+ Needs Node.js 22 or newer.
5
+
6
+ ## Set up
7
+
8
+ 1. Sign in at https://mcp.getshellway.com/dashboard and press "Generate pairing code".
9
+ 2. On the computer you want to control:
10
+
11
+ ```
12
+ npx shellway pair YOUR-CODE
13
+ npx shellway start
14
+ ```
15
+
16
+ Keep the second command running. Add `--readonly` to `start` so your AI can read files and list folders but cannot write files or run commands.
17
+
18
+ Optional: `--name "Home laptop"` on `pair` sets the computer's name. `--server URL` points at a different relay.
19
+
20
+ ## What it does
21
+
22
+ The agent makes an outbound connection to the Shellway relay. Requests from your AI app are passed to this computer and the result is passed back. File contents and command output are not stored by Shellway.
23
+
24
+ Support: support@getshellway.com
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "shellway",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shellway agent: lets ChatGPT, Claude and Cursor work on this computer through the Shellway relay.",
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"],
10
+ "homepage": "https://getshellway.com",
11
+ "bugs": { "email": "support@getshellway.com" },
12
+ "author": "Sandeep Kumar Saini",
13
+ "license": "UNLICENSED"
14
+ }
package/shellway.js ADDED
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from 'node:child_process';
3
+ import { homedir, hostname, platform, release } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { mkdirSync, readFileSync, writeFileSync, chmodSync, existsSync } from 'node:fs';
6
+ import { readFile, writeFile, appendFile, readdir, stat } from 'node:fs/promises';
7
+
8
+ if (Number(process.versions.node.split('.')[0]) < 22) {
9
+ console.error(`Shellway needs Node.js 22 or newer (you have ${process.versions.node}). Get it at https://nodejs.org`);
10
+ process.exit(1);
11
+ }
12
+
13
+ const CONF_DIR = join(process.env.SHELLWAY_HOME || homedir(), '.shellway');
14
+ const CONF = join(CONF_DIR, 'config.json');
15
+ const MAX_OUT = 200_000;
16
+
17
+ const args = process.argv.slice(2);
18
+ const flag = (n) => { const i = args.indexOf(`--${n}`); return i >= 0 ? args[i + 1] : undefined; };
19
+ const has = (n) => args.includes(`--${n}`);
20
+ const cmd = args[0];
21
+
22
+ function loadConf() {
23
+ if (!existsSync(CONF)) { console.error('Not paired yet. Run: shellway pair <CODE> --server <URL>'); process.exit(1); }
24
+ return JSON.parse(readFileSync(CONF, 'utf8'));
25
+ }
26
+
27
+ async function pair() {
28
+ const code = args[1];
29
+ const server = (flag('server') || 'https://mcp.getshellway.com').replace(/\/$/, '');
30
+ if (!code || code.startsWith('--')) { console.error('Usage: shellway pair <CODE> [--server URL] [--name NAME]'); process.exit(1); }
31
+ const r = await fetch(`${server}/agent/pair`, {
32
+ method: 'POST',
33
+ headers: { 'content-type': 'application/json' },
34
+ body: JSON.stringify({ code, name: flag('name') || hostname(), platform: `${platform()} ${release()}` }),
35
+ });
36
+ const body = await r.json().catch(() => ({}));
37
+ if (!r.ok) { console.error('Pairing failed:', body.error || r.status); process.exit(1); }
38
+ mkdirSync(CONF_DIR, { recursive: true });
39
+ writeFileSync(CONF, JSON.stringify({ server, device_token: body.device_token, device_name: body.device_name }, null, 2));
40
+ try { chmodSync(CONF, 0o600); } catch {}
41
+ console.log(`Paired as "${body.device_name}". Now run: shellway start`);
42
+ }
43
+
44
+ // ---------- tool handlers (run on this computer) ----------
45
+ const cap = (s) => (s.length > MAX_OUT ? s.slice(0, MAX_OUT) + `\n…[truncated ${s.length - MAX_OUT} chars]` : s);
46
+
47
+ function runCommand({ command, cwd, timeout_seconds }) {
48
+ return new Promise((done) => {
49
+ const timeout = Math.min(Math.max(Number(timeout_seconds) || 60, 1), 600) * 1000;
50
+ const child = spawn(command, { shell: true, cwd: cwd ? resolve(cwd) : homedir(), env: process.env });
51
+ let stdout = '', stderr = '', timedOut = false;
52
+ const t = setTimeout(() => { timedOut = true; child.kill('SIGKILL'); }, timeout);
53
+ child.stdout.on('data', (d) => { if (stdout.length < MAX_OUT * 2) stdout += d; });
54
+ child.stderr.on('data', (d) => { if (stderr.length < MAX_OUT * 2) stderr += d; });
55
+ child.on('error', (e) => { clearTimeout(t); done({ stdout, stderr: String(e.message), code: -1 }); });
56
+ child.on('close', (code) => { clearTimeout(t); done({ stdout: cap(stdout), stderr: cap(stderr), code: code ?? -1, timedOut }); });
57
+ });
58
+ }
59
+
60
+ const readonly = has('readonly');
61
+ const handlers = {
62
+ run_command: runCommand,
63
+ async read_file({ path, max_bytes }) {
64
+ const p = resolve(path);
65
+ const buf = await readFile(p);
66
+ const max = Number(max_bytes) || 200_000;
67
+ const s = buf.subarray(0, max).toString('utf8');
68
+ return buf.length > max ? `${s}\n…[truncated, file is ${buf.length} bytes]` : s;
69
+ },
70
+ async write_file({ path, content, append }) {
71
+ const p = resolve(path);
72
+ await (append ? appendFile(p, content) : writeFile(p, content));
73
+ return `Wrote ${Buffer.byteLength(content)} bytes to ${p}`;
74
+ },
75
+ async list_directory({ path }) {
76
+ const p = resolve(path);
77
+ const names = await readdir(p);
78
+ const out = [];
79
+ for (const n of names.slice(0, 1000)) {
80
+ try { const s = await stat(join(p, n)); out.push(`${s.isDirectory() ? 'd' : '-'} ${String(s.size).padStart(10)} ${n}`); }
81
+ catch { out.push(`? ${n}`); }
82
+ }
83
+ return out.join('\n') + (names.length > 1000 ? `\n…[${names.length - 1000} more]` : '');
84
+ },
85
+ };
86
+ const writeMethods = new Set(['run_command', 'write_file']);
87
+
88
+ async function tokenValid(conf) {
89
+ try {
90
+ const r = await fetch(`${conf.server}/agent/check`, { headers: { authorization: `Bearer ${conf.device_token}` } });
91
+ return r.status !== 401;
92
+ } catch { return true; } // network down: keep retrying
93
+ }
94
+
95
+ function start() {
96
+ const conf = loadConf();
97
+ const wsUrl = conf.server.replace(/^http/, 'ws') + '/agent';
98
+ let delay = 1000;
99
+ const connect = async () => {
100
+ if (!(await tokenValid(conf))) { console.error('This device was removed or its token is invalid. Pair again.'); process.exit(1); }
101
+ const ws = new WebSocket(wsUrl, { headers: { authorization: `Bearer ${conf.device_token}` } });
102
+ ws.onopen = () => { delay = 1000; console.log(`Connected as "${conf.device_name}"${readonly ? ' (read-only)' : ''}. Leave this running.`); };
103
+ ws.onmessage = async (ev) => {
104
+ let m; try { m = JSON.parse(String(ev.data)); } catch { return; }
105
+ if (m.type === 'hello' || !m.id) return;
106
+ try {
107
+ if (readonly && writeMethods.has(m.method)) throw new Error('This computer is in read-only mode');
108
+ const h = handlers[m.method];
109
+ if (!h) throw new Error(`unknown method ${m.method}`);
110
+ ws.send(JSON.stringify({ id: m.id, result: await h(m.params || {}) }));
111
+ } catch (e) {
112
+ ws.send(JSON.stringify({ id: m.id, error: e.message }));
113
+ }
114
+ };
115
+ ws.onclose = () => { console.log(`Disconnected. Retrying in ${Math.round(delay / 1000)}s…`); setTimeout(connect, delay); delay = Math.min(delay * 2, 30_000); };
116
+ ws.onerror = () => {};
117
+ };
118
+ connect();
119
+ }
120
+
121
+ if (cmd === 'pair') await pair();
122
+ else if (cmd === 'start') start();
123
+ else console.log('shellway pair <CODE> [--server URL] [--name NAME]\nshellway start [--readonly]');