diff --git a/.github/agents.md b/.github/agents.md new file mode 100644 index 0000000..954eedb --- /dev/null +++ b/.github/agents.md @@ -0,0 +1,265 @@ +# GitHub Copilot Agent Personas + +This file defines specialized agent personas for the Espargne retirement planning application. These agents have specific roles, boundaries, and capabilities tailored to this project. + +--- + +## Test Agent + +**Name**: `test-agent` +**Description**: Writes and maintains comprehensive test suites for the TypeScript/React retirement planning application. + +### Responsibilities +- Write new unit tests using Vitest framework +- Update existing tests when code changes +- Ensure test coverage for financial calculations +- Validate Big.js precision in tests +- Test React component behavior + +### Technology Stack +- **Test Framework**: Vitest 4.0.18 +- **React Testing**: @testing-library/react 16.3.2 +- **Assertion Library**: Vitest built-in matchers +- **Coverage Tool**: v8 (via Vitest) + +### Commands +```bash +pnpm test run # Run all tests once +pnpm test # Watch mode +pnpm test:ui # Interactive UI +pnpm test:coverage # Generate coverage report +``` + +### Boundaries & Constraints +- ✅ **DO**: Write tests in `src/tests/` directory +- ✅ **DO**: Use Big.js helpers for financial assertions +- ✅ **DO**: Follow existing test patterns and naming conventions +- ✅ **DO**: Ensure tests are deterministic and isolated +- ❌ **DO NOT**: Modify production code in `src/lib/` without explicit request +- ❌ **DO NOT**: Remove or skip existing tests +- ❌ **DO NOT**: Use floating-point numbers for currency assertions +- ❌ **DO NOT**: Commit test artifacts or coverage files + +### Test Patterns +```typescript +// Good: Using Big.js for financial assertions +import { toBig, multiply } from '../lib/bigHelpers'; + +test('calculates correct balance growth', () => { + const balance = toBig(100000); + const growth = multiply(balance, 0.05); + expect(growth.toString()).toBe('5000.00'); +}); + +// Bad: Using raw numbers for currency +test('calculates balance growth', () => { + const balance = 100000; + const growth = balance * 0.05; // ❌ Floating-point errors + expect(growth).toBe(5000); +}); +``` + +### Coverage Targets +- **Overall**: 80%+ coverage maintained +- **Critical Paths**: 100% coverage for: + - Tax calculations (`taxCalculator.ts`) + - RMD calculations (`rmdCalculator.ts`) + - Withdrawal coordinator (`withdrawalCoordinator.ts`) + - Big.js helpers (`bigHelpers.ts`) + +--- + +## Documentation Agent + +**Name**: `docs-agent` +**Description**: Maintains and improves documentation for the retirement planning application. + +### Responsibilities +- Update README.md and documentation files +- Keep inline code comments current +- Update API documentation when interfaces change +- Maintain architectural decision records +- Update copilot-instructions.md when patterns change + +### Technology Stack +- **Format**: Markdown +- **Code Docs**: TSDoc comments +- **Architecture Docs**: ADR format (optional) + +### Commands +```bash +pnpm build # Verify TypeScript compiles +pnpm dev # Test documentation examples work +``` + +### Boundaries & Constraints +- ✅ **DO**: Update documentation when code changes +- ✅ **DO**: Keep examples accurate and tested +- ✅ **DO**: Use clear, concise language +- ✅ **DO**: Include code examples with proper syntax highlighting +- ❌ **DO NOT**: Make breaking changes to public APIs +- ❌ **DO NOT**: Remove or significantly alter existing documentation without discussion +- ❌ **DO NOT**: Include sensitive information or credentials +- ❌ **DO NOT**: Modify `.github/copilot-instructions.md` without clear justification + +### Documentation Files +- `README.md` - Project overview, setup, features +- `.github/copilot-instructions.md` - Coding patterns and conventions +- `.github/instructions/CodingConventions.instructions.md` - Code style rules +- `VISUALIZATION_PORT.md` - Chart implementation details +- `WITHDRAWAL_COORDINATOR.md` - Withdrawal strategy documentation + +--- + +## Build Agent + +**Name**: `build-agent` +**Description**: Handles build configuration, dependencies, and deployment setup. + +### Responsibilities +- Update build configuration when needed +- Manage dependency updates (with security checks) +- Optimize build performance +- Configure deployment pipelines +- Maintain GitHub Actions workflows + +### Technology Stack +- **Build Tool**: Vite 7.2.4 +- **Package Manager**: pnpm 10.x +- **CI/CD**: GitHub Actions +- **Deployment**: GitHub Pages (static site) + +### Commands +```bash +pnpm install # Install dependencies +pnpm build # Production build +pnpm preview # Test production build locally +``` + +### Boundaries & Constraints +- ✅ **DO**: Test build changes locally before committing +- ✅ **DO**: Check security advisories before updating dependencies +- ✅ **DO**: Maintain Node.js version compatibility (20.19+, 22.12+) +- ✅ **DO**: Preserve build output size (~686KB target) +- ❌ **DO NOT**: Update major versions without testing +- ❌ **DO NOT**: Add unnecessary dependencies +- ❌ **DO NOT**: Change deployment configuration without approval +- ❌ **DO NOT**: Commit `node_modules/`, `dist/`, or lock files unnecessarily + +### Critical Dependencies +- `big.js@7.0.1` - Must maintain version for financial precision +- `react@19.2.0` - Core framework +- `vite@7.2.4` - Build tool (requires Node 20.19+/22.12+) +- `recharts@2.12.7` - Visualization library + +--- + +## Code Agent (Default) + +**Name**: `code-agent` +**Description**: General-purpose coding agent for feature development and bug fixes. + +### Responsibilities +- Implement new features +- Fix bugs and issues +- Refactor code for maintainability +- Optimize performance +- Ensure code quality and type safety + +### Technology Stack +- **Language**: TypeScript 5.9.3 (strict mode) +- **Framework**: React 19.2.0 +- **State Management**: React hooks + localStorage +- **Styling**: CSS Modules +- **Financial Math**: Big.js 7.0.1 + +### Commands +```bash +pnpm dev # Start dev server +pnpm build # Build and type check +pnpm test # Run tests +``` + +### Boundaries & Constraints +- ✅ **DO**: Use Big.js for all financial calculations +- ✅ **DO**: Follow existing code patterns and conventions +- ✅ **DO**: Write tests for new features +- ✅ **DO**: Use TypeScript strict mode +- ✅ **DO**: Follow form visibility toggle pattern +- ❌ **DO NOT**: Use JavaScript number type for currency +- ❌ **DO NOT**: Inline CSS styles in JSX +- ❌ **DO NOT**: Add console.log statements in production code +- ❌ **DO NOT**: Modify financial calculation logic without extensive testing +- ❌ **DO NOT**: Change localStorage keys without migration path + +### Critical Code Patterns +See `.github/copilot-instructions.md` for detailed patterns including: +- Big.js for financial calculations +- Account type discrimination +- localStorage persistence +- Form callback pattern +- Component organization + +--- + +## General Guidelines for All Agents + +### Security & Privacy +- Never commit secrets, API keys, or credentials +- Validate all user inputs +- Use Big.js to avoid floating-point security issues +- Keep dependencies updated for security patches + +### Quality Standards +- Maintain TypeScript strict mode compliance +- Write deterministic, testable code +- Follow existing architectural patterns +- Keep functions small and focused +- Use explicit return types + +### Collaboration +- Create clear, focused PRs +- Write descriptive commit messages +- Request review for significant changes +- Update documentation with code changes +- Run tests before committing + +### Temporary Files +**Always use `/tmp/espargne-web/` for temporary files:** +```bash +mkdir -p /tmp/espargne-web +# Use for: logs, test artifacts, debug output, temporary scripts +# Clean up when finished +``` + +--- + +## Agent Selection Guide + +**For testing tasks**: Use `@test-agent` +- Writing new tests +- Fixing failing tests +- Improving test coverage +- Test refactoring + +**For documentation**: Use `@docs-agent` +- README updates +- API documentation +- Architecture docs +- Comment updates + +**For build/deploy**: Use `@build-agent` +- Dependency updates +- Build configuration +- CI/CD workflows +- Performance optimization + +**For feature work**: Use `@code-agent` (default) +- New features +- Bug fixes +- Code refactoring +- UI improvements + +**For complex tasks**: Combine agents +- Feature + tests: `@code-agent` then `@test-agent` +- Build change + docs: `@build-agent` then `@docs-agent` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3339480 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,83 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + name: Build and Test + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.19.x, 22.12.x] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run tests (if tests exist) + run: pnpm test run || echo "No tests found - skipping" + continue-on-error: true + + - name: Build + run: pnpm build + + - name: Clean coverage directory + if: matrix.node-version == '22.12.x' + run: rm -rf coverage + + - name: Generate coverage report + if: matrix.node-version == '22.12.x' + run: pnpm test:coverage + + - name: Upload coverage to GitHub + if: matrix.node-version == '22.12.x' && hashFiles('coverage/coverage-final.json') != '' + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage/ + if-no-files-found: error + retention-days: 7 + + lint: + name: Lint Code + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 10 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 22.12.x + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Run ESLint + run: pnpm lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9fd1b25 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,308 @@ +# Contributing to Espargne + +Thank you for your interest in contributing to Espargne! This document provides guidelines for contributing to the project. + +## Table of Contents + +- [Code of Conduct](#code-of-conduct) +- [Getting Started](#getting-started) +- [Development Workflow](#development-workflow) +- [Coding Standards](#coding-standards) +- [Testing Guidelines](#testing-guidelines) +- [Pull Request Process](#pull-request-process) +- [Working with Copilot Agent](#working-with-copilot-agent) + +## Code of Conduct + +This project follows standard open-source community guidelines: +- Be respectful and inclusive +- Focus on constructive feedback +- Prioritize collaboration over ego +- Help others learn and grow + +## Getting Started + +### Prerequisites + +- Node.js 20.19+ or 22.12+ +- pnpm package manager (10.x) +- Git for version control + +### Initial Setup + +```bash +# Clone the repository +git clone https://github.com/frouaix/espargne-web.git +cd espargne-web + +# Install dependencies +pnpm install + +# Start development server +pnpm dev + +# Run tests +pnpm test +``` + +The development server will be available at `http://localhost:5174`. + +## Development Workflow + +### 1. Create a Branch + +```bash +git checkout -b feature/your-feature-name +# or +git checkout -b fix/bug-description +``` + +Branch naming conventions: +- `feature/` - New features +- `fix/` - Bug fixes +- `docs/` - Documentation changes +- `refactor/` - Code refactoring +- `test/` - Test additions or updates + +### 2. Make Changes + +- Follow the coding standards (see below) +- Write tests for new functionality +- Update documentation as needed +- Keep commits small and focused + +### 3. Test Your Changes + +```bash +# Run linter +pnpm lint + +# Run type check +pnpm build # Includes type checking + +# Run tests +pnpm test run + +# Generate coverage report +pnpm test:coverage +``` + +### 4. Commit Your Changes + +Write clear, descriptive commit messages: + +```bash +git add . +git commit -m "feat: Add Monte Carlo simulation variance control" +# or +git commit -m "fix: Correct RMD calculation for age 73-75" +# or +git commit -m "docs: Update withdrawal strategy documentation" +``` + +Commit message prefixes: +- `feat:` - New feature +- `fix:` - Bug fix +- `docs:` - Documentation only +- `style:` - Code style/formatting +- `refactor:` - Code refactoring +- `test:` - Test changes +- `chore:` - Build/tooling changes + +### 5. Push and Create PR + +```bash +git push origin your-branch-name +``` + +Then create a Pull Request on GitHub. + +## Coding Standards + +### TypeScript Conventions + +See `.github/instructions/CodingConventions.instructions.md` for detailed rules. Key points: + +- **Always use semicolons** (`;`) +- **Use explicit return types** for functions +- **Prefer destructuring** over direct property access +- **No console.log** in production code +- **No inline CSS** - use CSS Modules or styled components + +### Financial Calculations + +**CRITICAL**: Always use Big.js for monetary values: + +```typescript +// ✅ Correct +import { toBig, multiply } from '../lib/bigHelpers'; +const balance = toBig(100000); +const growth = multiply(balance, 0.05); + +// ❌ Wrong - Floating-point errors +const balance = 100000; +const growth = balance * 0.05; +``` + +### Component Patterns + +Follow established patterns (see `.github/copilot-instructions.md`): +- Form visibility toggle pattern +- localStorage persistence pattern +- Account type discrimination +- Form callback pattern + +## Testing Guidelines + +### Test Coverage Requirements + +- **Minimum 80% overall coverage** +- **100% coverage for critical paths**: + - Tax calculations + - RMD calculations + - Withdrawal coordination + - Big.js helpers + +### Writing Tests + +```typescript +import { describe, it, expect } from 'vitest'; +import { toBig, multiply } from '../lib/bigHelpers'; + +describe('Financial Calculation', () => { + it('should calculate correct balance growth', () => { + const balance = toBig(100000); + const rate = toBig(0.05); + const growth = multiply(balance, rate); + + expect(growth.toString()).toBe('5000.00'); + }); +}); +``` + +### Running Tests + +```bash +# Run all tests +pnpm test run + +# Watch mode +pnpm test + +# UI mode +pnpm test:ui + +# Coverage report +pnpm test:coverage +``` + +## Pull Request Process + +### Before Submitting + +1. ✅ All tests pass (`pnpm test run`) +2. ✅ Linter passes (`pnpm lint`) +3. ✅ Build succeeds (`pnpm build`) +4. ✅ Coverage maintained or improved +5. ✅ Documentation updated if needed +6. ✅ No console.log statements in code +7. ✅ Git history is clean (squash if needed) + +### PR Template + +When creating a PR, include: + +```markdown +## Description +Brief description of changes + +## Type of Change +- [ ] Bug fix +- [ ] New feature +- [ ] Documentation update +- [ ] Refactoring +- [ ] Testing + +## Testing +- [ ] All existing tests pass +- [ ] New tests added for new functionality +- [ ] Manual testing completed + +## Checklist +- [ ] Code follows project conventions +- [ ] No console.log statements +- [ ] Big.js used for all financial calculations +- [ ] Documentation updated +- [ ] Tests pass +- [ ] Build succeeds +``` + +### Review Process + +1. **Automated Checks**: CI workflow runs automatically +2. **Code Review**: Maintainer reviews code quality and approach +3. **Feedback**: Address any requested changes +4. **Approval**: Once approved, PR will be merged +5. **Deployment**: Changes deploy automatically via GitHub Pages + +### Review Expectations + +- Respond to feedback within 48 hours +- Be open to suggestions and improvements +- Explain your approach if asked +- Update PR based on feedback + +## Working with Copilot Agent + +This repository is configured for GitHub Copilot coding agent. See `.github/agents.md` for agent-specific guidelines. + +### Agent Personas + +- `@test-agent` - Testing tasks +- `@docs-agent` - Documentation updates +- `@build-agent` - Build/deployment configuration +- `@code-agent` - General development (default) + +### Assigning Issues to Copilot + +When creating issues for Copilot agent: + +1. **Be specific**: Clear goal, acceptance criteria, affected files +2. **Set boundaries**: What should/shouldn't be changed +3. **Provide context**: Link to related issues or docs +4. **Start small**: Well-scoped tasks work best + +Example: +```markdown +## Task +Add validation for Social Security claiming age + +## Acceptance Criteria +- Validate age is between 62-70 +- Show error message for invalid ages +- Update tests to cover validation + +## Files to Modify +- src/components/SSAIncomeForm.tsx +- src/tests/integration/SSAIncomeForm.test.tsx + +## Constraints +- Use existing form validation pattern +- Don't modify SSA calculation logic +- Include unit tests +``` + +## Getting Help + +- **Documentation**: See `.github/copilot-instructions.md` +- **Issues**: Open a GitHub issue for bugs or feature requests +- **Questions**: Start a GitHub Discussion +- **Security**: Email security concerns privately + +## License + +By contributing, you agree that your contributions will be licensed under the MIT License. + +--- + +Thank you for contributing to Espargne! 🎉 diff --git a/README.md b/README.md index b08bc57..55adff1 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,30 @@ This software is provided "AS IS" under the MIT License, WITHOUT WARRANTY OF ANY **By using this application, you acknowledge that you understand these limitations and accept full responsibility for your financial decisions.** +## Contributing + +Contributions are welcome! This project is set up to work with GitHub Copilot coding agent. + +- See [CONTRIBUTING.md](CONTRIBUTING.md) for development guidelines and workflow +- See [.github/agents.md](.github/agents.md) for Copilot agent personas and boundaries +- See [.github/copilot-instructions.md](.github/copilot-instructions.md) for detailed coding patterns + +### Quick Start for Contributors + +```bash +git clone https://github.com/frouaix/espargne-web.git +cd espargne-web +pnpm install +pnpm dev +pnpm test +``` + +Before submitting a PR: +- ✅ Run tests: `pnpm test run` +- ✅ Run linter: `pnpm lint` +- ✅ Run build: `pnpm build` +- ✅ Update documentation if needed + ## License MIT License - see [LICENSE](LICENSE) file for details.