-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(acp): wake agents for mentions added by edits #4741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7ad7d79
914418d
fa5a74e
e72d70b
a0d4991
531a206
5e005f6
ced3224
d29968c
80d9ec6
f471814
122acdd
63bbdf6
70ccecd
2620958
35edff0
80b8ddb
75ef80b
782899e
acd0a06
9811b89
2e470fd
663bfd9
ab8411f
5c7f5ac
bfa6469
5e03c2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ | |
| use std::collections::{HashMap, HashSet}; | ||
| use std::path::PathBuf; | ||
|
|
||
| use buzz_core::kind::{ | ||
| KIND_STREAM_MESSAGE, KIND_STREAM_MESSAGE_EDIT, KIND_STREAM_REMINDER, | ||
| KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| }; | ||
| use clap::Parser; | ||
| use clap::ValueEnum; | ||
| use nostr::Keys; | ||
|
|
@@ -1249,16 +1253,26 @@ pub fn load_rules(path: &std::path::Path) -> Result<Vec<SubscriptionRule>, Confi | |
| Ok(config.rules) | ||
| } | ||
|
|
||
| /// Event kinds that carry actionable direct mentions by default. | ||
| /// | ||
| /// Message edits are included because Desktop emits `p` tags only for | ||
| /// recipients newly added by an edit. Receiving kind 40003 therefore wakes an | ||
| /// agent once for a newly added mention without re-waking it for ordinary edits. | ||
| pub(crate) fn default_mention_kinds() -> Vec<u32> { | ||
| vec![ | ||
| KIND_STREAM_MESSAGE, | ||
| KIND_STREAM_MESSAGE_EDIT, | ||
|
loganj marked this conversation as resolved.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When this newly subscribed edit targets a threaded reply and starts a normal turn, Useful? React with 👍 / 👎. |
||
| KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| KIND_STREAM_REMINDER, | ||
| ] | ||
| } | ||
|
|
||
| /// Resolve per-channel NIP-01 filters from config + discovered channels. | ||
| pub fn resolve_channel_filters( | ||
| config: &Config, | ||
| discovered_channels: &[Uuid], | ||
| rules: &[SubscriptionRule], | ||
| ) -> HashMap<Uuid, ChannelFilter> { | ||
| use buzz_core::kind::{ | ||
| KIND_STREAM_MESSAGE, KIND_STREAM_REMINDER, KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| }; | ||
|
|
||
| let target_channels: Vec<Uuid> = if let Some(ref overrides) = config.channels_override { | ||
| overrides | ||
| .iter() | ||
|
|
@@ -1273,13 +1287,10 @@ pub fn resolve_channel_filters( | |
|
|
||
| match config.subscribe_mode { | ||
| SubscribeMode::Mentions => { | ||
| let kinds = config.kinds_override.clone().unwrap_or_else(|| { | ||
| vec![ | ||
| KIND_STREAM_MESSAGE, | ||
| KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| KIND_STREAM_REMINDER, | ||
| ] | ||
| }); | ||
| let kinds = config | ||
| .kinds_override | ||
| .clone() | ||
| .unwrap_or_else(default_mention_kinds); | ||
| let require_mention = !config.no_mention_filter; | ||
| for ch in &target_channels { | ||
| result.insert( | ||
|
|
@@ -1357,10 +1368,6 @@ pub fn resolve_dynamic_channel_filter( | |
| channel_id: Uuid, | ||
| rules: &[crate::filter::SubscriptionRule], | ||
| ) -> Option<ChannelFilter> { | ||
| use buzz_core::kind::{ | ||
| KIND_STREAM_MESSAGE, KIND_STREAM_REMINDER, KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| }; | ||
|
|
||
| // In Mentions/All mode, if the operator explicitly constrained channels | ||
| // with --channels, only allow dynamic subscription to channels in that | ||
| // allowlist. Config mode ignores --channels (per CLI contract) and uses | ||
|
|
@@ -1378,13 +1385,12 @@ pub fn resolve_dynamic_channel_filter( | |
|
|
||
| match config.subscribe_mode { | ||
| SubscribeMode::Mentions => Some(ChannelFilter { | ||
| kinds: Some(config.kinds_override.clone().unwrap_or_else(|| { | ||
| vec![ | ||
| KIND_STREAM_MESSAGE, | ||
| KIND_WORKFLOW_APPROVAL_REQUESTED, | ||
| KIND_STREAM_REMINDER, | ||
| ] | ||
| })), | ||
| kinds: Some( | ||
| config | ||
| .kinds_override | ||
| .clone() | ||
| .unwrap_or_else(default_mention_kinds), | ||
| ), | ||
| require_mention: !config.no_mention_filter, | ||
| }), | ||
| SubscribeMode::All => Some(ChannelFilter { | ||
|
|
@@ -1529,11 +1535,28 @@ mod tests { | |
| assert!(f.require_mention, "mentions mode requires mention"); | ||
| let kinds = f.kinds.as_ref().expect("should have kinds"); | ||
| assert!(kinds.contains(&buzz_core::kind::KIND_STREAM_MESSAGE)); | ||
| assert!(kinds.contains(&buzz_core::kind::KIND_STREAM_MESSAGE_EDIT)); | ||
| assert!(kinds.contains(&buzz_core::kind::KIND_WORKFLOW_APPROVAL_REQUESTED)); | ||
| assert!(kinds.contains(&buzz_core::kind::KIND_STREAM_REMINDER)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_dynamic_mentions_mode_includes_message_edits() { | ||
| let config = test_config(SubscribeMode::Mentions); | ||
| let filter = resolve_dynamic_channel_filter(&config, Uuid::new_v4(), &[]) | ||
| .expect("dynamic channel should be subscribed"); | ||
|
|
||
| assert!(filter.require_mention); | ||
| assert!( | ||
| filter | ||
| .kinds | ||
| .expect("mentions mode should constrain kinds") | ||
| .contains(&KIND_STREAM_MESSAGE_EDIT), | ||
| "newly mentioned agents must receive message edits on dynamic channels" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_mentions_mode_custom_kinds() { | ||
| let mut config = test_config(SubscribeMode::Mentions); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.