workspace-sync: auto-resync on first run
This commit is contained in:
parent
65b2b0479b
commit
364ac8f919
@ -27,6 +27,7 @@ type SyncManagerState = {
|
|||||||
lastSyncOk: boolean | null;
|
lastSyncOk: boolean | null;
|
||||||
syncCount: number;
|
syncCount: number;
|
||||||
errorCount: number;
|
errorCount: number;
|
||||||
|
hasSuccessfulSync: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const state: SyncManagerState = {
|
const state: SyncManagerState = {
|
||||||
@ -35,6 +36,7 @@ const state: SyncManagerState = {
|
|||||||
lastSyncOk: null,
|
lastSyncOk: null,
|
||||||
syncCount: 0,
|
syncCount: 0,
|
||||||
errorCount: 0,
|
errorCount: 0,
|
||||||
|
hasSuccessfulSync: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let currentConfig: MoltbotConfig | null = null;
|
let currentConfig: MoltbotConfig | null = null;
|
||||||
@ -79,20 +81,39 @@ async function runSync(): Promise<void> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Run bisync - pure file operation, no LLM involvement
|
// Run bisync - pure file operation, no LLM involvement
|
||||||
const result = await runBisync({
|
// Auto-resync on first run if no prior sync state exists
|
||||||
|
const needsResync = !state.hasSuccessfulSync;
|
||||||
|
|
||||||
|
let result = await runBisync({
|
||||||
configPath: resolved.configPath,
|
configPath: resolved.configPath,
|
||||||
remoteName: resolved.remoteName,
|
remoteName: resolved.remoteName,
|
||||||
remotePath: resolved.remotePath,
|
remotePath: resolved.remotePath,
|
||||||
localPath: resolved.localPath,
|
localPath: resolved.localPath,
|
||||||
conflictResolve: resolved.conflictResolve,
|
conflictResolve: resolved.conflictResolve,
|
||||||
exclude: resolved.exclude,
|
exclude: resolved.exclude,
|
||||||
|
resync: needsResync,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If failed with resync error and we didn't already try resync, retry with resync
|
||||||
|
if (!result.ok && result.error?.includes("--resync") && !needsResync) {
|
||||||
|
logger.info("[workspace-sync] First-time sync detected, running with --resync");
|
||||||
|
result = await runBisync({
|
||||||
|
configPath: resolved.configPath,
|
||||||
|
remoteName: resolved.remoteName,
|
||||||
|
remotePath: resolved.remotePath,
|
||||||
|
localPath: resolved.localPath,
|
||||||
|
conflictResolve: resolved.conflictResolve,
|
||||||
|
exclude: resolved.exclude,
|
||||||
|
resync: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
state.lastSyncAt = new Date();
|
state.lastSyncAt = new Date();
|
||||||
state.syncCount++;
|
state.syncCount++;
|
||||||
|
|
||||||
if (result.ok) {
|
if (result.ok) {
|
||||||
state.lastSyncOk = true;
|
state.lastSyncOk = true;
|
||||||
|
state.hasSuccessfulSync = true;
|
||||||
logger.info("[workspace-sync] Periodic sync completed");
|
logger.info("[workspace-sync] Periodic sync completed");
|
||||||
} else {
|
} else {
|
||||||
state.lastSyncOk = false;
|
state.lastSyncOk = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user