Skip to content

feat: vm_sync / boxery sync push a local git checkout into a VM - #207

Merged
benvinegar merged 5 commits into
masterfrom
feat/vm-sync
Nov 9, 2026
Merged

benvinegar merged 5 commits into
masterfrom
feat/vm-sync

Conversation

@benvinegar

@benvinegar benvinegar commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Adds vm_sync (agent tool) and boxery sync (CLI): push a local git checkout into a VM so the VM's tree matches it exactly. Push only.

synced 3f2a9c1 + 2 modified, 1 untracked, 0 deleted → demo:/home/agent/project · tree matches

How it works

  1. Snapshot: local HEAD plus staged, unstaged and untracked (not ignored) changes become one commit, built in a scratch index. The local repo isn't modified.
  2. Push: git push over the VM's own ssh connection into a hidden ref. Only missing objects are sent, with no hooks on either side, no user git config, and no contact with any remote.
  3. Swap: the VM checks out HEAD detached and switches its working tree to the snapshot. Leftovers are deleted and ignored files (node_modules, builds) stay. A failed swap rolls back, and an interrupted one is finished or undone by the next sync.
  4. Verify: both sides hash the working tree the same way and compare. The result also reports lockfile_changed.

Refuses, changing nothing

  • VM edits that the last sync didn't make.
  • Credential files (.env*, .npmrc, keys, …) in the tree or in any commit being pushed. The error points to vm_grant.
  • A sync that would overwrite or delete ignored VM files.
  • A target inside another checkout, or a non-git, shallow or partial-clone source.

Where

  • Code: core/sync.mjs and core/sync-guest.sh. The tool is in the shared table, and boxery sync runs the same entry, as cp does.
  • MCP: same rule as vm_copy's local:. Refused over HTTP without --copy-root, and confined to that directory with it.
  • Docs: docs/sync.md, plus links from cli.md, mcp.md, copy.md and pi-extension.md.

Verified

  • lint, typecheck, npm test (457) and test:shell (47) pass.
  • test/sync.test.mjs: 32 offline cases using real git receive-pack in a fake VM, covering the brief's list plus fixes from two subagent reviews. I reverted each review fix and confirmed its test fails without it.
  • Live, on throwaway libvirt VMs, removed afterwards:
    • First sync of this repo: about 2,900 objects in 1.2 s. Checksums of all 371 files matched on both sides.
    • Repeat sync: nothing pushed, 0.2 s.
    • One new commit: 3 objects sent.

Not verified / limits

  • Ctrl-C during the VM's apply step: checked by reading the code only. Not run on macOS.
  • LFS files arrive as pointers, and submodules as gitlinks.
  • The credential check on pushed history relies on the VM's own report of which refs it has.

This PR description was generated by Pi using Claude Opus 5.5

Commits go as a git bundle over vm_copy's streaming transport; neither side
contacts a git remote. The VM checks out local HEAD (detached) and switches
its working directory to a snapshot of HEAD plus staged, unstaged and
untracked changes, keeping ignored files. Refuses (changing nothing) on
VM-side edits since the last sync (refs/boxery/synced) and on credential
files. Staged swap with a pending record, rollback and crash recovery.
Reports a tree hash computed on both sides and lockfile changes.
… ignored-file clobbering

- Refuse credentials anywhere in the commits the bundle sends, not just the tree.
- Confined (--copy-root): no repo discovery above the root, git dir/objects/alternates
  must be inside it, and no fsmonitor, hooks or filter drivers run.
- Crash recovery refuses rather than overwrite files edited since the crash.
- Refuse when the new tree would overwrite or delete ignored VM files, or when new
  ignore rules expose VM files (rolled back, nothing recorded).
- Refuse a VM target inside another checkout; clear errors for shallow clones.
- Case-insensitive, broader deny list; pipefail; mkdir lock without flock;
  two-tree read-tree -m so a file changed mid-swap aborts before any write;
  no LFS smudge or lazy fetch; Ctrl-C waits for an in-progress apply.
git push over the VM's own ssh_config streams only the objects the VM lacks
(negotiated against all its refs) into receive-pack, to a hidden
refs/boxery/incoming/<id> ref. No bundle file, tar or staging directory;
receive-pack's quarantine makes a cancelled push leave nothing. No hooks run
on either side. The history credential check now excludes everything
reachable from the VM's ref tips. The VM repo is created (in a missing or
empty dir only) after the checks, just before the push.

Result fields: transferred_bytes -> pushed, objects_sent.
…ig isolation

- Copy the index with its mtime (both sides): a newer copy hid same-second,
  same-size edits, so local changes went unsynced and VM edits were missed.
- History scan uses rev-list --objects (what the push sends), so merge
  commits and roots count; deny-dir check covers history too.
- The push and its scratch repo read no user/system config and no GIT_*
  env: url.(push)insteadOf can't redirect it to another VM.
- Push ssh uses ControlMaster=no; receive.autogc=false; cancel escalates
  TERM to KILL and doesn't wait forever on stderr.
- Guest: no hooks or fsmonitor from the VM repo's config.
- Undo init when the push into a new dir fails; drop only this sync's
  incoming ref plus abandoned ones over an hour old.
- core.splitIndex=false for scratch-index ops; refuse partial clones.
@benvinegar
benvinegar merged commit 327bb7d into master Nov 9, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant