diff --git a/cmd/bdrive/cmds.go b/cmd/bdrive/cmds.go index 70fc458..de959ae 100644 --- a/cmd/bdrive/cmds.go +++ b/cmd/bdrive/cmds.go @@ -15,6 +15,7 @@ import ( func syncCmd() *cobra.Command { var note string var noteTTL time.Duration + var hookLabel string c := &cobra.Command{ Use: "sync [folder]", Short: "Sync a mounted folder with its remote now", @@ -24,6 +25,11 @@ func syncCmd() *cobra.Command { if err != nil { return err } + if hookLabel != "" { + // Agent-hook mode: event JSON on stdin, silent best-effort + // sync, link-formula context on stdout. Never fails. + return runHookSync(cmd, folder, hookLabel) + } sess, proj, err := openSession(cmd.Context(), folder, true) if err != nil { return err @@ -51,6 +57,7 @@ func syncCmd() *cobra.Command { } c.Flags().StringVar(¬e, "note", "", "session context stamped onto changes (e.g. an agent session id); shown in history; empty clears") c.Flags().DurationVar(¬eTTL, "note-ttl", 30*time.Minute, "how long the note keeps applying to daemon-committed changes") + c.Flags().StringVar(&hookLabel, "hook", "", "agent-hook mode: read the platform's hook event JSON from stdin, sync with a session note labeled by this value, and emit the project's link-formula context (Claude Code hook JSON) on stdout") return c } diff --git a/cmd/bdrive/hooksync.go b/cmd/bdrive/hooksync.go new file mode 100644 index 0000000..bc78ea5 --- /dev/null +++ b/cmd/bdrive/hooksync.go @@ -0,0 +1,79 @@ +package main + +import ( + "encoding/json" + "fmt" + "io" + "time" + + "github.com/spf13/cobra" +) + +// `bdrive sync --hook