Repository navigation
Commit c6e3fe7
feat(workflows): reply in-thread from send_message action (#6178)
The `send_message` workflow action could only post new top-level channel
messages. This adds a `reply_in_thread` option so a `message_posted`
workflow can reply in the triggering message's thread, plus a
`trigger_is_reply` filter variable so a workflow can fire only on
top-level messages.
Every NIP-10 thread-marker reader in the tree now routes through one
shared parser and one collapse rule in `buzz-core`, deleting four
hand-rolled copies that had drifted on id-validity and marker semantics.
## What changed
- **Schema** (`crates/buzz-workflow/src/schema.rs`): new
`reply_in_thread: bool` (serde default `false`) on
`ActionDef::SendMessage`. `validate()` rejects `reply_in_thread: true`
on `schedule`/`webhook` triggers — they carry no message to reply to.
- **Executor** (`crates/buzz-workflow/src/executor.rs`): threads
`reply_to: Option<&str>` (the trigger `message_id`) through
`ActionSink::send_message` when `reply_in_thread` is set; errors clearly
if the trigger has no `message_id`. `resolve_step_templates` carries the
new field. Adds `trigger_is_reply` (boolean) to the eval context.
- **Relay sink** (`crates/buzz-relay/src/workflow_sink.rs`): when
`reply_to` is set, resolves parent/root/depth from the known trigger
event, persists real thread metadata instead of the hardcoded top-level
`depth: 0`, and pushes the live kind:39005 thread-summary overlay after
insert so subscribed desktops update the root's reply badge without
refetching — matching the human ingest path. Emits the same NIP-10
`e`-tag shape as `buzz_sdk::builders::thread_tags`: a single `["e", id,
"", "reply"]` tag for a direct reply (parent == root), and the `root` +
`reply` pair only when nested — so every writer produces one wire shape
per reply kind.
- **Ingest resolver** (`crates/buzz-relay/src/handlers/ingest.rs`): new
`resolve_relay_reply_thread_meta` + `ReplyAncestry`. Unlike the
client-facing `resolve_nip10_thread_meta` (which validates
client-supplied tags), this computes root/depth from the known parent
and enforces the same same-channel and depth-limit invariants. When the
parent has no `thread_metadata` row, both resolvers share
`derive_ancestry_from_parent_tags`, which applies
`ThreadMarkers::resolve()`: a marked nested parent remains depth 2,
while a root-only, malformed, or unmarked parent is top-level and starts
its reply thread at itself. Both the client resolver and the
parent-ancestor fallback now read markers via the shared parser instead
of hand-scanning `e`-tags.
- **Shared NIP-10 parser** (`crates/buzz-core/src/nip10.rs`):
`parse_thread_markers` reads an event's `root`/`reply` markers, honoring
a marker only when its event id is exactly 64 ASCII-hex characters.
`ThreadMarkers::resolve()` is the single definition of the (root, reply)
→ (root_id, parent_id) collapse: `root`+`reply` as-is, `reply`-only →
`(reply, reply)`, a lone `root` or neither → top-level. A slice-based
`parse_thread_markers_from_parts` entry point serves consumers holding
raw JSON tag arrays. Relay ingest, the workflow `trigger_is_reply`
predicate, ACP anchoring, and the CLI reply resolver all call these, so
they cannot drift on marker, id-validity, or collapse semantics.
- **ACP** (`crates/buzz-acp/src/queue.rs`): `parse_thread_tags`
delegates marker parsing and collapse to `buzz_core::nip10`, keeping
only its local `p`-tag mention collection. This fixes a parity gap with
ingest: a malformed non-64-hex marker id is no longer counted as a
thread link, and a lone `root` marker is now top-level rather than being
treated as root == parent.
- **CLI** (`crates/buzz-cli/src/commands/messages.rs`):
`find_root_from_tags` routes its JSON tags through the shared slice
parser and collapse rule. CLI replies to root-only, malformed, or
unmarked parents now correctly start at that immediate parent;
reply-only and root+reply parent ancestry remain intact.
- **Trigger context** (`crates/buzz-workflow/src/lib.rs`):
`build_trigger_context` derives `is_reply` solely from a valid NIP-10
`reply` marker (no DB hit). A lone `root` marker is top-level to ingest,
so it does not count; neither does a `reply` marker whose event id is
malformed, nor a bare/unmarked `e`-tag (mentions, quotes).
- **Desktop** (`workflowFormTypes.ts`, `WorkflowStepCard.tsx`):
`replyInThread` form field with YAML round-trip, and a "Reply to
triggering message in thread" checkbox shown only for message-based
triggers. Switching to `schedule` or `webhook` clears the option on
every step before serialization, so a value hidden behind an action
change cannot resurrect when the action is switched back. The form
parser also requires `reply_in_thread` to be a boolean and refuses
`reply_in_thread: true` under an ineligible trigger, falling back to
YAML mode rather than silently normalizing a backend-invalid definition.
## Usage
```yaml
trigger:
on: message_posted
filter: trigger_is_reply == false
steps:
- id: auto_reply
action: send_message
text: "pre-written reply text"
reply_in_thread: true
```
---------
Signed-off-by: Will Pfleger <[email protected]>
Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>1 parent c63ac74 commit c6e3fe7
15 files changed
Lines changed: 1606 additions & 182 deletions
File tree
- crates
- buzz-acp/src
- buzz-cli/src/commands
- buzz-core/src
- buzz-relay/src
- handlers
- buzz-test-client/tests
- buzz-workflow/src
- desktop/src/features/workflows/ui
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
875 | 875 | | |
876 | 876 | | |
877 | 877 | | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
883 | 881 | | |
884 | | - | |
885 | | - | |
886 | | - | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
887 | 887 | | |
888 | | - | |
889 | | - | |
890 | | - | |
891 | | - | |
892 | | - | |
893 | | - | |
894 | | - | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
905 | | - | |
906 | | - | |
907 | | - | |
908 | | - | |
909 | | - | |
910 | | - | |
911 | | - | |
912 | | - | |
913 | | - | |
914 | | - | |
915 | | - | |
916 | | - | |
917 | | - | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
918 | 892 | | |
919 | 893 | | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
920 | 903 | | |
921 | 904 | | |
922 | 905 | | |
| |||
3192 | 3175 | | |
3193 | 3176 | | |
3194 | 3177 | | |
| 3178 | + | |
3195 | 3179 | | |
3196 | 3180 | | |
3197 | | - | |
| 3181 | + | |
3198 | 3182 | | |
3199 | 3183 | | |
3200 | | - | |
3201 | | - | |
| 3184 | + | |
| 3185 | + | |
3202 | 3186 | | |
3203 | 3187 | | |
3204 | 3188 | | |
3205 | 3189 | | |
3206 | 3190 | | |
| 3191 | + | |
| 3192 | + | |
3207 | 3193 | | |
3208 | 3194 | | |
3209 | 3195 | | |
3210 | | - | |
3211 | | - | |
| 3196 | + | |
| 3197 | + | |
3212 | 3198 | | |
3213 | 3199 | | |
3214 | 3200 | | |
3215 | | - | |
3216 | | - | |
| 3201 | + | |
| 3202 | + | |
3217 | 3203 | | |
3218 | 3204 | | |
3219 | 3205 | | |
| |||
3231 | 3217 | | |
3232 | 3218 | | |
3233 | 3219 | | |
3234 | | - | |
3235 | | - | |
| 3220 | + | |
| 3221 | + | |
| 3222 | + | |
| 3223 | + | |
| 3224 | + | |
3236 | 3225 | | |
3237 | | - | |
3238 | | - | |
| 3226 | + | |
| 3227 | + | |
3239 | 3228 | | |
3240 | 3229 | | |
3241 | | - | |
3242 | | - | |
| 3230 | + | |
| 3231 | + | |
| 3232 | + | |
| 3233 | + | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
| 3237 | + | |
| 3238 | + | |
| 3239 | + | |
| 3240 | + | |
| 3241 | + | |
| 3242 | + | |
| 3243 | + | |
| 3244 | + | |
| 3245 | + | |
| 3246 | + | |
| 3247 | + | |
| 3248 | + | |
| 3249 | + | |
3243 | 3250 | | |
3244 | 3251 | | |
3245 | 3252 | | |
| |||
3312 | 3319 | | |
3313 | 3320 | | |
3314 | 3321 | | |
3315 | | - | |
| 3322 | + | |
3316 | 3323 | | |
3317 | 3324 | | |
3318 | 3325 | | |
| |||
3330 | 3337 | | |
3331 | 3338 | | |
3332 | 3339 | | |
3333 | | - | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
3334 | 3343 | | |
3335 | 3344 | | |
3336 | 3345 | | |
| |||
3340 | 3349 | | |
3341 | 3350 | | |
3342 | 3351 | | |
3343 | | - | |
| 3352 | + | |
3344 | 3353 | | |
3345 | 3354 | | |
3346 | 3355 | | |
| |||
3645 | 3654 | | |
3646 | 3655 | | |
3647 | 3656 | | |
3648 | | - | |
| 3657 | + | |
3649 | 3658 | | |
3650 | 3659 | | |
3651 | 3660 | | |
| |||
3698 | 3707 | | |
3699 | 3708 | | |
3700 | 3709 | | |
3701 | | - | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
3702 | 3713 | | |
3703 | 3714 | | |
3704 | 3715 | | |
| |||
3712 | 3723 | | |
3713 | 3724 | | |
3714 | 3725 | | |
3715 | | - | |
| 3726 | + | |
3716 | 3727 | | |
3717 | 3728 | | |
3718 | 3729 | | |
| |||
5310 | 5321 | | |
5311 | 5322 | | |
5312 | 5323 | | |
5313 | | - | |
| 5324 | + | |
5314 | 5325 | | |
5315 | 5326 | | |
5316 | 5327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
47 | 56 | | |
48 | 57 | | |
49 | 58 | | |
| |||
80 | 89 | | |
81 | 90 | | |
82 | 91 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| |||
1057 | 1059 | | |
1058 | 1060 | | |
1059 | 1061 | | |
1060 | | - | |
| 1062 | + | |
| 1063 | + | |
1061 | 1064 | | |
1062 | 1065 | | |
1063 | 1066 | | |
| |||
1132 | 1135 | | |
1133 | 1136 | | |
1134 | 1137 | | |
1135 | | - | |
| 1138 | + | |
1136 | 1139 | | |
1137 | 1140 | | |
1138 | 1141 | | |
| |||
1171 | 1174 | | |
1172 | 1175 | | |
1173 | 1176 | | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
1174 | 1194 | | |
1175 | 1195 | | |
1176 | 1196 | | |
| |||
1194 | 1214 | | |
1195 | 1215 | | |
1196 | 1216 | | |
1197 | | - | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
1198 | 1220 | | |
1199 | 1221 | | |
1200 | 1222 | | |
1201 | 1223 | | |
1202 | 1224 | | |
1203 | 1225 | | |
1204 | | - | |
| 1226 | + | |
1205 | 1227 | | |
1206 | 1228 | | |
1207 | 1229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
0 commit comments