t1385.5: Add Nostr bot subagent doc for DM-based runner dispatch#2764
t1385.5: Add Nostr bot subagent doc for DM-based runner dispatch#2764marcusquinn wants to merge 1 commit intomainfrom
Conversation
Create .agents/services/communications/nostr.md covering: - NIP-01 events, NIP-04/NIP-44 encrypted DMs, NIP-17 gift-wrapped DMs - Relay architecture (WebSocket, redundancy, self-hosted options) - Keypair identity (nsec/npub, secp256k1, NIP-19 bech32) - nostr-tools SDK (TypeScript) with DM-only bot implementation - Access control via pubkey allowlists - Privacy/security assessment (metadata exposure, no forward secrecy) - Comparison with SimpleX, Matrix, XMTP, Bitchat - aidevops runner dispatch integration architecture Also update subagent-index.toon and AGENTS.md domain index. Closes #2752
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request integrates Nostr, a decentralized messaging protocol, into the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Tue Mar 3 04:44:33 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive documentation for a Nostr bot subagent, which is a valuable addition. The new documentation is well-structured and detailed. My review includes suggestions to enhance its correctness and consistency, specifically addressing an inconsistency in the secret key variable name used and providing a more robust TypeScript code example.
Note: Security Review is unavailable for this PR.
| ```bash | ||
| # Generate keypair (do NOT log or expose the nsec) | ||
| # Store nsec via gopass or credentials.sh (600 permissions) | ||
| aidevops secret set NOSTR_BOT_NSEC |
There was a problem hiding this comment.
For consistency throughout the document, it's better to use NOSTR_BOT_SK_HEX here. The rest of the documentation, including the code example, configuration, and environment variable list, refers to a hex-encoded secret key (SK_HEX) rather than an nsec-encoded one.
| aidevops secret set NOSTR_BOT_NSEC | |
| aidevops secret set NOSTR_BOT_SK_HEX |
| import { | ||
| generateSecretKey, | ||
| getPublicKey, | ||
| finalizeEvent, | ||
| nip04, | ||
| nip19, | ||
| SimplePool, | ||
| } from "nostr-tools"; | ||
|
|
||
| // Load bot private key from secure storage (never hardcode) | ||
| const sk = hexToBytes(process.env.NOSTR_BOT_SK_HEX!); | ||
| const pk = getPublicKey(sk); | ||
|
|
||
| console.log(`Bot pubkey: ${nip19.npubEncode(pk)}`); | ||
|
|
||
| // Allowed pubkeys (access control) | ||
| const ALLOWED_PUBKEYS = new Set( | ||
| (process.env.NOSTR_ALLOWED_PUBKEYS || "").split(",").filter(Boolean) | ||
| ); | ||
|
|
||
| // Connect to relays | ||
| const pool = new SimplePool(); | ||
| const relays = [ | ||
| "wss://relay.damus.io", | ||
| "wss://nos.lol", | ||
| "wss://relay.nostr.band", | ||
| ]; | ||
|
|
||
| // Subscribe to kind-4 DMs addressed to this bot | ||
| const sub = pool.subscribeMany( | ||
| relays, | ||
| [{ kinds: [4], "#p": [pk], since: Math.floor(Date.now() / 1000) }], | ||
| { | ||
| onevent: async (event) => { | ||
| // Access control: check sender pubkey | ||
| if (!ALLOWED_PUBKEYS.has(event.pubkey)) { | ||
| console.log(`Ignored DM from unauthorized pubkey: ${event.pubkey}`); | ||
| return; | ||
| } | ||
|
|
||
| // Decrypt NIP-04 message | ||
| const plaintext = await nip04.decrypt(sk, event.pubkey, event.content); | ||
| console.log(`DM from ${event.pubkey}: ${plaintext}`); | ||
|
|
||
| // Dispatch to aidevops runner | ||
| const response = await dispatchToRunner(plaintext); | ||
|
|
||
| // Encrypt and send reply | ||
| const ciphertext = await nip04.encrypt(sk, event.pubkey, response); | ||
| const replyEvent = finalizeEvent( | ||
| { | ||
| kind: 4, | ||
| created_at: Math.floor(Date.now() / 1000), | ||
| tags: [["p", event.pubkey]], | ||
| content: ciphertext, | ||
| }, | ||
| sk | ||
| ); | ||
|
|
||
| await Promise.any(pool.publish(relays, replyEvent)); | ||
| }, | ||
| } | ||
| ); |
There was a problem hiding this comment.
The code example has a few issues that would prevent it from running correctly and could be made more robust:
hexToBytesis not a standard function and is not exported bynostr-tools. It needs to be imported from a library like@noble/bytes, which would be a new dependency.- The
eventparameter in theoneventhandler should be explicitly typed asEventfor type safety. - Using the non-null assertion
!onprocess.env.NOSTR_BOT_SK_HEXcan lead to runtime errors if the variable is not set. It's safer to check for its existence. - The
oneventhandler would benefit from atry...catchblock to gracefully handle potential errors during message decryption or processing, preventing the bot from crashing. - The
generateSecretKeyimport is unused.
Here is a revised version of the code that addresses these points:
import {
getPublicKey,
finalizeEvent,
nip04,
nip19,
SimplePool,
type Event,
} from "nostr-tools";
import { hexToBytes } from "@noble/bytes"; // NOTE: You may need to `npm install @noble/bytes`
// Load bot private key from secure storage (never hardcode)
const skHex = process.env.NOSTR_BOT_SK_HEX;
if (!skHex) {
throw new Error("NOSTR_BOT_SK_HEX environment variable is not set.");
}
const sk = hexToBytes(skHex);
const pk = getPublicKey(sk);
console.log(`Bot pubkey: ${nip19.npubEncode(pk)}`);
// Allowed pubkeys (access control)
const ALLOWED_PUBKEYS = new Set(
(process.env.NOSTR_ALLOWED_PUBKEYS || "").split(",").filter(Boolean)
);
// Connect to relays
const pool = new SimplePool();
const relays = [
"wss://relay.damus.io",
"wss://nos.lol",
"wss://relay.nostr.band",
];
// Subscribe to kind-4 DMs addressed to this bot
const sub = pool.subscribeMany(
relays,
[{ kinds: [4], "#p": [pk], since: Math.floor(Date.now() / 1000) }],
{
onevent: async (event: Event) => {
// Access control: check sender pubkey
if (!ALLOWED_PUBKEYS.has(event.pubkey)) {
console.log(`Ignored DM from unauthorized pubkey: ${event.pubkey}`);
return;
}
try {
// Decrypt NIP-04 message
const plaintext = await nip04.decrypt(sk, event.pubkey, event.content);
console.log(`DM from ${event.pubkey}: ${plaintext}`);
// Dispatch to aidevops runner
const response = await dispatchToRunner(plaintext);
// Encrypt and send reply
const ciphertext = await nip04.encrypt(sk, event.pubkey, response);
const replyEvent = finalizeEvent(
{
kind: 4,
created_at: Math.floor(Date.now() / 1000),
tags: [["p", event.pubkey]],
content: ciphertext,
},
sk
);
await Promise.any(pool.publish(relays, replyEvent));
} catch (e) {
console.error(`Failed to process DM ${event.id} from ${event.pubkey}:`, e);
}
}
}
);
|
This PR was superseded by the batch merge in PR #2771 (feat: t1385 — add 11 chat platform integration agents), which merged all the content from this branch. Closing as the content is already in main. |



Summary
.agents/services/communications/nostr.md— comprehensive subagent doc for Nostr bot integration covering NIP-01 events, NIP-04/NIP-44 encrypted DMs, NIP-17 gift-wrapped DMs, relay architecture, keypair identity, nostr-tools SDK, DM-only bot scope, pubkey allowlist access control, and privacy/security assessmentsubagent-index.toonto include nostr in the communications folder entry.agents/AGENTS.mddomain index to reference the new nostr subagentDetails
Follows the established communications subagent conventions (simplex.md, xmtp.md, bitchat.md) with:
Closes #2752