Skip to content

refactor: extract ama fundamentals into a framework - #224

Merged
didinele merged 3 commits into
mainfrom
refactor/bot-framework
Jul 24, 2026
Merged

refactor: extract ama fundamentals into a framework#224
didinele merged 3 commits into
mainfrom
refactor/bot-framework

Conversation

@didinele

Copy link
Copy Markdown
Member

Closes #217

@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chatsift-website Ready Ready Preview, Comment Jul 24, 2026 6:39pm

@coderabbitai

coderabbitai Bot commented Jul 24, 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 Plus

Run ID: b094a4f8-ebc1-457a-9b8c-834df2bf37a8

📥 Commits

Reviewing files that changed from the base of the PR and between 21b14d5 and b8744e3.

📒 Files selected for processing (1)
  • packages/private/bot-core/src/lib/__tests__/components.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/private/bot-core/src/lib/tests/components.test.ts

📝 Walkthrough

Walkthrough

Changes

The PR extracts reusable Discord bot infrastructure into @chatsift/bot-core, rewires services/ama-bot to use it, adds tests and lint support, updates architecture documentation, and reformats unrelated website and API code without changing behavior.

Bot Core Framework

Layer / File(s) Summary
Package contracts and Discord factories
packages/private/bot-core/*
Adds package metadata, configuration, public exports, REST and gateway factories, and shared deployment wiring.
Registration, dispatch, and client lifecycle
packages/private/bot-core/src/lib/*.ts
Adds caller-provided handler loading, centralized registration, modal collection, injected client creation, interaction routing, and bot-scoped guild syncing.
AMA bot integration
services/ama-bot/*, docs/roadmap/01-architecture.md
Constructs the AMA bot with shared factories, registers handler directories, and imports shared command, component, and modal APIs.
Framework validation and lint support
packages/private/bot-core/src/lib/__tests__/*, eslint.config.js
Adds tests for collection, registration, dispatch, deployment, fixtures, environment setup, and test-specific lint rules.

Formatting Updates

Layer / File(s) Summary
Website JSX and expression formatting
apps/website/src/.../modmail/*, apps/website/src/components/common/*
Reformats JSX, conditional expressions, and category field declarations while preserving behavior.
API type export formatting
services/api/src/index.ts
Reformats the guild type re-export without changing its exported type set.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AmaBotBin
  participant BotCore
  participant AmaBotHandlers
  participant Discord
  AmaBotBin->>BotCore: create REST, gateway, and client
  AmaBotBin->>AmaBotHandlers: register commands and components
  AmaBotBin->>Discord: connect gateway
  Discord->>BotCore: deliver interaction
  BotCore->>AmaBotHandlers: dispatch registered handler
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated formatting-only changes in website, docs, and ESLint config that are outside the AMA framework extraction scope. Split the unrelated website/docs/config formatting changes into separate PRs or remove them from this change set.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: extracting AMA fundamentals into a reusable framework.
Description check ✅ Passed The description is brief but directly references the linked issue and overall purpose of the PR.
Linked Issues check ✅ Passed The changes implement the requested AMA fundamentals framework extraction to reduce duplication for modmail-bot.
✨ 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 refactor/bot-framework

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: 4

🧹 Nitpick comments (1)
packages/private/bot-core/src/lib/components.ts (1)

30-41: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the directory-registration path.

The supplied tests exercise registerComponentHandler() directly, not registerComponentHandlers(). A broken glob, dynamic import, or invalid-default-export check would ship undetected. Add a fixture-based test covering valid and invalid handler modules.

🤖 Prompt for 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.

In `@packages/private/bot-core/src/lib/components.ts` around lines 30 - 41, Extend
test coverage for registerComponentHandlers by creating fixture modules in a
temporary components directory, including valid and invalid default exports.
Exercise directory discovery, dynamic importing, validation, and registration,
and assert valid handlers are registered while invalid modules are skipped.
🤖 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 `@packages/private/bot-core/src/lib/__tests__/commands.test.ts`:
- Around line 94-99: Update the fallback reply assertion in the relevant command
test to verify that the response includes the ephemeral MessageFlags value,
while preserving the existing content assertion and logger warning check.

In `@packages/private/bot-core/src/lib/__tests__/deploy.test.ts`:
- Around line 67-71: Update the fakeReply assertion in the authorization-denial
test to also verify the response is marked ephemeral, while retaining the
existing checks for interaction-1, tok, and the “not authorized” content.

In `@packages/private/bot-core/src/lib/client.ts`:
- Around line 97-99: Update the interval callback around GuildList.set to handle
rejected synchronization promises instead of discarding them: catch failures
from GuildList.set and log them using the client’s existing logging mechanism,
while preserving the existing periodic update behavior.

In `@packages/private/bot-core/src/lib/gateway.ts`:
- Line 26: Update the WebSocketShardEvents.Error callback in the gateway event
handler to accept parameters in WebSocketManager’s emitted order, `(error,
shardId)`, and keep the logger fields mapped to the corresponding values.

---

Nitpick comments:
In `@packages/private/bot-core/src/lib/components.ts`:
- Around line 30-41: Extend test coverage for registerComponentHandlers by
creating fixture modules in a temporary components directory, including valid
and invalid default exports. Exercise directory discovery, dynamic importing,
validation, and registration, and assert valid handlers are registered while
invalid modules are skipped.
🪄 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 Plus

Run ID: 09f9ce22-d696-4b06-a861-8642ad42a88a

📥 Commits

Reviewing files that changed from the base of the PR and between 643ad20 and b48c322.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (44)
  • apps/website/src/api/routes/modmail.ts
  • apps/website/src/app/dashboard/[id]/modmail/blocks/_components/BlockCard.tsx
  • apps/website/src/app/dashboard/[id]/modmail/categories/_components/AddCategoryCard.tsx
  • apps/website/src/app/dashboard/[id]/modmail/categories/_components/CategoryCard.tsx
  • apps/website/src/app/dashboard/[id]/modmail/panels/[panelId]/_components/EditPanelForm.tsx
  • apps/website/src/app/dashboard/[id]/modmail/panels/new/_components/CreatePanelForm.tsx
  • apps/website/src/app/dashboard/[id]/modmail/panels/new/_components/PanelPreview.tsx
  • apps/website/src/app/dashboard/[id]/modmail/snippets/_components/AddSnippetCard.tsx
  • apps/website/src/components/common/EmojiInput.tsx
  • apps/website/src/components/common/ForumTagSelect.tsx
  • docs/roadmap/01-architecture.md
  • eslint.config.js
  • packages/private/bot-core/package.json
  • packages/private/bot-core/src/index.ts
  • packages/private/bot-core/src/lib/__tests__/collector.test.ts
  • packages/private/bot-core/src/lib/__tests__/commands.test.ts
  • packages/private/bot-core/src/lib/__tests__/components.test.ts
  • packages/private/bot-core/src/lib/__tests__/deploy.test.ts
  • packages/private/bot-core/src/lib/__tests__/testEnv.ts
  • packages/private/bot-core/src/lib/client.ts
  • packages/private/bot-core/src/lib/collector.ts
  • packages/private/bot-core/src/lib/commands.ts
  • packages/private/bot-core/src/lib/components.ts
  • packages/private/bot-core/src/lib/deploy.ts
  • packages/private/bot-core/src/lib/gateway.ts
  • packages/private/bot-core/src/lib/rest.ts
  • packages/private/bot-core/tsconfig.eslint.json
  • packages/private/bot-core/tsconfig.json
  • packages/private/bot-core/vitest.config.ts
  • services/ama-bot/package.json
  • services/ama-bot/src/bin.ts
  • services/ama-bot/src/commands/ama.ts
  • services/ama-bot/src/components/amaEndSelect.ts
  • services/ama-bot/src/components/amaRepostSelect.ts
  • services/ama-bot/src/components/guestApprove.ts
  • services/ama-bot/src/components/guestSkip.ts
  • services/ama-bot/src/components/modApprove.ts
  • services/ama-bot/src/components/modDeny.ts
  • services/ama-bot/src/components/modFlag.ts
  • services/ama-bot/src/components/submitQuestion.ts
  • services/ama-bot/src/index.ts
  • services/ama-bot/src/lib/gateway.ts
  • services/ama-bot/src/lib/rest.ts
  • services/api/src/index.ts
💤 Files with no reviewable changes (2)
  • services/ama-bot/src/lib/gateway.ts
  • services/ama-bot/src/lib/rest.ts

Comment thread packages/private/bot-core/src/lib/__tests__/commands.test.ts
Comment thread packages/private/bot-core/src/lib/__tests__/deploy.test.ts
Comment thread packages/private/bot-core/src/lib/client.ts
Comment thread packages/private/bot-core/src/lib/gateway.ts Outdated

@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 `@packages/private/bot-core/src/lib/__tests__/components.test.ts`:
- Around line 96-102: Reset the imported fixture’s calls array before invoking
handleComponentInteraction by setting calls.length to zero after importing
validComponent.js. Keep the existing assertion that the handler records exactly
one call with the expected interaction, logger, and state.
🪄 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 Plus

Run ID: 14dead25-96a0-43dc-ab01-6d8f0c1cdb27

📥 Commits

Reviewing files that changed from the base of the PR and between b48c322 and 21b14d5.

📒 Files selected for processing (8)
  • packages/private/bot-core/src/lib/__tests__/commands.test.ts
  • packages/private/bot-core/src/lib/__tests__/components.test.ts
  • packages/private/bot-core/src/lib/__tests__/deploy.test.ts
  • packages/private/bot-core/src/lib/__tests__/fixtures/invalidComponent.js
  • packages/private/bot-core/src/lib/__tests__/fixtures/validComponent.d.ts
  • packages/private/bot-core/src/lib/__tests__/fixtures/validComponent.js
  • packages/private/bot-core/src/lib/client.ts
  • packages/private/bot-core/src/lib/gateway.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/private/bot-core/src/lib/gateway.ts
  • packages/private/bot-core/src/lib/tests/deploy.test.ts
  • packages/private/bot-core/src/lib/tests/commands.test.ts
  • packages/private/bot-core/src/lib/client.ts

Comment thread packages/private/bot-core/src/lib/__tests__/components.test.ts
@didinele
didinele merged commit f52e627 into main Jul 24, 2026
6 checks passed
@didinele
didinele deleted the refactor/bot-framework branch July 24, 2026 18:40
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.

Framework-ify the basics we've put down in AMA bot

1 participant