Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 72 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,75 @@ go vet ./...
- **Error handling**: Target 80%+ coverage (currently 84.6%)
- **Security modules**: 100% coverage required
- **Core functionality**: 70%+ coverage minimum
- **Configuration**: Comprehensive constant validation required
- **Configuration**: Comprehensive constant validation required

## Architecture Insights

### Tailscale Integration (`tsnet` Library)
- **Authentication URL Display**: `tsnet.Server.UserLogf` controls where authentication URLs are shown
- **Key Discovery**: `UserLogf` outputs to stderr by default, but can be redirected to io.Discard in non-verbose mode
- **Critical Pattern**: Always use a dedicated stderr logger for UserLogf to ensure auth URLs are visible:
```go
stderrLogger := log.New(os.Stderr, "", 0)
srv.UserLogf = stderrLogger.Printf
```
- **Logger Configuration**: `srv.Logf` vs `srv.UserLogf` serve different purposes - Logf for debug info, UserLogf for user-facing messages

### Internationalization System
- **Translation Coverage**: Currently supports 11 languages (en, es, zh, hi, ar, bn, pt, ru, ja, de, fr)
- **Missing Translation Detection**: Use `rg "T\(\"[^\"]*\"\)" -o -h --no-filename | sort | uniq` to find all translation keys
- **Translation Validation**: Check for missing translations by running app with different LANG settings
- **Key Patterns**: Connection status messages like "Starting Tailscale connection..." need translation coverage
- **Format String Safety**: Use `fmt.Errorf("%s", T("key"))` instead of `fmt.Errorf(T("key"))` to avoid go vet warnings

### CLI Framework (Cobra/Fang)
- **Text Rendering Issue**: Cobra/Fang may strip spaces from Example fields in help text
- **Workaround Patterns**: Use non-breaking spaces or alternative formatting for help examples
- **Translation Integration**: Example text should be translated and may need language-specific formatting

### Code Organization Best Practices
- **Function Extraction**: Break large functions into smaller, focused helpers (e.g., `initTsNet()` refactored into multiple helper functions)
- **Error Handling**: Use consistent error wrapping patterns with translated messages
- **Logger Management**: Distinguish between verbose debug logging and user-facing messages
- **Terminal State**: Centralize terminal state management for consistent behavior across interactive sessions

## Debugging Workflows

### Authentication Issues
1. Check if auth URL appears in verbose mode: `./ts-ssh connect -v target`
2. Verify UserLogf configuration in tsnet_handler.go
3. Test logger output destination (should be stderr, not io.Discard)

### Missing Translations
1. Extract all translation keys: `rg "T\(\"[^\"]*\"\)" -o -h --no-filename | sort | uniq`
2. Test different languages: `LANG=es ./ts-ssh --help`
3. Look for untranslated strings in output (they appear as key names)

### CLI Rendering Issues
1. Check help output formatting: `./ts-ssh --help`
2. Verify example text spacing in different languages
3. Test both modern and legacy CLI modes

## Development Workflow

### Before Committing
```bash
# Format and validate code
go fmt ./...
go vet ./...

# Run comprehensive tests
go test ./...

# Check for translation issues
for lang in es zh hi ar bn pt ru ja de fr; do
echo "Testing $lang..."
LANG=$lang ./ts-ssh --help | head -10
done
```

### Code Quality Checks
- Run `go vet ./...` to catch format string issues
- Use `golangci-lint run` for comprehensive linting
- Test auth URL display in both verbose and non-verbose modes
- Validate translation coverage for new user-facing messages
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,28 @@ Once authorized, `ts-ssh` stores authentication keys in the state directory (`~/

For detailed security information, see [Security Documentation](docs/security/)

## Recent Improvements (Latest Version)

### ๐ŸŽฏ Authentication Flow Enhancement
- **Fixed Authentication URL Display**: Auth URLs now properly appear in non-verbose mode
- **Improved Tailscale Integration**: Better `tsnet` logger configuration for user-facing messages
- **Streamlined Connection Process**: Cleaner output with essential information prioritized

### ๐ŸŒ Enhanced Internationalization
- **Comprehensive Translation Coverage**: All user-facing messages now properly translated
- **Missing Translation Detection**: Added systematic approach to identify untranslated strings
- **Improved Format String Safety**: Fixed go vet warnings for non-constant format strings

### ๐Ÿ”ง Code Quality & Organization
- **Refactored Core Functions**: Broke down large functions into focused, maintainable helpers
- **Enhanced Error Handling**: Consistent error wrapping with proper translation support
- **Improved Testing**: All tests passing with better coverage of edge cases

### ๐ŸŽจ CLI Framework Improvements
- **Better Help Text Rendering**: Addressed spacing issues in command examples
- **Enhanced User Experience**: Improved styling and consistency across all commands
- **Robust Translation Integration**: All CLI text properly supports multi-language display

## Architecture

ts-ssh follows enterprise-grade Go project standards with a modular internal package structure:
Expand All @@ -493,8 +515,16 @@ ts-ssh follows enterprise-grade Go project standards with a modular internal pac
- **`internal/client/ssh/`**: SSH connection management and authentication
- **`internal/client/scp/`**: SCP file transfer implementation
- **`internal/platform/`**: Cross-platform process and environment handling
- **`tsnet_handler.go`**: Tailscale network integration with proper auth URL handling
- **`i18n.go`**: Comprehensive internationalization system supporting 11 languages

### Key Technical Insights
- **Authentication URLs**: Properly configured via `tsnet.Server.UserLogf` using dedicated stderr logger
- **Translation System**: Dynamic language detection with environment variable priority
- **Logger Management**: Clear separation between debug logging and user-facing messages
- **CLI Framework**: Modern Cobra/Fang integration with legacy compatibility mode

This architecture ensures maintainability, testability, and security isolation.
This architecture ensures maintainability, testability, security isolation, and excellent user experience.

## Testing

Expand Down
Loading