Skip to content

refactor: optimize ;run command and expand its judge0 language alias map#34

Merged
calebephrem merged 1 commit into
open-devhub:mainfrom
calebephrem:main
Jul 7, 2026
Merged

refactor: optimize ;run command and expand its judge0 language alias map#34
calebephrem merged 1 commit into
open-devhub:mainfrom
calebephrem:main

Conversation

@calebephrem

Copy link
Copy Markdown
Member

…s map

@devhub-bot devhub-bot Bot added the refactor code restructure label Jul 7, 2026
@beetle-ai

beetle-ai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary by Beetle

This PR refactors the ;run command to significantly improve language detection and code execution reliability. The primary enhancement is the introduction of a comprehensive canonical language alias mapping system that replaces the previous limited alias dictionary. This change enables the bot to recognize a much wider variety of language names and aliases (e.g., py, python2, python3, pyml all map to Python), making the command more user-friendly and robust. Additionally, the refactor includes code cleanup by removing commented-out code and improving type safety with proper TypeScript generics.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
src/commands/code/run.ts Modified +85/-42 Replaced simple alias dictionary with comprehensive CANONICAL_GROUPS mapping system covering 40+ programming languages with multiple aliases each. Refactored findLanguageId() function to use canonical name resolution with exact and fuzzy matching. Removed commented-out code blocks and improved TypeScript type safety with ActionRowBuilder<ButtonBuilder> generic.

Total Changes: 1 file changed, +85 additions, -42 deletions

🗺️ Walkthrough:

graph TD
A["User invokes ;run command"] --> B["Parse code block and language"]
B --> C["Clean input: lowercase, remove special chars"]
C --> D{"Check ALIAS_MAP"}
D -->|"Found"| E["Map to canonical name"]
D -->|"Not found"| F["Use input as-is"]
E --> G["Search Judge0 languages"]
F --> G
G --> H{"Exact match?"}
H -->|"Yes"| I["Return language ID"]
H -->|"No"| J["Fuzzy match search"]
J --> K{"Fuzzy match found?"}
K -->|"Yes"| I
K -->|"No"| L["Return null"]
I --> M["Execute code via Judge0 API"]
M --> N["Display results with embed"]
CANON["CANONICAL_GROUPS: 40+ languages Each with multiple aliases Example: python → py, py2, py3, pyml"]
D -.-> CANON
Loading

🎯 Key Changes:

  • Comprehensive Language Alias System: Introduced CANONICAL_GROUPS object mapping 40+ programming languages to their common aliases (e.g., Python recognizes python, py, python2, python3, py2, py3, pythonml, pyml, mlpy)
  • Improved Language Resolution: Refactored findLanguageId() to use a two-stage matching process: exact canonical name match first, then fuzzy matching as fallback
  • Enhanced Input Normalization: Added robust input cleaning that removes backticks, spaces, hyphens, and underscores before matching
  • Code Quality Improvements: Removed multiple blocks of commented-out code (stdout/stderr field additions) and improved TypeScript type safety with proper generics
  • Better Maintainability: Centralized alias management makes it easy to add new language aliases without modifying the matching logic

📊 Impact Assessment:

  • Security: ✅ No security concerns introduced. The refactor maintains the existing Judge0 API integration without adding new external dependencies or changing authentication flows. Input sanitization is improved through better normalization.
  • Performance: ✅ Slight improvement expected. The pre-computed ALIAS_MAP (built once at module load) provides O(1) lookup time for alias resolution, replacing the previous linear search through a small dictionary. The two-stage matching (exact then fuzzy) optimizes for common cases while maintaining fallback support.
  • Maintainability: ✅✅ Significantly improved. The CANONICAL_GROUPS structure is self-documenting and makes it trivial to add new language aliases. Removing 20+ lines of commented code reduces noise. The explicit typing with ActionRowBuilder<ButtonBuilder> prevents type errors at compile time. The separation of concerns (alias mapping → canonical resolution → language lookup) makes the code easier to understand and test.
  • Testing: ⚠️ No test changes included in this PR. Recommend adding unit tests for:
  • Alias resolution edge cases (e.g., c++, c#, f# with special characters)
  • Case insensitivity verification across all 40+ languages
  • Fuzzy matching behavior with partial matches
  • Null handling for invalid language inputs
⚙️ 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

@calebephrem calebephrem changed the title refactor: optimize ;run command and expand its judge0 language alia… refactor: optimize ;run command and expand its judge0 language alias map Jul 7, 2026
@beetle-ai

beetle-ai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

✅ You're good to merge this PR! No issues found. Great job!

Settings
⚙️ 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

@devhub-bot

devhub-bot Bot commented Jul 7, 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 27b779c into open-devhub:main Jul 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor code restructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant