Skip to content

feat(messages): carry app-defined extra tags on kind-9 chat/reply#767

Merged
dannym-arx merged 3 commits into
masterfrom
feat/kind9-extra-tags
Jul 2, 2026
Merged

feat(messages): carry app-defined extra tags on kind-9 chat/reply#767
dannym-arx merged 3 commits into
masterfrom
feat/kind9-extra-tags

Conversation

@dannym-arx

@dannym-arx dannym-arx commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

marmot

What this does

Message effects (the Telegram-style bursts) used to travel inside the message body. The sender appended an invisible marker like ⁣dmfx:fire⁣ to the text, and the receiver stripped it back off. Any client that did not know the trick showed the raw dmfx:fire suffix or a tofu box, and the control characters leaked into copy, quote, reply previews, and search.

This moves the effect out of the body and onto the kind-9 event as a real nostr tag. Like a tidy marmot stamping a label on the envelope instead of scribbling inside the letter.

Changes

  • Chat and Reply intents gain an extra_tags: Vec<Vec<String>> field. build_inner_event appends those tags after the protocol-derived ones. Only malformed (empty) tags are dropped; marmot stays agnostic about what a tag means.
  • New Runtime::send_message_with_tags and Runtime::reply_to_message_with_tags. They route through the existing SendAppEvent worker path, so the worker and command layers did not change.
  • Tests cover both intents: extra tags ride along, the body stays clean, and empty tags get filtered.

Why a tag

A nostr tag is out of band. A client that does not understand it ignores it and renders clean text, so no marker ever appears in the visible message. The receive side already carried arbitrary inner-event tags through the projection onto AppMessageRecord.tags, so reading the effect back needs no protocol change.

The host app (darkmatter-linux) owns the convention and sends ["effect", "fire"]. Marmot just carries whatever tags it is handed.


Open in Stage

Summary by CodeRabbit

  • New Features
    • Messages and replies can now carry additional, well-formed extra tags with the outbound event.
    • Added send_message_with_tags to post tagged messages, plus reply_to_message_with_tags for tagged replies.
  • Bug Fixes
    • Extra tags are sanitized: only valid ["effect", <value>] tags with a non-empty value are accepted; others (including reserved/empty forms) are ignored.
    • Sending now validates message payloads are valid UTF-8.
  • Tests
    • Updated intent/event construction and assertions to cover sanitized tag behavior.

Add extra_tags to the Chat/Reply intents and expose send_message_with_tags
/ reply_to_message_with_tags so host apps can attach out-of-band metadata
(e.g. a message-effect key) as a real nostr kind-9 tag instead of smuggling
it into the visible message body. Marmot stays agnostic about tag meaning;
only malformed (empty) tags are dropped. Routes through the existing
SendAppEvent worker path, so no worker/command-layer changes are needed.
@stage-review

stage-review Bot commented Jun 30, 2026

Copy link
Copy Markdown

Ready to review this PR? Stage has broken it down into 5 individual chapters for you:

Title
1 Define extra tags and sanitization logic
2 Integrate extra tags into event construction
3 Expose tag-aware sending methods in Runtime
4 Update internal callers and existing tests
5 Verify tag sanitization and persistence
Open in Stage

Chapters generated by Stage for commit faddb20 on Jul 1, 2026 11:38pm UTC.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 586f4578-a0e8-498a-b408-48f38ff033ac

📥 Commits

Reviewing files that changed from the base of the PR and between ac44e3c and faddb20.

📒 Files selected for processing (1)
  • crates/marmot-app/src/messages/intents.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/marmot-app/src/messages/intents.rs

Walkthrough

This PR adds an extra_tags: Vec<Vec<String>> field to chat and reply intents, filters those tags before event construction, and exposes runtime APIs that can send tagged messages. Existing client and test call sites are updated to pass empty tag vectors where needed.

Changes

Extra Tags Feature

