Commit graph

18 commits

Author SHA1 Message Date
3ea8df85aa round4-client: surface last sync error per mount in status
Track lastErr per mount (mirroring lastSync pattern), cleared on
success so a recovered mount shows clean. Errors from LoadIgnoreWith,
Pull, and Sync all land in the map and surface through StateSnapshot
into 'devbox status' (human ⚠️ warning) and --json (last_err field).
2026-06-30 14:23:42 -05:00
84a4ff53e8 feat(cli): doctor --json, conflicts --rm, status sync-age, opt-in default ignores 🧰🙈
- 🩺 `doctor --json`: structured check report for cron/monitoring; still exits
  non-zero on ❌ (collects checks into a slice, JSON path suppresses the human lines).
- 🗑️ `conflicts --rm`: delete every `.conflict-` copy after review (lazy cleanup,
  not a resolver). Only touches conflict copies — real files untouched.
- ⏱️ `status` shows per-mount last-sync age ("synced 12s ago" / "not synced yet")
  from a daemon-tracked timestamp (control.MountState.LastSyncUnix); also in --json.
- 🙈 the reversed no-go: `settings.sync.ignore_defaults` (opt-in, default off) layers
  a built-in junk set (node_modules, .git, target, dist, build, .venv, __pycache__,
  .next, .DS_Store) onto the matcher — don't ship gigabytes of regenerable junk over
  the now-live WAN. Reuses round-1 --exclude plumbing; honored by daemon + publish.

Tests: doctor --json valid+exit-code, conflicts --rm deletes only conflicts,
ignore.Defaults match. go test ./... -race + vet clean.
2026-06-30 13:26:24 -05:00
11fe999ca2 feat(transfer): opt-in gzip blob compression for WAN sync 🌐🗜️
The "changed my mind" feature: deferred as YAGNI on a LAN, but the hub is now
WAN-reachable (port-forwarded), so over-the-internet sync is a real path and
compression earns its keep.

- client (settings.transfer.compress, default off): gzip a blob upload only
  when it actually shrinks — incompressible chunks (media, encrypted) go raw so
  we never inflate the wire. Sets Content-Encoding: gzip. Wired into the daemon
  sync loop and the initial `publish` upload.
- hub: decompresses gzip uploads before hashing, so dedup + content-address
  integrity are unchanged. Bomb-safe — caps BOTH the compressed stream
  (MaxBytesReader) and the decompressed size (LimitReader), rejecting a gzip
  header over a non-gzip body.

Tests: client gzip-when-smaller / raw-when-not, hub decompress round-trip +
bad-gzip rejection. go test ./... -race clean, go vet clean.
2026-06-30 12:34:27 -05:00
8c5d576a72 feat(device): --json output, streaming chunker, pause --for, per-mount exclude, rescan knob ✨
Five device-side wins from the feature review:

- 🤖 `--json` on status/log/conflicts: machine-readable output for fleet
  scripting/monitoring. status prefers live daemon state (paused +
  base-snapshot), falls back to disk; not-joined → {"joined":false}.
- 🌊 streaming chunker: chunk.SplitReader feeds FastCDC from an io.Reader so
  the manifest build no longer slurps whole files into RAM — a multi-GB file
  can't OOM the daemon. Identical boundaries/hashes (proven vs fragmented reads).
- ⏱️  `devbox pause --for 2h`: control socket carries a duration; the daemon
  schedules an auto-resume timer. Re-pause replaces it; plain pause/resume
  cancel it (no surprise resume).
- 🙈 per-mount `devbox mount --exclude <pat>`: device-local ignore layered on
  the shared .devignore (LoadIgnoreWith) — skip a local build dir without
  touching the shared file. Honored by daemon sync, restore, and deploy.
- 🎛️  rescan cadence is now settings.sync.rescan_seconds (was a hardcoded 60s
  const) — tune the watcher fallback per machine without a rebuild.

#6 (doctor non-zero exit) was already shipped — doctor returns an error on ❌.
Tests: SplitReader-vs-buffered, PauseFor auto-resume + cancel, wire duration,
LoadIgnoreWith layering, status/conflicts --json. go test ./... -race clean.
2026-06-30 12:29:02 -05:00
03469958d3 chore: prep for public release — MIT license + github.com module path 🌍⚖️
Some checks are pending
CI / vet-build-test (push) Waiting to run
- LICENSE: MIT (enables the adoption push; public repo was all-rights-reserved).
- go.mod + all imports: git.shoemoney.ai/shoemoney/devbox -> github.com/shoemoney/devbox,
  so outsiders can 'go install github.com/shoemoney/devbox/cmd/devbox@latest'. Forgejo
  stays the self-hosted home; the registry (devbox-hub) + public dist (devbox-dist) are
  unchanged. vet + build + go test -race all green after the rename.
- README: document the go install path.

