nstantpage-agent 0.5.14 → 0.5.16

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.
@@ -25,7 +25,7 @@ import { TunnelClient } from '../tunnel.js';
25
25
  import { LocalServer } from '../localServer.js';
26
26
  import { PackageInstaller } from '../packageInstaller.js';
27
27
  import { probeLocalPostgres, ensureLocalProjectDb, closeAdminPool, writeDatabaseUrlToEnv } from '../projectDb.js';
28
- const VERSION = '0.5.14';
28
+ const VERSION = '0.5.16';
29
29
  /**
30
30
  * Resolve the backend API base URL.
31
31
  * - If --backend is passed, use it
@@ -499,8 +499,23 @@ async function startStandbyMode(token, options, backendUrl, deviceId) {
499
499
  projectId: '_standby_',
500
500
  apiPort: 0,
501
501
  devPort: 0,
502
- onStartProject: async (pid) => {
503
- if (activeProjects.has(pid)) {
502
+ onStartProject: async (pid, opts) => {
503
+ const isClean = opts?.clean === true;
504
+ // If clean reset requested and project is already running, stop it first
505
+ if (isClean && activeProjects.has(pid)) {
506
+ console.log(chalk.yellow(` Stopping existing project ${pid} for clean reset...`));
507
+ const existing = activeProjects.get(pid);
508
+ existing.tunnel.disconnect();
509
+ await existing.localServer.stop();
510
+ activeProjects.delete(pid);
511
+ // Wipe the project directory
512
+ const projectDir = resolveProjectDir('.', pid);
513
+ if (fs.existsSync(projectDir)) {
514
+ console.log(chalk.gray(` Wiping project directory: ${projectDir}`));
515
+ fs.rmSync(projectDir, { recursive: true, force: true });
516
+ }
517
+ }
518
+ else if (activeProjects.has(pid)) {
504
519
  console.log(chalk.yellow(` Project ${pid} is already running`));
505
520
  return;
506
521
  }
@@ -14,7 +14,6 @@
14
14
  */
15
15
  import http from 'http';
16
16
  import fs from 'fs';
17
- import path from 'path';
18
17
  import os from 'os';
19
18
  import { createRequire } from 'module';
20
19
  import { spawn } from 'child_process';
@@ -745,28 +744,8 @@ export class LocalServer {
745
744
  // ─── /live/dev/restart ───────────────────────────────────────
746
745
  async handleDevRestart(_req, res) {
747
746
  try {
748
- // Full recovery: stop dev server, ensure deps installed, ensure DB, restart
749
- console.log(' [LocalServer] Full dev server restart with recovery...');
750
- // 1. Stop dev server
751
- await this.devServer.stop();
752
- // 2. Check if project dir has files (could be wiped)
753
- const pkgPath = path.join(this.options.projectDir, 'package.json');
754
- if (!fs.existsSync(pkgPath)) {
755
- console.log(' [LocalServer] ⚠ package.json missing — project files may have been deleted');
756
- // Can't install deps without package.json —the .NET backend /restart-dev-server
757
- // should have already synced files before calling us. If files still missing, error out.
758
- res.statusCode = 500;
759
- this.json(res, { success: false, error: 'Project files missing (no package.json). Sync files first.' });
760
- return;
761
- }
762
- // 3. Ensure database is provisioned
763
- await this.ensureDatabase();
764
- // 4. Ensure dependencies are installed
765
- await this.packageInstaller.ensureDependencies();
766
- // 5. Restart dev server
767
- await new Promise(r => setTimeout(r, 300));
768
- await this.devServer.start();
769
- this.json(res, { success: true, message: 'Dev server restarted with full recovery' });
747
+ await this.devServer.restart();
748
+ this.json(res, { success: true, message: 'Dev server restarted' });
770
749
  }
771
750
  catch (err) {
772
751
  res.statusCode = 500;
package/dist/tunnel.d.ts CHANGED
@@ -24,7 +24,9 @@ interface TunnelClientOptions {
24
24
  /** Port where the dev server (Vite/Next.js) runs */
25
25
  devPort: number;
26
26
  /** Callback when gateway requests starting a new project on this device */
27
- onStartProject?: (projectId: string) => Promise<void>;
27
+ onStartProject?: (projectId: string, options?: {
28
+ clean?: boolean;
29
+ }) => Promise<void>;
28
30
  /** Callback for setup progress — lets the standby tunnel relay phases to gateway */
29
31
  onSetupProgress?: (projectId: string, phase: string, message: string) => void;
30
32
  }
package/dist/tunnel.js CHANGED
@@ -246,8 +246,8 @@ export class TunnelClient {
246
246
  * Handle start-project: gateway wants this agent to start serving a new project.
247
247
  * Called when user clicks "Connect" in the web editor's Cloud panel.
248
248
  */
249
- async handleStartProject(projectId) {
250
- console.log(` [Tunnel] Received start-project command for ${projectId}`);
249
+ async handleStartProject(projectId, clean) {
250
+ console.log(` [Tunnel] Received start-project command for ${projectId}${clean ? ' (clean)' : ''}`);
251
251
  if (!projectId) {
252
252
  this.send({ type: 'start-project-result', success: false, error: 'Missing projectId' });
253
253
  return;
@@ -256,7 +256,7 @@ export class TunnelClient {
256
256
  try {
257
257
  // Send initial progress
258
258
  this.sendSetupProgress(projectId, 'starting', 'Starting project setup...');
259
- await this.options.onStartProject(projectId);
259
+ await this.options.onStartProject(projectId, clean ? { clean: true } : undefined);
260
260
  this.sendSetupProgress(projectId, 'ready', 'Project is live!');
261
261
  this.send({ type: 'start-project-result', projectId, success: true });
262
262
  }
@@ -300,7 +300,7 @@ export class TunnelClient {
300
300
  this.handleWsClose(msg.wsId);
301
301
  break;
302
302
  case 'start-project':
303
- this.handleStartProject(msg.projectId);
303
+ this.handleStartProject(msg.projectId, msg.clean);
304
304
  break;
305
305
  default:
306
306
  console.warn(` [Tunnel] Unknown message type: ${msg.type}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nstantpage-agent",
3
- "version": "0.5.14",
3
+ "version": "0.5.16",
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": {