nstantpage-agent 0.8.10 → 0.8.12

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.
@@ -5,6 +5,7 @@ import chalk from 'chalk';
5
5
  import open from 'open';
6
6
  import http from 'http';
7
7
  import { getConfig } from '../config.js';
8
+ import { serviceInstallCommand } from './service.js';
8
9
  /**
9
10
  * Resolve the frontend URL based on gateway.
10
11
  * - If gateway points to localhost → frontend is http://localhost:5001
@@ -178,6 +179,16 @@ export async function loginCommand(options = {}) {
178
179
  if (email)
179
180
  console.log(chalk.gray(` Account: ${email}`));
180
181
  console.log(chalk.gray(` Server: ${isLocal ? 'localhost (dev)' : 'nstantpage.com'}`));
181
- console.log(chalk.gray(' Run "nstantpage start" to connect your machine'));
182
+ // Auto-install background service with the new token
183
+ const gateway = conf.get('gatewayUrl') || 'wss://webprev.live';
184
+ try {
185
+ await serviceInstallCommand({ gateway });
186
+ console.log(chalk.green(' ✓ Agent is running as a background service.'));
187
+ console.log(chalk.gray(' Use "nstantpage logs" to view agent output.'));
188
+ }
189
+ catch (err) {
190
+ console.log(chalk.yellow(` ⚠ Could not install background service: ${err.message}`));
191
+ console.log(chalk.gray(' Run "nstantpage run" to start manually.'));
192
+ }
182
193
  }
183
194
  //# sourceMappingURL=login.js.map
@@ -1,4 +1,9 @@
1
1
  /**
2
- * Status command — show agent connection status
2
+ * Status command — show agent connection status.
3
+ *
4
+ * Checks three sources:
5
+ * 1. Status server at localhost:18999 (most accurate — shows live tunnel state)
6
+ * 2. OS service (launchd on macOS, systemd on Linux)
7
+ * 3. Stored config (auth, gateway)
3
8
  */
4
9
  export declare function statusCommand(): Promise<void>;
@@ -1,53 +1,103 @@
1
1
  /**
2
- * Status command — show agent connection status
2
+ * Status command — show agent connection status.
3
+ *
4
+ * Checks three sources:
5
+ * 1. Status server at localhost:18999 (most accurate — shows live tunnel state)
6
+ * 2. OS service (launchd on macOS, systemd on Linux)
7
+ * 3. Stored config (auth, gateway)
3
8
  */
4
9
  import chalk from 'chalk';
10
+ import os from 'os';
11
+ import { execSync } from 'child_process';
5
12
  import { getConfig } from '../config.js';
13
+ import { getPackageVersion } from '../version.js';
14
+ const STATUS_PORT = 18999;
15
+ async function fetchAgentStatus() {
16
+ try {
17
+ const controller = new AbortController();
18
+ const timeout = setTimeout(() => controller.abort(), 2000);
19
+ const res = await fetch(`http://localhost:${STATUS_PORT}/status`, { signal: controller.signal });
20
+ clearTimeout(timeout);
21
+ if (!res.ok)
22
+ return null;
23
+ return await res.json();
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ }
29
+ function checkOsService() {
30
+ const platform = os.platform();
31
+ if (platform === 'darwin') {
32
+ try {
33
+ const result = execSync('launchctl list | grep com.nstantpage.agent', { encoding: 'utf-8' }).trim();
34
+ if (result) {
35
+ const pid = result.split('\t')[0];
36
+ return { installed: true, pid: pid !== '-' ? pid : undefined };
37
+ }
38
+ }
39
+ catch { }
40
+ }
41
+ else if (platform === 'linux') {
42
+ try {
43
+ const result = execSync('systemctl --user is-active nstantpage-agent 2>/dev/null', { encoding: 'utf-8' }).trim();
44
+ return { installed: true, pid: result === 'active' ? 'active' : undefined };
45
+ }
46
+ catch { }
47
+ }
48
+ return { installed: false };
49
+ }
50
+ function formatUptime(ms) {
51
+ const s = Math.floor(ms / 1000);
52
+ if (s < 60)
53
+ return `${s}s`;
54
+ const m = Math.floor(s / 60);
55
+ if (m < 60)
56
+ return `${m}m ${s % 60}s`;
57
+ const h = Math.floor(m / 60);
58
+ return `${h}h ${m % 60}m`;
59
+ }
6
60
  export async function statusCommand() {
7
61
  const conf = getConfig();
8
62
  const token = conf.get('token');
9
- const projectId = conf.get('projectId');
10
- const pid = conf.get('agentPid');
11
- const lastConnected = conf.get('lastConnected');
12
- const devPort = conf.get('devPort') || 3000;
13
- const apiPort = conf.get('apiPort') || 18924;
14
- console.log(chalk.blue('\n nstantpage agent v0.2.0\n'));
63
+ const email = conf.get('email');
64
+ const gateway = conf.get('gatewayUrl') || 'wss://webprev.live';
65
+ const isLocal = /^wss?:\/\/(localhost|127\.0\.0\.1)/.test(gateway);
66
+ console.log(chalk.blue(`\n nstantpage agent v${getPackageVersion()}\n`));
15
67
  // Auth
16
68
  if (token) {
17
- console.log(chalk.green(' ✓ Authenticated'));
69
+ console.log(chalk.green(` ✓ Authenticated${email ? ` (${email})` : ''}`));
18
70
  }
19
71
  else {
20
72
  console.log(chalk.red(' ✗ Not authenticated (run "nstantpage login")'));
21
73
  }
22
- // Project
23
- if (projectId) {
24
- console.log(chalk.gray(` Project: ${projectId}`));
25
- console.log(chalk.gray(` Preview: https://${projectId}.webprev.live`));
26
- }
27
- else {
28
- console.log(chalk.gray(' No project linked'));
29
- }
30
- // Running
31
- if (pid) {
32
- try {
33
- process.kill(pid, 0); // Check if process exists
34
- console.log(chalk.green(` ✓ Agent running (PID ${pid})`));
35
- console.log(chalk.gray(` Dev server: http://localhost:${devPort}`));
36
- console.log(chalk.gray(` API server: http://localhost:${apiPort}`));
74
+ console.log(chalk.gray(` Server: ${isLocal ? 'localhost (dev)' : 'nstantpage.com'}`));
75
+ // Try live status from the status server
76
+ const live = await fetchAgentStatus();
77
+ const service = checkOsService();
78
+ if (live) {
79
+ console.log(chalk.green(` ✓ Agent running`));
80
+ console.log(chalk.gray(` Tunnel: ${live.tunnelStatus}`));
81
+ console.log(chalk.gray(` Uptime: ${formatUptime(live.uptime)}`));
82
+ console.log(chalk.gray(` Gateway: ${live.gatewayUrl}`));
83
+ if (live.activeProjects.length > 0) {
84
+ console.log(chalk.gray(` Projects: ${live.activeProjects.map(p => p.projectId).join(', ')}`));
85
+ }
86
+ else {
87
+ console.log(chalk.gray(` Projects: none (standby mode)`));
37
88
  }
38
- catch {
39
- console.log(chalk.gray(' Agent not running'));
40
- conf.delete('agentPid');
89
+ }
90
+ else if (service.installed) {
91
+ console.log(chalk.yellow(` ⚠ Service installed but agent not responding`));
92
+ if (service.pid) {
93
+ console.log(chalk.gray(` PID: ${service.pid}`));
41
94
  }
95
+ console.log(chalk.gray(' Try: nstantpage logs'));
42
96
  }
43
97
  else {
44
98
  console.log(chalk.gray(' Agent not running'));
99
+ console.log(chalk.gray(' Run "nstantpage run" to start'));
45
100
  }
46
- // Last connected
47
- if (lastConnected) {
48
- console.log(chalk.gray(` Last connected: ${lastConnected}`));
49
- }
50
- console.log(chalk.gray(`\n Mode: Agent (replaces cloud containers)`));
51
101
  console.log('');
52
102
  }
53
103
  //# sourceMappingURL=status.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nstantpage-agent",
3
- "version": "0.8.10",
3
+ "version": "0.8.12",
4
4
  "description": "Local development agent for nstantpage.com — run your projects locally, preview in the cloud. Replaces cloud containers for faster builds.",
5
5
  "type": "module",
6
6
  "bin": {