sam-coder-cli 1.0.21 → 1.0.23

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.
@@ -19,12 +19,33 @@ async function isPortInUse(port) {
19
19
  });
20
20
  }
21
21
 
22
+ async function findAvailablePort(startPort = 8080, maxAttempts = 10) {
23
+ let port = startPort;
24
+ let attempts = 0;
25
+
26
+ while (attempts < maxAttempts) {
27
+ const inUse = await isPortInUse(port);
28
+ if (!inUse) {
29
+ return port;
30
+ }
31
+ port++;
32
+ attempts++;
33
+ }
34
+ throw new Error(`Could not find an available port after ${maxAttempts} attempts`);
35
+ }
36
+
22
37
  async function ensureServerRunning(port = 8080) {
23
- const portInUse = await isPortInUse(port);
24
- if (!portInUse) {
38
+ try {
39
+ const availablePort = await findAvailablePort(port);
40
+ const isDefaultPort = (availablePort === port);
41
+
42
+ if (!isDefaultPort) {
43
+ console.log(chalk.yellow(`Port ${port} is in use, trying port ${availablePort}...`));
44
+ }
45
+
25
46
  console.log('Starting local multiplayer server...');
26
47
  // Start server in a detached process
27
- const serverProcess = spawn('node', [__filename, '--server', '--port', port.toString()], {
48
+ const serverProcess = spawn('node', [__filename, '--server', '--port', availablePort.toString()], {
28
49
  detached: true,
29
50
  stdio: 'ignore',
30
51
  windowsHide: true
@@ -34,9 +55,12 @@ async function ensureServerRunning(port = 8080) {
34
55
 
35
56
  // Wait for server to start
36
57
  await new Promise(resolve => setTimeout(resolve, 1000));
37
- console.log('Local multiplayer server started');
58
+ console.log(chalk.green(`Local multiplayer server started on port ${availablePort}`));
59
+ return `ws://localhost:${availablePort}`;
60
+ } catch (error) {
61
+ console.error(chalk.red('Failed to start multiplayer server:'), error.message);
62
+ throw error;
38
63
  }
39
- return `ws://localhost:${port}`;
40
64
  }
41
65
 
42
66
  class MultiplayerServer {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sam-coder-cli",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "SAM-CODER: An animated command-line AI assistant with agency capabilities.",
5
5
  "main": "bin/agi-cli.js",
6
6
  "bin": {