Development Guide
August 22, 2025 · View on GitHub
This document contains development-specific information for contributors and maintainers of the sc-cli project.
Prerequisites
- Rust - Install from rustup.rs
- Git - For version control and branch management
- Shortcut API Token - For testing (get yours from: https://app.shortcut.com/settings/account/api-tokens)
Project Structure
sc-cli/
├── .gitignore # Git ignore patterns
├── .tool-versions # asdf version management
├── CLAUDE.md # AI assistant guidance
├── Cargo.toml # Rust project manifest
├── Cargo.lock # Rust dependency lock file
├── README.md # User documentation
├── DEVELOPMENT.md # This file
├── src/ # Rust source code
│ ├── main.rs # Application entry point
│ ├── lib.rs # Library root
│ ├── config.rs # Configuration management
│ ├── git.rs # Git integration functionality
│ ├── story_creator.rs # Story creation logic
│ ├── story_editor.rs # Story editing functionality
│ ├── api/ # Shortcut API client
│ │ ├── mod.rs # API types and traits
│ │ └── client.rs # API client implementation
│ └── ui/ # TUI components
│ └── mod.rs # UI implementation and tests
├── tests/ # Integration tests
│ ├── cli_test.rs # CLI argument tests
│ └── integration_test.rs # API integration tests
└── target/ # Rust build artifacts (git ignored)
Architecture Overview
Core Components
- Main Application (
src/main.rs) - Entry point and command handling - API Layer (
src/api/) - Shortcut API client and data structures - UI Layer (
src/ui/) - Terminal UI implementation using ratatui - Configuration (
src/config.rs) - Multi-workspace configuration management - Git Integration (
src/git.rs) - Git repository detection and branch creation - Story Management - Creation (
src/story_creator.rs) and editing (src/story_editor.rs)
Key Features
- Multi-workspace Support - Manage multiple Shortcut workspaces
- Interactive TUI - Column-based view with keyboard navigation
- Story Management - Create, edit, move, and assign stories
- Git Integration - Create branches for stories with editable names
- Pagination - Load stories incrementally for performance
Building and Running
Development Commands
# Development build
cargo build
# Release build (optimized)
cargo build --release
# Run with cargo (for development)
cargo run -- <args>
# Run with debug output
cargo run -- --debug <args>
# Install locally for testing
cargo install --path .
Testing
# Run all tests
cargo test
# Run specific test module
cargo test config::tests
# Run with debug output
cargo test -- --nocapture
# Run integration tests only
cargo test --test integration_test
Code Quality
# Check code (fast)
cargo check
# Run linter
cargo clippy
# Format code
cargo fmt
# Check format without changes
cargo fmt -- --check
Development Workflow
Setting Up Development Environment
-
Clone the repository
git clone <repository-url> cd sc-cli -
Create test configuration
# Create config for testing mkdir -p ~/.config/sc-cli cp config.toml.example ~/.config/sc-cli/config.toml # Edit with your API tokens -
Run tests to verify setup
cargo test
Development Best Practices
-
Code Style
- Follow Rust naming conventions
- Use
cargo fmtto format code - Run
cargo clippyand fix warnings - Write tests for new functionality
-
Testing
- Write unit tests alongside source code
- Add integration tests for CLI commands
- Use mock APIs for testing (see
src/story_creator/tests.rs) - Test both success and error scenarios
-
Error Handling
- Use
anyhowfor error propagation - Use
thiserrorfor custom error types - Provide helpful error messages to users
- Include debug information when
--debugis used
- Use
-
Documentation
- Update
CLAUDE.mdfor AI assistant guidance - Update
README.mdfor user-facing changes - Update this file for development changes
- Add inline documentation for complex code
- Update
Adding New Features
-
Plan the feature
- Consider CLI interface design
- Think about TUI integration
- Plan error handling
- Consider configuration needs
-
Implement with tests
- Write failing tests first (TDD)
- Implement the feature
- Ensure tests pass
- Add integration tests if needed
-
Update documentation
- Add to appropriate sections in README.md
- Update help text and command descriptions
- Update CLAUDE.md if relevant
Testing with Real API
# Test with your Shortcut workspace
cargo run -- --workspace your-workspace --debug
# Test specific commands
cargo run -- add "Test story" --workspace your-workspace
cargo run -- finish 123 --workspace your-workspace
cargo run -- edit 123 --workspace your-workspace
API Integration
Shortcut API
- Base URL:
https://api.app.shortcut.com/api/v3 - Authentication: Bearer token via API key
- Rate limits: Respect Shortcut's API limits
- Error handling: Handle 401, 403, 404, 422 responses appropriately
TUI Development
Key Libraries
- ratatui - Terminal UI framework
- crossterm - Cross-platform terminal handling
- tokio - Async runtime (if needed for future features)
UI Components
- App - Main application state
- Popups - Story creation, editing, git branch creation
- Navigation - Column and list view modes
- State Management - Stories organized by workflow state
Adding New Popups
- Create state struct for popup data
- Add popup state to main App struct
- Add key handling in
handle_key_event - Add rendering in
draw_*_popupfunction - Add popup to main draw function
Git Integration
Features
- Repository Detection - Normal vs bare repositories
- Branch Creation - Interactive branch naming
- Worktree Support - For bare repositories
- Branch Name Editing - Users can customize suggested names
Adding Git Features
- Add functions to
src/git.rs - Add UI components for user interaction
- Add error handling for git command failures
- Test with different repository types
Release Process
-
Prepare Release
# Update version in Cargo.toml # Update CHANGELOG (if exists) # Run full test suite cargo test cargo clippy -
Create Release Build
cargo build --release -
Test Release Build
./target/release/sc-cli --version ./target/release/sc-cli --help -
Tag and Release
git tag v0.1.0 git push origin v0.1.0
Contributing
-
Fork the repository
-
Create a feature branch
git checkout -b feature/your-feature-name -
Make your changes
- Follow the development workflow above
- Write tests for new functionality
- Update documentation as needed
-
Test thoroughly
cargo test cargo clippy cargo build --release -
Submit a pull request
- Include description of changes
- Reference any related issues
- Ensure CI passes
Debugging
Common Issues
-
API Authentication
# Test with debug output cargo run -- --debug --workspace your-workspace -
Configuration Problems
# Check config file location ls -la ~/.config/sc-cli/config.toml -
Git Integration
# Test in git repository cd /path/to/git/repo cargo run -- --workspace your-workspace # Press 'g' on a story to test git integration
Debug Output
Use --debug flag to see:
- API requests and responses
- Configuration loading details
- Git command execution
- Internal state changes
Logging
The application uses eprintln! for debug output and println! for user output. This allows piping user output while seeing debug information.
Performance Considerations
- Story Loading - Use pagination to avoid loading too many stories
- API Calls - Cache member information to avoid repeated lookups
- UI Rendering - Efficient list rendering with scrolling
- Memory Usage - Consider story count limits for large workspaces
Security
- API Tokens - Store securely in config files (not in environment)
- File Permissions - Config files should be user-readable only
- Error Messages - Don't expose API tokens in error output
- Input Validation - Sanitize user input for API calls