Layer / File(s) Summary
Intent contract and tag sanitization
crates/marmot-app/src/messages/intents.rs
Adds extra_tags to Chat and Reply intent variants and defines sanitized_extra_tags to keep only allowed effect tags.
Event construction with extra tags
crates/marmot-app/src/messages/intents.rs
build_inner_event appends sanitized extra tags after derived mention p-tags for both Chat and Reply, and the intent tests cover accepted and rejected tag shapes.
Runtime APIs for sending tagged messages
crates/marmot-app/src/runtime/mod.rs
Adds send_message_with_tags, extends reply_to_message_with_tags to accept extra_tags, and routes reply_to_message through the tagged helper with an empty vector.
Client call site updates and test fixtures
crates/marmot-app/src/client/mod.rs, crates/marmot-app/src/tests.rs
AppClient chat/reply construction and existing test fixtures are updated to explicitly set extra_tags: Vec::new().

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding app-defined extra tags to chat and reply kind-9 intents.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/kind9-extra-tags

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/marmot-app/src/messages/intents.rs`:
- Around line 149-160: The sanitized_extra_tags helper currently only removes
empty tags, so host-supplied imeta can still pass through and later be rejected
by decode_received_event during media validation. Update sanitized_extra_tags to
treat imeta as a reserved tag and filter it out before returning the tag list,
or otherwise clearly reserve it in this path. Use the sanitized_extra_tags
function and its call sites for Chat event outgoing tag preparation to locate
the fix.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c779cd11-1370-4c30-aad2-5be60e512d75

📥 Commits

Reviewing files that changed from the base of the PR and between c38348d and 31311a3.

📒 Files selected for processing (4)
  • crates/marmot-app/src/client/mod.rs
  • crates/marmot-app/src/messages/intents.rs
  • crates/marmot-app/src/runtime/mod.rs
  • crates/marmot-app/src/tests.rs

Comment thread crates/marmot-app/src/messages/intents.rs Outdated

@erskingardner erskingardner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: extra_tags lets callers inject reserved kind-9 semantics, not just out-of-band metadata.

sanitized_extra_tags drops only empty tags, then appends everything else to chat/reply events. But timeline projection treats kind-9 tags as first-class semantics: q/e make a row a reply, imeta makes it media, and stream* makes it an agent stream final. Since the new public runtime API accepts arbitrary Vec<Vec<String>>, a plain text send can be projected as a reply/media/stream message by passing reserved tags. That contradicts the “out of band / clients ignore it” framing for message effects.

I’d fix by whitelisting the intended extension tag, e.g. only ["effect", value], or by rejecting feature-owned/reserved tag names (e, q, imeta, stream, stream-start, stream-hash, etc.) from this helper. If this is meant to be a fully general app-event authoring escape hatch, I’d rename/document it that way rather than attaching it to chat/reply.

@dannym-arx

Copy link
Copy Markdown
Contributor Author

ok I'll add the rejection

Address Jeff's P1: extra_tags let callers inject reserved kind-9
semantics (e/q/imeta/stream*), so a plain text send could be projected
as a reply/media/stream message. sanitized_extra_tags now whitelists a
well-formed ["effect", <value>] tag and drops everything else.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/marmot-app/src/messages/intents.rs`:
- Around line 168-170: The tag filter in the intent/message parsing logic is
currently allowing `effect` tags with extra trailing fields; tighten the match
in the `matches!` expression so `EFFECT_TAG` is accepted only when the tag has
exactly two elements, and apply the same validation anywhere else the `effect`
tag is parsed or filtered (including the other referenced locations) to keep the
`["effect", <value>]` shape enforced consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 12f66c39-019f-4498-8d8c-a2f1a95b3515

📥 Commits

Reviewing files that changed from the base of the PR and between 31311a3 and ac44e3c.

📒 Files selected for processing (1)
  • crates/marmot-app/src/messages/intents.rs

Comment thread crates/marmot-app/src/messages/intents.rs Outdated
Tighten sanitized_extra_tags so an effect tag with trailing fields is
dropped too — enforce exactly two elements, not a two-or-more prefix.
@dannym-arx
dannym-arx merged commit e43fd5e into master Jul 2, 2026
20 checks passed
@dannym-arx
dannym-arx deleted the feat/kind9-extra-tags branch July 2, 2026 07:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants