Skip to content

Normalize Nostr subscribe filters; add --debug-echo; doc updates#7

Merged
AustinKelsay merged 1 commit intomasterfrom
staging
Oct 21, 2025
Merged

Normalize Nostr subscribe filters; add --debug-echo; doc updates#7
AustinKelsay merged 1 commit intomasterfrom
staging

Conversation

@AustinKelsay
Copy link
Copy Markdown
Member

@AustinKelsay AustinKelsay commented Oct 21, 2025

  • Add global SimplePool subscribeMany shim (src/polyfills/nostr.ts), import at startup.
  • Remove duplicate signer patch; KeysetSigner now imports shared polyfill.
  • Add --debug-echo (-E) flag to toggle IGLOO_DEBUG_ECHO without env vars.
  • Echo listener logs active relay set when debug enabled.
  • Update Help panel, README, and LLM context with echo testing tips.

Summary by CodeRabbit

  • New Features

    • Added --debug-echo flag for verbose echo logging during testing
    • Introduced IGLOO_TEST_RELAY environment variable to pin a specific relay
  • Bug Fixes

    • Fixed relay compatibility issues with Nostr subscribe filter normalization
  • Documentation

    • Enhanced README with echo debugging tips and relay troubleshooting guidance
    • Updated help text with new debug options

  - Add global SimplePool subscribeMany shim (src/polyfills/nostr.ts), import at startup.
  - Remove duplicate signer patch; KeysetSigner now imports shared polyfill.
  - Add --debug-echo (-E) flag to toggle IGLOO_DEBUG_ECHO without env vars.
  - Echo listener logs active relay set when debug enabled.
  - Update Help panel, README, and LLM context with echo testing tips.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 21, 2025

Walkthrough

This PR adds debugging infrastructure and a runtime polyfill to igloo-cli. It introduces a --debug-echo CLI flag to enable verbose logging for echo relay interactions, adds a polyfill that normalizes Nostr filter subscriptions to handle relay incompatibilities, and documents the debugging workflow. The polyfill replaces previous inline monkey-patching with a dedicated module.

Changes

Cohort / File(s) Summary
Documentation
README.md, llm/context/igloo-core-readme.md
Added sections describing --debug-echo flag, IGLOO_DEBUG_ECHO environment variable, and IGLOO_TEST_RELAY pinning for testing. Documented known issue with single-element filter arrays and recommended normalization pattern.
CLI Flag Support
src/cli.tsx, src/components/Help.tsx
Introduced --debug-echo / -E flag with boolean coercion logic via toBool(). Added flag handling in IIFE to set IGLOO_DEBUG_ECHO environment variable early. Registered help text for the new flag.
Polyfill Implementation
src/polyfills/nostr.ts
New module that patches SimplePool.subscribeMany to normalize filter arguments, converting [[filter]]filter with idempotent guard flag and silent error handling.
Debug Logging & Relay Initialization
src/components/keyset/KeysetSigner.tsx, src/components/keyset/useShareEchoListener.ts
Replaced inline SimplePool monkey-patching with polyfill import in KeysetSigner. Added guarded debug logging in useShareEchoListener to print relay configuration when IGLOO_DEBUG_ECHO is enabled.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

The changes are largely additive and follow consistent patterns (flag handling, polyfill boilerplate, documentation). The polyfill implementation is straightforward filter normalization with defensive try/catch. No complex logic density or surprising interactions across files—each modification is focused and isolated in its domain.

Possibly related PRs

Poem

🐰 A filter runs wild through the relay's door,
So we wrap it in normalization lore—
With --debug-echo, the echoes now sing,
And logs paint the relay dance, everything! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Normalize Nostr subscribe filters; add --debug-echo; doc updates" accurately describes the three main categories of changes in this PR. It maps directly to the actual modifications: the new polyfill for filter normalization in src/polyfills/nostr.ts, the addition of the --debug-echo CLI flag with supporting infrastructure, and the documentation updates across README, Help, and context files. The title is specific and concrete rather than vague, using clear technical terms that a reviewer can understand without ambiguity. The semicolon-separated structure appropriately handles multiple significant changes while remaining concise and readable.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch staging

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/cli.tsx (1)

133-141: Consider extracting the boolean coercion logic.

The toBool function duplicates similar logic in KeysetSigner.tsx (parseBooleanFlag, lines 70-86). Consider extracting this to a shared utility module to maintain consistency and reduce duplication.

Example location: src/utils/flags.ts

export function toBool(value: string | boolean | undefined): boolean {
  if (typeof value === 'boolean') return value;
  if (typeof value === 'string') {
    const v = value.trim().toLowerCase();
    if (['1', 'true', 'yes', 'on'].includes(v)) return true;
    if (['0', 'false', 'no', 'off'].includes(v)) return false;
  }
  return false;
}
src/polyfills/nostr.ts (1)

1-25: Runtime prototype patching requires caution.

The polyfill achieves its goal of normalizing filters for relay compatibility, but runtime prototype modification is inherently fragile. Here are some observations:

Positives:

  • Idempotent check via __iglooFilterNormalizePatched prevents double-patching
  • Silent failure (try/catch) won't break the app if nostr-tools changes
  • Centralized in a polyfill vs. scattered runtime patches
  • Preserves original function with proper call(this, ...)

Potential concerns:

  • The normalization logic assumes filters[0] is always the filter object when filters.length === 1. This works for the current nostr-tools API but could break if the library changes its signature.
  • The __iglooFilterNormalizePatched property is added to the prototype, which pollutes the SimplePool prototype. Consider using a WeakSet or module-level flag instead.
  • No TypeScript types for the patched method, which could lead to type safety issues.

