Skip to content

Discord news integration: finny_discord_read tool + community link - #15

Merged
Jaiminp007 merged 1 commit into
devfrom
discord-news-integration
May 7, 2026
Merged

Jaiminp007 merged 1 commit into
devfrom
discord-news-integration

Conversation

@Jaiminp007

Copy link
Copy Markdown
Collaborator

Summary

  • Adds finny_discord_read, a native OpenCode tool that fetches the latest N posts from a curated Finny Discord news channel and returns clean {title, excerpt, url, timestamp} triples Finny can reason over. Eight channels wired up: trump, options-flow, dark-pool, china-us-news, market-news, congressional-trades, fed-fomc, fed-speakers.
  • Repurposes the TUI sidebar's bottom "Feedback" item to "Discord" (opens the community invite). The web feedback page is gone; community support lives in Discord now.
  • Hardens @finny-ai/integrations packaging so a stray .env can't ride into a tarball, and removes 21 unmaintained non-English READMEs.

Why

When asked something like "check on Trump's recent movements and sketch an algo," Finny was scraping Truth Social directly via WebFetch and failing. MonitoRSS already mirrors curated RSS feeds into our Discord channels in a structured form — reading them via Discord's REST API gives Finny grounded, dated context with source links it can cite.

What's in the diff

Tool runtime (packages/opencode/src/tool/discord.ts) — a Tool.define-style implementation registered in registry.ts. Parses both legacy embeds (Politico, SCMP, Fed press releases) and Discord's new Components V2 layout (MonitoRSS Trump posts use this). Pulls DISCORD_BOT_TOKEN and DISCORD_CHANNEL_* from process.env, falling back to ~/.finny/discord.env so the secret stays out of the repo and survives different launch cwds.

TUI sidebar (packages/opencode/src/cli/cmd/tui/component/sidebar-nav.tsx) — bottom-left "Feedback" item becomes "Discord", opens https://discord.gg/Y68pqQju8 via open().

Packaging (packages/finny-integrations/) — adds .npmignore excluding .env*, *.pem, *.key, *.p12, plus a files allowlist in package.json that ships only src/ and .env.example. Verified with bun pm pack --dry-run — no .env in the tarball.

Cleanup — drops 21 stale README.<locale>.md files (no internal links pointed at them).

Security notes

  • DISCORD_BOT_TOKEN only ever lives in env / ~/.finny/discord.env (mode 600, gitignored). Never committed, never logged, never echoed in errors (HTTP error path explicitly redacts the token if Discord ever returns it in a body).
  • Channel IDs are validated as 17-20 digit Discord snowflakes before any HTTP call — defense in depth so a misconfigured env var can't smuggle path segments into the outbound URL.
  • Bot is on a minimal Finny Bot role with only View Channels + Read Message History. No write/admin permissions.
  • Tool channel parameter is constrained to a Zod enum of the 8 allow-listed names — defense in depth at the schema layer.

Test plan

  • Pull the branch, run `bun install` (lockfile changes are just removing a stale `packages/schedule-status` workspace).
  • Set up `~/.finny/discord.env` with `DISCORD_BOT_TOKEN` + the eight `DISCORD_CHANNEL_*` IDs.
  • Start the TUI; ask Finny to read the last 3 posts from the trump channel. Confirm Finny calls `finny_discord_read` (not WebFetch) and returns title/excerpt/url per post.
  • Ask Finny to pull fed-fomc + fed-speakers and synthesize Fed signaling. Confirm two tool calls in sequence.
  • Hit an unknown channel name and confirm the tool returns a clean error listing known channels.
  • Sidebar: confirm bottom-left button reads Discord and opens https://discord.gg/Y68pqQju8.
  • `cd packages/finny-integrations && bun pm pack --dry-run` — confirm `.env` is not in the file list.
  • `bun run --filter 'finny' typecheck` and `bun run --filter '@finny-ai/integrations' typecheck` pass.

