remote-cli-agent 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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import { connect, disconnect } from './connection.js';
4
- import { listTmuxSessions, attachTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
4
+ import { listTmuxSessions, attachTmuxSession, createTmuxSession, spawnSession, cleanupAll, getSessionList } from './terminal.js';
5
5
  import fs from 'fs';
6
6
  import path from 'path';
7
7
  import os from 'os';
@@ -45,7 +45,8 @@ program
45
45
  .description('Connect to the server and register available sessions')
46
46
  .option('-s, --server <url>', 'Server URL (overrides config)')
47
47
  .option('-t, --token <token>', 'Agent token (overrides config)')
48
- .option('--spawn [command]', 'Spawn a new session on connect')
48
+ .option('--spawn [command]', 'Spawn a new PTY session (not shared locally)')
49
+ .option('--no-tmux', 'Disable tmux (use isolated PTY instead)')
49
50
  .action((opts) => {
50
51
  const config = loadConfig();
51
52
  const server = opts.server || config?.server;
@@ -58,14 +59,30 @@ program
58
59
  // Convert http(s) to ws(s) for WebSocket connection
59
60
  const wsUrl = server.replace(/^http/, 'ws');
60
61
  console.log(`Connecting to ${server}...`);
61
- // List tmux sessions
62
- const tmuxSessions = listTmuxSessions();
63
- if (tmuxSessions.length > 0) {
64
- console.log(`Found ${tmuxSessions.length} tmux session(s):`);
65
- tmuxSessions.forEach(s => console.log(` - ${s}`));
66
- // Auto-attach all tmux sessions
67
- for (const sessionName of tmuxSessions) {
68
- attachTmuxSession(sessionName);
62
+ const useTmux = opts.tmux !== false;
63
+ if (useTmux) {
64
+ // List tmux sessions
65
+ const tmuxSessions = listTmuxSessions();
66
+ if (tmuxSessions.length > 0) {
67
+ console.log(`Found ${tmuxSessions.length} tmux session(s):`);
68
+ tmuxSessions.forEach(s => console.log(` - ${s}`));
69
+ // Auto-attach all tmux sessions
70
+ for (const sessionName of tmuxSessions) {
71
+ attachTmuxSession(sessionName);
72
+ }
73
+ }
74
+ else {
75
+ // No tmux sessions - create one
76
+ console.log('No tmux sessions found. Creating one...');
77
+ const name = createTmuxSession('remote-cli');
78
+ if (name) {
79
+ attachTmuxSession(name);
80
+ console.log(`\nTo use this session locally: tmux attach -t ${name}`);
81
+ }
82
+ else {
83
+ console.log('Failed to create tmux session. Falling back to PTY...');
84
+ spawnSession();
85
+ }
69
86
  }
70
87
  }
71
88
  // Spawn a session if requested
@@ -73,9 +90,8 @@ program
73
90
  const command = typeof opts.spawn === 'string' ? opts.spawn : undefined;
74
91
  spawnSession(command);
75
92
  }
76
- // If no sessions available, spawn a default one
93
+ // If no sessions available (--no-tmux or tmux failed), spawn a default one
77
94
  if (getSessionList().length === 0) {
78
- console.log('No tmux sessions found. Spawning a default shell session...');
79
95
  spawnSession();
80
96
  }
81
97
  // Connect to server
@@ -12,6 +12,7 @@ export declare function getSessionList(): {
12
12
  name: string;
13
13
  command?: string;
14
14
  }[];
15
+ export declare function createTmuxSession(name?: string): string | null;
15
16
  export declare function listTmuxSessions(): string[];
16
17
  export declare function attachTmuxSession(sessionName: string): TerminalSession | null;
17
18
  export declare function spawnSession(command?: string): TerminalSession;
package/dist/terminal.js CHANGED
@@ -27,6 +27,19 @@ export function getSessionList() {
27
27
  command: s.command
28
28
  }));
29
29
  }
30
+ // Create a new tmux session
31
+ export function createTmuxSession(name) {
32
+ const sessionName = name || `remote-cli-${Date.now()}`;
33
+ try {
34
+ execSync(`tmux new-session -d -s ${sessionName}`, { encoding: 'utf-8' });
35
+ console.log(`Created tmux session: ${sessionName}`);
36
+ return sessionName;
37
+ }
38
+ catch (err) {
39
+ console.error('Failed to create tmux session:', err.message);
40
+ return null;
41
+ }
42
+ }
30
43
  // List available tmux sessions
31
44
  export function listTmuxSessions() {
32
45
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote-cli-agent",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "remote-cli": "./dist/index.js"