Skip to content

feat: replace latex-to-unicode with @devhub-io/latex-to-unicode#35

Merged
calebephrem merged 5 commits into
open-devhub:mainfrom
calebephrem:main
Jul 13, 2026
Merged

feat: replace latex-to-unicode with @devhub-io/latex-to-unicode#35
calebephrem merged 5 commits into
open-devhub:mainfrom
calebephrem:main

Conversation

@calebephrem

Copy link
Copy Markdown
Member
  • Replace latex-to-unicode package with @devhub-io/latex-to-unicode (open-devhub/latex-to-unicode)
  • Add dev mode check on all messageCreate event files
  • clear context every 1 hr instead of 30 mins
  • update system prompts

@devhub-bot devhub-bot Bot added chore maintenance, configs, formatting, dependencies feat New feature fix Bug fix labels Jul 13, 2026
@beetle-ai

beetle-ai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR contains a series of maintenance and configuration updates to the Rael Discord bot project. The changes span five commits that collectively: (1) refine system prompts for clarity and accuracy, (2) add dev mode checks across message event handlers to restrict functionality during development, (3) optimize context clearing intervals, (4) downgrade and update dependencies for compatibility, and (5) replace a deprecated LaTeX-to-Unicode library with a maintained alternative. These are primarily housekeeping and stability improvements rather than feature additions.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/prompts/base.ts Modified +2/-2 Updated system prompt wording: changed "Never" to "NEVER" for emphasis on security rules, and changed "do not announce" to "do NOT announce" for consistency in tool usage instructions.
src/prompts/info.ts Modified +1/-1 Corrected creator attribution: removed clarification about underscore in Aditya's username (reverted back to original format after initial correction).
src/events/messageCreate/aiMode.ts Modified +7/-3 Added dev mode check: imports devs from config, adds null safety checks for message/guild, and restricts AI mode to dev users when NODE_ENV is "dev".
src/events/messageCreate/handleCommands.ts Modified +1/-1 Enhanced null safety: added !client.user check to existing validation logic for message event handling.
src/events/messageCreate/mention.ts Modified +10/-2 Added dev mode check: imports config and devs list, adds comprehensive null safety checks, and restricts mention-based AI responses to dev users during development.
src/utils/context.ts Modified +2/-2 Increased context clearing interval from 30 minutes to 1 hour (1800000ms to 3600000ms) and updated console log message accordingly.
bun.lock Modified +27/-19 Updated dependency lock file: downgraded @ai-sdk/groq (4.0.2→2.0.43), ai (7.0.8→6.0.224), @types/node (26.0.1→24.13.3), typescript (6.0.3→5.9.3); added @devhub-io/latex-to-unicode (2.0.1); removed latex-to-unicode (0.1.0).
package.json Modified +5/-5 Updated dependency versions: downgraded @ai-sdk/groq to ^2.0.0, ai to ^6.0.0, @types/node to ^24.0.15, typescript to ^5.9.2; added @devhub-io/latex-to-unicode ^2.0.1; removed latex-to-unicode ^0.1.0.
src/declarations/ltu.d.ts Deleted +0/-4 Removed TypeScript declaration file for the old latex-to-unicode module (no longer needed with the new typed package).
src/utils/pretty.ts Modified +1/-1 Updated import statement: changed from default import of latex-to-unicode to named import from @devhub-io/latex-to-unicode.

Total Changes: 10 files changed, +56 additions, -40 deletions

🗺️ Walkthrough:

graph TD
A["Message Event Received"] --> B{"Dev Mode Enabled?"}
B -->|Yes| C{"User is Dev?"}
C -->|No| D["Return Early"]
C -->|Yes| E["Process Message"]
B -->|No| E
E --> F{"Message Type?"}
F -->|AI Mode Prefix| G["Execute AI Mode"]
F -->|Bot Mention| H["Execute Mention Handler"]
F -->|Command| I["Execute Command"]
G --> J["Get/Clear Context"]
H --> J
I --> J
J --> K["Context Cleared Every 1 Hour"]
G --> L["Format with LaTeX-to-Unicode"]
H --> L
L --> M["Send Response"]
Loading

🎯 Key Changes:

  • Prompt Refinements: Enhanced system prompt clarity by capitalizing "NEVER" for security emphasis and standardizing tool usage language ("do NOT" instead of "do not").
  • Dev Mode Enforcement: Added comprehensive dev mode checks across three message event handlers (aiMode.ts, mention.ts, handleCommands.ts) to restrict bot functionality to authorized developers during development, preventing unintended public interactions.
  • Context Management Optimization: Extended conversation context clearing interval from 30 minutes to 1 hour, reducing memory churn and allowing longer conversation histories before reset.
  • Dependency Modernization: Downgraded AI SDK packages (@ai-sdk/groq, ai) and TypeScript tooling to more stable versions, likely addressing compatibility issues with the current codebase.
  • Library Migration: Replaced unmaintained latex-to-unicode package with @devhub-io/latex-to-unicode (v2.0.1), a maintained alternative with proper TypeScript support, eliminating the need for manual type declarations.
  • Null Safety Improvements: Enhanced defensive programming by adding explicit null checks for message, message.guild, and client.user across event handlers.

