tacticremote 1.7.0 → 1.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.
- package/LICENSE +28 -0
- package/README.md +32 -41
- package/bin/tacticremote.js +51 -99
- package/package.json +29 -42
- package/bin/tactic-remote-server.js +0 -636
- package/lib/authChallengeManager.js +0 -1
- package/lib/bonjourPublisher.js +0 -68
- package/lib/claudeSessionManager.js +0 -1
- package/lib/claudeTransport.js +0 -1
- package/lib/errorCodes.js +0 -1
- package/lib/execSafe.js +0 -1
- package/lib/fileService.js +0 -1
- package/lib/hookInstaller.js +0 -253
- package/lib/outputParser.js +0 -1
- package/lib/pushClient.js +0 -1
- package/lib/rateLimiter.js +0 -1
- package/lib/serverIdentity.js +0 -1
- package/lib/streamJsonParser.js +0 -1
- package/lib/tmuxManager.js +0 -1
- package/lib/uploadService.js +0 -1
- package/lib/validators.js +0 -1
- package/middleware/authMiddleware.js +0 -152
- package/routes/httpHandler.js +0 -111
- package/routes/wsHandler.js +0 -1094
- package/server.js +0 -236
- package/shared/server-core/authChallengeManager.js +0 -108
- package/shared/server-core/claudeSessionManager.js +0 -222
- package/shared/server-core/claudeTransport.js +0 -176
- package/shared/server-core/errorCodes.js +0 -91
- package/shared/server-core/execSafe.js +0 -185
- package/shared/server-core/fileService.js +0 -155
- package/shared/server-core/outputParser.js +0 -174
- package/shared/server-core/protocol-manifest.json +0 -59
- package/shared/server-core/protocol-manifest.schema.json +0 -90
- package/shared/server-core/protocolManifest.js +0 -42
- package/shared/server-core/pushClient.js +0 -198
- package/shared/server-core/rateLimiter.js +0 -98
- package/shared/server-core/serverConnectionLifecycle.js +0 -118
- package/shared/server-core/serverHandshake.js +0 -72
- package/shared/server-core/serverIdentity.js +0 -102
- package/shared/server-core/streamJsonParser.js +0 -321
- package/shared/server-core/tmuxManager.js +0 -596
- package/shared/server-core/unixProcessLifecycle.js +0 -96
- package/shared/server-core/unixServerHooks.js +0 -148
- package/shared/server-core/unixWsRuntime.js +0 -412
- package/shared/server-core/uploadService.js +0 -321
- package/shared/server-core/validators.js +0 -274
- package/shared/server-core/windowsServerHooks.js +0 -174
- package/shared/server-core/windowsWsRuntime.js +0 -413
|
@@ -1,636 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const os = require('os');
|
|
6
|
-
const path = require('path');
|
|
7
|
-
const crypto = require('crypto');
|
|
8
|
-
const readline = require('readline');
|
|
9
|
-
const { spawn, spawnSync } = require('child_process');
|
|
10
|
-
|
|
11
|
-
const VERSION = require('../package.json').version;
|
|
12
|
-
const QR_PROTOCOL_VERSION = '1.0'; // Fixed protocol version — iOS app validates this exactly
|
|
13
|
-
|
|
14
|
-
// ── ANSI (zero dependency) ──────────────────────────────────────────
|
|
15
|
-
|
|
16
|
-
const isTTY = process.stdout.isTTY;
|
|
17
|
-
const useColor = !process.env.NO_COLOR && isTTY;
|
|
18
|
-
const c = {
|
|
19
|
-
reset: useColor ? '\x1b[0m' : '',
|
|
20
|
-
bold: useColor ? '\x1b[1m' : '',
|
|
21
|
-
dim: useColor ? '\x1b[2m' : '',
|
|
22
|
-
green: useColor ? '\x1b[32m' : '',
|
|
23
|
-
red: useColor ? '\x1b[31m' : '',
|
|
24
|
-
yellow: useColor ? '\x1b[33m' : '',
|
|
25
|
-
cyan: useColor ? '\x1b[36m' : '',
|
|
26
|
-
magenta: useColor ? '\x1b[35m' : '',
|
|
27
|
-
gray: useColor ? '\x1b[90m' : '',
|
|
28
|
-
white: useColor ? '\x1b[37m' : '',
|
|
29
|
-
inverse: useColor ? '\x1b[7m' : '',
|
|
30
|
-
hide: useColor ? '\x1b[?25l' : '',
|
|
31
|
-
show: useColor ? '\x1b[?25h' : '',
|
|
32
|
-
up: useColor ? '\x1b[1A' : '',
|
|
33
|
-
erase: useColor ? '\x1b[2K' : '',
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const ok = `${c.green}✔${c.reset}`;
|
|
37
|
-
const fail = `${c.red}✖${c.reset}`;
|
|
38
|
-
const warn = `${c.yellow}!${c.reset}`;
|
|
39
|
-
const dot = `${c.dim}·${c.reset}`;
|
|
40
|
-
|
|
41
|
-
// ── Brand ───────────────────────────────────────────────────────────
|
|
42
|
-
|
|
43
|
-
const LOGO = [
|
|
44
|
-
`${c.cyan} ╔╦╗${c.reset}${c.bold}╔═╗╔═╗╔╦╗╦╔═╗${c.reset} ${c.cyan}╦═╗╔═╗╔╦╗╔═╗╔╦╗╔═╗${c.reset}`,
|
|
45
|
-
`${c.cyan} ║ ${c.reset}${c.bold}╠═╣║ ║ ║║ ${c.reset} ${c.cyan}╠╦╝║╣ ║║║║ ║ ║ ║╣ ${c.reset}`,
|
|
46
|
-
`${c.cyan} ╩ ${c.reset}${c.bold}╩ ╩╚═╝ ╩ ╩╚═╝${c.reset} ${c.cyan}╩╚═╚═╝╩ ╩╚═╝ ╩ ╚═╝${c.reset}`,
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
// ── Utilities ───────────────────────────────────────────────────────
|
|
50
|
-
|
|
51
|
-
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
52
|
-
|
|
53
|
-
function which(cmd) {
|
|
54
|
-
const extraPaths = process.platform === 'darwin'
|
|
55
|
-
? ['/opt/homebrew/bin', '/usr/local/bin', '/opt/homebrew/sbin', '/usr/local/sbin']
|
|
56
|
-
: ['/usr/local/bin'];
|
|
57
|
-
const env = { ...process.env };
|
|
58
|
-
const currentPath = env.PATH || '';
|
|
59
|
-
const missing = extraPaths.filter(p => !currentPath.split(':').includes(p));
|
|
60
|
-
if (missing.length) env.PATH = [...missing, currentPath].join(':');
|
|
61
|
-
|
|
62
|
-
const r = spawnSync('which', [cmd], { encoding: 'utf-8', env, timeout: 5000 });
|
|
63
|
-
return r.status === 0 ? r.stdout.trim() : null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getVersion(cmd, flag = '--version') {
|
|
67
|
-
try {
|
|
68
|
-
const r = spawnSync(cmd, [flag], { encoding: 'utf-8', timeout: 5000 });
|
|
69
|
-
if (r.status === 0) {
|
|
70
|
-
const m = (r.stdout + r.stderr).match(/(\d+\.\d+[\.\d]*)/);
|
|
71
|
-
return m ? m[1] : null;
|
|
72
|
-
}
|
|
73
|
-
} catch (_e) { /* ignore */ }
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getLocalIP() {
|
|
78
|
-
const interfaces = os.networkInterfaces();
|
|
79
|
-
for (const name of Object.keys(interfaces)) {
|
|
80
|
-
for (const iface of interfaces[name]) {
|
|
81
|
-
if (iface.family === 'IPv4' && !iface.internal) {
|
|
82
|
-
return iface.address;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return '127.0.0.1';
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ── Interactive menu ────────────────────────────────────────────────
|
|
90
|
-
|
|
91
|
-
function selectMenu(title, items) {
|
|
92
|
-
return new Promise((resolve) => {
|
|
93
|
-
if (!isTTY) {
|
|
94
|
-
resolve(items[0].value);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let selected = 0;
|
|
99
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
100
|
-
readline.emitKeypressEvents(process.stdin, rl);
|
|
101
|
-
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
102
|
-
|
|
103
|
-
function render() {
|
|
104
|
-
// Move up and clear previous render
|
|
105
|
-
if (selected !== -1) {
|
|
106
|
-
for (let i = 0; i < items.length; i++) {
|
|
107
|
-
process.stdout.write(c.up + c.erase);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (let i = 0; i < items.length; i++) {
|
|
111
|
-
const item = items[i];
|
|
112
|
-
const pointer = i === selected ? `${c.cyan}❯${c.reset}` : ' ';
|
|
113
|
-
const label = i === selected ? `${c.bold}${item.label}${c.reset}` : `${c.dim}${item.label}${c.reset}`;
|
|
114
|
-
const desc = item.desc ? ` ${c.dim}${item.desc}${c.reset}` : '';
|
|
115
|
-
console.log(` ${pointer} ${label}${desc}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
console.log(` ${c.bold}${title}${c.reset} ${c.dim}(↑↓ to select, Enter to confirm)${c.reset}`);
|
|
120
|
-
console.log('');
|
|
121
|
-
// Initial placeholder lines
|
|
122
|
-
for (let i = 0; i < items.length; i++) {
|
|
123
|
-
console.log('');
|
|
124
|
-
}
|
|
125
|
-
render();
|
|
126
|
-
|
|
127
|
-
process.stdin.on('keypress', (_ch, key) => {
|
|
128
|
-
if (!key) return;
|
|
129
|
-
if (key.name === 'up' && selected > 0) {
|
|
130
|
-
selected--;
|
|
131
|
-
render();
|
|
132
|
-
} else if (key.name === 'down' && selected < items.length - 1) {
|
|
133
|
-
selected++;
|
|
134
|
-
render();
|
|
135
|
-
} else if (key.name === 'return') {
|
|
136
|
-
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
137
|
-
rl.close();
|
|
138
|
-
resolve(items[selected].value);
|
|
139
|
-
} else if (key.name === 'c' && key.ctrl) {
|
|
140
|
-
if (process.stdin.isTTY) process.stdin.setRawMode(false);
|
|
141
|
-
rl.close();
|
|
142
|
-
process.stdout.write(c.show);
|
|
143
|
-
console.log('');
|
|
144
|
-
process.exit(0);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function promptInput(question, defaultVal = '') {
|
|
151
|
-
return new Promise((resolve) => {
|
|
152
|
-
if (!isTTY) {
|
|
153
|
-
resolve(defaultVal);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
157
|
-
const prompt = defaultVal
|
|
158
|
-
? ` ${question} ${c.dim}(${defaultVal})${c.reset}: `
|
|
159
|
-
: ` ${question}: `;
|
|
160
|
-
rl.question(prompt, (answer) => {
|
|
161
|
-
rl.close();
|
|
162
|
-
resolve(answer.trim() || defaultVal);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ── Argument parsing (non-interactive fast path) ────────────────────
|
|
168
|
-
|
|
169
|
-
function parseArgs(argv) {
|
|
170
|
-
const args = argv.slice(2);
|
|
171
|
-
const opts = {
|
|
172
|
-
port: parseInt(process.env.PORT, 10) || 8765,
|
|
173
|
-
path: process.env.CLAUDE_REMOTE_ALLOWED_PATH || os.homedir(),
|
|
174
|
-
apiKey: process.env.CLAUDE_REMOTE_API_KEY || null,
|
|
175
|
-
bonjour: true,
|
|
176
|
-
qr: true,
|
|
177
|
-
tunnel: false,
|
|
178
|
-
hooks: null, // null = ask in interactive, true = install, false = skip
|
|
179
|
-
interactive: null, // null = auto (TTY → true)
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
for (let i = 0; i < args.length; i++) {
|
|
183
|
-
switch (args[i]) {
|
|
184
|
-
case '-v': case '--version':
|
|
185
|
-
console.log(VERSION);
|
|
186
|
-
process.exit(0);
|
|
187
|
-
break;
|
|
188
|
-
case '-h': case '--help':
|
|
189
|
-
printHelp();
|
|
190
|
-
process.exit(0);
|
|
191
|
-
break;
|
|
192
|
-
case '-p': case '--port':
|
|
193
|
-
opts.port = parseInt(args[++i], 10) || 8765;
|
|
194
|
-
break;
|
|
195
|
-
case '--path':
|
|
196
|
-
opts.path = path.resolve(args[++i] || os.homedir());
|
|
197
|
-
break;
|
|
198
|
-
case '--api-key':
|
|
199
|
-
opts.apiKey = args[++i];
|
|
200
|
-
break;
|
|
201
|
-
case '--tunnel':
|
|
202
|
-
opts.tunnel = true;
|
|
203
|
-
opts.interactive = false;
|
|
204
|
-
break;
|
|
205
|
-
case '--no-bonjour':
|
|
206
|
-
opts.bonjour = false;
|
|
207
|
-
break;
|
|
208
|
-
case '--no-qr':
|
|
209
|
-
opts.qr = false;
|
|
210
|
-
break;
|
|
211
|
-
case '--install-hooks':
|
|
212
|
-
opts.hooks = true;
|
|
213
|
-
break;
|
|
214
|
-
case '--no-hooks':
|
|
215
|
-
opts.hooks = false;
|
|
216
|
-
break;
|
|
217
|
-
case '--remove-hooks': {
|
|
218
|
-
const { removeHooks } = require('../lib/hookInstaller');
|
|
219
|
-
removeHooks();
|
|
220
|
-
console.log(` ${ok} Claude Code hooks removed`);
|
|
221
|
-
process.exit(0);
|
|
222
|
-
break;
|
|
223
|
-
}
|
|
224
|
-
case '--no-color':
|
|
225
|
-
break;
|
|
226
|
-
case '--no-interactive':
|
|
227
|
-
opts.interactive = false;
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (opts.interactive === null) {
|
|
233
|
-
opts.interactive = isTTY;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return opts;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function printHelp() {
|
|
240
|
-
console.log('');
|
|
241
|
-
for (const line of LOGO) console.log(line);
|
|
242
|
-
console.log(`
|
|
243
|
-
${c.dim}v${VERSION}${c.reset} Control Claude Code from your iPhone/iPad
|
|
244
|
-
|
|
245
|
-
${c.bold}Usage${c.reset}
|
|
246
|
-
$ npx tacticremote ${c.dim}[options]${c.reset}
|
|
247
|
-
|
|
248
|
-
${c.bold}Options${c.reset}
|
|
249
|
-
-p, --port <n> Port to listen on ${c.dim}[8765]${c.reset}
|
|
250
|
-
--path <dir> Allowed base directory ${c.dim}[$HOME]${c.reset}
|
|
251
|
-
--api-key <key> Require authentication
|
|
252
|
-
--tunnel Enable Cloudflare tunnel ${c.dim}(public access)${c.reset}
|
|
253
|
-
--install-hooks Install Claude Code hooks ${c.dim}(notifications)${c.reset}
|
|
254
|
-
--no-hooks Skip hook installation
|
|
255
|
-
--remove-hooks Remove installed hooks and exit
|
|
256
|
-
--no-bonjour Disable mDNS discovery
|
|
257
|
-
--no-qr Don't show QR code
|
|
258
|
-
--no-interactive Skip interactive prompts
|
|
259
|
-
--no-color Disable colored output
|
|
260
|
-
-v, --version Show version
|
|
261
|
-
-h, --help Show this help
|
|
262
|
-
|
|
263
|
-
${c.bold}Examples${c.reset}
|
|
264
|
-
${c.dim}$${c.reset} npx tacticremote
|
|
265
|
-
${c.dim}$${c.reset} npx tacticremote --tunnel --api-key mysecret
|
|
266
|
-
${c.dim}$${c.reset} npx tacticremote -p 9000
|
|
267
|
-
|
|
268
|
-
${c.cyan}https://tacticremote.com${c.reset}
|
|
269
|
-
`);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// ── Preflight ───────────────────────────────────────────────────────
|
|
273
|
-
|
|
274
|
-
async function preflight(opts) {
|
|
275
|
-
console.log(` ${c.bold}Preflight${c.reset}`);
|
|
276
|
-
console.log('');
|
|
277
|
-
|
|
278
|
-
const checks = [];
|
|
279
|
-
|
|
280
|
-
// Node
|
|
281
|
-
const nodeVer = process.versions.node;
|
|
282
|
-
const nodeMajor = parseInt(nodeVer.split('.')[0], 10);
|
|
283
|
-
if (nodeMajor < 16) {
|
|
284
|
-
checks.push({ ok: false, msg: `Node.js v${nodeVer}`, hint: 'requires >= 16', fatal: true });
|
|
285
|
-
} else {
|
|
286
|
-
checks.push({ ok: true, msg: `Node.js ${c.dim}v${nodeVer}${c.reset}` });
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// tmux
|
|
290
|
-
const tmuxPath = which('tmux');
|
|
291
|
-
if (!tmuxPath) {
|
|
292
|
-
const hint = process.platform === 'darwin' ? 'brew install tmux' : 'sudo apt install tmux';
|
|
293
|
-
checks.push({ ok: false, msg: 'tmux', hint, fatal: true });
|
|
294
|
-
} else {
|
|
295
|
-
const tmuxVer = getVersion('tmux', '-V');
|
|
296
|
-
checks.push({ ok: true, msg: `tmux ${c.dim}${tmuxVer || ''} (${tmuxPath})${c.reset}` });
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Claude
|
|
300
|
-
const claudePath = which('claude');
|
|
301
|
-
if (claudePath) {
|
|
302
|
-
checks.push({ ok: true, msg: `claude ${c.dim}(${claudePath})${c.reset}` });
|
|
303
|
-
} else {
|
|
304
|
-
checks.push({ ok: 'warn', msg: `claude ${c.dim}not in PATH (optional)${c.reset}` });
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
// cloudflared (if tunnel requested)
|
|
308
|
-
if (opts.tunnel) {
|
|
309
|
-
const cfPath = which('cloudflared');
|
|
310
|
-
if (!cfPath) {
|
|
311
|
-
const hint = process.platform === 'darwin'
|
|
312
|
-
? 'brew install cloudflared'
|
|
313
|
-
: 'https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/';
|
|
314
|
-
checks.push({ ok: false, msg: 'cloudflared', hint, fatal: true });
|
|
315
|
-
} else {
|
|
316
|
-
checks.push({ ok: true, msg: `cloudflared ${c.dim}(${cfPath})${c.reset}` });
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// Animate checks
|
|
321
|
-
for (const check of checks) {
|
|
322
|
-
if (isTTY) await sleep(120);
|
|
323
|
-
const icon = check.ok === true ? ok : check.ok === 'warn' ? warn : fail;
|
|
324
|
-
console.log(` ${icon} ${check.msg}`);
|
|
325
|
-
if (!check.ok && check.ok !== 'warn' && check.hint) {
|
|
326
|
-
console.log(` ${c.dim}${check.hint}${c.reset}`);
|
|
327
|
-
}
|
|
328
|
-
if (check.fatal && !check.ok) {
|
|
329
|
-
console.log('');
|
|
330
|
-
process.exit(1);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
console.log('');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// ── Cloudflare Tunnel ───────────────────────────────────────────────
|
|
338
|
-
|
|
339
|
-
function startTunnel(port) {
|
|
340
|
-
return new Promise((resolve, reject) => {
|
|
341
|
-
const cfPath = which('cloudflared');
|
|
342
|
-
const proc = spawn(cfPath, ['tunnel', '--protocol', 'http2', '--url', `http://localhost:${port}`], {
|
|
343
|
-
stdio: ['ignore', 'pipe', 'pipe']
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
let resolved = false;
|
|
347
|
-
const urlPattern = /https:\/\/[a-zA-Z0-9-]+\.trycloudflare\.com/;
|
|
348
|
-
const timeout = setTimeout(() => {
|
|
349
|
-
if (!resolved) { resolved = true; reject(new Error('Tunnel timed out (30s)')); }
|
|
350
|
-
}, 30000);
|
|
351
|
-
|
|
352
|
-
const handleData = (data) => {
|
|
353
|
-
const match = data.toString().match(urlPattern);
|
|
354
|
-
if (match && !resolved) {
|
|
355
|
-
resolved = true;
|
|
356
|
-
clearTimeout(timeout);
|
|
357
|
-
resolve({ url: match[0], process: proc });
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
proc.stdout.on('data', handleData);
|
|
362
|
-
proc.stderr.on('data', handleData);
|
|
363
|
-
proc.on('error', (err) => { if (!resolved) { resolved = true; clearTimeout(timeout); reject(err); } });
|
|
364
|
-
proc.on('exit', (code) => { if (!resolved) { resolved = true; clearTimeout(timeout); reject(new Error(`cloudflared exited (${code})`)); } });
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// ── Banner ──────────────────────────────────────────────────────────
|
|
369
|
-
|
|
370
|
-
function printBanner(opts, tunnelUrl) {
|
|
371
|
-
const ip = getLocalIP();
|
|
372
|
-
const line = `${c.dim}${'─'.repeat(42)}${c.reset}`;
|
|
373
|
-
|
|
374
|
-
console.log(line);
|
|
375
|
-
console.log('');
|
|
376
|
-
|
|
377
|
-
if (tunnelUrl) {
|
|
378
|
-
console.log(` ${c.cyan}PUBLIC${c.reset} ${c.bold}${tunnelUrl}${c.reset}`);
|
|
379
|
-
console.log(` ${c.dim}LAN ws://${ip}:${opts.port}${c.reset}`);
|
|
380
|
-
} else {
|
|
381
|
-
console.log(` ${c.dim}LAN${c.reset} ${c.cyan}ws://${ip}:${opts.port}${c.reset}`);
|
|
382
|
-
}
|
|
383
|
-
console.log(` ${c.dim}Hook${c.reset} http://${ip}:${opts.port}/hook`);
|
|
384
|
-
console.log(` ${c.dim}Auth${c.reset} ${opts.apiKey ? c.green + 'enabled' + c.reset : c.yellow + 'disabled' + c.reset}`);
|
|
385
|
-
console.log(` ${c.dim}Path${c.reset} ${opts.path}`);
|
|
386
|
-
console.log('');
|
|
387
|
-
|
|
388
|
-
if (opts.qr) {
|
|
389
|
-
try {
|
|
390
|
-
const qrcode = require('qrcode-terminal');
|
|
391
|
-
const qrData = tunnelUrl
|
|
392
|
-
? JSON.stringify({ ip: '', port: 0, tunnelUrl, apiKey: opts.apiKey, mode: 'cloudflare', version: QR_PROTOCOL_VERSION })
|
|
393
|
-
: JSON.stringify({ ip, port: opts.port, apiKey: opts.apiKey || null, mode: 'lan', version: QR_PROTOCOL_VERSION });
|
|
394
|
-
|
|
395
|
-
qrcode.generate(qrData, { small: true }, (code) => {
|
|
396
|
-
const lines = code.split('\n');
|
|
397
|
-
for (const l of lines) {
|
|
398
|
-
if (l.trim()) console.log(` ${l}`);
|
|
399
|
-
}
|
|
400
|
-
console.log('');
|
|
401
|
-
console.log(` ${c.dim}Scan with Tactic Remote app${c.reset}`);
|
|
402
|
-
console.log(` ${c.dim}Get the app:${c.reset} ${c.cyan}https://apps.apple.com/app/tactic-remote-ai-coding/id6758008464${c.reset}`);
|
|
403
|
-
console.log(` ${c.cyan}https://tacticremote.com${c.reset}`);
|
|
404
|
-
console.log('');
|
|
405
|
-
console.log(line);
|
|
406
|
-
console.log(` ${c.dim}Ctrl+C to stop${c.reset}`);
|
|
407
|
-
console.log('');
|
|
408
|
-
});
|
|
409
|
-
} catch (_e) {
|
|
410
|
-
printFooter(line, tunnelUrl || `ws://${ip}:${opts.port}`);
|
|
411
|
-
}
|
|
412
|
-
} else {
|
|
413
|
-
printFooter(line, tunnelUrl || `ws://${ip}:${opts.port}`);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
function printFooter(line, url) {
|
|
418
|
-
console.log(` ${c.dim}Connect:${c.reset} ${url}`);
|
|
419
|
-
console.log('');
|
|
420
|
-
console.log(line);
|
|
421
|
-
console.log(` ${c.dim}Ctrl+C to stop${c.reset}`);
|
|
422
|
-
console.log('');
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
// ── Main ────────────────────────────────────────────────────────────
|
|
426
|
-
|
|
427
|
-
async function main() {
|
|
428
|
-
const opts = parseArgs(process.argv);
|
|
429
|
-
|
|
430
|
-
// ── Logo ──
|
|
431
|
-
console.log('');
|
|
432
|
-
for (const line of LOGO) console.log(line);
|
|
433
|
-
console.log('');
|
|
434
|
-
console.log(` ${c.dim}v${VERSION} ${process.platform}/${os.arch()}${c.reset}`);
|
|
435
|
-
console.log('');
|
|
436
|
-
|
|
437
|
-
// ── Preflight (before interactive choices, so user sees deps) ──
|
|
438
|
-
await preflight(opts);
|
|
439
|
-
|
|
440
|
-
// ── Hooks ──
|
|
441
|
-
const { checkHooksInstalled, installHooks } = require('../lib/hookInstaller');
|
|
442
|
-
const hooksInstalled = checkHooksInstalled();
|
|
443
|
-
|
|
444
|
-
if (opts.hooks === true) {
|
|
445
|
-
// --install-hooks flag
|
|
446
|
-
if (!hooksInstalled) {
|
|
447
|
-
installHooks();
|
|
448
|
-
console.log(` ${ok} Claude Code hooks installed`);
|
|
449
|
-
console.log('');
|
|
450
|
-
} else {
|
|
451
|
-
console.log(` ${ok} Claude Code hooks already installed`);
|
|
452
|
-
console.log('');
|
|
453
|
-
}
|
|
454
|
-
} else if (opts.hooks === false) {
|
|
455
|
-
// --no-hooks flag — skip silently
|
|
456
|
-
} else if (hooksInstalled) {
|
|
457
|
-
console.log(` ${ok} Claude Code hooks installed`);
|
|
458
|
-
console.log('');
|
|
459
|
-
} else if (opts.interactive) {
|
|
460
|
-
// Ask user
|
|
461
|
-
const answer = await selectMenu('Install Claude Code hooks?', [
|
|
462
|
-
{ label: 'Yes', desc: 'enable task completion & tool notifications', value: 'yes' },
|
|
463
|
-
{ label: 'No', desc: 'skip (can install later with --install-hooks)', value: 'no' },
|
|
464
|
-
]);
|
|
465
|
-
console.log('');
|
|
466
|
-
if (answer === 'yes') {
|
|
467
|
-
installHooks();
|
|
468
|
-
console.log(` ${ok} Claude Code hooks installed`);
|
|
469
|
-
console.log('');
|
|
470
|
-
}
|
|
471
|
-
} else {
|
|
472
|
-
console.log(` ${warn} Claude Code hooks not installed ${c.dim}(use --install-hooks)${c.reset}`);
|
|
473
|
-
console.log('');
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// ── Interactive mode: choose connection ──
|
|
477
|
-
if (opts.interactive && !opts.tunnel) {
|
|
478
|
-
const mode = await selectMenu('Connection mode', [
|
|
479
|
-
{ label: 'LAN', desc: 'local network (default)', value: 'lan' },
|
|
480
|
-
{ label: 'Cloudflare Tunnel', desc: 'public access via wss://', value: 'tunnel' },
|
|
481
|
-
]);
|
|
482
|
-
|
|
483
|
-
if (mode === 'tunnel') {
|
|
484
|
-
opts.tunnel = true;
|
|
485
|
-
|
|
486
|
-
// Check cloudflared
|
|
487
|
-
const cfPath = which('cloudflared');
|
|
488
|
-
if (!cfPath) {
|
|
489
|
-
console.log('');
|
|
490
|
-
console.log(` ${fail} cloudflared not found`);
|
|
491
|
-
const hint = process.platform === 'darwin' ? 'brew install cloudflared' : 'see cloudflare docs';
|
|
492
|
-
console.log(` ${c.dim}${hint}${c.reset}`);
|
|
493
|
-
console.log('');
|
|
494
|
-
process.exit(1);
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// API key — required for tunnel, offer auto-generate
|
|
498
|
-
if (!opts.apiKey) {
|
|
499
|
-
console.log('');
|
|
500
|
-
const keyMode = await selectMenu('API Key (required for tunnel)', [
|
|
501
|
-
{ label: 'Auto-generate', desc: 'random 32-char key', value: 'auto' },
|
|
502
|
-
{ label: 'Enter manually', desc: 'type your own key', value: 'manual' },
|
|
503
|
-
]);
|
|
504
|
-
|
|
505
|
-
if (keyMode === 'auto') {
|
|
506
|
-
opts.apiKey = crypto.randomBytes(16).toString('hex');
|
|
507
|
-
console.log('');
|
|
508
|
-
console.log(` ${ok} API Key: ${c.bold}${opts.apiKey}${c.reset}`);
|
|
509
|
-
console.log(` ${c.dim}Enter this key in the iOS app to connect${c.reset}`);
|
|
510
|
-
} else {
|
|
511
|
-
console.log('');
|
|
512
|
-
const key = await promptInput(`${c.bold}API key${c.reset}`);
|
|
513
|
-
if (!key) {
|
|
514
|
-
console.log(` ${fail} API key is required for tunnel mode`);
|
|
515
|
-
console.log('');
|
|
516
|
-
process.exit(1);
|
|
517
|
-
}
|
|
518
|
-
opts.apiKey = key;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// Ask port if user wants to change
|
|
524
|
-
console.log('');
|
|
525
|
-
const portAnswer = await promptInput(`${c.bold}Port${c.reset}`, String(opts.port));
|
|
526
|
-
const parsedPort = parseInt(portAnswer, 10);
|
|
527
|
-
if (parsedPort && parsedPort > 0 && parsedPort < 65536) {
|
|
528
|
-
opts.port = parsedPort;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
console.log('');
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
// Non-interactive tunnel checks
|
|
535
|
-
if (opts.tunnel && !opts.apiKey) {
|
|
536
|
-
console.log(` ${fail} --api-key is required for --tunnel`);
|
|
537
|
-
console.log(` ${c.dim}npx tacticremote --tunnel --api-key mysecret${c.reset}`);
|
|
538
|
-
console.log('');
|
|
539
|
-
process.exit(1);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
// ── Start server ──
|
|
543
|
-
console.log(` ${c.bold}Starting${c.reset}`);
|
|
544
|
-
|
|
545
|
-
const { ClaudeRemoteServer } = require('../server');
|
|
546
|
-
const server = new ClaudeRemoteServer({
|
|
547
|
-
port: opts.port,
|
|
548
|
-
allowedPath: opts.path,
|
|
549
|
-
apiKey: opts.apiKey,
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
let bonjour = null;
|
|
553
|
-
let tunnelProc = null;
|
|
554
|
-
let tunnelUrl = null;
|
|
555
|
-
|
|
556
|
-
try {
|
|
557
|
-
await server.start();
|
|
558
|
-
console.log(` ${ok} WebSocket server on 0.0.0.0:${opts.port}`);
|
|
559
|
-
} catch (err) {
|
|
560
|
-
if (err.code === 'EADDRINUSE') {
|
|
561
|
-
console.log(` ${fail} Port ${opts.port} is already in use`);
|
|
562
|
-
console.log(` ${c.dim}Try: --port ${opts.port + 1}${c.reset}`);
|
|
563
|
-
} else if (err.code === 'EACCES') {
|
|
564
|
-
console.log(` ${fail} Permission denied on port ${opts.port}`);
|
|
565
|
-
console.log(` ${c.dim}Use a port above 1024${c.reset}`);
|
|
566
|
-
} else {
|
|
567
|
-
console.log(` ${fail} ${err.message}`);
|
|
568
|
-
}
|
|
569
|
-
console.log('');
|
|
570
|
-
process.exit(1);
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// Bonjour
|
|
574
|
-
if (opts.bonjour && !opts.tunnel) {
|
|
575
|
-
try {
|
|
576
|
-
const { BonjourPublisher } = require('../lib/bonjourPublisher');
|
|
577
|
-
bonjour = new BonjourPublisher(opts.port, !!opts.apiKey, { silent: true });
|
|
578
|
-
bonjour.start();
|
|
579
|
-
console.log(` ${ok} Bonjour mDNS`);
|
|
580
|
-
} catch (_e) {
|
|
581
|
-
console.log(` ${warn} Bonjour unavailable`);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
// Cloudflare tunnel
|
|
586
|
-
if (opts.tunnel) {
|
|
587
|
-
console.log(` ${dot} Cloudflare tunnel ${c.dim}connecting...${c.reset}`);
|
|
588
|
-
try {
|
|
589
|
-
const result = await startTunnel(opts.port);
|
|
590
|
-
tunnelUrl = result.url;
|
|
591
|
-
tunnelProc = result.process;
|
|
592
|
-
process.stdout.write(c.up + c.erase);
|
|
593
|
-
console.log(` ${ok} Cloudflare tunnel ${c.dim}→${c.reset} ${c.cyan}${tunnelUrl}${c.reset}`);
|
|
594
|
-
} catch (err) {
|
|
595
|
-
process.stdout.write(c.up + c.erase);
|
|
596
|
-
console.log(` ${fail} Tunnel: ${err.message}`);
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
console.log('');
|
|
601
|
-
|
|
602
|
-
// ── Ready banner ──
|
|
603
|
-
printBanner(opts, tunnelUrl);
|
|
604
|
-
|
|
605
|
-
// ── Graceful shutdown ──
|
|
606
|
-
const shutdown = async (_signal) => {
|
|
607
|
-
console.log('');
|
|
608
|
-
console.log(` ${c.dim}Shutting down...${c.reset}`);
|
|
609
|
-
|
|
610
|
-
if (tunnelProc) {
|
|
611
|
-
tunnelProc.kill('SIGTERM');
|
|
612
|
-
console.log(` ${ok} Stopped tunnel`);
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const killed = await server.stop();
|
|
616
|
-
if (killed.length > 0) {
|
|
617
|
-
console.log(` ${ok} Cleaned up ${killed.length} tmux session${killed.length > 1 ? 's' : ''}`);
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
if (bonjour) {
|
|
621
|
-
bonjour.stop();
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
console.log(` ${ok} Server closed`);
|
|
625
|
-
console.log('');
|
|
626
|
-
process.exit(0);
|
|
627
|
-
};
|
|
628
|
-
|
|
629
|
-
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
630
|
-
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
main().catch((err) => {
|
|
634
|
-
console.error(` ${fail} ${err.message}`);
|
|
635
|
-
process.exit(1);
|
|
636
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('../shared/server-core/authChallengeManager');
|