farseer-cli 1.0.6 → 1.0.9
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/commands/checkout.js +2 -1
- package/dist/commands/checkout.js.map +2 -2
- package/dist/commands/diff.js +3 -1
- package/dist/commands/diff.js.map +2 -2
- package/dist/commands/dimensions.js +1 -1
- package/dist/commands/dimensions.js.map +2 -2
- package/dist/commands/files.js +1 -1
- package/dist/commands/files.js.map +2 -2
- package/dist/commands/install.js +3 -3
- package/dist/commands/install.js.map +2 -2
- package/dist/commands/pull.js +48 -2
- package/dist/commands/pull.js.map +3 -3
- package/dist/commands/push.js +14 -2
- package/dist/commands/push.js.map +2 -2
- package/dist/commands/status.js +12 -2
- package/dist/commands/status.js.map +2 -2
- package/dist/commands/variables.js +1 -1
- package/dist/commands/variables.js.map +2 -2
- package/dist/index.js +1 -0
- package/dist/index.js.map +2 -2
- package/dist/mcp/prompts/workflows.js +24 -13
- package/dist/mcp/prompts/workflows.js.map +2 -2
- package/dist/mcp/tools/appTools.js +77 -77
- package/dist/mcp/tools/appTools.js.map +3 -3
- package/dist/mcp/tools/authTools.js +3 -2
- package/dist/mcp/tools/authTools.js.map +2 -2
- package/dist/mcp/tools/dataTools.js +43 -47
- package/dist/mcp/tools/dataTools.js.map +2 -2
- package/dist/mcp/tools/modelTools.js +15 -19
- package/dist/mcp/tools/modelTools.js.map +2 -2
- package/dist/mcp/tools/runTools.js +28 -26
- package/dist/mcp/tools/runTools.js.map +2 -2
- package/dist/mcp/tools/syncTools.js +36 -8
- package/dist/mcp/tools/syncTools.js.map +2 -2
- package/dist/services/syncService.js +386 -112
- package/dist/services/syncService.js.map +3 -3
- package/dist/utils/constants.js +1 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/helpers.js +3 -3
- package/dist/utils/helpers.js.map +1 -1
- package/docs/api-reference.md +372 -0
- package/docs/arquero-patterns.md +158 -0
- package/docs/cli-guide.md +160 -0
- package/docs/how-farseer-works.md +113 -0
- package/docs/import-workflows.md +306 -0
- package/docs/model-export.md +95 -0
- package/docs/new-app-template.md +240 -0
- package/docs/query-formulas.md +97 -0
- package/docs/troubleshooting.md +140 -0
- package/package.json +2 -1
|
@@ -89,7 +89,8 @@ class SyncService {
|
|
|
89
89
|
modifiedRemotely: [],
|
|
90
90
|
onlyLocal: [],
|
|
91
91
|
onlyRemote: [],
|
|
92
|
-
inSync: []
|
|
92
|
+
inSync: [],
|
|
93
|
+
conflicts: []
|
|
93
94
|
};
|
|
94
95
|
for (const localFile of localFiles) {
|
|
95
96
|
const localPath = path.join(filesDir, localFile);
|
|
@@ -104,7 +105,15 @@ class SyncService {
|
|
|
104
105
|
}
|
|
105
106
|
} else {
|
|
106
107
|
if (syncInfo && syncInfo.remoteHash) {
|
|
107
|
-
|
|
108
|
+
if (localHash !== syncInfo.localHash) {
|
|
109
|
+
status.conflicts.push({
|
|
110
|
+
filePath: localFile,
|
|
111
|
+
type: "local_modified_remote_deleted",
|
|
112
|
+
description: "File modified locally but deleted on remote"
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
status.modifiedRemotely.push(localFile);
|
|
116
|
+
}
|
|
108
117
|
} else {
|
|
109
118
|
status.onlyLocal.push(localFile);
|
|
110
119
|
}
|
|
@@ -131,11 +140,11 @@ class SyncService {
|
|
|
131
140
|
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.toLowerCase().endsWith(ext))
|
|
132
141
|
);
|
|
133
142
|
}
|
|
134
|
-
const
|
|
143
|
+
const localHashes = /* @__PURE__ */ new Map();
|
|
135
144
|
for (const file of localFiles) {
|
|
136
145
|
const fullPath = path.join(filesDir, file);
|
|
137
146
|
const content = fs.readFileSync(fullPath);
|
|
138
|
-
|
|
147
|
+
localHashes.set(file, (0, import_helpers.calculateHash)(content));
|
|
139
148
|
}
|
|
140
149
|
let remoteFiles = await this.farseerClient.listFiles();
|
|
141
150
|
if (!options?.all) {
|
|
@@ -143,7 +152,7 @@ class SyncService {
|
|
|
143
152
|
(f) => import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => f.name.toLowerCase().endsWith(ext))
|
|
144
153
|
);
|
|
145
154
|
}
|
|
146
|
-
const
|
|
155
|
+
const remoteHashes = /* @__PURE__ */ new Map();
|
|
147
156
|
const fileContents = await (0, import_helpers.fetchWithConcurrency)(
|
|
148
157
|
remoteFiles,
|
|
149
158
|
async (file) => {
|
|
@@ -152,52 +161,46 @@ class SyncService {
|
|
|
152
161
|
},
|
|
153
162
|
15
|
|
154
163
|
);
|
|
155
|
-
for (const { path:
|
|
156
|
-
|
|
164
|
+
for (const { path: filePath, hash } of fileContents) {
|
|
165
|
+
remoteHashes.set(filePath, hash);
|
|
157
166
|
}
|
|
167
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: options?.all });
|
|
158
168
|
const status = {
|
|
159
169
|
modifiedLocally: [],
|
|
160
170
|
modifiedRemotely: [],
|
|
161
171
|
onlyLocal: [],
|
|
162
172
|
onlyRemote: [],
|
|
163
|
-
inSync: []
|
|
173
|
+
inSync: [],
|
|
174
|
+
conflicts: []
|
|
164
175
|
};
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
status.onlyLocal.push(file);
|
|
194
|
-
}
|
|
195
|
-
} else if (!localHash && remoteHash) {
|
|
196
|
-
if (syncInfo && syncInfo.localHash) {
|
|
197
|
-
status.modifiedLocally.push(file);
|
|
198
|
-
} else {
|
|
199
|
-
status.onlyRemote.push(file);
|
|
200
|
-
}
|
|
176
|
+
for (const c of comparisons) {
|
|
177
|
+
switch (c.changeType) {
|
|
178
|
+
case "unchanged":
|
|
179
|
+
status.inSync.push(c.filePath);
|
|
180
|
+
break;
|
|
181
|
+
case "local_modified":
|
|
182
|
+
status.modifiedLocally.push(c.filePath);
|
|
183
|
+
break;
|
|
184
|
+
case "remote_modified":
|
|
185
|
+
status.modifiedRemotely.push(c.filePath);
|
|
186
|
+
break;
|
|
187
|
+
case "local_new":
|
|
188
|
+
status.onlyLocal.push(c.filePath);
|
|
189
|
+
break;
|
|
190
|
+
case "remote_new":
|
|
191
|
+
status.onlyRemote.push(c.filePath);
|
|
192
|
+
break;
|
|
193
|
+
case "remote_deleted":
|
|
194
|
+
status.modifiedRemotely.push(c.filePath);
|
|
195
|
+
break;
|
|
196
|
+
case "local_deleted":
|
|
197
|
+
status.modifiedLocally.push(c.filePath);
|
|
198
|
+
break;
|
|
199
|
+
default:
|
|
200
|
+
status.conflicts.push(
|
|
201
|
+
SyncService.buildConflicts([c])[0]
|
|
202
|
+
);
|
|
203
|
+
break;
|
|
201
204
|
}
|
|
202
205
|
}
|
|
203
206
|
return status;
|
|
@@ -216,9 +219,10 @@ class SyncService {
|
|
|
216
219
|
const result = {
|
|
217
220
|
downloaded: [],
|
|
218
221
|
deleted: [],
|
|
219
|
-
unchanged: []
|
|
222
|
+
unchanged: [],
|
|
223
|
+
conflicts: [],
|
|
224
|
+
conflictFilesWritten: []
|
|
220
225
|
};
|
|
221
|
-
const remoteFilePaths = new Set(remoteFiles.map((f) => f.path));
|
|
222
226
|
import_logger.logger.dim(`Fetching ${remoteFiles.length} files in parallel...`);
|
|
223
227
|
const fileContents = await (0, import_helpers.fetchWithConcurrency)(
|
|
224
228
|
remoteFiles,
|
|
@@ -234,43 +238,147 @@ class SyncService {
|
|
|
234
238
|
if (remoteFiles.length > 0) {
|
|
235
239
|
process.stdout.write("\r" + " ".repeat(50) + "\r");
|
|
236
240
|
}
|
|
241
|
+
const remoteContentMap = /* @__PURE__ */ new Map();
|
|
242
|
+
const remoteHashes = /* @__PURE__ */ new Map();
|
|
237
243
|
for (const { file, content } of fileContents) {
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (fs.existsSync(localPath)) {
|
|
242
|
-
const localContent = fs.readFileSync(localPath);
|
|
243
|
-
const localHash = (0, import_helpers.calculateHash)(localContent);
|
|
244
|
-
if (localHash === remoteHash) {
|
|
245
|
-
needsUpdate = false;
|
|
246
|
-
result.unchanged.push(file.path);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (needsUpdate) {
|
|
250
|
-
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
251
|
-
fs.writeFileSync(localPath, content);
|
|
252
|
-
result.downloaded.push(file.path);
|
|
253
|
-
}
|
|
254
|
-
syncState.files[file.path] = {
|
|
255
|
-
localHash: remoteHash,
|
|
256
|
-
remoteHash,
|
|
257
|
-
metadata: file.metadata ? {
|
|
258
|
-
uploadTime: file.metadata.uploadTime,
|
|
259
|
-
uploaderEmail: file.metadata.uploader?.email,
|
|
260
|
-
uploaderName: file.metadata.uploader ? `${file.metadata.uploader.firstName} ${file.metadata.uploader.lastName}`.trim() : void 0,
|
|
261
|
-
lastFetched: (/* @__PURE__ */ new Date()).toISOString()
|
|
262
|
-
} : void 0
|
|
263
|
-
};
|
|
244
|
+
const hash = (0, import_helpers.calculateHash)(content);
|
|
245
|
+
remoteContentMap.set(file.path, { file, content, hash });
|
|
246
|
+
remoteHashes.set(file.path, hash);
|
|
264
247
|
}
|
|
265
248
|
const localFiles = (0, import_helpers.getAllFilesInDir)(filesDir);
|
|
249
|
+
const localHashes = /* @__PURE__ */ new Map();
|
|
266
250
|
for (const localFile of localFiles) {
|
|
267
|
-
if (!
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
251
|
+
if (!options?.all && !import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => localFile.toLowerCase().endsWith(ext))) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const localPath = path.join(filesDir, localFile);
|
|
255
|
+
const content = fs.readFileSync(localPath);
|
|
256
|
+
localHashes.set(localFile, (0, import_helpers.calculateHash)(content));
|
|
257
|
+
}
|
|
258
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: options?.all });
|
|
259
|
+
const resolutions = options?.conflictResolutions ?? {};
|
|
260
|
+
for (const comparison of comparisons) {
|
|
261
|
+
const { filePath, changeType } = comparison;
|
|
262
|
+
const localPath = path.join(filesDir, filePath);
|
|
263
|
+
const remoteInfo = remoteContentMap.get(filePath);
|
|
264
|
+
switch (changeType) {
|
|
265
|
+
case "unchanged":
|
|
266
|
+
case "local_modified":
|
|
267
|
+
case "local_new":
|
|
268
|
+
result.unchanged.push(filePath);
|
|
269
|
+
if (remoteInfo) {
|
|
270
|
+
const existingSync = syncState.files[filePath];
|
|
271
|
+
if (existingSync) {
|
|
272
|
+
existingSync.remoteHash = remoteInfo.hash;
|
|
273
|
+
existingSync.metadata = this.buildMetadata(remoteInfo.file);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
case "local_deleted":
|
|
278
|
+
result.unchanged.push(filePath);
|
|
279
|
+
break;
|
|
280
|
+
case "remote_modified":
|
|
281
|
+
case "remote_new":
|
|
282
|
+
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
283
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
284
|
+
result.downloaded.push(filePath);
|
|
285
|
+
syncState.files[filePath] = {
|
|
286
|
+
localHash: remoteInfo.hash,
|
|
287
|
+
remoteHash: remoteInfo.hash,
|
|
288
|
+
metadata: this.buildMetadata(remoteInfo.file)
|
|
289
|
+
};
|
|
290
|
+
break;
|
|
291
|
+
case "remote_deleted":
|
|
292
|
+
if (fs.existsSync(localPath)) {
|
|
293
|
+
fs.unlinkSync(localPath);
|
|
294
|
+
}
|
|
295
|
+
result.deleted.push(filePath);
|
|
296
|
+
delete syncState.files[filePath];
|
|
297
|
+
break;
|
|
298
|
+
case "conflict_both_modified":
|
|
299
|
+
case "conflict_local_modified_remote_deleted":
|
|
300
|
+
case "conflict_local_deleted_remote_modified":
|
|
301
|
+
case "conflict_both_new": {
|
|
302
|
+
if (options?.force) {
|
|
303
|
+
if (remoteInfo) {
|
|
304
|
+
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
305
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
306
|
+
result.downloaded.push(filePath);
|
|
307
|
+
syncState.files[filePath] = {
|
|
308
|
+
localHash: remoteInfo.hash,
|
|
309
|
+
remoteHash: remoteInfo.hash,
|
|
310
|
+
metadata: this.buildMetadata(remoteInfo.file)
|
|
311
|
+
};
|
|
312
|
+
} else {
|
|
313
|
+
if (fs.existsSync(localPath)) {
|
|
314
|
+
fs.unlinkSync(localPath);
|
|
315
|
+
result.deleted.push(filePath);
|
|
316
|
+
}
|
|
317
|
+
delete syncState.files[filePath];
|
|
318
|
+
}
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
const resolution = resolutions[filePath];
|
|
322
|
+
if (!resolution) {
|
|
323
|
+
result.conflicts.push(SyncService.buildConflicts([comparison])[0]);
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
switch (resolution) {
|
|
327
|
+
case "keep_local":
|
|
328
|
+
if (fs.existsSync(localPath)) {
|
|
329
|
+
const localContent = fs.readFileSync(localPath);
|
|
330
|
+
const localHash = (0, import_helpers.calculateHash)(localContent);
|
|
331
|
+
syncState.files[filePath] = {
|
|
332
|
+
localHash,
|
|
333
|
+
remoteHash: comparison.currentRemoteHash ?? "",
|
|
334
|
+
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : void 0
|
|
335
|
+
};
|
|
336
|
+
} else {
|
|
337
|
+
delete syncState.files[filePath];
|
|
338
|
+
}
|
|
339
|
+
result.unchanged.push(filePath);
|
|
340
|
+
break;
|
|
341
|
+
case "keep_remote":
|
|
342
|
+
if (remoteInfo) {
|
|
343
|
+
(0, import_helpers.ensureDirectoryExists)(path.dirname(localPath));
|
|
344
|
+
fs.writeFileSync(localPath, remoteInfo.content);
|
|
345
|
+
result.downloaded.push(filePath);
|
|
346
|
+
syncState.files[filePath] = {
|
|
347
|
+
localHash: remoteInfo.hash,
|
|
348
|
+
remoteHash: remoteInfo.hash,
|
|
349
|
+
metadata: this.buildMetadata(remoteInfo.file)
|
|
350
|
+
};
|
|
351
|
+
} else {
|
|
352
|
+
if (fs.existsSync(localPath)) {
|
|
353
|
+
fs.unlinkSync(localPath);
|
|
354
|
+
result.deleted.push(filePath);
|
|
355
|
+
}
|
|
356
|
+
delete syncState.files[filePath];
|
|
357
|
+
}
|
|
358
|
+
break;
|
|
359
|
+
case "keep_both":
|
|
360
|
+
if (remoteInfo) {
|
|
361
|
+
const ext = path.extname(filePath);
|
|
362
|
+
const base = filePath.slice(0, -ext.length || void 0);
|
|
363
|
+
const conflictFileName = `${base}.remote${ext}`;
|
|
364
|
+
const conflictPath = path.join(filesDir, conflictFileName);
|
|
365
|
+
(0, import_helpers.ensureDirectoryExists)(path.dirname(conflictPath));
|
|
366
|
+
fs.writeFileSync(conflictPath, remoteInfo.content);
|
|
367
|
+
result.conflictFilesWritten.push(conflictFileName);
|
|
368
|
+
}
|
|
369
|
+
if (fs.existsSync(localPath)) {
|
|
370
|
+
const localContent = fs.readFileSync(localPath);
|
|
371
|
+
const localHash = (0, import_helpers.calculateHash)(localContent);
|
|
372
|
+
syncState.files[filePath] = {
|
|
373
|
+
localHash,
|
|
374
|
+
remoteHash: comparison.currentRemoteHash ?? "",
|
|
375
|
+
metadata: remoteInfo ? this.buildMetadata(remoteInfo.file) : void 0
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
result.unchanged.push(filePath);
|
|
379
|
+
break;
|
|
380
|
+
}
|
|
381
|
+
break;
|
|
274
382
|
}
|
|
275
383
|
}
|
|
276
384
|
}
|
|
@@ -278,14 +386,24 @@ class SyncService {
|
|
|
278
386
|
this.saveSyncState(syncState);
|
|
279
387
|
return result;
|
|
280
388
|
}
|
|
281
|
-
|
|
389
|
+
buildMetadata(file) {
|
|
390
|
+
if (!file.metadata) return void 0;
|
|
391
|
+
return {
|
|
392
|
+
uploadTime: file.metadata.uploadTime,
|
|
393
|
+
uploaderEmail: file.metadata.uploader?.email,
|
|
394
|
+
uploaderName: file.metadata.uploader ? `${file.metadata.uploader.firstName} ${file.metadata.uploader.lastName}`.trim() : void 0,
|
|
395
|
+
lastFetched: (/* @__PURE__ */ new Date()).toISOString()
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
async push(options) {
|
|
282
399
|
const filesDir = (0, import_helpers.getTenantFilesDir)(this.tenant);
|
|
283
400
|
const syncState = this.loadSyncState();
|
|
284
401
|
const result = {
|
|
285
402
|
uploaded: [],
|
|
286
403
|
updated: [],
|
|
287
404
|
deleted: [],
|
|
288
|
-
unchanged: []
|
|
405
|
+
unchanged: [],
|
|
406
|
+
conflicts: []
|
|
289
407
|
};
|
|
290
408
|
const remoteFiles = await this.farseerClient.listFiles();
|
|
291
409
|
const remoteFileMap = /* @__PURE__ */ new Map();
|
|
@@ -293,51 +411,87 @@ class SyncService {
|
|
|
293
411
|
remoteFileMap.set(file.path, file);
|
|
294
412
|
}
|
|
295
413
|
const localFiles = (0, import_helpers.getAllFilesInDir)(filesDir);
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
const filesUnchanged = [];
|
|
414
|
+
const localHashes = /* @__PURE__ */ new Map();
|
|
415
|
+
const localContents = /* @__PURE__ */ new Map();
|
|
299
416
|
for (const localFile of localFiles) {
|
|
300
417
|
const localPath = path.join(filesDir, localFile);
|
|
301
418
|
const content = fs.readFileSync(localPath);
|
|
302
|
-
|
|
419
|
+
localHashes.set(localFile, (0, import_helpers.calculateHash)(content));
|
|
420
|
+
localContents.set(localFile, content);
|
|
421
|
+
}
|
|
422
|
+
const candidateFiles = [];
|
|
423
|
+
for (const localFile of localFiles) {
|
|
424
|
+
const syncInfo = syncState.files[localFile];
|
|
425
|
+
const localHash = localHashes.get(localFile);
|
|
426
|
+
if (!syncInfo || localHash !== syncInfo.localHash) {
|
|
427
|
+
if (remoteFileMap.has(localFile)) {
|
|
428
|
+
candidateFiles.push(localFile);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
const locallyDeletedFiles = Object.keys(syncState.files).filter(
|
|
433
|
+
(f) => !localFiles.includes(f) && remoteFileMap.has(f)
|
|
434
|
+
);
|
|
435
|
+
const filesToFetchRemote = [.../* @__PURE__ */ new Set([...candidateFiles, ...locallyDeletedFiles])];
|
|
436
|
+
const remoteHashes = /* @__PURE__ */ new Map();
|
|
437
|
+
if (filesToFetchRemote.length > 0 && !options?.force) {
|
|
438
|
+
const toFetch = filesToFetchRemote.filter((f) => remoteFileMap.has(f)).map((f) => remoteFileMap.get(f));
|
|
439
|
+
const fetched = await (0, import_helpers.fetchWithConcurrency)(toFetch, async (file) => {
|
|
440
|
+
const content = await this.farseerClient.getFileContentAsBuffer(file.reference);
|
|
441
|
+
return { file, hash: (0, import_helpers.calculateHash)(content) };
|
|
442
|
+
}, 15);
|
|
443
|
+
for (const { file, hash } of fetched) {
|
|
444
|
+
remoteHashes.set(file.path, hash);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
const comparisons = this.compareFiles({ localHashes, remoteHashes, syncState, all: true });
|
|
448
|
+
const conflictPaths = /* @__PURE__ */ new Set();
|
|
449
|
+
if (!options?.force) {
|
|
450
|
+
for (const c of comparisons) {
|
|
451
|
+
if (c.changeType.startsWith("conflict_")) {
|
|
452
|
+
const conflict = SyncService.buildConflicts([c])[0];
|
|
453
|
+
result.conflicts.push(conflict);
|
|
454
|
+
conflictPaths.add(c.filePath);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
for (const localFile of localFiles) {
|
|
459
|
+
if (conflictPaths.has(localFile)) continue;
|
|
460
|
+
const localPath = path.join(filesDir, localFile);
|
|
461
|
+
const content = localContents.get(localFile);
|
|
462
|
+
const localHash = localHashes.get(localFile);
|
|
303
463
|
const remoteFile = remoteFileMap.get(localFile);
|
|
304
464
|
const syncInfo = syncState.files[localFile];
|
|
305
465
|
if (remoteFile) {
|
|
306
466
|
if (syncInfo && localHash === syncInfo.localHash) {
|
|
307
|
-
|
|
467
|
+
result.unchanged.push(localFile);
|
|
308
468
|
} else {
|
|
309
|
-
|
|
469
|
+
await this.farseerClient.updateFile(remoteFile.reference, content, path.basename(localFile));
|
|
470
|
+
result.updated.push(localFile);
|
|
471
|
+
syncState.files[localFile] = {
|
|
472
|
+
localHash,
|
|
473
|
+
remoteHash: localHash
|
|
474
|
+
};
|
|
310
475
|
}
|
|
311
476
|
} else {
|
|
312
|
-
|
|
477
|
+
if (syncInfo && localHash === syncInfo.localHash) {
|
|
478
|
+
result.unchanged.push(localFile);
|
|
479
|
+
} else {
|
|
480
|
+
const pathParts = localFile.split("/");
|
|
481
|
+
const fileName = pathParts.pop();
|
|
482
|
+
const folderPath = ["Files", ...pathParts];
|
|
483
|
+
await this.farseerClient.createFile(content, fileName, folderPath);
|
|
484
|
+
result.uploaded.push(localFile);
|
|
485
|
+
syncState.files[localFile] = {
|
|
486
|
+
localHash,
|
|
487
|
+
remoteHash: localHash
|
|
488
|
+
};
|
|
489
|
+
}
|
|
313
490
|
}
|
|
314
491
|
}
|
|
315
|
-
for (const localFile of filesToUpload) {
|
|
316
|
-
const localPath = path.join(filesDir, localFile);
|
|
317
|
-
const content = fs.readFileSync(localPath);
|
|
318
|
-
const localHash = (0, import_helpers.calculateHash)(content);
|
|
319
|
-
const pathParts = localFile.split("/");
|
|
320
|
-
const fileName = pathParts.pop();
|
|
321
|
-
const folderPath = ["Files", ...pathParts];
|
|
322
|
-
await this.farseerClient.createFile(content, fileName, folderPath);
|
|
323
|
-
result.uploaded.push(localFile);
|
|
324
|
-
syncState.files[localFile] = {
|
|
325
|
-
localHash,
|
|
326
|
-
remoteHash: localHash
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
for (const { localFile, remoteFile, content, localHash } of filesToUpdate) {
|
|
330
|
-
await this.farseerClient.updateFile(remoteFile.reference, content, path.basename(localFile));
|
|
331
|
-
result.updated.push(localFile);
|
|
332
|
-
syncState.files[localFile] = {
|
|
333
|
-
localHash,
|
|
334
|
-
remoteHash: localHash
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
result.unchanged = filesUnchanged;
|
|
338
492
|
const localFileSet = new Set(localFiles);
|
|
339
493
|
for (const [remotePath, remoteFile] of remoteFileMap) {
|
|
340
|
-
if (!localFileSet.has(remotePath)) {
|
|
494
|
+
if (!localFileSet.has(remotePath) && !conflictPaths.has(remotePath)) {
|
|
341
495
|
const syncInfo = syncState.files[remotePath];
|
|
342
496
|
if (syncInfo) {
|
|
343
497
|
await this.farseerClient.deleteFile(remoteFile.reference);
|
|
@@ -386,6 +540,126 @@ class SyncService {
|
|
|
386
540
|
}
|
|
387
541
|
return { localContent, remoteContent };
|
|
388
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Three-way comparison of all files.
|
|
545
|
+
* Compares current local state, current remote state, and baseline from sync state.
|
|
546
|
+
*/
|
|
547
|
+
compareFiles(options) {
|
|
548
|
+
const { localHashes, remoteHashes, syncState } = options;
|
|
549
|
+
const allPaths = /* @__PURE__ */ new Set([
|
|
550
|
+
...localHashes.keys(),
|
|
551
|
+
...remoteHashes.keys(),
|
|
552
|
+
...Object.keys(syncState.files)
|
|
553
|
+
]);
|
|
554
|
+
const results = [];
|
|
555
|
+
for (const filePath of allPaths) {
|
|
556
|
+
if (!options.all) {
|
|
557
|
+
if (!import_farseerFactory.DEFAULT_SCRIPT_EXTENSIONS.some((ext) => filePath.toLowerCase().endsWith(ext))) {
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
const currentLocalHash = localHashes.get(filePath) ?? null;
|
|
562
|
+
const currentRemoteHash = remoteHashes.get(filePath) ?? null;
|
|
563
|
+
const baseline = syncState.files[filePath];
|
|
564
|
+
const baselineLocalHash = baseline?.localHash ?? null;
|
|
565
|
+
const baselineRemoteHash = baseline?.remoteHash ?? null;
|
|
566
|
+
const localExists = currentLocalHash !== null;
|
|
567
|
+
const remoteExists = currentRemoteHash !== null;
|
|
568
|
+
const hadBaseline = baseline != null;
|
|
569
|
+
let changeType;
|
|
570
|
+
if (localExists && remoteExists) {
|
|
571
|
+
if (currentLocalHash === currentRemoteHash) {
|
|
572
|
+
changeType = "unchanged";
|
|
573
|
+
} else if (!hadBaseline) {
|
|
574
|
+
changeType = "conflict_both_new";
|
|
575
|
+
} else {
|
|
576
|
+
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
577
|
+
const remoteChanged = currentRemoteHash !== baselineRemoteHash;
|
|
578
|
+
if (localChanged && remoteChanged) {
|
|
579
|
+
changeType = "conflict_both_modified";
|
|
580
|
+
} else if (localChanged) {
|
|
581
|
+
changeType = "local_modified";
|
|
582
|
+
} else if (remoteChanged) {
|
|
583
|
+
changeType = "remote_modified";
|
|
584
|
+
} else {
|
|
585
|
+
changeType = "unchanged";
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
} else if (localExists && !remoteExists) {
|
|
589
|
+
if (!hadBaseline) {
|
|
590
|
+
changeType = "local_new";
|
|
591
|
+
} else {
|
|
592
|
+
const localChanged = currentLocalHash !== baselineLocalHash;
|
|
593
|
+
if (localChanged) {
|
|
594
|
+
changeType = "conflict_local_modified_remote_deleted";
|
|
595
|
+
} else {
|
|
596
|
+
changeType = "remote_deleted";
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
} else if (!localExists && remoteExists) {
|
|
600
|
+
if (!hadBaseline) {
|
|
601
|
+
changeType = "remote_new";
|
|
602
|
+
} else {
|
|
603
|
+
const remoteChanged = currentRemoteHash !== baselineRemoteHash;
|
|
604
|
+
if (remoteChanged) {
|
|
605
|
+
changeType = "conflict_local_deleted_remote_modified";
|
|
606
|
+
} else {
|
|
607
|
+
changeType = "local_deleted";
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
} else {
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
results.push({
|
|
614
|
+
filePath,
|
|
615
|
+
changeType,
|
|
616
|
+
currentLocalHash,
|
|
617
|
+
currentRemoteHash,
|
|
618
|
+
baselineLocalHash,
|
|
619
|
+
baselineRemoteHash
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
return results;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Extract SyncConflict[] from FileCompareResult[].
|
|
626
|
+
*/
|
|
627
|
+
static buildConflicts(comparisons) {
|
|
628
|
+
const conflicts = [];
|
|
629
|
+
for (const c of comparisons) {
|
|
630
|
+
switch (c.changeType) {
|
|
631
|
+
case "conflict_both_modified":
|
|
632
|
+
conflicts.push({
|
|
633
|
+
filePath: c.filePath,
|
|
634
|
+
type: "both_modified",
|
|
635
|
+
description: "Both local and remote versions modified since last sync"
|
|
636
|
+
});
|
|
637
|
+
break;
|
|
638
|
+
case "conflict_local_modified_remote_deleted":
|
|
639
|
+
conflicts.push({
|
|
640
|
+
filePath: c.filePath,
|
|
641
|
+
type: "local_modified_remote_deleted",
|
|
642
|
+
description: "File modified locally but deleted on remote"
|
|
643
|
+
});
|
|
644
|
+
break;
|
|
645
|
+
case "conflict_local_deleted_remote_modified":
|
|
646
|
+
conflicts.push({
|
|
647
|
+
filePath: c.filePath,
|
|
648
|
+
type: "local_deleted_remote_modified",
|
|
649
|
+
description: "File deleted locally but modified on remote"
|
|
650
|
+
});
|
|
651
|
+
break;
|
|
652
|
+
case "conflict_both_new":
|
|
653
|
+
conflicts.push({
|
|
654
|
+
filePath: c.filePath,
|
|
655
|
+
type: "both_new",
|
|
656
|
+
description: "File exists both locally and remotely with different content (no sync baseline)"
|
|
657
|
+
});
|
|
658
|
+
break;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return conflicts;
|
|
662
|
+
}
|
|
389
663
|
/**
|
|
390
664
|
* Batch fetch metadata for multiple files in parallel.
|
|
391
665
|
* Fetches metadata in batches of 10 to avoid overwhelming the API.
|