---
name: default-k4000-data-folder
description: If no data folder is defined, set the default to ~/.config/k4000 and create the folder automatica...
status: done
---

# Feature: default-k4000-data-folder

## Description

If no data folder is defined, set the default to ~/.config/k4000 and create the folder automatically.

## Requirements

1. **Platform-specific default paths:**
   - Linux/macOS: `~/.config/k4000`
   - Windows: `%APPDATA%\k4000`

2. **Automatic directory creation:**
   - Create the default directory automatically if it doesn't exist
   - Log a message when creating the directory for the first time

3. **Fallback behavior:**
   - If directory creation fails (e.g., permission denied), fall back to a system-determined safe location (e.g., temp directory)

4. **Shared logic:**
   - Both MCP servers (feature and review) share the same default directory logic
   - Implement as a shared function in `src/lib.rs`

5. **Documentation:**
   - Update CLAUDE.md to reflect that `K4000_DATA_DIR` is now optional

---

## Q & A

### Q1: Should the default path be `~/.config/k4000` (Linux/macOS standard) or should it use platform-specific conventions like `%APPDATA%\k4000` on Windows?
**Category:** clarification
**Answer:** Use platform-specific conventions: `~/.config/k4000` for Linux/macOS, and `%APPDATA%\k4000` for Windows.

### Q2: Should the MCP server log a message when it creates the default directory for the first time?
**Category:** clarification
**Answer:** Yes, log a message when creating the default directory for the first time.

### Q3: If directory creation fails (e.g., permission denied), should the server fail to start or fall back to a different location (e.g., current working directory)?
**Category:** edge_case
**Answer:** Fall back to a system-determined safe location if directory creation fails.

### Q4: Should both MCP servers (feature and review) share the same default directory logic, or should they have independent implementations?
**Category:** integration
**Answer:** Yes, both MCP servers should share the same default directory logic.

### Q5: Should the CLAUDE.md documentation be updated to reflect that K4000_DATA_DIR is now optional with a sensible default?
**Category:** clarification
**Answer:** Yes, update CLAUDE.md to reflect that K4000_DATA_DIR is now optional with a sensible default.

---

## Implementation Plan

### Task Summary

| ID | Task | Files |
|----|------|-------|
| T1 | Add `dirs` crate dependency for platform-specific paths | `Cargo.toml` |
| T2 | Create shared `get_data_dir()` function with fallback logic | `src/lib.rs` |
| T3 | Update feature MCP server to use shared function | `src/bin/feature_mcp.rs` |
| T4 | Update review MCP server to use shared function | `src/bin/review_mcp.rs` |
| T5 | Update documentation to reflect optional env var | `CLAUDE.md` |

### Tasks

- [ ] **T1**: Add the `dirs` crate to Cargo.toml for cross-platform directory resolution
- [ ] **T2**: Implement `get_data_dir()` in `src/lib.rs` that:
  - Checks for `K4000_DATA_DIR` environment variable first
  - Falls back to platform-specific config directory (`~/.config/k4000` or `%APPDATA%\k4000`)
  - Creates the directory if it doesn't exist (with logging)
  - Falls back to temp directory if creation fails
- [ ] **T3**: Update `feature_mcp.rs` to use the shared `get_data_dir()` function
- [ ] **T4**: Update `review_mcp.rs` to use the shared `get_data_dir()` function
- [ ] **T5**: Update CLAUDE.md Configuration table to show the new default behavior

### Testing Considerations

- Test with `K4000_DATA_DIR` set to verify it takes precedence
- Test without `K4000_DATA_DIR` to verify platform default is used
- Test with unwritable path to verify fallback to temp directory

---

## Estimate

**Senior Developer Profile:** 5+ years experience, familiar with the project's tech stack.

| Scenario | Time |
|----------|------|
| Optimistic | 30 minutes |
| Normal | 45 minutes |
| Pessimistic | 1.5 hours |

### Assumptions
- The `dirs` crate is suitable for cross-platform path resolution
- No complex permission issues during testing
- Excludes code review iterations
