fix(cli): preserve attachments on buzz messages edit (#3022)
Problem
buzz messages edit silently deletes a message's attachments. build_edit (crates/buzz-sdk/src/builders.rs) emits only h + e tags — never imeta. The desktop render/cache overlay (desktop/src/features/messages/lib/applyEditTagOverlay.mjs) treats an edit carrying zero imeta tags as "the attachment set is now empty" — this is intentional (it's how deliberate attachment removal works), and is pinned by a test. Because the CLI never carried imeta forward, an agent fixing a typo in its own message deletes the screenshot it attached. buzz exits 0, nothing warns, and there's no flag to restore them.
Desktop was fixed for its own builder in #755; the CLI was never brought along. Closes #3022.
Fix
Fixed at the builder + CLI, not the overlay (the overlay's replace-on-imeta semantics is correct and load-bearing for desktop removal).
build_editgains amedia_tags: &[Vec<String>]parameter and emitsimetavia the sameimeta_tags()helperbuild_messagealready uses (same validation path).buzz messages editgains--fileand--no-media:- (neither flag — default) carry-forward: fetch the target event and preserve its existing
imetatags, so today's invocations stop losing attachments. --file <path>(repeatable): upload and replace attachments — identical upload path tobuzz messages send(this is why the flag is--file, matchingsend, not--media).--no-media: clear all attachments (explicit). Mutually exclusive with--file(enforced by clap).
- (neither flag — default) carry-forward: fetch the target event and preserve its existing
The single relay fetch already performed to resolve the channel id is reused to read the carry-forward imeta — no extra round-trip. A failed/absent fetch aborts before signing, so an attachment-wiping edit can never be published on error.
Tests
buzz-sdk:edit_with_media(imeta emitted),edit_without_media_has_no_imeta(clear contract),edit_rejects_malformed_media_tag.buzz-cli:extract_imeta_tags_returns_only_imeta/_empty_when_none/_handles_missing_tags(onlyimetacarried, full vectors preserved), and a clap test that--file+--no-mediais rejected.
cargo test -p buzz-sdk # 238 passed
cargo test -p buzz-cli # 254 passed
cargo fmt --all -- --check # clean
cargo clippy -p buzz-sdk -p buzz-cli -- -D warnings # clean
Known follow-ups (non-blocking)
- No automated end-to-end test for the full fetch→extract→build path — the unit tests cover the pieces; the full flow is covered by the manual runbook in
crates/buzz-cli/TESTING.md(no mocked-relay harness exists for CLI command handlers). Verified manually. - Inline
markdown in the old body is not carried forward —--contentreplaces the body wholesale. Theimetaattachment (what desktop renders) is preserved; only inline markdown in a plaintext client would be affected. Left as-is to keep the change surgical.
Rebased onto latest main (f53bbd115).
- Conflict was only in
crates/buzz-cli/src/lib.rs(new projects clap tests on main vs our edit-flag clap test) — kept both. - Local verification on rebased tip:
cargo test -p buzz-sdk(257 passed) andcargo test -p buzz-cli(325 passed). - Branch is now up to date / should be mergeable pending review.
vs #3062: same issue (#3022). This PR stays the surgical path — fix at build_edit + CLI carry-forward default, with explicit --file (replace) and --no-media (clear). Happy to close as duplicate if maintainers prefer #3062's approach once one lands.
Re-requesting review from @block/buzz-oss-team.