Files
beardrive/cmd/bdrive/main.go
T
594a027c15 feat(cli): bdrive grep — search the text inside the files a project syncs (BEA-99) (#136)
The ⌘K palette searches file names, projects and actions; nothing in the
product searched file contents. Three personas independently typed a phrase
that lives inside a synced file and got "No matches".

`bdrive grep <pattern> [folder]` searches the working folder — RE2 or -F
literal, -i, -l, -n (default 200, 0 = all), output `path:line: text`, exit 0
on match and 1 on none.

It searches exactly what the project syncs, via a new syncer.SyncedFiles that
wraps the existing walkFolder: the one copy of the sync predicate, so an
ignore rule or a narrowed scope excludes a file from search the same way it
excludes it from sync, and .bdrive/ state can never surface. Not Explain,
which countFiles every pruned dir — a grep in a repo with node_modules/ would
walk it in full for a count it discards.

A read stays a read: LoadProject, not ResolveMount (no registry self-heal, no
device enrollment), no session, no flock, and the volume store is opened for
IgnoreAccepted only when it already exists, so a search creates nothing.
Both the path and the matched line go through safeField — a matched line is a
teammate's file content, the widest version of the surface that function
exists for.

The hub-side content index stays deliberately unbuilt; the issue records its
cost. ROADMAP's "Search across the hub" line is reworded rather than removed.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-11 04:27:20 +09:00

123 lines
3.3 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 serve — 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(),
grepCmd(),
forgetCmd(),
syncCmd(),
readLogCmd(),
hooksCmd(),
resumeCmd(),
autostartCmd(),
statusCmd(),
logCmd(),
restoreCmd(),
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 + ">"
}
// Name and email are whatever the hub answered at sign-in.
fmt.Printf("account: %s (from `bdrive login`; changes are attributed to this)\n", safeField(who, 160))
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
},
}
}