Skip to content

Commit 9081ab0

Browse files
authored
feat(desktop): make pull request reviews actionable (#2510)
1 parent 9cc9652 commit 9081ab0

32 files changed

Lines changed: 1557 additions & 567 deletions

‎crates/buzz-acp/src/base_prompt.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ The `buzz` CLI is your primary interface. Auth env vars: `BUZZ_RELAY_URL`, `BUZZ
1717
| `buzz feed` | `get` |
1818
| `buzz social` | `publish`, `notes` |
1919
| `buzz repos` | `create`, `get`, `list` |
20+
| `buzz pr` | `open`, `update`, `get`, `list`, `status` |
2021
| `buzz upload` | `file` |
2122

2223
Run `buzz --help` or `buzz <group> --help` for full usage. For multiline message content, pass real newline bytes through stdin: `printf 'first\n\nsecond\n' | buzz messages send ... --content -`. Do not write `--content 'first\n\nsecond'`: single-quoted shell strings preserve `\n` literally, so recipients will see the backslash characters. `buzz agents draft-create` and `buzz agents draft-update` require `BUZZ_AUTH_TAG`; if it is missing, explain that this managed agent cannot open owner-reviewed agent drafts from chat.
2324

25+
When opening a pull request in response to channel work, always pass `--channel <current-channel-uuid>` using the UUID from `[Context]`. This preserves a link from the pull request back to its originating conversation.
26+
2427
## Conversational Agent Creation
2528

2629
When someone asks to create an agent, ask for at most two things: the agent's name and what it should do day-to-day. Turn the user's rough purpose into the `--system-prompt` yourself; do not separately ask for purpose, tone, constraints, access, runtime, provider, or model unless the user's request is genuinely ambiguous.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub async fn cmd_open_pr(
3131
euc: Option<&str>,
3232
labels: &[String],
3333
to: &[String],
34+
channel: Option<&str>,
3435
revision_of: Option<&str>,
3536
) -> Result<(), CliError> {
3637
validate_hex64(repo_owner)?;
@@ -44,6 +45,7 @@ pub async fn cmd_open_pr(
4445
let meta = GitPullRequestMeta {
4546
euc: euc.map(str::to_string),
4647
recipients: to.to_vec(),
48+
channel_id: channel.map(str::to_string),
4749
subject: subject.to_string(),
4850
labels: labels.to_vec(),
4951
commit: commit.to_string(),
@@ -227,6 +229,7 @@ pub async fn dispatch(cmd: crate::PrCmd, client: &BuzzClient) -> Result<(), CliE
227229
euc,
228230
label,
229231
to,
232+
channel,
230233
revision_of,
231234
} => {
232235
cmd_open_pr(
@@ -243,6 +246,7 @@ pub async fn dispatch(cmd: crate::PrCmd, client: &BuzzClient) -> Result<(), CliE
243246
euc.as_deref(),
244247
&label,
245248
&to,
249+
channel.as_deref(),
246250
revision_of.as_deref(),
247251
)
248252
.await

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,9 @@ pub enum PrCmd {
13381338
/// Additional recipient pubkey(s) — can be specified multiple times
13391339
#[arg(long = "to")]
13401340
to: Vec<String>,
1341+
/// Channel where this pull request originated (NIP-29 h-tag)
1342+
#[arg(long)]
1343+
channel: Option<String>,
13411344
/// Root patch event id this PR revises
13421345
#[arg(long)]
13431346
revision_of: Option<String>,

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,8 @@ pub struct GitPullRequestMeta {
13061306
pub euc: Option<String>,
13071307
/// Additional pubkeys to `p`-tag besides the repo owner.
13081308
pub recipients: Vec<String>,
1309+
/// NIP-29 channel where the pull request originated (`h` tag).
1310+
pub channel_id: Option<String>,
13091311
/// PR subject line (`subject` tag) — required, used as the header.
13101312
pub subject: String,
13111313
/// Labels (`t` tags).
@@ -1365,6 +1367,11 @@ pub fn build_git_pull_request(
13651367
tags.push(tag(&["t", label])?);
13661368
}
13671369
tags.push(tag(&["c", &meta.commit])?);
1370+
if let Some(ref channel_id) = meta.channel_id {
1371+
let channel_id = Uuid::parse_str(channel_id)
1372+
.map_err(|e| SdkError::InvalidInput(format!("channel_id must be a valid UUID: {e}")))?;
1373+
tags.push(tag(&["h", &channel_id.to_string()])?);
1374+
}
13681375
let mut clone_tag = vec!["clone"];
13691376
clone_tag.extend(meta.clone_urls.iter().map(String::as_str));
13701377
tags.push(tag(&clone_tag)?);
@@ -3410,6 +3417,7 @@ mod tests {
34103417
clone_urls: vec!["https://example.com/repo.git".to_string()],
34113418
branch_name: Some("feat/x".to_string()),
34123419
labels: vec!["enhancement".to_string()],
3420+
channel_id: Some("11111111-1111-4111-8111-111111111111".to_string()),
34133421
..Default::default()
34143422
};
34153423
let ev = sign(build_git_pull_request(&pr_repo(), "PR body", &meta).unwrap());
@@ -3420,6 +3428,7 @@ mod tests {
34203428
assert!(has_tag(&ev, "subject", "Add feature X"));
34213429
assert!(has_tag(&ev, "c", &"c".repeat(40)));
34223430
assert!(has_tag(&ev, "t", "enhancement"));
3431+
assert!(has_tag(&ev, "h", "11111111-1111-4111-8111-111111111111"));
34233432
assert!(has_tag(&ev, "branch-name", "feat/x"));
34243433
assert_eq!(
34253434
full_clone_tag(&ev),
@@ -3478,6 +3487,34 @@ mod tests {
34783487
assert!(matches!(err, SdkError::InvalidInput(_)));
34793488
}
34803489

3490+
#[test]
3491+
fn git_pr_rejects_invalid_channel_id() {
3492+
for channel_id in ["not-a-uuid", " 11111111-1111-4111-8111-111111111111 "] {
3493+
let meta = GitPullRequestMeta {
3494+
subject: "s".to_string(),
3495+
commit: "c".repeat(40),
3496+
clone_urls: vec!["https://example.com/repo.git".to_string()],
3497+
channel_id: Some(channel_id.to_string()),
3498+
..Default::default()
3499+
};
3500+
let err = build_git_pull_request(&pr_repo(), "body", &meta).unwrap_err();
3501+
assert!(matches!(err, SdkError::InvalidInput(_)));
3502+
}
3503+
}
3504+
3505+
#[test]
3506+
fn git_pr_canonicalizes_channel_id() {
3507+
let meta = GitPullRequestMeta {
3508+
subject: "s".to_string(),
3509+
commit: "c".repeat(40),
3510+
clone_urls: vec!["https://example.com/repo.git".to_string()],
3511+
channel_id: Some("AAAAAAAA-BBBB-4CCC-8DDD-EEEEEEEEEEEE".to_string()),
3512+
..Default::default()
3513+
};
3514+
let ev = sign(build_git_pull_request(&pr_repo(), "body", &meta).unwrap());
3515+
assert!(has_tag(&ev, "h", "aaaaaaaa-bbbb-4ccc-8ddd-eeeeeeeeeeee"));
3516+
}
3517+
34813518
#[test]
34823519
fn git_pr_revision_of_emits_e_tag() {
34833520
let patch = event_id().to_hex();

‎desktop/src-tauri/src/commands/project_git_workflow.rs‎

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ pub struct ProjectPullRequestReviewRequestInput {
126126
reviewer_label: String,
127127
}
128128

129+
/// Repository-scoped metadata for an agent-signed lifecycle status.
130+
#[derive(Deserialize)]
131+
#[serde(rename_all = "camelCase")]
132+
pub struct ProjectPullRequestStatusInput {
133+
target_owner: String,
134+
repo_address: String,
135+
pull_request_id: String,
136+
pull_request_author: String,
137+
status: String,
138+
created_at: u64,
139+
}
140+
129141
/// A previously signed merged-status event that needs publishing again.
130142
#[derive(Deserialize)]
131143
#[serde(rename_all = "camelCase")]
@@ -249,6 +261,44 @@ fn build_merged_status_event(
249261
.map_err(|error| format!("sign merged pull request status: {error}"))
250262
}
251263

264+
fn build_pull_request_status_event(
265+
keys: &Keys,
266+
repo_address: &str,
267+
pull_request_id: &str,
268+
pull_request_author: &str,
269+
status: &str,
270+
created_at: u64,
271+
) -> Result<String, String> {
272+
let owner = keys.public_key().to_hex();
273+
let (pull_request_id, pull_request_author) =
274+
validate_merge_status_metadata(repo_address, &owner, pull_request_id, pull_request_author)?;
275+
let kind = match status {
276+
"open" => Kind::Custom(1630),
277+
"closed" => Kind::Custom(1632),
278+
"draft" => Kind::Custom(1633),
279+
_ => return Err("Invalid pull request lifecycle status.".to_string()),
280+
};
281+
let mut raw_tags = vec![
282+
vec!["e", pull_request_id.as_str(), "", "root"],
283+
vec!["a", repo_address],
284+
vec!["p", owner.as_str()],
285+
];
286+
if pull_request_author != owner {
287+
raw_tags.push(vec!["p", pull_request_author.as_str()]);
288+
}
289+
let tags = raw_tags
290+
.into_iter()
291+
.map(Tag::parse)
292+
.collect::<Result<Vec<_>, _>>()
293+
.map_err(|error| format!("build pull request status tags: {error}"))?;
294+
EventBuilder::new(kind, "")
295+
.tags(tags)
296+
.custom_created_at(Timestamp::from(created_at.max(Timestamp::now().as_secs())))
297+
.sign_with_keys(keys)
298+
.map(|event| event.as_json())
299+
.map_err(|error| format!("sign pull request status: {error}"))
300+
}
301+
252302
fn build_review_request_event(
253303
keys: &Keys,
254304
repo_address: &str,
@@ -433,6 +483,31 @@ pub async fn clone_project_repository(
433483
.map_err(|error| format!("repo clone task failed: {error}"))?
434484
}
435485

486+
#[tauri::command]
487+
pub async fn sign_project_pull_request_status(
488+
input: ProjectPullRequestStatusInput,
489+
app: AppHandle,
490+
state: State<'_, AppState>,
491+
) -> Result<(), String> {
492+
let target_owner = input.target_owner.trim().to_ascii_lowercase();
493+
if normalize_event_id(&target_owner).is_none() {
494+
return Err("Invalid target repository owner.".to_string());
495+
}
496+
let identity = project_owner_identity(&app, &state, &target_owner)?;
497+
let event = Event::from_json(build_pull_request_status_event(
498+
&identity.keys,
499+
&input.repo_address,
500+
&input.pull_request_id,
501+
&input.pull_request_author,
502+
&input.status,
503+
input.created_at,
504+
)?)
505+
.map_err(|error| format!("parse signed pull request status: {error}"))?;
506+
submit_signed_event_with_keys(&event, &state, &identity.keys, identity.auth_tag.as_deref())
507+
.await?;
508+
Ok(())
509+
}
510+
436511
#[tauri::command]
437512
pub async fn sign_project_pull_request_review_request(
438513
input: ProjectPullRequestReviewRequestInput,
@@ -663,9 +738,9 @@ pub async fn merge_project_pull_request(
663738
#[cfg(test)]
664739
mod tests {
665740
use super::{
666-
align_unborn_head_branch, build_merged_status_event, build_review_request_event,
667-
classify_merge_error, normalize_commit, same_repository, validate_merge_status_metadata,
668-
ProjectPullRequestMergeError,
741+
align_unborn_head_branch, build_merged_status_event, build_pull_request_status_event,
742+
build_review_request_event, classify_merge_error, normalize_commit, same_repository,
743+
validate_merge_status_metadata, ProjectPullRequestMergeError,
669744
};
670745
use crate::commands::project_git_exec::{build_test_git_auth_config, run_git};
671746
use nostr::{Event, JsonUtil, Keys, Timestamp};
@@ -834,6 +909,49 @@ mod tests {
834909
.is_err());
835910
}
836911

912+
#[test]
913+
fn lifecycle_status_is_signed_by_repository_owner() {
914+
let keys = Keys::generate();
915+
let owner = keys.public_key().to_hex();
916+
let author = "b".repeat(64);
917+
let event = Event::from_json(
918+
build_pull_request_status_event(
919+
&keys,
920+
&format!("30617:{owner}:buzz"),
921+
&"d".repeat(64),
922+
&author,
923+
"closed",
924+
Timestamp::now().as_secs(),
925+
)
926+
.unwrap(),
927+
)
928+
.unwrap();
929+
930+
assert_eq!(event.pubkey, keys.public_key());
931+
assert_eq!(event.kind.as_u16(), 1632);
932+
assert!(event
933+
.tags
934+
.iter()
935+
.any(|tag| tag.as_slice() == ["p", author.as_str()]));
936+
assert!(event.verify().is_ok());
937+
}
938+
939+
#[test]
940+
fn lifecycle_status_rejects_merged_alias() {
941+
let keys = Keys::generate();
942+
let owner = keys.public_key().to_hex();
943+
944+
assert!(build_pull_request_status_event(
945+
&keys,
946+
&format!("30617:{owner}:buzz"),
947+
&"d".repeat(64),
948+
&"b".repeat(64),
949+
"merged",
950+
Timestamp::now().as_secs(),
951+
)
952+
.is_err());
953+
}
954+
837955
#[test]
838956
fn review_request_is_signed_by_repository_owner() {
839957
let keys = Keys::generate();

‎desktop/src-tauri/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ pub fn run() {
683683
delete_project_remote_branch,
684684
push_project_local_repository,
685685
pull_project_local_repository,
686+
sign_project_pull_request_status,
686687
sign_project_pull_request_review_request,
687688
publish_project_pull_request_merged_status,
688689
merge_project_pull_request,

0 commit comments

Comments
 (0)