Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

When users input project paths with tilde (~), they were not being expanded correctly, causing all project operations to fail. This fix implements automatic tilde expansion and path validation.

Changes

  • Add pathUtils module with expandTilde() and validateProjectPath()
  • Update PROJECT_CREATE handler to validate and normalize paths
  • Update PROJECT_LIST_BRANCHES handler to handle tilde paths
  • Prevent adding non-existent paths as projects
  • Reject file paths (only directories are valid projects)
  • Normalize paths with .. to avoid duplicate entries

Testing

Unit tests (12 tests):

  • Tilde expansion in various formats
  • Path validation for existing directories
  • Error handling for non-existent paths
  • Error handling for file paths (non-directories)
  • Path normalization

Integration tests (7 tests):

  • Full IPC flow with tilde expansion
  • Rejection of non-existent paths
  • Rejection of non-existent tilde paths
  • Rejection of file paths
  • Path normalization
  • Duplicate detection with normalized paths

All tests pass. Linter and type checker satisfied.

Generated with cmux

When users input project paths with tilde (~), they were not being
expanded correctly, causing all project operations to fail. This fix
implements automatic tilde expansion and path validation.

Changes:
- Add pathUtils module with expandTilde() and validateProjectPath()
- Update PROJECT_CREATE handler to validate and normalize paths
- Update PROJECT_LIST_BRANCHES handler to handle tilde paths
- Prevent adding non-existent paths as projects
- Reject file paths (only directories are valid projects)
- Normalize paths with .. to avoid duplicate entries

Testing:
- Unit tests for expandTilde() and validateProjectPath()
- Integration tests for PROJECT_CREATE IPC handler covering:
  * Tilde expansion in project paths
  * Rejection of non-existent paths
  * Rejection of file paths (non-directories)
  * Path normalization with .. segments
  * Duplicate detection with normalized paths

All tests pass. Linter and type checker satisfied.

_Generated with `cmux`_
- Add .git directory validation to prevent non-git paths
- Return normalized path from PROJECT_CREATE for frontend use
- Fix duplicate detection using backend-normalized paths
- Add proper error display with alert() in frontend
- Update integration tests for new response format

Fixes issues:
- Projects showing in UI even when creation failed
- Duplicate projects appearing due to path normalization mismatch
- Missing git repository validation
- Silent errors not shown to users
- Replace all alert() calls in useProjectManagement with proper error state
- Add ProjectErrorModal component to display validation and create errors
- Wire error state through AppContext to App component
- Clean up unnecessary console.log statements in loadProjects
- Add Storybook stories for ProjectErrorModal demonstrating all error types

Error flow now properly blocks project creation in both native dialog and web
versions without using alert(). Errors are displayed in a modal that must be
dismissed before continuing.

_Generated with `cmux`_
Remove native Electron file dialog in favor of web dialog for consistency:
- Update useProjectManagement to dispatch directory-select-request event
- Remove dialog IPC handler (DIALOG_SELECT_DIR) from ipcMain
- Remove dialog API from IPCApi interface, preload, and browser API
- Update App.stories.tsx mock to remove dialog API
- Remove DIALOG_SELECT_DIR constant from ipc-constants

Both native and web versions now use DirectorySelectModal for path input,
providing consistent UX across deployment modes.

_Generated with `cmux`_
Move error handling into DirectorySelectModal to keep modal open on error:
- Modal now calls window.api.projects.create() directly
- Backend validation errors displayed inline with path preserved
- Duplicate project check moved to modal (using normalized path)
- Remove ProjectErrorModal component (no longer needed)
- Remove error state from useProjectManagement hook
- Remove projectError/clearProjectError from AppContext
- Add loading state with "Adding..." button text

Modal stays open until project successfully created or user cancels.
User can correct path without re-entering everything.

_Generated with `cmux`_
Rename for better discoverability and clarity:
- File: DirectorySelectModal.tsx → ProjectCreateModal.tsx
- Component: DirectorySelectModal → ProjectCreateModal
- Update imports in App.tsx
- Update component documentation

The modal now clearly indicates it handles project creation, not just
directory selection.

_Generated with `cmux`_
Replace custom event system with standard React props pattern:
- ProjectCreateModal now accepts isOpen, onClose, onSuccess props
- Remove event listener and promise-based communication
- Update useProjectManagement.addProject to accept params directly
- App.tsx manages projectCreateModalOpen state
- Simpler flow: button click → setState(true) → modal opens

Eliminates unnecessary indirection. Modal is just a normal React component
controlled by parent state.

_Generated with `cmux`_
Convert validateProjectPath from sync to async to avoid blocking IPC handlers:
- Use fs/promises instead of sync fs methods
- Update IPC handlers to await validation
- Update all tests to handle async function
- Better error handling with try/catch instead of existsSync

Removes eslint-disable comments for sync fs methods.

_Generated with `cmux`_
_Generated with `cmux`_
@ammario ammario merged commit f0290f6 into main Oct 30, 2025
13 checks passed
@ammario ammario deleted the fix-project-tilde branch October 30, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants