Skip to content

t1385.5: Add Nostr bot subagent doc for DM-based runner dispatch#2764

Closed
marcusquinn wants to merge 1 commit intomainfrom
chore/t1385.5-nostr-agent
Closed

t1385.5: Add Nostr bot subagent doc for DM-based runner dispatch#2764
marcusquinn wants to merge 1 commit intomainfrom
chore/t1385.5-nostr-agent

Conversation

@marcusquinn
Copy link
Owner

Summary

  • Create .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 assessment
  • Update subagent-index.toon to include nostr in the communications folder entry
  • Update .agents/AGENTS.md domain index to reference the new nostr subagent

Details

Follows the established communications subagent conventions (simplex.md, xmtp.md, bitchat.md) with:

  • YAML frontmatter with tool permissions
  • AI-CONTEXT-START/END quick reference block
  • Architecture diagram with message flow
  • Protocol coverage (NIP-01, NIP-04, NIP-44, NIP-17, NIP-65)
  • SDK installation and bot implementation code (nostr-tools TypeScript)
  • Privacy/security assessment with threat model and protocol comparison table
  • Relay selection guidance (public, paid, self-hosted)
  • Deployment patterns (PM2, Docker, systemd)
  • aidevops runner dispatch integration architecture
  • Limitations section (no forward secrecy, metadata exposure, key recovery)

Closes #2752

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
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

Warning

Rate limit exceeded

@marcusquinn has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 29 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between ac2beaf and c64304a.

📒 Files selected for processing (3)
  • .agents/AGENTS.md
  • .agents/services/communications/nostr.md
  • .agents/subagent-index.toon
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/t1385.5-nostr-agent

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.

❤️ Share

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

@github-actions github-actions bot added the enhancement Auto-created from TODO.md tag label Mar 3, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 aidevops agent ecosystem by adding extensive subagent documentation. The new documentation provides a detailed guide for developing and deploying Nostr bots, covering its architecture, various NIPs (Nostr Implementation Possibilities) for events and encrypted direct messages, key management, and a thorough privacy and security assessment. This enables aidevops agents to leverage Nostr for censorship-resistant, pseudonymous, and potentially Lightning-integrated communication, particularly for DM-based runner dispatch.

Highlights

  • New Nostr Subagent Documentation: A comprehensive subagent documentation file for Nostr bot integration has been introduced, detailing its architecture, protocols, and implementation.
  • Nostr Protocol Coverage: The documentation covers key Nostr protocols including NIP-01 events, NIP-04/NIP-44 encrypted DMs, NIP-17 gift-wrapped DMs, and NIP-65 relay list metadata.
  • Bot Implementation Details: Guidance is provided on keypair identity, nostr-tools SDK usage, DM-only bot scope, and pubkey allowlist for access control.
  • Privacy and Security Assessment: The new documentation includes a thorough privacy and security assessment, threat model, and comparison with other communication protocols like SimpleX and Matrix.
  • Index Updates: The main .agents/AGENTS.md domain index and subagent-index.toon have been updated to reference the newly added Nostr subagent documentation.
Changelog
  • .agents/AGENTS.md
    • Added services/communications/nostr.md to the "Communications" section.
  • .agents/services/communications/nostr.md
    • Created a new file detailing the Nostr subagent, including quick reference, architecture, protocol specifics (NIP-01, NIP-04, NIP-44, NIP-17, NIP-65), identity management, SDK usage, bot implementation (DM-only, access control), relay architecture, deployment, privacy/security assessment, and limitations.
  • .agents/subagent-index.toon
    • Appended nostr to the list of keywords for services/communications/.
Activity
  • No human activity (comments, reviews, etc.) has occurred on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Mar 3, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 113 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Tue Mar 3 04:44:30 UTC 2026: Code review monitoring started
Tue Mar 3 04:44:31 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 113

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 113
  • VULNERABILITIES: 0

Generated on: Tue Mar 3 04:44:33 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

medium

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.

Suggested change
aidevops secret set NOSTR_BOT_NSEC
aidevops secret set NOSTR_BOT_SK_HEX

Comment on lines +228 to +290
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));
},
}
);

Choose a reason for hiding this comment

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

medium

The code example has a few issues that would prevent it from running correctly and could be made more robust:

  • hexToBytes is not a standard function and is not exported by nostr-tools. It needs to be imported from a library like @noble/bytes, which would be a new dependency.
  • The event parameter in the onevent handler should be explicitly typed as Event for type safety.
  • Using the non-null assertion ! on process.env.NOSTR_BOT_SK_HEX can lead to runtime errors if the variable is not set. It's safer to check for its existence.
  • The onevent handler would benefit from a try...catch block to gracefully handle potential errors during message decryption or processing, preventing the bot from crashing.
  • The generateSecretKey import 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);
      }
    }
  }
);

@alex-solovyev
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

t1385.5: Nostr bot agent

2 participants