Security: full git-history scan (manual blob sweep + gitleaks, 84 commits) found
ZERO secrets — Forgejo token never committed, no keys/passwords/private keys.
2026-06-23 19:19:09 -05:00
9f90f2c147 refactor(M8): drop the control /events SSE stream — no consumer yet (ponytail) ✂️
ponytail-review caught it: publishActivity -> ctrl.Publish -> broker -> SSE
was a producer with nothing on the other end. GET /events only feeds the
M11 TUI, which is demand-driven and not built. /state + /pause + /resume
cover every real caller (devbox status/pause/resume). Cut the broker,
handleEvents, Publish, publishActivity, and the ctrl handle — re-add the
(small, known) fan-out when a TUI actually consumes it. Net -100 lines.
2026-06-23 10:50:45 -05:00
20579b0aae feat(M8): daemon control socket + pause/resume 🎛️
Add internal/control: an HTTP/1.1 control plane the daemon hosts on a
0600 Unix socket (control.sock) in the config dir — GET /state, GET
/events (SSE), POST /pause|/resume — plus a stdlib net/http client
(DialState/Pause/Resume) that returns a typed ErrNotRunning when the
daemon is down so callers can fall back.

Wire into the daemon: paused atomic.Bool gates runMount's trigger loop
(drains while paused, no-ops the initial nudge), a per-mount nudge
registry lets Resume catch every mount up, and StateSnapshot feeds
/state. The control server starts in Run and is non-fatal — sync never
depends on it. Windows gets a build-tagged stub (named-pipe upgrade
path noted).

CLI: devbox pause/resume call the client (friendly 'daemon not running'
when absent); status prefers the live socket but ONLY on a TTY, so piped
output stays byte-identical to v1 for scripts.
2026-06-23 10:38:22 -05:00
04f94d7730 harden(auth): require proof-of-possession on join 🪪🔐
The device id is derived from the pubkey in JoinRequest, but the hub never
checked the joiner actually held that key — anyone with a token could enroll
claiming another device's identity. Now the client signs JoinChallenge(token,
pubkey) with its ed25519 private key and the hub verifies it (ed25519.Verify)
BEFORE redeeming the token — so a bad request can't burn a legitimate one-time
token either. proto gains a Signature field + the shared JoinChallenge helper.
Regression test: garbage/missing/wrong-key sigs all 401, token survives, valid
join enrolls.
2026-06-23 03:08:23 -05:00
56b8be924b fix(daemon): stagger rescans, guard jitter panic, tighten backoff reset 🔁⚙️
- rescan tickers for all mounts started in lockstep, so every 60s they rebuilt
  manifests simultaneously (self-synchronized load spike on big trees). Stagger
  the first tick by a random offset.
- jittered() called rand.Int63n(int64(d/2)) which panics for sub-2ns durations
  (d/2==0). Guard it. (Latent: a panic in a recover-less goroutine.)
- healthyStream was 2min — 4x larger than typical SSE recycle (~30-60s), so a
  recycled-but-healthy stream never reset backoff and sat at the 30s ceiling.
  Lowered to 20s. Regression test for the jitter panic.
2026-06-23 02:38:46 -05:00
88aa53064f feat(M7): periodic rescan fallback for dead/limited watchers 🔁🍓
The v1 daemon only re-syncs a mount on a watcher event or a hub event. If the
watcher can't start (inotify max_user_instances/max_user_watches exhausted on a
big Pi tree — PRD risk #1) the mount silently stops pushing local edits.

Add a 60s per-mount rescan ticker that nudges a sync regardless, so a mount
reconverges even with no working watcher. Watcher-start failure now logs the
fallback + points at 'devbox doctor' instead of going quiet.

Fleet-verified on linux/arm64: with fs.inotify.max_user_instances=0 (watcher
dead) a local edit still propagated to a peer via the rescan tick.
scripts/m7-fleet-verify.sh exercises the full M7 surface + this rescan path.
2026-06-23 01:53:24 -05:00
5bfccdb297 fix(M7): review fixes — pidfile O_EXCL, publish race, backoff reset 🐛
Code-review pass on M6.5+M7:
- pidfile: claim via O_CREATE|O_EXCL and arbitrate live-vs-stale, so two
  `devbox start` invocations can't both win the guard and run concurrently
- hub: serialize publish (publishMu) so a case-clash check + create is atomic;
  reject share names ending in '.' (Windows strips it → silent collision)
- daemon: reset SSE backoff only after a genuinely healthy stream (2m), not the
  30s ceiling, so a hub that recycles connections doesn't pin a 30s event lag
