From 6628718f1d826054eca593c2723c98c92e66616d Mon Sep 17 00:00:00 2001 From: "Snow W. Lee (Sungwon)" Date: Fri, 24 Jul 2026 15:53:23 +0900 Subject: [PATCH] fix(cli): agent hooks never sync folders this device didn't opt into (#44) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(cli): agent hooks never sync folders this device didn't opt into The turn hooks decided "this folder is managed" from the mere presence of .bdrive/config.json — a file designed to travel with the folder. Two holes: - A config.json arriving via git clone / copied dir made one hook firing silently mint a device identity, register the mount, create a volume store, journal the whole folder, and inject the hub-link formula — on a device that never ran init or login. - `bdrive stop` only killed the daemon: the next agent turn's `bdrive sync --hook` resumed a full sync cycle and kept injecting links, and `stop --forget` was undone within one turn by registry self-heal. Fix: one gate (`syncBlocked`) in the paths all hooks route through — sync/sync --hook/read-log now require the mount to already be enrolled in this device's mounts.json (read without ResolveMount's enrolling self-heal) and not paused. Hook mode exits silently; plain `bdrive sync` errors with a `bdrive init` pointer. New per-device paused marker in the volume dir: set by `bdrive stop`, cleared by `bdrive init` (startSync). Only init enrolls or resumes; folder moves still self-heal since enrollment is keyed by mount id, not path. Docs updated (README, SKILL.md, docs cli reference, CHANGELOG). Tests: hook/read-log no-op + no-enrollment on unenrolled and paused mounts, plain-sync refusals, stop→pause→forget regression, paused marker contract. Co-Authored-By: Claude Fable 5 * docs: architecture-diagram PRs must show before/after excerpts of changed classes The "Architecture changes" PR section now names exactly what changed and shows Before and After mermaid excerpts scoped to the affected classes and their immediate relationships — never the full diagram (Before = merge base). Convention updated in CLAUDE.md, architecture/README.md, and the pre-PR hook's reminder text. Co-Authored-By: Claude Fable 5 * docs: add cli-sync architecture diagram; widen diagram convention to the CLI architecture/cli-sync.md draws the CLI and sync engine (cmd/bdrive + internal/{syncer,store,journal,config,daemon,agenthooks}): the Session cycle over Store/journal/remote, and the command layer with the new syncBlocked opt-in gate, paused marker, and enrollment ownership. The pre-PR hook and CLAUDE.md now watch these packages too, so CLI-side structural changes trigger the before/after-excerpt convention the same way server changes do. Co-Authored-By: Claude Fable 5 * docs: full-coverage architecture diagrams — overview, frontend, agentskills Every application package is now drawn somewhere: overview.md (system diagram — package map, device↔hub↔storage flow, agent surfaces, and the private cloud/ repo as an external seam consumer), webapp-frontend.md (the hub SPA's modules: App/HubApp/VolumeApp/Browser, the in-repo nav/router, api layer, hooks, components), and agentskills added to cli-sync.md. The pre-PR hook now watches all of cmd/, internal Go code, and frontend/src (generated static/ excluded); CLAUDE.md and architecture/README.md state the coverage rule: every code change lands in exactly one detail diagram's scope, web/docs and cloud/ deliberately excluded. Co-Authored-By: Claude Fable 5 * docs: PR bodies start with a TL;DR — max 5 informal one-liners Co-Authored-By: Claude Fable 5 --------- Co-authored-by: Claude Fable 5 --- .claude/hooks/check-arch-diagrams.sh | 16 +- CHANGELOG.md | 10 ++ CLAUDE.md | 6 +- README.md | 5 +- architecture/README.md | 26 +++- architecture/cli-sync.md | 164 +++++++++++++++++++++ architecture/overview.md | 54 +++++++ architecture/webapp-frontend.md | 76 ++++++++++ cmd/bdrive/cmds.go | 19 +++ cmd/bdrive/helpers.go | 20 +++ cmd/bdrive/hooksync_test.go | 99 ++++++++++++- cmd/bdrive/readlog.go | 9 +- cmd/bdrive/readlog_test.go | 63 ++++++++ cmd/bdrive/sync_run.go | 15 +- cmd/bdrive/sync_run_test.go | 82 +++++++++++ internal/store/paused.go | 36 +++++ internal/store/paused_test.go | 41 ++++++ plugin/skills/beardrive/SKILL.md | 6 +- web/docs/src/content/docs/reference/cli.md | 4 +- 19 files changed, 725 insertions(+), 26 deletions(-) create mode 100644 architecture/cli-sync.md create mode 100644 architecture/overview.md create mode 100644 architecture/webapp-frontend.md create mode 100644 cmd/bdrive/sync_run_test.go create mode 100644 internal/store/paused.go create mode 100644 internal/store/paused_test.go diff --git a/.claude/hooks/check-arch-diagrams.sh b/.claude/hooks/check-arch-diagrams.sh index cad90e8..593fd62 100755 --- a/.claude/hooks/check-arch-diagrams.sh +++ b/.claude/hooks/check-arch-diagrams.sh @@ -12,17 +12,23 @@ case "$cmd" in *skip-diagram-check*) exit 0 ;; esac base=$(git merge-base origin/main HEAD 2>/dev/null || git merge-base main HEAD 2>/dev/null) || exit 0 -code=$(git diff --name-only "$base" HEAD -- 'internal/webapp/*.go' 'internal/remote/*.go') +# Every application package is drawn in architecture/ (see its README); +# frontend static/ is generated output, excluded via the src-only pathspec. +code=$(git diff --name-only "$base" HEAD -- 'cmd/' 'internal/*.go' \ + 'internal/webapp/frontend/src/') diag=$(git diff --name-only "$base" HEAD -- architecture/) if [ -n "$code" ] && [ -z "$diag" ]; then cat >&2 <` | | `bdrive logout` | Sign this device out — clear the saved token/account (`--forget` also drops the remembered server) | | `bdrive init [folder]` | Create/connect a project and start syncing — interactive on a TTY, flags (`--name/--project/--shared/--yes`) for scripts; re-run to resume | -| `bdrive stop [folder]` | Stop syncing (files stay; `bdrive init` resumes) | +| `bdrive stop [folder]` | Stop syncing, including agent sync hooks (files stay; `bdrive init` resumes) | | `bdrive url [path]` | Internal hub link for a file/folder (sign-in + membership required; `--sync` pushes first; no arg = project home). Computed locally | | `bdrive share ` | Public URL for a synced file (`--list`, `--revoke`, `--expires`) | | `bdrive sync [folder]` | Run one sync cycle now. `--note ` stamps session context (e.g. an agent session id) onto changes — shown in `bdrive log` and hub history; keeps applying to daemon-committed changes until `--note-ttl` (default 30m) expires. `--hook