Fix package root path calculation in rules service#78
Merged
Conversation
- Correct path resolution for built environment (dist/src/rules) - Detect build vs dev environment and adjust path steps accordingly - Update comments to reflect actual build structure close #77
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Package Root Path Calculation in Rules Service
Summary
This PR fixes a critical bug in the
RulesServicewhere the package root path calculation was incorrect for built environments. The service was using a hardcoded 2-step path resolution (../..) which worked for development but failed in production builds where the structure isdist/src/rules/instead ofdist/rules/.Problem
Bug Description
The
RulesServicewas incorrectly calculating the package root path in built environments:Before:
../..(2 steps up) regardless of environmentdist/rules/rules.service.jsdist/src/rules/rules.service.jsImpact:
.ai-rulesdirectoryRoot Cause
The code assumed the build output structure matched the source structure, but TypeScript compilation preserves the
src/directory structure in thedist/output:Solution
Changes Made
Environment Detection
__dirnamecontains/dist/or\dist\(cross-platform)Dynamic Path Resolution
../../..(3 steps up fromdist/src/rules/)../..(2 steps up fromsrc/rules/)Updated Comments
Code Changes
File:
mcp-server/src/rules/rules.service.tsImpact
Before Fix
.ai-rulesdirectoryAfter Fix
Testing
Test Scenarios
Development Environment
src/rules/.ai-rulesdirectory at package rootProduction Build
dist/src/rules/.ai-rulesdirectory at package rootCross-Platform
\dist\detection)/dist/detection)Verification Steps
npm run build.ai-rulesdirectory is found correctlyRelated Issue
Closes #77
Files Changed
mcp-server/src/rules/rules.service.ts- Fixed path calculation logicStatistics
Technical Details
Path Resolution Logic
Environment Detection
The fix uses a simple string check on
__dirname:/dist/(Unix-style paths)\dist\(Windows-style paths)pathmodule operationsNotes
This is a critical fix for production deployments. Without this fix, the MCP server would fail to locate rules files when running from built code, making it unusable in production environments.
The fix maintains backward compatibility with development environments while correctly handling the production build structure.