Out of scope (intentional)

  • No two-way Discord listener. Read-only fetch only.
  • No persistent caching; each tool call hits Discord live.
  • No filtering at fetch time — relevance ranking is the LLM's job.

Add finny_discord_read tool so Finny can read MonitoRSS-mirrored news
from a curated set of Discord channels (trump, options-flow, dark-pool,
china-us-news, market-news, congressional-trades, fed-fomc, fed-speakers)
and ground answers in current events when sketching algos.

Why: scraping Truth Social / SCMP / Fed press pages directly is brittle
and rate-limited. MonitoRSS already aggregates these feeds into a single
channel surface; reading them via Discord's REST API gives Finny clean,
structured headline+excerpt+url triples plus timestamps.

Notes:
- Tool reads from process.env, falling back to ~/.finny/discord.env so
  the secret stays outside the repo and survives different launch cwds.
- Channel IDs are validated as Discord snowflakes before any HTTP call,
  and the bot token is redacted from any error message echoed back.
- Swap the TUI sidebar's Feedback button to point at the Discord invite
  (the community is now the support surface).
- Add .npmignore + files allowlist on @finny-ai/integrations so .env
  can't ride into a tarball even if private:true is ever flipped off.
- Drop the unmaintained non-English READMEs.
Copilot AI review requested due to automatic review settings May 7, 2026 19:57
@Jaiminp007
Jaiminp007 merged commit 18e8eae into dev May 7, 2026
3 of 4 checks passed
@Jaiminp007
Jaiminp007 removed the request for review from Copilot May 7, 2026 20:20
spandanniroula pushed a commit to spandanniroula/finny that referenced this pull request Jun 12, 2026
Fixes all 17 Copilot comments:

Telemetry opt-out (polarline-markets#1, polarline-markets#2, polarline-markets#3, polarline-markets#9, polarline-markets#16):
- tracker.ts now reads FINNY_TELEMETRY=0 / OPENCODE_TELEMETRY=0 at module
  load, so the opt-out applies in every entrypoint (TUI worker, server,
  CLI), not just the bootstrap path.
- Email dialog auto-prompt and /subscribe slash command also gated on
  Analytics.isEnabled() — email POST goes to the same Convex deployment.

Tracker correctness (polarline-markets#5, polarline-markets#14, polarline-markets#17):
- drain() now also waits for the DeviceProfile.userId() resolution promise,
  not just the post-send promise.
- worker rpc.shutdown() and main-thread thread.ts both call
  Analytics.drain() before tearing down — neither beforeExit nor SIGTERM
  fire on worker.terminate() / process.exit(0).
- beforeExit handler runs at most once per process, preventing an infinite
  drain loop when a hung telemetry request later resolves and re-empties
  the loop.

Privacy (polarline-markets#10, polarline-markets#11, polarline-markets#12):
- Drop process.argv from tui.worker.booted (could include --prompt text
  and project paths).
- error.surfaced now sends only error.name; error messages frequently
  embed user prompt content and local file paths.
- Don't persist the submitted email address to local KV (no reader, just
  unnecessary PII retention).

Email dialog state machine (polarline-markets#4, polarline-markets#6, polarline-markets#8):
- Wait for kv.ready before evaluating the prompt gate so we don't re-show
  the dialog to users who already submitted/skipped.
- Conditional dismiss handler — only marks "skipped" when no terminal
  status has been set, so a successful submit isn't overwritten by the
  dismiss callback that fires on dialog.clear() and isn't suppressed by
  another dialog replacing this one.

Server-side validation (polarline-markets#15):
- subscribe mutation now rejects empty / oversized / regex-failing emails
  with a ConvexError, so the public Convex client can't bypass the TUI
  regex.

Command coverage (polarline-markets#13):
- Hook Analytics.track() in DialogCommand.trigger() instead of the bus
  event handler. trigger() is the central activation point for palette,
  slash, keybind, plugin, and bus paths — single hook, full coverage,
  no double-counting.

Comment wording (polarline-markets#7):
- bootstrap.ts: "opt-in by default" → "enabled by default" (correct
  description of opt-out semantics).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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