- document that restore/deploy's delete pass is ignore/guard-filtered on purpose
  (never delete a user's gitignored runtime files or local secrets)
- test: pidfile claim/refuse/stale-reclaim arbitration
2026-06-23 01:37:58 -05:00
bf40d209c1 feat(M7): devbox doctor, stop, and hook edit/list 🩺⏹️🪝
- devbox doctor: checks identity/join, hub reachability + bearer acceptance,
  bash for hooks, fsnotify watcher (catches inotify exhaustion), and each mount's
  writability; exits non-zero on any failure
- devbox stop + pidfile: start writes ~/.config/devbox/daemon.pid and refuses a
  second daemon; stop SIGTERMs it (liveness-checked, cleans stale pidfiles)
- devbox hook edit <share> <event>: scaffolds an executable, documented bash
  sample then opens $EDITOR/$VISUAL; hook list shows installed vs available
- hooks: AllEvents/IsEvent/Dir/Sample helpers
2026-06-23 01:30:49 -05:00
38766fdcd5 feat(M7): SSE reconnect backoff + share-name validation 🛡️
- daemon: exponential backoff (1s→30s) + ±25% jitter on SSE reconnect so a fleet
  that drops together doesn't reconnect in lockstep; a long-lived stream resets it
- hub: ValidateShareName rejects path separators, traversal, control/non-ASCII
  chars, reserved Windows device names (CON/NUL/COM1…), and case-clashes with an
  existing share (Foo vs foo would collide on case-insensitive filesystems)
- tests for both
2026-06-23 01:26:04 -05:00
2c6dba2dd2 feat(M6.5): devbox deploy — pin a mount to a snapshot (no push) 🚀
deploy applies a snapshot's manifest to a mount's local dir WITHOUT pushing a
new head — blue/green for /var/www boxes. History stays untouched; the mount is
pinned (config.Mount.Pinned) so the daemon won't live-advance it back to head.
Re-mount clears the pin.

- syncer.Deploy + shared applySnapshot helper (Restore now reuses it)
- config.Mount.Pinned; daemon skips pinned mounts
- CLI: devbox deploy <share> <snapshot> (prefers the --ro mount); status shows pinned
- test: deploy applies v1 while hub head stays v2 (the no-push property)
2026-06-23 01:17:20 -05:00
613de19818 feat(M5): lifecycle hooks 🪝
- internal/hooks: Runner finds <mount>/.devbox/hooks/<event>, runs via bash (or
  .ps1->pwsh), injects DEVBOX_EVENT/MOUNT/SHARE/HOST/REMOTE/SNAPSHOT/CHANGED_FILES,
  60s timeout (WaitDelay bounds post-kill cleanup), pre-* non-zero exit = veto
- syncer fires pre-push/post-push (in Push) + pre-pull/post-pull/on-conflict (in
  Pull); pre-* veto -> PullResult/Result.Vetoed -> Sync skips, waits for next nudge
- daemon builds a Runner per mount; cmd mount/publish pass nil (daemon drives hooks)
- tests: env+changed-files injection, absent=no-op, pre-* veto, 60s timeout kill,
  post-pull fires with changed list, pre-push vetoes (head not advanced)
2026-06-23 00:48:16 -05:00
512e7f8b73 feat(M4): sub-path mounts 🎯
- mount share/subpath into any local dir; Pull filters+strips the share manifest
  to the subpath, Push splices the local subtree back into the full share head
  (entries outside the subpath preserved) so a partial mount never drops the rest
- declares all full-manifest chunks for correct hub refcounts (hub chunks size 0)
- cmd: 'devbox mount projects/p22/backend /var/www'; daemon threads Subpath
- state keyed by share+subpath+local
- test: sub-path mount sees only its subtree (stripped); editing+pushing from it
  preserves docs/ and root.txt elsewhere in the share
2026-06-23 00:36:11 -05:00
6532c510f5 feat(M4) + harden: bandwidth cap + M3 review fixes 🔒🛡️
Bandwidth cap (M4):
- transport rate-limited blob up/download (golang.org/x/time/rate); config.toml
  [transfer].max_kbps; daemon applies it per mount; [secrets].extra_patterns too

M3 ponytail review fixes (data-loss + resilience):
- C1: conflict-copy names use nanoseconds + collision probe — second-granularity
  timestamps could collide and os.Rename would overwrite a copy (lost edit)
- C3: pull resilience — a filesystem clash (file<->dir) skips that path instead of
  aborting the whole batch; network errors still abort+retry. PullResult.Skipped
- C2(partial): manifest skips .devbox-tmp-* (atomic-write temp files never sync).
  Kept conflict-copy propagation (design + Dropbox: losing edit survives device death)
- dedup: manifest.SameContent shared (was duplicated in pull)
- tests: file<->dir clash skips one path not the mount; rate-limit throttles
2026-06-23 00:29:50 -05:00
dd0db590c7 feat(M3): live two-way sync — SSE fan-out + daemon + mount 🔄
- pkg/proto + internal/hub/events.go: SSE /v1/events with a broker; hub broadcasts
  on genuine head ADVANCE only (idempotent re-push doesn't broadcast -> no storm)
- transport.Client.Events: SSE consumer (timeout-less, ctx-cancelled)
- internal/daemon: per-mount loop funnels watcher + SSE triggers into a serialized
  Sync; read-only mounts pull-only; base snapshot persisted in state.json
- cmd/devbox: 'mount <share> <dir> [--ro]' (clone+sync) and 'start' (foreground daemon)
- fix: serialize chunk.Split — jotfs/fastcdc-go mutates a package global in
  NewChunker, racing under concurrent chunking (caught by -race)
- test: two live daemons, an edit on one reaches the other automatically (race-clean)
2026-06-23 00:12:39 -05:00