Suggested improvements:

  1. Add a module-level flag instead of polluting the prototype:
+let patchApplied = false;
+
 try {
   const proto = (SimplePool as any)?.prototype;
-  if (proto && !proto.__iglooFilterNormalizePatched) {
+  if (proto && !patchApplied) {
     const original = proto.subscribeMany;
     if (typeof original === 'function') {
       proto.subscribeMany = function patchedSubscribeMany(this: unknown, relays: unknown, filters: unknown, params: unknown) {
         const normalized = Array.isArray(filters) && filters.length === 1 && filters[0] &&
           typeof filters[0] === 'object' && !Array.isArray(filters[0])
           ? filters[0]
           : filters;
         return original.call(this, relays, normalized, params);
       };
-      Object.defineProperty(proto, '__iglooFilterNormalizePatched', {value: true});
+      patchApplied = true;
     }
   }
 } catch {
   // Best-effort only; if nostr-tools changes, we fail silently.
 }
  1. Consider adding a comment explaining which relay implementations require this normalization and linking to any relevant issue tracker entries.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f20f886 and ee9075d.

📒 Files selected for processing (7)
  • README.md (1 hunks)
  • llm/context/igloo-core-readme.md (2 hunks)
  • src/cli.tsx (4 hunks)
  • src/components/Help.tsx (1 hunks)
  • src/components/keyset/KeysetSigner.tsx (1 hunks)
  • src/components/keyset/useShareEchoListener.ts (1 hunks)
  • src/polyfills/nostr.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

All import specifiers must include .js extensions (TypeScript ESM requirement) even though source files are .ts/.tsx

Files:

  • src/polyfills/nostr.ts
  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
  • src/cli.tsx
  • src/components/keyset/useShareEchoListener.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript with ESM, 2-space indentation, single quotes, and trailing commas
Order imports from shallow-to-deep
Use camelCase for utility function and variable names
Use SCREAMING_SNAKE_CASE for constants

Files:

  • src/polyfills/nostr.ts
  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
  • src/cli.tsx
  • src/components/keyset/useShareEchoListener.ts
src/**/*.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

Use Ink components (, , etc.) for terminal UI and do not use HTML elements

Files:

  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
  • src/cli.tsx
src/components/**

📄 CodeRabbit inference engine (CLAUDE.md)

All UI components should live under src/components/

Files:

  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
  • src/components/keyset/useShareEchoListener.ts
src/components/**/*.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

When adding a new command, implement it as a component under src/components/

Store reusable UI components under src/components/

Files:

  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
src/components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Name React components using PascalCase

Files:

  • src/components/keyset/KeysetSigner.tsx
  • src/components/Help.tsx
  • src/components/keyset/useShareEchoListener.ts
src/cli.tsx

📄 CodeRabbit inference engine (CLAUDE.md)

src/cli.tsx: Argument parsing is handled manually in cli.tsx via parseArgv() and must support --flag value, --flag=value, and -f value forms
When adding command flags, extend parseArgv() in cli.tsx for any custom parsing logic

src/cli.tsx: Keep the CLI entrypoint in src/cli.tsx and use it to bootstrap Ink rendering
Keep CLI flags lower-case (e.g., --verbose)

Files:

  • src/cli.tsx
llm/**

📄 CodeRabbit inference engine (AGENTS.md)

Keep protocol prompts and agent scripts in llm/ and update them when UX flows change

Files:

  • llm/context/igloo-core-readme.md
🔇 Additional comments (9)
src/components/Help.tsx (1)

47-47: LGTM!

The help text clearly documents the new --debug-echo flag and its purpose. The description is concise and consistent with other flag documentation in this file.

src/components/keyset/useShareEchoListener.ts (1)

161-166: LGTM!

The debug logging is well-guarded and consistent with the existing debugging pattern established earlier in this function. The try/catch wrapper around console.log prevents crashes in environments where console might not be available.

The placement before awaitShareEcho is ideal for debugging relay connectivity issues.

llm/context/igloo-core-readme.md (2)

324-324: LGTM!

The CLI debugging tip clearly explains how to enable echo logs and ensure relay overlap between desktop and CLI. The guidance is practical and actionable.


372-372: LGTM!

The troubleshooting note accurately documents the filter normalization behavior and provides clear guidance for users implementing custom listeners outside the CLI.

README.md (1)

158-170: LGTM!

The Echo debugging section is well-written with clear examples. The explanation of filter normalization provides useful context for users troubleshooting echo-related issues.

src/components/keyset/KeysetSigner.tsx (1)

20-21: LGTM!

The transition from runtime patching to a centralized polyfill import is a cleaner architecture. The comment clearly explains the purpose, and the .js extension follows the TypeScript ESM requirements specified in the coding guidelines.

The polyfill's silent failure mode (try/catch in nostr.ts) ensures this won't break if nostr-tools changes.

src/cli.tsx (3)

2-2: LGTM!

Importing the nostr polyfill at the CLI entry point ensures the SimplePool patch is applied before any nostr-tools usage. This guarantees consistent filter normalization behavior across the application.


118-122: LGTM!

The short alias mapping follows the established pattern for -t--threshold and -T--total. The cleanup of the short flag prevents duplication.


157-164: LGTM!

The IIFE appropriately initializes IGLOO_DEBUG_ECHO based on the --debug-echo flag after argument parsing but before rendering. This ensures the environment variable is available to all components that check it.

The fallback to (flags as any).debugEcho handles potential camelCase variants gracefully.

@AustinKelsay AustinKelsay merged commit 4d5d643 into master Oct 21, 2025
3 checks passed
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.

1 participant