Skip to content

Commit 47d068e

Browse files
wpfleger96Duncan
andauthored
feat(cli): add buzz gifs command group and NIP-30 emoji tags on messages (#7259)
## What Two new agent-facing capabilities in `buzz-cli`: ### 1. `buzz gifs` command group (agent KLIPY picker path) Agents can now search and share GIFs via the relay's authenticated KLIPY proxy without holding a provider credential. ```bash buzz gifs search # trending GIFs buzz gifs search --query "celebration" # search GIFs buzz gifs share --slug <slug> # report selection to provider Recents ``` Output is a JSON array of GIF objects. Paste the `cdn_url` field directly into `buzz messages send --content` — sending a GIF is a plain message containing the CDN URL, no special send-path handling. **Implementation details:** - Gates on NIP-11 `supported_extensions` containing `buzz-gif` and `gif.provider == "klipy"` - Uses relay-relative paths from the NIP-11 `gif` descriptor — no hardcoded paths; safe-path validation mirrors `desktop/src/features/gifs/api.ts` - New `post_json_authed` helper in `BuzzClient` handles NIP-98-signed JSON POSTs and 204 No Content responses - `customer_id` derived as `SHA-256(secret_key_bytes || '\0' || relay_url_bytes)[..16]` → 32 hex chars: stable, relay-scoped, not computable from public data, no storage needed - `locale` defaults to `$LANG` (stripped of encoding suffix) or `en_US` ### 2. NIP-30 custom emoji tags on outgoing messages `buzz messages send` now automatically attaches `["emoji", shortcode, url]` tags for any `:shortcode:` patterns in the content that resolve in the workspace palette — identical to the desktop composer behavior. ```bash buzz messages send --channel <uuid> --content "hello :wave: everyone :tada:" # → event carries ["emoji", "wave", "..."] and ["emoji", "tada", "..."] tags ``` **Implementation details:** - Hand-rolled single-pass scanner (no new dependency) implementing `:([a-z0-9_-]+):` case-insensitively with canonical lowercase output — mirrors `desktop/src/shared/lib/customEmojiTags.ts` exactly - Zero extra relay round-trips when content contains no `:` character; one `query` when candidates exist but none match - Palette fetch reuses the existing `union_custom_emoji` logic from `commands/emoji.rs` - `build_message` in `buzz-sdk` gains a new `emoji_tags: &[Vec<String>]` parameter (additive — all existing callers pass `&[]`); NIP-30 tag attachment lives in the SDK alongside `imeta` tags - MCP send path (`buzz-acp`) continues to pass `&[]` and is not affected; the MCP gap is noted in a comment ## Files changed | Crate | File | Change | |-------|------|--------| | `buzz-cli` | `src/commands/gifs.rs` | New — search + share handlers, NIP-11 gating, tests | | `buzz-cli` | `src/commands/mod.rs` | `pub mod gifs` | | `buzz-cli` | `src/lib.rs` | `Gifs(GifsCmd)` variant, dispatch arm, inventory test update | | `buzz-cli` | `src/client.rs` | `post_json_authed` helper | | `buzz-cli` | `src/commands/emoji.rs` | `scan_shortcodes` + `resolve_emoji_tags_for_content` + tests | | `buzz-cli` | `src/commands/messages.rs` | Emoji scan + tag injection in `cmd_send_message` + seam tests | | `buzz-cli` | `README.md` | `buzz gifs` section + emoji-in-messages note | | `buzz-sdk` | `src/builders.rs` | `build_message` gains `emoji_tags` param + tests | | `buzz-acp` | `src/pool.rs` | Update `build_message` call site (`&[]`) | | `buzz-acp` | `src/setup_mode.rs` | Update `build_message` call site (`&[]`) | | `countdown-bot` | `src/main.rs` | Update `build_message` call site (`&[]`) | Relates to: https://buzz.block.builderlab.xyz — buzz-team channel thread on agent GIF/emoji support --------- Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
1 parent ac5a186 commit 47d068e

11 files changed

Lines changed: 2007 additions & 36 deletions

File tree

‎crates/buzz-acp/src/pool.rs‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4989,14 +4989,21 @@ pub(crate) async fn post_failure_notice(
49894989
parent_event_id: parent_id,
49904990
})
49914991
});
4992-
let builder =
4993-
match buzz_sdk::build_message(channel_id, content, thread_ref.as_ref(), &[], false, &[]) {
4994-
Ok(b) => b,
4995-
Err(e) => {
4996-
tracing::warn!(channel = %channel_id, "failure notice: build failed: {e}");
4997-
return;
4998-
}
4999-
};
4992+
let builder = match buzz_sdk::build_message(
4993+
channel_id,
4994+
content,
4995+
thread_ref.as_ref(),
4996+
&[],
4997+
false,
4998+
&[],
4999+
&[],
5000+
) {
5001+
Ok(b) => b,
5002+
Err(e) => {
5003+
tracing::warn!(channel = %channel_id, "failure notice: build failed: {e}");
5004+
return;
5005+
}
5006+
};
50005007
let event = match builder.sign_with_keys(&rest.keys) {
50015008
Ok(e) => e,
50025009
Err(e) => {

‎crates/buzz-acp/src/setup_mode.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ async fn publish_setup_nudge(
669669
&[recipient_hex], // p-tag the verified effective asker
670670
false,
671671
&[],
672+
&[],
672673
)
673674
.map_err(|e| anyhow::anyhow!("failed to build setup nudge: {e}"))?;
674675

‎crates/buzz-cli/README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ buzz channels topic --channel <uuid> --topic "New topic"
5353
buzz reactions add --event <event-id> --emoji "👍"
5454
buzz reactions get --event <event-id>
5555

56+
# GIFs (requires relay to advertise buzz-gif / KLIPY)
57+
buzz gifs search # trending GIFs
58+
buzz gifs search --query "celebration" # search GIFs
59+
buzz gifs share --slug <slug> # report selection to provider Recents
60+
# Paste the `cdn_url` from a search result directly into messages send --content
61+
62+
# Custom emoji in messages
63+
# buzz messages send scans outgoing content for :shortcode: patterns and
64+
# automatically attaches NIP-30 ["emoji", shortcode, url] tags from the
65+
# workspace palette — identical to the desktop composer behavior.
66+
5667
# Users & Presence
5768
buzz users get # your own profile
5869
buzz users get --pubkey <hex> # single user
@@ -130,6 +141,8 @@ stored rules in `validation_error` so an owner can remove and repair them.
130141
| `reactions` | `add` | React to a message |
131142
| | `remove` | Remove a reaction |
132143
| | `get` | List reactions |
144+
| `gifs` | `search` | Search or browse trending GIFs (requires relay buzz-gif support) |
145+
| | `share` | Report a selected GIF to the provider's Recents |
133146
| `dms` | `list` | List DM conversations |
134147
| | `open` | Open a DM (1–8 pubkeys) |
135148
| | `add-member` | Add member to DM group |

‎crates/buzz-cli/src/client.rs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,47 @@ impl BuzzClient {
870870
.await
871871
}
872872

873+
/// POST a JSON body to a relay-relative path with NIP-98 authentication.
874+
///
875+
/// Used by `buzz gifs search` and `buzz gifs share` to reach the relay's
876+
/// KLIPY proxy endpoints. Returns the raw response body as a string (may
877+
/// be empty for 204 No Content responses).
878+
pub async fn post_json_authed(
879+
&self,
880+
path: &str,
881+
body: &serde_json::Value,
882+
) -> Result<String, CliError> {
883+
let url = format!("{}{path}", self.relay_url);
884+
let body_bytes = bytes::Bytes::from(
885+
serde_json::to_vec(body)
886+
.map_err(|e| CliError::Other(format!("request serialization failed: {e}")))?,
887+
);
888+
self.with_retry_body(|| {
889+
let body_bytes = body_bytes.clone();
890+
let url = url.clone();
891+
async move {
892+
let auth = sign_nip98(&self.keys, "POST", &url, Some(&body_bytes))?;
893+
let resp = self
894+
.with_auth_tag(
895+
self.http
896+
.post(&url)
897+
.header("Authorization", auth)
898+
.header("Content-Type", "application/json")
899+
.body(body_bytes),
900+
)
901+
.send()
902+
.await?;
903+
// 204 No Content: return empty string rather than failing on
904+
// an empty body that cannot be parsed as JSON.
905+
if resp.status() == reqwest::StatusCode::NO_CONTENT {
906+
return Ok(String::new());
907+
}
908+
self.handle_response(resp).await
909+
}
910+
})
911+
.await
912+
}
913+
873914
/// Submit a signed Nostr event via POST /events.
874915
///
875916
/// For non-idempotent moderation command kinds (9040–9044), an ambiguous

0 commit comments

Comments
 (0)