mirror of
https://github.com/runbear-io/beardrive.git
synced 2026-08-25 08:08:08 +02:00
Adding a path to .bdriveignore only stopped future uploads: anything that synced before the rule existed stayed on the hub forever, with no command that removed it without deleting it from local disk on every device. Two engine changes make an explicit removal safe: - materialize's delete loop now consults the filter. A cached path absent from the replayed target that the rules exclude is dropped from tracking instead of unlinked — without this, any delete op for a now-filtered path wipes every peer's local copy, which is the data loss this issue is about. - the filter is reloaded mid-cycle from the pulled .bdriveignore, before materialize. A peer receiving the new rules and the deletes they justify in one batch would otherwise materialize with stale rules and the guard would never fire. materialize's write side is split into materializeFile so the ignore file can land on its own. On top of that, Session.Prune journals a delete for every path the replayed state still holds that the SHARED rules exclude — reconciling against the replay, not the local cache, because a path filtered out in an earlier cycle was dropped from the cache back then and is invisible locally today. The rules are deliberately ignore-only: the include scope lives in each device's own .bdrive/config.json and does not sync, so pruning against it would let a narrow-scope device delete a whole-folder teammate's files. Plain `bdrive sync` and the daemon are unchanged — pruning is never a side effect of editing .bdriveignore. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
119 lines
3.2 KiB
Go
119 lines
3.2 KiB
Go
// bdrive is the BearDrive CLI: mount a folder, and its
|
|
// contents stay synchronized across devices and teammates through a
|
|
// BearDrive hub, with full per-file change history and offline support.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime/debug"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/runbear-io/beardrive/internal/config"
|
|
)
|
|
|
|
// version is set at release time via -ldflags "-X main.version=...".
|
|
// `go install …@vX.Y.Z` builds skip ldflags, so fall back to the module
|
|
// version Go stamps into the binary.
|
|
var version = "0.1.0-dev"
|
|
|
|
func resolvedVersion() string {
|
|
if version != "0.1.0-dev" {
|
|
return version
|
|
}
|
|
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Version != "" && bi.Main.Version != "(devel)" {
|
|
return strings.TrimPrefix(bi.Main.Version, "v")
|
|
}
|
|
return version
|
|
}
|
|
|
|
func main() {
|
|
root := &cobra.Command{
|
|
Use: "bdrive",
|
|
Short: "BearDrive: a synced file system for AI agents",
|
|
Long: `bdrive — the BearDrive CLI. A mountable, offline-first, synced file
|
|
system for AI agents.
|
|
|
|
Mount any folder and BearDrive keeps it synchronized across your devices and
|
|
teammates through a BearDrive hub (bdrive web — self-hosted or BearDrive
|
|
Cloud). Every change is journaled — you can always see which device and
|
|
author changed which file, and when. Files are real files on disk, so
|
|
everything keeps working offline; changes sync when the remote is reachable.`,
|
|
SilenceUsage: true,
|
|
Version: resolvedVersion(),
|
|
}
|
|
root.SetVersionTemplate("beardrive {{.Version}}\n")
|
|
root.AddCommand(
|
|
loginCmd(),
|
|
logoutCmd(),
|
|
initCmd(),
|
|
shareCmd(),
|
|
urlCmd(),
|
|
stopCmd(),
|
|
scopeCmd(),
|
|
forgetCmd(),
|
|
syncCmd(),
|
|
readLogCmd(),
|
|
hooksCmd(),
|
|
skillCmd(),
|
|
statusCmd(),
|
|
logCmd(),
|
|
exportCmd(),
|
|
importCmd(),
|
|
webCmd(),
|
|
whoamiCmd(),
|
|
daemonCmd(),
|
|
versionCmd(),
|
|
)
|
|
if err := root.Execute(); err != nil {
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func versionCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print the bdrive version",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
fmt.Println("beardrive", resolvedVersion())
|
|
},
|
|
}
|
|
}
|
|
|
|
func whoamiCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "whoami",
|
|
Short: "Show this device's identity used in change tracking",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
dev, err := config.LoadDevice()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
home, err := config.Home()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Printf("device id: %s\n", dev.ID)
|
|
fmt.Printf("device name: %s\n", dev.Name)
|
|
settings, serr := config.LoadSettings()
|
|
if serr != nil {
|
|
fmt.Printf("account: unknown — cannot read settings: %v\n", serr)
|
|
} else if settings.Email != "" {
|
|
who := settings.Email
|
|
if settings.Name != "" {
|
|
who = settings.Name + " <" + settings.Email + ">"
|
|
}
|
|
fmt.Printf("account: %s (from `bdrive login`; changes are attributed to this)\n", who)
|
|
fmt.Printf("author: %s (git/OS fallback, used only when signed out)\n", dev.Author)
|
|
} else {
|
|
fmt.Printf("account: not signed in — changes are attributed to the author below (run `bdrive login`)\n")
|
|
fmt.Printf("author: %s (detected from git config / OS user)\n", dev.Author)
|
|
}
|
|
fmt.Printf("beardrive home: %s\n", home)
|
|
return nil
|
|
},
|
|
}
|
|
}
|