Skip to content

Conversation

@jack-arturo
Copy link
Contributor

@jack-arturo jack-arturo commented Jul 24, 2025

Replaced usage of URL and import.meta.url.pathname with fileURLToPath for consistent file path resolution in Provider and promptLoader modules. This improves compatibility across environments and fixes issues with locating config files (i.e. when using LocalWP and running WordPress in ~/Local Sites/)

Summary by CodeRabbit

  • Refactor

    • Improved internal file-path resolution used when loading provider pricing, system prompts, and other runtime resources for more reliable cross-platform behavior. No user-facing API changes.
  • Tests

    • Updated internal test utilities to use the improved path-resolution approach.

Replaced usage of URL and import.meta.url.pathname with fileURLToPath for consistent file path resolution in Provider and promptLoader modules. This improves compatibility across environments and fixes issues with locating config files.
@coderabbitai
Copy link

coderabbitai bot commented Jul 24, 2025

Walkthrough

Replaced URL->pathname conversions with file-system-safe conversions using fileURLToPath(import.meta.url) across multiple modules to resolve current module directories for locating config and prompt files. No public APIs or control flow were changed.

Changes

Cohort / File(s) Change Summary
Providers
src/providers/base/Provider.js
Switched module directory resolution to path.dirname(fileURLToPath(import.meta.url)) and updated pricing file path construction to use path.resolve/path.join.
Utilities
src/utils/promptLoader.js, src/utils/costTracker.js
Replaced new URL(import.meta.url).pathname with fileURLToPath(import.meta.url) when computing currentDir to reliably locate prompt and pricing files.
Tools / Tests
tools/ab-prompt-test
Replaced URL pathname usage with fileURLToPath(import.meta.url) in top-level load and testTranslation dictionary path resolution.

Sequence Diagram(s)

(Skipped — changes are local path-resolution adjustments; control flow unchanged.)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit found a clearer track,
From URL crumbs it turned back.
fileURLToPath lights the way,
Config and prompts no longer stray.
Hop on, small fixes, saved the day 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/providers/base/Provider.js (1)

46-47: LGTM: Improved file path resolution with minor suggestion for robustness.

The change to use fileURLToPath(import.meta.url) with path.dirname and path.resolve correctly addresses the cross-platform file path resolution issues. This is consistent with the changes in src/utils/promptLoader.js.

Consider making the path construction more robust by using fewer relative path traversals.

-		const currentDir = path.dirname(fileURLToPath(import.meta.url));
-		const pricingPath = path.resolve(currentDir, '..', '..', '..', 'config', `${providerName}-pricing.json`);
+		const currentDir = path.dirname(fileURLToPath(import.meta.url));
+		const configDir = path.resolve(currentDir, '../../../config');
+		const pricingPath = path.join(configDir, `${providerName}-pricing.json`);

This approach separates the config directory resolution from the filename construction, making it clearer and slightly more maintainable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b12317 and 67763a3.

