nstantpage-agent 0.8.6 → 0.8.8
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/agentSync.d.ts +0 -1
- package/dist/agentSync.js +8 -35
- package/dist/commands/start.js +39 -12
- package/package.json +1 -1
package/dist/agentSync.d.ts
CHANGED
package/dist/agentSync.js
CHANGED
|
@@ -98,7 +98,6 @@ export class AgentSync {
|
|
|
98
98
|
// State
|
|
99
99
|
fileWatcher = null;
|
|
100
100
|
debounceTimer = null;
|
|
101
|
-
pendingChangedFiles = new Set();
|
|
102
101
|
syncing = false;
|
|
103
102
|
lastVersionId = null;
|
|
104
103
|
lastSyncAt = null;
|
|
@@ -120,13 +119,11 @@ export class AgentSync {
|
|
|
120
119
|
return;
|
|
121
120
|
if (shouldSkipPath(filename))
|
|
122
121
|
return;
|
|
123
|
-
|
|
122
|
+
// Debounce — just fire HMR notification, no file tracking
|
|
124
123
|
if (this.debounceTimer)
|
|
125
124
|
clearTimeout(this.debounceTimer);
|
|
126
125
|
this.debounceTimer = setTimeout(() => {
|
|
127
|
-
|
|
128
|
-
const preview = [...this.pendingChangedFiles].slice(0, 5).join(', ');
|
|
129
|
-
console.log(` [AgentSync] Change detected: ${count} file(s) — ${preview}${count > 5 ? '...' : ''}`);
|
|
126
|
+
console.log(` [AgentSync] File change detected — notifying for HMR`);
|
|
130
127
|
if (this.onSyncDirty) {
|
|
131
128
|
this.onSyncDirty(this.projectId);
|
|
132
129
|
}
|
|
@@ -154,30 +151,25 @@ export class AgentSync {
|
|
|
154
151
|
}
|
|
155
152
|
// ─── Sync Status ─────────────────────────────────────────
|
|
156
153
|
async getSyncStatus() {
|
|
157
|
-
const pending = this.pendingChangedFiles.size;
|
|
158
|
-
const isDirty = pending > 0 && !this.syncing;
|
|
159
154
|
return {
|
|
160
|
-
inSync:
|
|
161
|
-
direction:
|
|
155
|
+
inSync: true,
|
|
156
|
+
direction: 'in-sync',
|
|
162
157
|
diskChecksum: null,
|
|
163
158
|
backendChecksum: null,
|
|
164
159
|
diskFileCount: 0,
|
|
165
160
|
backendFileCount: 0,
|
|
166
|
-
modifiedFiles: [
|
|
161
|
+
modifiedFiles: [],
|
|
167
162
|
diskOnlyFiles: [],
|
|
168
163
|
backendOnlyFiles: [],
|
|
169
164
|
lastSyncedVersionId: this.lastVersionId,
|
|
170
165
|
lastSyncedAt: this.lastSyncAt,
|
|
171
|
-
diskDirty:
|
|
166
|
+
diskDirty: false,
|
|
172
167
|
computedAt: Date.now(),
|
|
173
168
|
};
|
|
174
169
|
}
|
|
175
170
|
// ─── Per-File Status ──────────────────────────────────────
|
|
176
171
|
async getPerFileStatus() {
|
|
177
|
-
return [
|
|
178
|
-
path: f,
|
|
179
|
-
status: 'modified',
|
|
180
|
-
}));
|
|
172
|
+
return [];
|
|
181
173
|
}
|
|
182
174
|
// ─── Push to Backend (Full Sync) ──────────────────────────
|
|
183
175
|
//
|
|
@@ -186,13 +178,6 @@ export class AgentSync {
|
|
|
186
178
|
// 2. Collect ALL files from disk
|
|
187
179
|
// 3. POST /api/sandbox/push-files — push ALL files in batches of 100
|
|
188
180
|
async pushToBackend() {
|
|
189
|
-
if (this.pendingChangedFiles.size === 0) {
|
|
190
|
-
return {
|
|
191
|
-
success: true, filesPushed: 0, filesDeleted: 0,
|
|
192
|
-
modifiedFiles: [], addedFiles: [], deletedFiles: [],
|
|
193
|
-
message: 'Already in sync — no changes to push',
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
181
|
if (this.syncing) {
|
|
197
182
|
return {
|
|
198
183
|
success: true, filesPushed: 0, filesDeleted: 0,
|
|
@@ -238,8 +223,7 @@ export class AgentSync {
|
|
|
238
223
|
}
|
|
239
224
|
totalPushed += batch.length;
|
|
240
225
|
}
|
|
241
|
-
// Done
|
|
242
|
-
this.pendingChangedFiles.clear();
|
|
226
|
+
// Done
|
|
243
227
|
this.lastVersionId = String(syncData.versionId);
|
|
244
228
|
this.lastSyncAt = Date.now();
|
|
245
229
|
const fileNames = allFiles.map(f => f.relativePath);
|
|
@@ -266,11 +250,6 @@ export class AgentSync {
|
|
|
266
250
|
markSynced(versionId) {
|
|
267
251
|
this.lastVersionId = versionId;
|
|
268
252
|
this.lastSyncAt = Date.now();
|
|
269
|
-
this.pendingChangedFiles.clear();
|
|
270
|
-
if (this.debounceTimer) {
|
|
271
|
-
clearTimeout(this.debounceTimer);
|
|
272
|
-
this.debounceTimer = null;
|
|
273
|
-
}
|
|
274
253
|
console.log(` [AgentSync] Marked synced at version ${versionId}`);
|
|
275
254
|
}
|
|
276
255
|
/** Read a single file from disk (for diff view) */
|
|
@@ -320,18 +299,12 @@ export class AgentSync {
|
|
|
320
299
|
}
|
|
321
300
|
this.lastVersionId = String(data.versionId);
|
|
322
301
|
this.lastSyncAt = Date.now();
|
|
323
|
-
this.pendingChangedFiles.clear();
|
|
324
|
-
if (this.debounceTimer) {
|
|
325
|
-
clearTimeout(this.debounceTimer);
|
|
326
|
-
this.debounceTimer = null;
|
|
327
|
-
}
|
|
328
302
|
console.log(` [AgentSync] Pulled ${written} files from backend (version ${data.versionId})`);
|
|
329
303
|
return { success: true, filesWritten: written, versionId: String(data.versionId) };
|
|
330
304
|
}
|
|
331
305
|
// ─── Cleanup ──────────────────────────────────────────────
|
|
332
306
|
destroy() {
|
|
333
307
|
this.stopFileWatcher();
|
|
334
|
-
this.pendingChangedFiles.clear();
|
|
335
308
|
}
|
|
336
309
|
}
|
|
337
310
|
//# sourceMappingURL=agentSync.js.map
|
package/dist/commands/start.js
CHANGED
|
@@ -268,13 +268,16 @@ export async function startCommand(directory, options) {
|
|
|
268
268
|
console.log(chalk.gray(` API server: port ${apiPort}`));
|
|
269
269
|
console.log(chalk.gray(` Gateway: ${options.gateway}`));
|
|
270
270
|
console.log(chalk.gray(` Backend: ${backendUrl}\n`));
|
|
271
|
-
//
|
|
271
|
+
// Determine if this is a user-managed local directory (--dir flag or explicit path)
|
|
272
|
+
// For local projects: disk is truth, NEVER overwrite disk from DB
|
|
273
|
+
const isLocalDir = !!(options.dir) || directory !== '.';
|
|
274
|
+
// 1. Fetch or sync project files
|
|
272
275
|
const installer = new PackageInstaller({ projectDir });
|
|
273
276
|
let fetchedVersionId;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
//
|
|
277
|
+
if (isLocalDir) {
|
|
278
|
+
// Local project — SKIP DB→disk fetch. Disk is truth.
|
|
279
|
+
console.log(chalk.gray(` Local project — using files from disk (not fetching from DB)`));
|
|
280
|
+
// Install dependencies if needed
|
|
278
281
|
if (!installer.areDependenciesInstalled()) {
|
|
279
282
|
if (fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
280
283
|
console.log(chalk.gray(' Installing dependencies...'));
|
|
@@ -292,13 +295,37 @@ export async function startCommand(directory, options) {
|
|
|
292
295
|
console.log(chalk.gray(` Dependencies already installed`));
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
298
|
+
else {
|
|
299
|
+
// Cloud/managed project — fetch files from DB to disk
|
|
300
|
+
try {
|
|
301
|
+
const { fileCount, isNew, versionId } = await fetchProjectFiles(backendUrl, projectId, projectDir, token);
|
|
302
|
+
fetchedVersionId = versionId;
|
|
303
|
+
// 2. Install dependencies if needed (verifies actual packages, not just folder)
|
|
304
|
+
if (!installer.areDependenciesInstalled()) {
|
|
305
|
+
if (fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
306
|
+
console.log(chalk.gray(' Installing dependencies...'));
|
|
307
|
+
try {
|
|
308
|
+
await installer.ensureDependencies();
|
|
309
|
+
console.log(chalk.green(` ✓ Dependencies installed`));
|
|
310
|
+
}
|
|
311
|
+
catch (err) {
|
|
312
|
+
console.log(chalk.yellow(` ⚠ Install failed: ${err.message?.slice(0, 200)}`));
|
|
313
|
+
console.log(chalk.gray(` Will retry when dev server starts`));
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
console.log(chalk.gray(` Dependencies already installed`));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
console.log(chalk.yellow(` ⚠ Could not fetch project files: ${err.message}`));
|
|
323
|
+
console.log(chalk.gray(' Continuing with existing local files (if any)...'));
|
|
324
|
+
if (!fs.existsSync(path.join(projectDir, 'package.json'))) {
|
|
325
|
+
console.log(chalk.red(`\n✗ No package.json found and cannot fetch files from backend.`));
|
|
326
|
+
console.log(chalk.gray(' Check your project ID and authentication.'));
|
|
327
|
+
process.exit(1);
|
|
328
|
+
}
|
|
302
329
|
}
|
|
303
330
|
}
|
|
304
331
|
// Save .nstantpage.json for future runs
|
package/package.json
CHANGED