Skip to content

fix(project): map Windows drive-root basename to unknown in MCP detection #659

Description

@dnlrsls

📋 Pre-flight Checks

  • I have searched existing issues and this is not a duplicate
  • I understand this issue needs status:approved before a PR can be opened

📝 Bug Description

On Windows, starting engram mcp with the process current working directory at a drive root (C:\) causes Go project auto-detection to return a backslash as the project name. That value is rejected when supplied explicitly to mem_save, creating an inconsistent MCP contract.

🔄 Steps to Reproduce

  1. On Windows, start engram mcp with process cwd C:\.
  2. Call mem_current_project from an OpenCode MCP client.
  3. Observe the returned project value, then pass it as project to mem_save.

✅ Expected Behavior

Auto-detection must never return a project value that explicit project validation rejects. For a Windows drive root without Git/config detection, return project: "unknown" while retaining project_source: "dir_basename".

❌ Actual Behavior

mem_current_project returns:

{ "cwd":"C:\\", "project":"\\", "project_path":"C:\\", "project_source":"dir_basename" }

Passing project: "\\" to mem_save returns error_code: invalid_project, because a project must be a name rather than a path.

Operating System

Windows

Engram Version

v1.20.1-0.20260720141607-763a6ba43271 (commit 763a6ba432713725d6ce82a2416eec6cbd9ec94e)

Agent / Client

OpenCode

📋 Relevant Logs

mem_current_project -> { "cwd":"C:\\", "project":"\\", "project_path":"C:\\", "project_source":"dir_basename" }
mem_save(project: "\\") -> error_code: invalid_project

💡 Additional Context

Environment: Windows, OpenCode MCP client, PowerShell 7. The current template has no shell field; if one is added, select Other.

Root cause: internal/project/detect.go in DetectProjectFull Case 5 uses filepath.Base(dir) and maps only "" and "." to "unknown". On Windows, filepath.Base("C:\\") == "\\". internal/mcp/mcp.go (handleCurrentProject) returns the detection result verbatim. Explicit project validation correctly rejects path separators, while omitted-project write resolution can accept the auto-detected backslash.

Suggested tests:

  • Windows drive root in DetectProjectFull.
  • mem_current_project never emits a separator as project.
  • Explicit backslash remains rejected.

Related but not duplicates: #652 and #656 address separator handling in the OpenCode TypeScript plugin, not the Go detector.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions