@hmduc16031996/claude-mb-bridge 2.4.7 → 2.4.9

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/dist/index.js CHANGED
@@ -3,65 +3,54 @@ import { Command } from 'commander';
3
3
  import { CloudflareTunnel } from './tunnel.js';
4
4
  import { startTerminalServer } from './server.js';
5
5
  const program = new Command();
6
+ const CLOUDFLARE_TUNNEL_TOKEN = 'eyJhIjoiZmM5YTQ4ZTU3NjY4NjI3MjY2OWE3YzBiMTliNTcyYzgiLCJ0IjoiMjgzM2E5NjMtNTBiYi00YThjLWJhMGMtNDI4NWE4ZTJkZmJjIiwicyI6IllqYzVaakF3T1RJdFpEWXdZeTAwWkRFNUxUZzVNR0l0WXpBeE1UazJNamc1T1dZeCJ9';
7
+ const CLOUDFLARE_PUBLIC_URL = 'https://mobileideforusers.kanddlabs.com';
6
8
  program
7
9
  .name('claude-mobile-bridge')
8
10
  .description('Bridge Claude Code CLI to mobile via WebView')
9
11
  .version('2.4.1')
10
12
  .option('--token <token>', 'Pairing token from mobile app')
11
- .option('--server <url>', 'Backend server URL', 'http://127.0.0.1:3110')
13
+ .option('--server <url>', 'Backend server URL', 'https://mobileide.kanddlabs.com')
12
14
  .option('--path <path>', 'Working directory', process.cwd())
13
15
  .option('--port <port>', 'Local port for terminal server', '38473')
14
- .option('--ide <type>', 'IDE type: claude_code, cursor, or gemini', 'claude_code')
15
- // Named tunnel options (use your own Cloudflare tunnel instead of trycloudflare)
16
- .option('--cloudflare-token <cfToken>', 'Cloudflare tunnel token for named tunnel')
17
- .option('--tunnel-url <url>', 'Public URL of your named Cloudflare tunnel (e.g. https://mobileideforusers.kanddlabs.com)')
16
+ .option('--ide <type>', 'IDE type: claude_code or cursor', 'claude_code')
17
+ .option('--tunnel-token <token>', 'Cloudflare Tunnel token (managed tunnel)', CLOUDFLARE_TUNNEL_TOKEN)
18
+ .option('--public-url <url>', 'Static public URL for the tunnel', CLOUDFLARE_PUBLIC_URL)
18
19
  .action(async (options) => {
19
- const { token, server, path, port, ide, cloudflareToken, tunnelUrl } = options;
20
+ const { token, server, path, port, ide, tunnelToken, publicUrl } = options;
20
21
  if (!token) {
21
22
  console.error('Error: --token is required');
22
23
  process.exit(1);
23
24
  }
24
- // Validate named-tunnel options: both must be provided together or neither
25
- const useNamedTunnel = !!(cloudflareToken || tunnelUrl);
26
- if (useNamedTunnel && !(cloudflareToken && tunnelUrl)) {
27
- console.error('Error: --cloudflare-token and --tunnel-url must both be provided when using a named tunnel');
28
- process.exit(1);
29
- }
30
- let tunnelResult = null;
31
- let terminalServer = null;
32
25
  // Define cleanup function
33
26
  const cleanup = async () => {
34
27
  console.log('\nšŸ‘‹ Cleaning up session and shutting down...');
35
28
  try {
29
+ // Optional: Notify server to end session
36
30
  await fetch(`${server}/api/sessions/${token}/expire`, { method: 'POST' }).catch(() => { });
37
31
  }
38
32
  finally {
39
- tunnelResult?.cleanup();
40
- terminalServer?.close();
33
+ tunnelResult.cleanup();
34
+ terminalServer.close();
41
35
  process.exit(0);
42
36
  }
43
37
  };
44
38
  // 1. Start local terminal server
45
39
  console.log('šŸ“¦ Starting terminal server...');
46
40
  const localPort = parseInt(port, 10);
47
- const { server: ts, actualPort } = await startTerminalServer(localPort, path, token, ide);
48
- terminalServer = ts;
41
+ const { server: terminalServer, actualPort } = await startTerminalServer(localPort, path, token, ide);
49
42
  console.log(`āœ… Terminal server started on port ${actualPort}`);
50
- // 2. Start Cloudflare Tunnel (named or quick)
43
+ // 2. Start Cloudflare Tunnel
44
+ console.log('🌐 Establishing secure tunnel...');
51
45
  const tunnel = new CloudflareTunnel();
52
- if (useNamedTunnel) {
53
- console.log(`🌐 Connecting named Cloudflare tunnel → ${tunnelUrl} ...`);
54
- tunnelResult = await tunnel.startNamed(cloudflareToken, tunnelUrl);
55
- }
56
- else {
57
- console.log('🌐 Establishing ephemeral Cloudflare tunnel...');
58
- tunnelResult = await tunnel.startQuick(actualPort);
59
- }
60
- if (!tunnelResult.url) {
61
- console.error('āŒ Failed to start Cloudflare Tunnel.');
46
+ const tunnelResult = await tunnel.start(actualPort, tunnelToken);
47
+ // If using a token, use the provided publicUrl or hardcoded one
48
+ const finalUrl = tunnelToken ? publicUrl : tunnelResult.url;
49
+ if (!finalUrl) {
50
+ console.error('āŒ Failed to establish secure tunnel.');
62
51
  process.exit(1);
63
52
  }
64
- console.log(`āœ… Tunnel active: ${tunnelResult.url}`);
53
+ console.log(`āœ… Secure tunnel established at ${finalUrl}`);
65
54
  // 3. Validate token and report public URL to central server
66
55
  console.log('šŸ”‘ Validating session token...');
67
56
  try {
@@ -71,19 +60,18 @@ program
71
60
  'Content-Type': 'application/json'
72
61
  },
73
62
  body: JSON.stringify({
74
- public_url: tunnelResult.url
63
+ public_url: finalUrl
75
64
  })
76
65
  });
77
66
  if (!res.ok) {
78
67
  throw new Error('Invalid token or session expired');
79
68
  }
80
69
  console.log('āœ… Session connected and authorized');
81
- console.log(`šŸ“± Mobile app can now connect via: ${tunnelResult.url}`);
82
70
  }
83
71
  catch (err) {
84
72
  console.error(`āŒ Validation failed: ${err.message}`);
85
73
  console.error(' Ensure the central server is available');
86
- await cleanup();
74
+ cleanup();
87
75
  }
88
76
  // Handle graceful shutdown signals
89
77
  process.on('SIGINT', cleanup);
package/dist/tunnel.d.ts CHANGED
@@ -4,15 +4,6 @@ export interface TunnelResult {
4
4
  }
5
5
  export declare class CloudflareTunnel {
6
6
  private process;
7
- /**
8
- * Start a named Cloudflare tunnel using a pre-existing tunnel token.
9
- * The public URL is known ahead of time (configured in Cloudflare dashboard).
10
- */
11
- startNamed(tunnelToken: string, publicUrl: string): Promise<TunnelResult>;
12
- /**
13
- * Start an ephemeral quick tunnel (trycloudflare.com).
14
- * The public URL is parsed from cloudflared stderr output.
15
- */
16
- startQuick(port: number): Promise<TunnelResult>;
7
+ start(port: number, token?: string): Promise<TunnelResult>;
17
8
  private cleanup;
18
9
  }
package/dist/tunnel.js CHANGED
@@ -1,65 +1,23 @@
1
1
  import { spawn } from 'child_process';
2
2
  export class CloudflareTunnel {
3
3
  process = null;
4
- /**
5
- * Start a named Cloudflare tunnel using a pre-existing tunnel token.
6
- * The public URL is known ahead of time (configured in Cloudflare dashboard).
7
- */
8
- async startNamed(tunnelToken, publicUrl) {
4
+ async start(port, token) {
9
5
  return new Promise((resolve) => {
10
6
  try {
11
- const proc = spawn('cloudflared', ['tunnel', 'run', '--token', tunnelToken], {
12
- stdio: ['ignore', 'pipe', 'pipe'],
13
- });
14
- this.process = proc;
15
- // Give cloudflared a moment to connect; fail if it exits immediately
16
- const timeout = setTimeout(() => {
17
- // Still resolving with the known public URL — named tunnels don't print the URL
18
- resolve({ url: publicUrl, cleanup: () => this.cleanup() });
19
- }, 5000);
20
- proc.stdout?.on('data', (data) => {
21
- console.log('[cloudflared]', data.toString().trim());
22
- });
23
- proc.stderr?.on('data', (data) => {
24
- const line = data.toString().trim();
25
- if (line)
26
- console.log('[cloudflared]', line);
27
- // If we see a connection established log, resolve immediately
28
- if (line.includes('Connection') || line.includes('registered')) {
29
- clearTimeout(timeout);
30
- resolve({ url: publicUrl, cleanup: () => this.cleanup() });
31
- }
32
- });
33
- proc.on('error', (err) => {
34
- clearTimeout(timeout);
35
- console.error('[cloudflared] Failed to start:', err.message);
36
- resolve({ url: null, cleanup: () => this.cleanup() });
37
- });
38
- proc.on('exit', (code) => {
39
- clearTimeout(timeout);
40
- if (code !== 0) {
41
- console.error(`[cloudflared] Exited with code ${code}`);
42
- }
43
- this.process = null;
44
- });
45
- }
46
- catch (err) {
47
- console.error('[cloudflared] Exception:', err.message);
48
- resolve({ url: null, cleanup: () => this.cleanup() });
49
- }
50
- });
51
- }
52
- /**
53
- * Start an ephemeral quick tunnel (trycloudflare.com).
54
- * The public URL is parsed from cloudflared stderr output.
55
- */
56
- async startQuick(port) {
57
- return new Promise((resolve) => {
58
- try {
59
- const proc = spawn('cloudflared', ['tunnel', '--url', `http://localhost:${port}`], {
7
+ const args = token
8
+ ? ['tunnel', 'run', '--token', token]
9
+ : ['tunnel', '--url', `http://localhost:${port}`];
10
+ const proc = spawn('cloudflared', args, {
60
11
  stdio: ['ignore', 'pipe', 'pipe'],
61
12
  });
62
13
  this.process = proc;
14
+ if (token) {
15
+ // For named tunnels, resolve immediately after a short delay
16
+ setTimeout(() => {
17
+ resolve({ url: null, cleanup: () => this.cleanup() });
18
+ }, 2000);
19
+ return;
20
+ }
63
21
  let output = '';
64
22
  const timeout = setTimeout(() => {
65
23
  resolve({ url: null, cleanup: () => this.cleanup() });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmduc16031996/claude-mb-bridge",
3
- "version": "2.4.7",
3
+ "version": "2.4.9",
4
4
  "description": "Bridge between Claude Code CLI and your mobile app via WebView",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",