Version: 1.0.0 | Created: 2026-01-12 | Adapted: 2026-01-28
This document defines the core principles for developing the Shortcuts project. These principles ensure code quality, maintainability, and consistency across the codebase.
Note: This document covers how we develop code. For what we plan to build, see:
docs/roadmap.md- High-level vision and planned featuresdocs/backlog/README.md- Detailed backlog of tasks and improvements
TDD is mandatory for all PowerShell code in this project.
- Tests MUST be written BEFORE implementation (Red-Green-Refactor cycle)
- Unit tests (
*.Tests.ps1) MUST pass before committing - Integration tests (
*.Integration.Tests.ps1) MUST pass for modified integration points - When modifying existing functions, tests MUST be updated first to reflect new behavior
- Tests and implementation MUST be committed together - never separately
Rationale: TDD ensures code correctness, prevents regressions, and maintains high code quality. The strict test-first approach prevents technical debt and ensures all code is testable by design.
All reusable functionality MUST be implemented as library functions in lib/.
- Library functions MUST be self-contained and independently testable
- Before writing new code, MUST check existing library functions in
lib/utils/andlib/wsl/ - Executable scripts MUST have
.batwrapper for command-line accessibility - External command execution MUST use
Invoke-CommandLinefrom pslib
Rationale: Promotes code reusability, reduces duplication, and ensures consistent behavior across all scripts. Centralized utilities are easier to test, maintain, and improve.
All PowerShell code MUST adhere to project coding standards.
- MUST use PowerShell 7.4+ syntax (
#Requires -Version 7.4), except bootstrap scripts (bin/install.ps1,.bootstrap/) which remain PS 5.1-compatible - MUST pass PSScriptAnalyzer checks (Error/Warning severity)
- MUST include proper help documentation (SYNOPSIS, DESCRIPTION, EXAMPLE)
- MUST use
[CmdletBinding()]and proper parameter declarations
Rationale: Requires PowerShell 7.4+ (installed via Scoop on developer machines; pre-installed on CI runners) to enable modern .NET libraries such as PwshSpectreConsole. Bootstrap scripts remain PS 5.1-compatible so they can run on a fresh Windows machine before pwsh is available.
All scripts MUST implement robust error handling.
- MUST set
Set-StrictMode -Version Latest - MUST set
$ErrorActionPreference = 'Stop' - MUST use try/catch blocks for main logic
- MUST provide clear, user-friendly error messages
- MUST validate paths and inputs before use
- MUST check for dependencies (e.g., Scoop availability) before executing commands
Rationale: Prevents silent failures, provides actionable error information, and ensures scripts fail fast with clear diagnostics.
Scripts MUST work correctly in both interactive and CI/test environments.
- MUST use
Test-RunningInCIorTestEnvironmentto detect execution context - MUST provide non-interactive paths for CI/automated scenarios
- MUST provide interactive prompts for user-driven scenarios
- MUST mock external dependencies in tests (file system, commands, environment variables)
- MUST test both CI and interactive behavior paths separately
Rationale: Ensures scripts work reliably in automated pipelines and manual execution, preventing CI failures and improving user experience.
Don't Repeat Yourself - reuse existing code and patterns.
- MUST check
lib/for existing functionality before implementing - MUST extract common patterns into library functions
- MUST follow SOLID principles in code design
- MUST avoid duplicating functionality across scripts
- MUST use parameterized tests and test fixtures to reduce test duplication
Rationale: Reduces maintenance burden, ensures consistent behavior, and makes the codebase easier to understand and modify.
Code changes MUST be documented and traceable.
- MUST use conventional commits (feat, fix, refactor, test, docs, chore)
- MUST include clear commit messages explaining "why" not just "what"
- MUST reference file:line in code reviews and discussions
- MUST update documentation when changing functionality
- MUST remind users to refresh Keypirinha catalog when adding/modifying shortcuts
Rationale: Maintains project history, enables effective code review, and ensures users understand how to use new features.
All code changes MUST follow this workflow:
- Update Backlog (Start): Move the backlog item to IN PROGRESS and check off any acceptance criteria that are already met
- Research: Check if functionality exists in
lib/or other scripts - Design: Plan the script structure and identify reusable components
- Test First: Write Pester tests before implementation (Red phase)
- Implement: Write the PowerShell script following guidelines (Green phase)
- Test Again: Verify all tests pass (Red-Green-Refactor complete)
- Pre-Commit Validation: Run unit tests and integration tests
- Document: Add comments and help documentation
- Update Backlog (Finish): Check off completed acceptance criteria, update status, and move to DONE when all criteria are met
- Commit Together: Tests, implementation, and backlog updates in same commit
Critical checkpoint: NEVER modify implementation without updating tests first.
Critical checkpoint: NEVER commit without updating docs/backlog/ - acceptance criteria MUST reflect the current state of the work.
Before any commit, ALL of these gates MUST pass:
pwsh -File ".\test\bin\testrunner.ps1" -UnitAll unit tests MUST pass.
pwsh -File ".\test\bin\testrunner.ps1" -IntegrationAll integration tests MUST pass.
PSScriptAnalyzer checks are automatically included in test suite. Code MUST have no Error or Warning severity violations.
Tests MUST pass on PowerShell 7.4+:
pwsh -File ".\test\bin\testrunner.ps1"For detailed technical implementation guidance:
AGENTS.md- Project-wide development guidelineslib/AGENTS.md- PowerShell library-specific guidanceREADME.md- User-facing installation and usage documentation