Skip to content

Commit eeb16ab

Browse files
kaganinwpfleger96
andauthored
feat(cli): add users set-status command for NIP-38 profile status (#3253)
## Summary The desktop client renders a persistent user status (NIP-38 kind:30315, `d:general`) as the status line on profiles, but the CLI had no way to set it — only ephemeral presence (`set-presence`, kind:20001). Integrations that want a scriptable, durable status line (for example a now-playing music bridge that shows the current TIDAL track on a profile) had no entry point. ## Screenshots <img width="1455" height="960" alt="1" src="https://github.com/user-attachments/assets/f1669ec6-212b-4f6e-ad53-07df9aacffc9" /> <img width="1455" height="960" alt="2" src="https://github.com/user-attachments/assets/5bf70f47-e5b5-4eb0-a426-b5f1ef90d2ec" /> This adds: ```bash buzz users set-status --text "Working on the relay" --emoji "🔧" buzz users set-status --text "" --emoji "🎶" # intentional emoji-only status buzz users set-status --clear # removes the status ``` - Signs and submits the replaceable kind:30315 event via the HTTP bridge (no WS needed — unlike presence, user status is a stored event). - Uses the `d:general` coordinate the desktop client already reads for the profile status line, and the same `emoji` tag shape `SetStatusDialog` publishes. - Event construction lives in `buzz_sdk::build_user_status()`, keyed off `buzz_core::kind::KIND_USER_STATUS`, so the CLI command is a thin sign/submit wrapper. Text and emoji are trimmed; a blank emoji is omitted rather than emitted as an empty tag. - Clearing is the explicit `--clear` flag, mutually exclusive with `--text`/`--emoji`. It publishes an empty-content event carrying only `d:general`, which the desktop treats as no status. `--text ""` with an `--emoji` is an emoji-only status, not a clear. --------- Signed-off-by: Kagan Yaldizkaya <[email protected]> Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Will Pfleger <[email protected]>
1 parent 9e4a731 commit eeb16ab

5 files changed

Lines changed: 155 additions & 5 deletions

File tree

‎crates/buzz-cli/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ buzz users get # your own profile
5757
buzz users get --pubkey <hex> # single user
5858
buzz users get --pubkey <hex> --pubkey <hex> # batch (max 200)
5959
buzz users set-presence --status online
60+
buzz users set-status --text "heads down on the CLI" --emoji "🚀"
61+
buzz users set-status --clear # remove your status
6062

6163
# DMs
6264
buzz dms open --pubkey <hex>
@@ -133,6 +135,7 @@ stored rules in `validation_error` so an owner can remove and repair them.
133135
| | `set-profile` | Update your profile |
134136
| | `presence` | Get presence status |
135137
| | `set-presence` | Set presence status |
138+
| | `set-status` | Set or clear your NIP-38 profile status |
136139
| `workflows` | `list` | List workflows |
137140
| | `get` | Get workflow definition |
138141
| | `create` | Create a workflow |

‎crates/buzz-cli/TESTING.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export BUZZ_PRIVATE_KEY="nsec1..." # from the mint output
8787
| `channels:read` | ✅ | `channels list`, `channels get`, `channels members` |
8888
| `channels:write` | ✅ | `channels create`, `channels update`, `channels join`, `channels leave`, `channels topic`, `channels purpose` |
8989
| `users:read` | ✅ | `users get`, `users presence` |
90-
| `users:write` | ✅ | `users set-profile`, `users set-presence` |
90+
| `users:write` | ✅ | `users set-profile`, `users set-presence`, `users set-status` |
9191
| `files:read` | ✅ | — |
9292
| `files:write` | ✅ | — |
9393
| `admin:channels` | ❌ | `channels archive`, `channels unarchive`, `channels delete`, `channels add-member`, `channels remove-member` |
@@ -331,6 +331,20 @@ buzz users set-presence --status online | jq .
331331
buzz users set-presence --status away | jq .
332332
buzz users set-presence --status offline | jq .
333333
# Note: set-presence may fail — kind:20001 is ephemeral and rejected by the HTTP bridge
334+
335+
# users set-status — NIP-38 kind:30315 on the d:general coordinate
336+
buzz users set-status --text "reviewing PRs" --emoji "🔍" | jq .
337+
buzz users set-status --text "no emoji this time" | jq .
338+
339+
# users set-status — emoji-only status (intentional: text is blank, emoji is kept)
340+
buzz users set-status --text "" --emoji "🎶" | jq .
341+
342+
# users set-status --clear — removes the status (empty content, d:general only)
343+
buzz users set-status --clear | jq .
344+
345+
# --clear is mutually exclusive with --text/--emoji
346+
buzz users set-status --clear --text "nope" 2>&1; echo "exit: $?"
347+
# Expected: exit 1 — clap conflict error
334348
```
335349

336350
### 6.8 Channel Members (add/remove require admin:channels)
@@ -606,3 +620,4 @@ buzz channels delete --channel "$FORUM_ID" | jq .
606620
| 59 | `notes get` | ☐ | By name, by naddr, --content-only, cross-author, ambiguous → exit 1 |
607621
| 60 | `notes ls` | ☐ | Own, --author all, --tag, --limit |
608622
| 61 | `notes rm` | ☐ | Delete→get 404, double-delete idempotent, missing slug → NotFound |
623+
| 62 | `users set-status` | ☐ | Text+emoji, text only, emoji-only (`--text ""`), `--clear`, `--clear` + `--text` → exit 1 |

‎crates/buzz-cli/src/commands/users.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,22 @@ pub async fn cmd_set_presence(client: &BuzzClient, status: &str) -> Result<(), C
304304
Ok(())
305305
}
306306

307+
/// Set user status — sign and submit a NIP-38 kind:30315 user status event.
308+
///
309+
/// Uses the `d:general` coordinate that the desktop client reads for the
310+
/// profile status line. A blank `text` with no `emoji` clears the status.
311+
pub async fn cmd_set_status(
312+
client: &BuzzClient,
313+
text: &str,
314+
emoji: Option<&str>,
315+
) -> Result<(), CliError> {
316+
let builder = buzz_sdk::build_user_status(text, emoji).map_err(crate::validate::sdk_err)?;
317+
let event = client.sign_event(builder)?;
318+
let resp = client.submit_event(event).await?;
319+
println!("{}", normalize_write_response(&resp));
320+
Ok(())
321+
}
322+
307323
pub async fn dispatch(
308324
cmd: crate::UsersCmd,
309325
client: &BuzzClient,
@@ -331,6 +347,16 @@ pub async fn dispatch(
331347
}
332348
UsersCmd::Presence { pubkeys } => cmd_get_presence(client, &pubkeys).await,
333349
UsersCmd::SetPresence { status } => cmd_set_presence(client, &status.to_string()).await,
350+
UsersCmd::SetStatus { text, emoji, clear } => {
351+
// `--clear` is mutually exclusive with `--text`/`--emoji`: publish the
352+
// empty `d:general` event that clients read as "no status".
353+
let (text, emoji) = if clear {
354+
("", None)
355+
} else {
356+
(text.as_deref().unwrap_or_default(), emoji.as_deref())
357+
};
358+
cmd_set_status(client, text, emoji).await
359+
}
334360
}
335361
}
336362

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,19 @@ pub enum UsersCmd {
838838
#[arg(long, value_enum)]
839839
status: PresenceStatus,
840840
},
841+
/// Set your user status (NIP-38 kind:30315 — the "status" line on your profile)
842+
#[command(name = "set-status")]
843+
SetStatus {
844+
/// Status text (required unless --clear)
845+
#[arg(long, required_unless_present = "clear")]
846+
text: Option<String>,
847+
/// Optional emoji shown before the status text
848+
#[arg(long)]
849+
emoji: Option<String>,
850+
/// Remove your status entirely
851+
#[arg(long, conflicts_with_all = ["text", "emoji"])]
852+
clear: bool,
853+
},
841854
}
842855

843856
#[derive(Subcommand)]
@@ -1803,6 +1816,30 @@ mod tests {
18031816
Cli::command().debug_assert();
18041817
}
18051818

1819+
#[test]
1820+
fn set_status_clear_rejects_text_and_emoji() {
1821+
for extra in [["--text", "busy"], ["--emoji", "🎶"]] {
1822+
let args = ["buzz", "users", "set-status", "--clear"]
1823+
.into_iter()
1824+
.chain(extra);
1825+
assert!(
1826+
Cli::try_parse_from(args).is_err(),
1827+
"--clear must conflict with {}",
1828+
extra[0]
1829+
);
1830+
}
1831+
}
1832+
1833+
#[test]
1834+
fn set_status_requires_text_or_clear() {
1835+
assert!(Cli::try_parse_from(["buzz", "users", "set-status"]).is_err());
1836+
assert!(
1837+
Cli::try_parse_from(["buzz", "users", "set-status", "--emoji", "🎶"]).is_err(),
1838+
"--emoji alone must not imply a status"
1839+
);
1840+
assert!(Cli::try_parse_from(["buzz", "users", "set-status", "--clear"]).is_ok());
1841+
}
1842+
18061843
#[test]
18071844
fn command_inventory_is_stable() {
18081845
let expected_groups: Vec<&str> = vec![
@@ -1924,7 +1961,13 @@ mod tests {
19241961
);
19251962
assert_eq!(
19261963
names(&cmd, "users"),
1927-
vec!["get", "presence", "set-presence", "set-profile"]
1964+
vec![
1965+
"get",
1966+
"presence",
1967+
"set-presence",
1968+
"set-profile",
1969+
"set-status"
1970+
]
19281971
);
19291972
assert_eq!(
19301973
names(&cmd, "workflows"),
@@ -2011,7 +2054,7 @@ mod tests {
20112054
("repos", 4),
20122055
("social", 7),
20132056
("upload", 1),
2014-
("users", 4),
2057+
("users", 5),
20152058
("workflows", 8),
20162059
];
20172060

‎crates/buzz-sdk/src/builders.rs‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use buzz_core::{
1111
KIND_GIT_STATUS_CLOSED, KIND_GIT_STATUS_DRAFT, KIND_GIT_STATUS_MERGED,
1212
KIND_GIT_STATUS_OPEN, KIND_IA_ARCHIVE_REQUEST, KIND_IA_UNARCHIVE_REQUEST,
1313
KIND_MODERATION_BAN, KIND_MODERATION_RESOLVE_REPORT, KIND_MODERATION_TIMEOUT,
14-
KIND_MODERATION_UNBAN, KIND_MODERATION_UNTIMEOUT, KIND_PRESENCE_UPDATE, KIND_WORKFLOW_DEF,
15-
KIND_WORKFLOW_TRIGGER,
14+
KIND_MODERATION_UNBAN, KIND_MODERATION_UNTIMEOUT, KIND_PRESENCE_UPDATE, KIND_USER_STATUS,
15+
KIND_WORKFLOW_DEF, KIND_WORKFLOW_TRIGGER,
1616
},
1717
observer::{
1818
content_looks_like_nip44, OBSERVER_AGENT_TAG, OBSERVER_FRAME_CONTROL, OBSERVER_FRAME_TAG,
@@ -1580,6 +1580,22 @@ pub fn build_presence_update(status: &str) -> Result<EventBuilder, SdkError> {
15801580
Ok(EventBuilder::new(Kind::Custom(KIND_PRESENCE_UPDATE as u16), status).tags(tags))
15811581
}
15821582

1583+
/// Build a NIP-38 user status event (kind 30315) on the `d:general` coordinate.
1584+
///
1585+
/// `text` becomes the event content and `emoji`, when non-blank, an
1586+
/// `["emoji", ...]` tag; both are trimmed. Blank text with no emoji clears the
1587+
/// status — kind 30315 is parameterized-replaceable, so an event carrying
1588+
/// neither is what clients read as "no status".
1589+
pub fn build_user_status(text: &str, emoji: Option<&str>) -> Result<EventBuilder, SdkError> {
1590+
let text = text.trim();
1591+
check_content(text, 64 * 1024)?;
1592+
let mut tags = vec![tag(&["d", "general"])?];
1593+
if let Some(emoji) = emoji.map(str::trim).filter(|e| !e.is_empty()) {
1594+
tags.push(tag(&["emoji", emoji])?);
1595+
}
1596+
Ok(EventBuilder::new(Kind::Custom(KIND_USER_STATUS as u16), text).tags(tags))
1597+
}
1598+
15831599
// ---------------------------------------------------------------------------
15841600
// Community moderation commands (kinds 9040–9044).
15851601
//
@@ -3391,6 +3407,53 @@ mod tests {
33913407
assert!(matches!(err, SdkError::InvalidInput(_)));
33923408
}
33933409

3410+
// ── build_user_status ─────────────────────────────────────────────────────
3411+
3412+
#[test]
3413+
fn user_status_carries_text_and_emoji_on_d_general() {
3414+
let ev = sign(build_user_status("shipping the CLI", Some("🚀")).unwrap());
3415+
assert_eq!(ev.kind.as_u16(), 30315);
3416+
assert_eq!(ev.content, "shipping the CLI");
3417+
assert_eq!(tag_values(&ev, "d"), vec!["general"]);
3418+
assert_eq!(tag_values(&ev, "emoji"), vec!["🚀"]);
3419+
}
3420+
3421+
#[test]
3422+
fn user_status_trims_text_and_emoji() {
3423+
let ev = sign(build_user_status(" heads down ", Some(" 🎧 ")).unwrap());
3424+
assert_eq!(ev.content, "heads down");
3425+
assert_eq!(tag_values(&ev, "emoji"), vec!["🎧"]);
3426+
}
3427+
3428+
#[test]
3429+
fn user_status_omits_blank_emoji_tag() {
3430+
let ev = sign(build_user_status("on call", Some(" ")).unwrap());
3431+
assert_eq!(ev.content, "on call");
3432+
assert!(tag_values(&ev, "emoji").is_empty());
3433+
}
3434+
3435+
#[test]
3436+
fn user_status_keeps_emoji_when_text_is_blank() {
3437+
let ev = sign(build_user_status("", Some("🎶")).unwrap());
3438+
assert_eq!(ev.content, "");
3439+
assert_eq!(tag_values(&ev, "emoji"), vec!["🎶"]);
3440+
}
3441+
3442+
#[test]
3443+
fn user_status_clear_shape_is_empty_content_and_d_tag_only() {
3444+
let ev = sign(build_user_status("", None).unwrap());
3445+
assert_eq!(ev.kind.as_u16(), 30315);
3446+
assert_eq!(ev.content, "");
3447+
assert_eq!(tag_values(&ev, "d"), vec!["general"]);
3448+
assert_eq!(ev.tags.len(), 1);
3449+
}
3450+
3451+
#[test]
3452+
fn user_status_rejects_oversize_text() {
3453+
let err = build_user_status(&"x".repeat(64 * 1024 + 1), None).unwrap_err();
3454+
assert!(matches!(err, SdkError::ContentTooLarge { .. }));
3455+
}
3456+
33943457
// ── build_git_pull_request / build_git_pr_update ──────────────────────────
33953458

33963459
fn pr_repo() -> GitRepoCoord {

0 commit comments

Comments
 (0)