📊 Impact Assessment:

  • Security: ✅ Positive - Dev mode checks prevent accidental bot responses in production during development. Prompt emphasis on "NEVER" for security rules reinforces safety-critical instructions. No new vulnerabilities introduced.
  • Performance: ✅ Positive - Extending context clearing from 30 to 60 minutes reduces garbage collection frequency and memory allocation overhead. Dependency downgrades may improve bundle size and startup time.
  • Maintainability: ✅ Positive - Replacing unmaintained latex-to-unicode with @devhub-io/latex-to-unicode improves long-term sustainability. Removal of manual type declarations (ltu.d.ts) reduces maintenance burden. Consistent null safety checks improve code robustness.
  • Testing: ⚠️ Requires Attention - Dev mode checks need testing to ensure: (1) dev users can still trigger all handlers, (2) non-dev users are properly blocked during dev mode, (3) production mode (NODE_ENV not "dev") allows all users. Context clearing interval change should be validated with load testing. Dependency downgrades require regression testing to ensure no API breaking changes.
⚙️ Settings

Severity Threshold: Medium — Balanced feedback — medium and high severity issues only.Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

if (!message || !message.guild || message.author.bot) return;
if (
process.env.NODE_ENV?.toLowerCase() === "dev" &&
!devs.includes(message.author.id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code calls devs.includes() without verifying that devs is actually an array. If the devs property is missing, undefined, or not an array in the config, this will throw a runtime error: TypeError: devs.includes is not a function.

Confidence: 4/5

Suggested Fix
Suggested change
!devs.includes(message.author.id)
Array.isArray(devs) && !devs.includes(message.author.id)

Add a type check to ensure devs is an array before calling .includes(). This prevents runtime errors if the config is malformed or missing the devs property.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/messageCreate/aiMode.ts around line 12, the code calls devs.includes()
without verifying that devs is an array; this will throw a runtime error if devs is
undefined or not an array. Add a type check using Array.isArray(devs) before calling
.includes() to safely handle cases where the config might be malformed or missing the
devs property.


export default async (client: Client, message: Message) => {
if (!message || !message.guild || message.author?.bot) return;
if (!message || !message.guild || message.author.bot || !client.user) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Removing optional chaining from message.author?.bot to message.author.bot introduces a potential runtime error. If message.author is null or undefined, accessing the .bot property will throw TypeError: Cannot read property 'bot' of null/undefined. The optional chaining was there for defensive programming to safely handle edge cases in the Discord.js API.

Confidence: 4/5

Suggested Fix
Suggested change
if (!message || !message.guild || message.author.bot || !client.user) return;
if (!message || !message.guild || message.author?.bot || !client.user) return;

Restore the optional chaining operator (?.) on message.author?.bot to safely handle cases where message.author might be null or undefined, while keeping the new !client.user check.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/messageCreate/handleCommands.ts around line 17, the code removes optional
chaining from message.author?.bot to message.author.bot; this will throw a runtime error
if message.author is null or undefined. Restore the optional chaining operator (?.bot)
to safely handle edge cases where the author property might not exist, while keeping the
new !client.user check that was added.


if (
process.env.NODE_ENV?.toLowerCase() === "dev" &&
!devs.includes(message.author.id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The code calls devs.includes() without verifying that devs is actually an array. If the devs property is missing, undefined, or not an array in the config, this will throw a runtime error: TypeError: devs.includes is not a function.

Confidence: 4/5

Suggested Fix
Suggested change
!devs.includes(message.author.id)
Array.isArray(devs) && !devs.includes(message.author.id)

Add a type check to ensure devs is an array before calling .includes(). This prevents runtime errors if the config is malformed or missing the devs property.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/messageCreate/mention.ts around line 13, the code calls devs.includes()
without verifying that devs is an array; this will throw a runtime error if devs is
undefined or not an array. Add a type check using Array.isArray(devs) before calling
.includes() to safely handle cases where the config might be malformed or missing the
devs property.

export default async (client: Client, message: Message) => {
if (message.author.bot) return;
if (!client.user) return;
if (!message || !message.guild || message.author.bot || !client.user) return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The guard clause accesses message.author.bot without optional chaining. If message.author is null or undefined, this will throw TypeError: Cannot read property 'bot' of null/undefined. The condition should use optional chaining to safely handle edge cases where the author property might not exist.

Confidence: 4/5

Suggested Fix
Suggested change
if (!message || !message.guild || message.author.bot || !client.user) return;
if (!message || !message.guild || message.author?.bot || !client.user) return;

Use optional chaining (?.) on message.author?.bot to safely handle cases where message.author might be null or undefined.

Prompt for AI

Copy this prompt to your AI IDE to fix this issue locally:

In src/events/messageCreate/mention.ts around line 9, the code accesses message.author.bot
without optional chaining; this will throw a runtime error if message.author is null or
undefined. Add the optional chaining operator (?.bot) to safely handle edge cases where
the author property might not exist.

@devhub-bot

devhub-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Note

Linting checks passed successfully 🎉

All formatting and code quality checks are clean.

You're good to merge 🚀

@calebephrem
calebephrem merged commit 497af44 into open-devhub:main Jul 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore maintenance, configs, formatting, dependencies feat New feature fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant