This document describes the development workflow for the needs-attention project. It incorporates lessons learned and establishes patterns for future development.
CRITICAL: This project follows Test-Driven Development (TDD) with a strict Red/Green/Refactor cycle and mandatory pre-commit quality gates. All code changes must pass the complete pre-commit process before being committed.
Red/Green/Refactor Cycle:
RED: Write failing test -> GREEN: Make it pass -> REFACTOR: Improve code -> Repeat
Process:
- RED: Write a failing test that defines desired behavior
- Test should fail for the right reason
- Compile error or assertion failure
- GREEN: Write minimal code to make the test pass
- Don't worry about perfection yet
- Just make it work
- REFACTOR: Improve the code while keeping tests green
- Remove duplication
- Improve names
- Simplify logic
- REPEAT: Continue cycle for next piece of functionality
Benefits:
- Tests document expected behavior
- High confidence in changes
- Catches regressions immediately
- Forces good design (testable code)
MANDATORY BEFORE EVERY COMMIT: No exceptions, no deferrals, no disabling checks.
All changes must pass the complete pre-commit process. If any step fails, fix it before proceeding.
Plan -> RED (Test) -> GREEN (Code) -> REFACTOR -> Review -> Pre-Commit -> Commit -> Push
Planning:
- Review PRD (docs/prd.md) for requirements
- Check design doc (docs/design.md) for patterns
- Update plan.md with task breakdown
- Create mental model before coding
- Write test scenarios first (TDD planning)
RED - Write Failing Test:
- Write test that defines expected behavior
- Run test to confirm it fails
- Verify failure is for the right reason
GREEN - Implement Minimum Code:
- Write simplest code to pass the test
- Run test to confirm it passes
- Don't optimize yet
REFACTOR - Improve Code:
- Keep tests passing while improving
- Remove duplication
- Improve naming and structure
- Keep functions under 50 lines
- Keep files under 500 lines
Testing (Continuous):
- Write unit tests alongside code (TDD)
- Add integration tests for database operations
- Use Playwright for UI testing
- Run tests frequently during development
- All tests must pass before proceeding
Review:
- Self-review changes before committing
- Check against docs/learnings.md for common mistakes
- Verify all acceptance criteria met
- Ensure all tests pass
Pre-Commit (MANDATORY):
- Follow pre-commit quality process (below)
- All steps must pass - NO EXCEPTIONS
- Fix issues, never disable checks
- Update docs/learnings.md if issues found
Commit:
- Write clear, detailed commit messages
- Include co-authorship attribution
- Reference related issues/PRs
Push:
- Push immediately after commit
- Enables testing on other systems
- Provides incremental backup
CRITICAL: This process is MANDATORY before every commit. No exceptions, no deferrals, no disabling checks.
When to Run:
- Before every commit (no exceptions)
- After completing a feature
- Before switching contexts
- End of development session
- When explicitly requested
Pre-Commit Sequence (Must be completed in order, all must pass):
cargo testRequirements:
- ALL tests must pass
- NO test failures allowed
- NO disabled tests allowed
- Fix all failing tests before proceeding
If tests fail:
- Debug and fix the failing test
- Do NOT disable the test
- Do NOT skip the test
- Do NOT defer the fix
cargo clippy --all-targets --all-features -- -D warningsRequirements:
- ZERO clippy warnings
- ALL warnings must be fixed
- NEVER use #[allow(...)] to suppress warnings
- NEVER use --allow-warnings flag
- Apply clippy's suggested fixes
If clippy fails:
- Fix each warning properly
- Do NOT disable clippy checks
- Do NOT use allow attributes
- Do NOT defer fixes
- Re-run until completely clean
cargo fmt --allRequirements:
- ALL code must be formatted
- Confirm no formatting changes remain
- Run
cargo fmt --checkto verify
markdown-checker -f "**/*.md"Requirements:
- All markdown must be ASCII-only
- Fix tree symbols and non-ASCII characters
- Use
--fixfor auto-fixable issues - Manual fixes for emojis and other unicode
git statusRequirements:
- No build artifacts in staging
- No temporary files in staging
- Update .gitignore if needed
- Verify only intentional files staged
sw-checklistRequirements:
- ALL checklist items must pass
- Address any non-compliant project elements
- Run with --help for project-specific requirements
If checklist fails:
- Fix each failed requirement
- Re-run until all checks pass
- Update project structure as needed
AI Agent Notes:
- This ensures project meets Software Wrighter standards
- Use
sw-checklist --helpfor detailed guidance - Common checks: documentation, structure, licensing, quality
CRITICAL: If any of the previous steps required changes, update docs/learnings.md
Update docs/learnings.md if:
- Clippy warnings were found (document the pattern)
- Tests failed (document root cause)
- Bug was fixed (document prevention strategy)
Root Cause Analysis Required: When updating learnings.md for bugs or test failures:
- What went wrong? - Describe the issue
- Why wasn't it caught sooner? - Identify process gap
- What process change prevents this? - Document prevention
- Add to proactive checklist - Update process.md if needed
Also Update:
- README.md if features added or changed
- CLAUDE.md if development patterns changed
- docs/status.md with progress
- docs/architecture.md if system design changed
- docs/design.md if design decisions made
Self-Review Checklist:
- All tests pass
- Zero clippy warnings
- Code formatted
- Markdown validated (if applicable)
- .gitignore appropriate
- sw-checklist passes
- Documentation updated
- docs/learnings.md updated if issues found
- No commented-out code
- No debug print statements
- Commit message clear and detailed
git add -A
git commit -m "Clear, descriptive message
Detailed explanation of changes...
If bugs were fixed:
- Root cause: <why the bug occurred>
- Prevention: <what process change prevents this>
- Updated learnings.md with <specific section>
[AI] Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>"
git pushCommit Message Requirements:
- Clear, descriptive summary (50 chars max)
- Detailed explanation of what and why
- Root cause analysis if bug fix
- Reference to learnings.md updates if applicable
- Co-authorship attribution
Code Quality:
- Zero clippy warnings (enforced with
-D warnings) - All code formatted with
cargo fmt - Rust 2024 edition idioms
- Inline format arguments:
format!("{name}")notformat!("{}", name) - Inner doc comments for modules:
//!not///+ empty line
Test Coverage:
- Unit tests for pure logic
- Integration tests for database operations
- UI tests for critical user flows
- Edge case handling
Documentation:
- Public APIs documented with
///comments - Module-level docs with
//!comments - README kept up-to-date
- Examples in doc comments where helpful
Tech Debt Limits:
- Maximum 3 TODO comments per file
- Files under 500 lines (prefer 200-300)
- Functions under 50 lines (prefer 10-30)
- Address TODOs within 2 development sessions
- Never commit FIXMEs (fix immediately)
Initial Setup:
# Install Rust (if needed)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# Install wasm-pack
cargo install wasm-pack
# Verify prerequisites
./scripts/check-setup.shBuild:
./scripts/build-all.shThis script:
- Builds Rust CLI (release mode)
- Generates build-info.json
- Builds WASM UI with wasm-pack
Development Iteration:
# Terminal 1: Run web server
./scripts/run-web.sh 2222
# Terminal 2: Make changes, then rebuild
./scripts/build-all.sh
# Refresh browser to see changesTesting:
# Run all tests
cargo test
# Run specific test
cargo test test_name
# Run tests with output
cargo test -- --nocapture(Not yet implemented, but planned)
GitHub Actions Workflow:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
- run: cargo test
- run: cargo clippy -- -D warnings
- run: cargo fmt -- --checkLocation: Same file as code, in #[cfg(test)] module
Example:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_detect_rust_project() {
let temp = tempfile::tempdir().unwrap();
let cargo_toml = temp.path().join("Cargo.toml");
fs::write(&cargo_toml, "[package]").unwrap();
assert_eq!(detect_project_type(temp.path()), ProjectType::Rust);
}
}What to Test:
- Pure functions (no I/O)
- Edge cases (empty input, max values)
- Error conditions
Location: src/lib.rs in test module (access to internal API)
Example:
#[test]
fn test_project_crud() {
let temp = tempfile::tempdir().unwrap();
let db = Database::open_or_create_at(temp.path()).unwrap();
let project = Project {
name: "test-project".to_string(),
// ...
};
let id = db.upsert_project(&project).unwrap();
let retrieved = db.get_project(id).unwrap().unwrap();
assert_eq!(retrieved.name, "test-project");
}What to Test:
- Database operations
- Scanner integration (find + analyze + insert)
- API endpoints (future: with test harness)
Tool: Playwright via MCP server
Setup:
# Install Playwright MCP
claude mcp add playwright -s user -- npx -y @playwright/mcp
# Verify
claude mcp listExample:
// In Claude Code session:
// "Use Playwright to test the project detail view"What to Test:
- Page loads correctly
- Table sorting works
- Search filtering works
- Detail view navigation
- Status update persistence
Temporary Directories:
use tempfile::tempdir;
let temp = tempdir()?;
// Create test data in temp.path()
// Automatic cleanup when temp dropsTest Databases:
let db = Database::open_or_create_at(temp.path())?;
// Fresh database for each test
// No shared state between testsMock Data:
fn create_test_project() -> Project {
Project {
id: 0,
name: "test-project".to_string(),
path: "/tmp/test".into(),
// ...
}
}Current: Direct commits to main
- Single developer
- Small changes
- Fast iteration
Future (Multi-developer):
- Feature branches:
feature/add-export - Bugfix branches:
fix/scanner-crash - PR-based review process
Format:
type: Short summary (50 chars max)
Detailed explanation of what changed and why.
Include context, rationale, and trade-offs.
Bullet points for multiple changes:
- Added feature X
- Fixed bug Y
- Refactored Z
[AI] Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Types:
feat:New featurefix:Bug fixdocs:Documentation onlystyle:Formatting, no code changerefactor:Code restructuringtest:Adding testschore:Build process, dependencies
Examples:
feat: Add row numbers to project table
Added index column with small font for easy reference in
discussions. Updated CSS for compact styling.
fix: Correct refresh mechanism to capture DOM state
Changed refresh to re-check git status without full rescan.
Prevents stale data when user modifies projects externally.
docs: Add screenshot and fix markdown formatting
Replaced Unicode tree symbols with ASCII for portability.
Added full-page screenshot to README for visual context.
Always push immediately after commit:
- Enables testing on other machines
- Provides backup of work
- Makes work visible for collaboration
Never:
- Force push to main (unless recovery needed)
- Rewrite history of pushed commits
- Skip pre-commit checks
Before committing, review your own changes:
- All tests pass
- No clippy warnings
- Code formatted
- Documentation updated
- No hardcoded values (use constants)
- Error handling appropriate
- No commented-out code
- No debug print statements
- Commit message clear and detailed
From learnings.md:
- Doc comments: Use
//!for modules,///for items, no empty lines - Unused imports: Remove after refactoring
- Format arguments: Use inline syntax
"{name}"not"{}", name - Needless borrows: Trust clippy on generic args
- File size: Keep under 500 lines
- TODO count: Max 3 per file
- All tests passing
- Zero clippy warnings
- Code formatted
- README up-to-date with screenshots
- CHANGELOG.md updated
- Version bumped in Cargo.toml
- Git tag created:
v0.1.0 - Build artifacts generated
# 1. Update version
# Edit Cargo.toml: version = "0.1.0"
# 2. Update CHANGELOG
# Document all changes since last release
# 3. Commit version bump
git add Cargo.toml CHANGELOG.md
git commit -m "chore: Bump version to 0.1.0"
# 4. Create tag
git tag -a v0.1.0 -m "Release v0.1.0"
# 5. Push
git push && git push --tags
# 6. Build release artifacts
./scripts/build-all.sh
tar -czf needs-attention-v0.1.0-macos.tar.gz \
target/release/needs-attention \
static/ \
wasm-ui/pkg/
# 7. Create GitHub release
# Upload tar.gz, add release notes from CHANGELOGMonthly Check:
cargo update
cargo test
cargo clippy
# If all pass, commit Cargo.lock updateBreaking Changes:
- Review changelog for dependencies
- Test thoroughly after major version bumps
- Update code if APIs changed
Current: Ignored ALTER TABLE statements
Future: Proper migration system
# Track version in database
# Run migrations on startup
# Provide rollback mechanism- Rust (latest stable)
- wasm-pack
- git
- markdown-checker (for docs)
- Playwright (for UI testing)
- cargo-watch (for auto-rebuild)
- cargo-bloat (analyze binary size)
- cargo-audit (security vulnerabilities)
- cargo-outdated (dependency updates)
# Undo last commit (not pushed)
git reset --soft HEAD~1
# Undo last commit (pushed)
# Create revert commit instead
git revert HEAD
git push# Restore from backup
cp needs_attention.db.backup needs_attention.db
# Or recreate
rm needs_attention.db
./scripts/gather.sh /path/to/projects# Clean build artifacts
cargo clean
rm -rf wasm-ui/pkg
./scripts/build-all.sh
# Reset to known-good commit
git log --oneline
git checkout <commit-sha>- Document issues in learnings.md
- Update process.md with prevention strategies
- Add to checkpoint checklist if recurring
- Consider automation for frequent issues
(Future implementation)
Track:
- Build times
- Test execution time
- Code coverage
- Clippy warnings over time
- Database size growth
Tools:
- cargo bench for performance
- tarpaulin for coverage
- GitHub Actions for CI metrics