📒 Files selected for processing (2)
  • src/providers/base/Provider.js (2 hunks)
  • src/utils/promptLoader.js (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/providers/base/Provider.js (2)
src/utils/promptLoader.js (1)
  • currentDir (53-53)
src/utils/costTracker.js (1)
  • currentDir (59-59)
src/utils/promptLoader.js (1)
src/utils/costTracker.js (1)
  • currentDir (59-59)
🔇 Additional comments (2)
src/utils/promptLoader.js (1)

11-11: LGTM: Proper import added for cross-platform compatibility.

The import of fileURLToPath from the 'url' module is correct and necessary for the improved file path resolution.

src/providers/base/Provider.js (1)

2-3: LGTM: Proper imports added for improved file path resolution.

The addition of path and fileURLToPath imports is correct and necessary for the cross-platform file path resolution improvements.

export function buildSystemPrompt(targetLang, sourceLang = 'English', promptFilePath = null) {
if (!promptFilePath) {
const currentDir = path.dirname(new URL(import.meta.url).pathname);
const currentDir = path.dirname(fileURLToPath(import.meta.url));
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

LGTM: Improved file path resolution for cross-platform compatibility.

The change from new URL(import.meta.url).pathname to fileURLToPath(import.meta.url) is correct and addresses the file path resolution issues mentioned in the PR objectives. This is particularly important for Windows environments where URL pathname handling can be problematic.

However, ensure consistency across the codebase with similar patterns.


🏁 Script executed:

#!/bin/bash
# Description: Check for remaining usage of the old URL pattern that should be updated for consistency
# Expected: Find any remaining instances that might need similar updates

echo "Searching for remaining instances of 'new URL(import.meta.url).pathname' pattern:"
rg -n "new URL\(import\.meta\.url\)\.pathname" --type js

echo -e "\nSearching for any URL-based path resolution patterns:"
rg -n "import\.meta\.url.*pathname" --type js

Length of output: 604


Update remaining file path resolution for cross-platform consistency

The change to fileURLToPath(import.meta.url) correctly addresses Windows pathname issues and should be applied uniformly.

• In src/utils/costTracker.js (line 59), replace the old URL-based pattern:

- const currentDir = path.dirname(new URL(import.meta.url).pathname);
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/utils/costTracker.js at line 59, update the file path resolution to use
path.dirname(fileURLToPath(import.meta.url)) instead of the old URL-based
pattern to ensure cross-platform consistency, especially on Windows. Replace the
existing code with this new pattern to standardize path handling.

@mrcasual mrcasual self-assigned this Jul 25, 2025
@mrcasual mrcasual added the enhancement New feature or request label Jul 25, 2025
@mrcasual mrcasual changed the base branch from main to develop August 20, 2025 16:29
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/utils/costTracker.js (1)

63-67: Minor: prefer path.join arguments over embedded slashes

Not a functional issue (Node handles forward slashes on Windows), but using path.join/readable resolve improves consistency and avoids accidental double-slashes.

Apply:

-const jsonPath = path.resolve(currentDir, `../../config/${providerName}-pricing.json`);
+const jsonPath = path.resolve(currentDir, '../../config', `${providerName}-pricing.json`);

-const fallbackPath = path.resolve(process.cwd(), `config/${providerName}-pricing.json`);
+const fallbackPath = path.join(process.cwd(), 'config', `${providerName}-pricing.json`);
tools/ab-prompt-test (3)

160-162: Good: use fileURLToPath(import.meta.url) to locate config

This fixes failures when running from paths with spaces (e.g., LocalWP’s “Local Sites”). Optional DRY improvement below.

To avoid recomputing the same directory multiple times, define a single constant once near the imports and reuse it:

-const currentDir = path.dirname(fileURLToPath(import.meta.url));
-const configPath = path.resolve(currentDir, '../config/openai-pricing.json');
+const configPath = path.resolve(CURRENT_DIR, '../config/openai-pricing.json');

Add near the top (outside this hunk):

// At top-level after imports
const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url));

284-286: Good: dictionary directory now resolves correctly on Windows

Same benefit here; consider reusing a shared CURRENT_DIR constant to reduce duplication.

Apply:

-const currentDir = path.dirname(fileURLToPath(import.meta.url));
-const dictionaryDir = currentDir; // Look for dictionary files in tools directory.
+const dictionaryDir = CURRENT_DIR; // Look for dictionary files in tools directory.

Add once at top-level (if not added already):

const CURRENT_DIR = path.dirname(fileURLToPath(import.meta.url));

623-623: Typo: “sgavings” → “savings”

Minor copy fix for console output.

- console.log(chalk.green(`  💰 Total sgavings: $${formatPrice(savings1000)}`));
+ console.log(chalk.green(`  💰 Total savings: $${formatPrice(savings1000)}`));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 67763a3 and ec4c42a.

📒 Files selected for processing (3)
  • src/providers/base/Provider.js (2 hunks)
  • src/utils/costTracker.js (2 hunks)
  • tools/ab-prompt-test (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/providers/base/Provider.js
🔇 Additional comments (3)
src/utils/costTracker.js (2)

60-60: Correct: derive module dir via fileURLToPath(import.meta.url)

This is the right way to compute the directory across environments; it fixes spaces/Unicode and Windows drive-letter quirks.


3-3: All clear: no URL.pathname usages remain — approved
Verified with ripgrep: zero matches for new URL(import.meta.url).pathname or import.meta.url.pathname. Using fileURLToPath now ensures ESM-safe, cross-platform path handling.

tools/ab-prompt-test (1)

8-8: Importing fileURLToPath is appropriate for ESM path resolution

This aligns with the PR objective to resolve config/dictionary files reliably on Windows and other environments.

@mrcasual mrcasual merged commit 6221278 into GravityKit:develop Aug 20, 2025
2 checks passed
@mrcasual
Copy link
Contributor

Thanks, @jack-arturo, and sorry it took me some time to review/merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants