Skip to content

fix(cli): properly parse project name on windows#5184

Merged
MichaelDoyle merged 2 commits intogenkit-ai:mainfrom
CatoPaus:main
Apr 27, 2026
Merged

fix(cli): properly parse project name on windows#5184
MichaelDoyle merged 2 commits intogenkit-ai:mainfrom
CatoPaus:main

Conversation

@CatoPaus
Copy link
Copy Markdown
Contributor

Issue Description

Describe the bug
When launching the Genkit Developer UI (genkit start) on a Windows machine without explicitly specifying a name inside genkit({ ... }), the Developer UI displays "unknown" for the project name (and falls back to something like unknown (1234-3100)).

This happens because projectNameFromGenkitFilePath inside @genkit-ai/tools-common relies on splitting the .genkit runtime file path using a hardcoded forward slash (/). Because Windows file paths predominantly use backslashes (\), the function fails to locate the .genkit directory in the path string, resulting in the fallback "unknown".

To Reproduce

  1. Initialize a Genkit project on a Windows machine.
  2. Ensure you have not explicitly provided a name property to your genkit() initialization.
  3. Start the dev server using genkit start -- tsx --watch backend/index.ts.
  4. Open the Developer UI and observe that the app name defaults to unknown instead of the actual project directory or package name.

Expected behavior
The Developer UI should correctly parse the project name from the file path on Windows exactly as it does on macOS and Linux.

Proposed Fix
Updating projectNameFromGenkitFilePath to split the file path using a regular expression that accounts for both forward slashes and backslashes /[/\\]/ resolves this issue entirely and remains safely cross-platform.

File: @genkit-ai/tools-common/src/utils/utils.ts

Current Code:

export function projectNameFromGenkitFilePath(filePath: string) {
  const parts = filePath.split('/'); // <-- Fails on Windows
  const basePath = parts
    .slice(0, Math.max(parts.findIndex((value) => value === '.genkit'), 0))
    .join('/');
  return basePath === '' ? 'unknown' : path.basename(basePath);
}

Proposed Code:

export function projectNameFromGenkitFilePath(filePath: string) {
  const parts = filePath.split(/[/\\]/); // <-- Supports Windows & POSIX
  const basePath = parts
    .slice(0, Math.max(parts.findIndex((value) => value === '.genkit'), 0))
    .join('/');
  return basePath === '' ? 'unknown' : path.basename(basePath);
}

Updated file path splitting to support both Windows and POSIX formats.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the projectNameFromGenkitFilePath function to support both Windows and POSIX path separators. A potential issue was identified where splitting by backslashes on POSIX systems could lead to incorrect results if a filename contains a backslash. It is recommended to use path.sep to determine the appropriate separator for the current operating system.

Comment thread genkit-tools/common/src/utils/utils.ts Outdated
@MichaelDoyle
Copy link
Copy Markdown
Contributor

@CatoPaus thank you!! if you can apply the gemini suggestion above to use path.sep instead, we'll merge this in.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@MichaelDoyle MichaelDoyle changed the title Bug: Developer UI fails to detect project name on Windows due to path parsing issue fix(cli): properly parse project name on windows Apr 26, 2026
@MichaelDoyle
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the projectNameFromGenkitFilePath function in genkit-tools/common/src/utils/utils.ts to use path.sep instead of a hardcoded forward slash when splitting file paths, which improves cross-platform compatibility. I have no feedback to provide.

@MichaelDoyle MichaelDoyle merged commit 4ee4cdb into genkit-ai:main Apr 27, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants