Repository navigation
Conversation
…port A CLI for a file store (ydisk next) can keep a local folder and a remote folder the same, whole files at a time. drive's pushDocuments is local-first, text-only and reads the remote once per file, so the file engine is new and shares the layer around it. - syncFileMirror: three-way comparison per path (local now, remote now, last sync) over one remote listing; same content is adopted, different changes are conflicts settled by keep local|remote|both (both keeps a dated copy); deletions go to the remote trash (expected sha256/md5) or <root>/.wirecat-trash/, behind a 50-file / 25% guard; a remote rename found by id renames the local file; every write is conditional, so a crash at any step is settled by the next listing; outcome_unknown is never retried in the run; downloads and uploads stream; a dry run writes nothing. - FileTarget port (list with root id, download, upload, trash, ensureFolder, optional revision), fileSyncState, fileMirrorStatus, syncFileMirrors and fileRemoteChanges, which lists only when the remote revision moved. - Shared changes: jsonState and eachMirror extracted from fileMirrorState and syncMirrors; scanLocal reports size and mtime and reuses a known hash; replaceLocal takes bytes or a stream writer, an expected content hash, and creates only while absent; watchMirrors takes localChanges; the guard's action gains delete and move; conflictReport adds sizes and drops an empty url. drive's behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ocal versions Owner rulings on #3116. - A file counts as deleted only when the last sync saw it, the side's listing is complete (FileTarget.list returns `complete`), and the side's root is the same folder: the remote root id, the local folder's device and inode, and a local folder that is not empty while the state has files (an unmounted drive). Anything else is reported in `unknown` and the run is partial; a broken root makes the run do nothing. - fileVersions: before a sync overwrites or deletes a local file, its content is kept by sha256 under the profile's state folder, with an append-only log per mirror of every change both ways (an upload logs the remote version it replaced). Retention: 30 days, and a deleted file's last version for good. restoreFileVersion puts one back. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leemour
force-pushed
the
feat/file-mirror
branch
from
November 18, 2026 18:01
bbc96e4 to
8f221aa
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
Step 1 of the ydisk two-way folder sync: a whole-file mirror engine in cli-core, with the
FileTargetport ydisk will implement for the Disk.Why
drive's
pushDocumentsis local-first, writes text only, reads the remote once per file and only reports deletions. A file store needs bytes both ways, one listing per run, deletions into trashes and renames by id. RewritingpushDocumentswould put drive's Docs/Sheets merge at risk, so the file engine is new and shares the layer around it.What
syncFileMirror(src/services/files/mirror.ts): three-way comparison per path (local now, remote now, last sync).keepsettles it:local,remote, orboth, which downloads the remote version asname (conflict YYYY-MM-DD <remote>).extand sends both.<root>/.wirecat-trash/YYYY-MM-DD/. A guard stops the run before any write at more than 50 deletions or 25% of the mirror, unlessallowDeletionscovers it. A dry run reportstooManyDeletions.id, renames the local file. A local rename is a deletion plus a new file.outcome_unknownis not retried within the run.A deletion must be proven. A file counts as deleted only when all of these hold:
listreturnscomplete);Anything else is reported in
unknown, nothing is deleted for it, and the run is partial. A broken root stops the whole run.Local versions (
src/services/files/versions.ts).fileVersions(dir)keeps a local file's content before the sync overwrites or deletes it. The content is stored by sha256 under the profile's state folder, and every change is added to an append-only log. An upload logs the remote version it replaced. Retention: versions stay 30 days, and the last version of a deleted file stays for good.restoreFileVersionputs a version back.FileTarget(src/documents/file-mirror-model.ts):identity,list(root) → { rootId, files, complete } | undefined,download(path, into),upload(path, from, expect),trash(path, expect),ensureFolder(path),revision?().Also exported:
syncFileMirrors(the lock andmirror.partial, assyncMirrorsdoes),fileSyncState,fileMirrorStatus, andfileRemoteChanges, which lists only when the remote revision moved.Shared changes. drive's behaviour is unchanged.
jsonStateandeachMirrorare pulled out offileMirrorStateandsyncMirrors.scanLocalreportssizeandmtimeMs, and reuses a known hash when both match.replaceLocaltakes bytes or a stream writer and an expected content hash, and can create a file only while it is absent.watchMirrorstakeslocalChanges.actiongainsdeleteandmove.conflictReportadds sizes and leaves out an emptyurl.Docs:
docs/dev/DOCUMENTS.md, "Plain files, both ways". Changelog fragment:changes/feat-file-mirror.md.Testing
src/services/files/mirror.test.ts(58 tests). Besides the cases below, it covers deletion proof (incomplete listing, failed listing, a local root that is gone, empty or replaced, a remote root that is gone or replaced, a file never synced, the partial issue) and versions (a pull,keep: "remote", a crossed deletion, an upload's replaced version, restore, retention, the dry run).expect. It covers:keeplocal, remote and both;outcome_unknownfollowed by adopt;mirror-watch.test.tsgains alocalChangescase.docs:checkand the full vitest suite. One unrelated test,notes-meaning-filters, timed out under load and passes alone.🤖 Generated with Claude Code