stand 0.2.0

A CLI tool for explicit environment variable management
Documentation
# Stand - Requirements Document

## 1. Project Overview

Stand is a command-line tool that simplifies environment variable management for developers who need to switch between multiple environment configurations within a single project directory. Unlike existing tools that automatically load variables on directory entry, Stand provides explicit control over environment switching to prevent accidental misconfigurations.

## 2. Problem Statement

Developers working on modern applications often need to:
- Test their code against different environments (development, staging, production)
- Switch between different API endpoints and database connections
- Maintain clear separation between environment configurations
- Avoid accidentally running commands with wrong environment variables

Current solutions either require verbose command prefixes for every execution or automatically load environments without clear visibility, leading to confusion and potential errors.

## 3. Project Goals

### Primary Goals
- Provide a simple, explicit way to switch between environment variable sets
- Minimize typing overhead for command execution after environment selection
- Offer clear visual feedback about the active environment
- Prevent accidental mixing of environment variables

### Secondary Goals
- Support hierarchical configuration (base + environment-specific variables)
- Enable both interactive and one-off command execution modes
- Work seamlessly across different shell environments
- Provide migration paths from existing tools

## 4. User Stories

### Story 1: Developer Daily Workflow
**As a** developer working on a web application  
**I want to** easily switch between development and production environments  
**So that** I can test my code with different configurations without manual variable management

**Acceptance Criteria:**
- I can start a shell session with a specific environment in under 3 seconds
- The active environment is clearly visible in my terminal prompt
- All commands I run inherit the environment variables automatically
- I can exit the environment cleanly and return to my original shell state

### Story 2: CI/CD Pipeline Integration
**As a** DevOps engineer  
**I want to** run specific commands with designated environments  
**So that** I can automate builds and deployments with the correct configurations

**Acceptance Criteria:**
- I can execute single commands with specific environment variables
- The tool returns the same exit code as the executed command
- No interactive prompts block automated execution
- Environment loading adds less than 100ms overhead

### Story 3: Team Configuration Management
**As a** team lead  
**I want to** define standard environment configurations  
**So that** all team members use consistent settings

**Acceptance Criteria:**
- I can define common variables shared across all environments
- I can override specific variables per environment
- Configuration files use a human-readable format
- New team members can get started with example configurations

### Story 4: Mistake Prevention
**As a** developer  
**I want to** be prevented from accidentally nesting environments  
**So that** I don't mix variables from different configurations

**Acceptance Criteria:**
- The tool detects if I'm already in a Stand environment
- Clear error messages explain what went wrong
- I receive suggestions on how to proceed correctly
- No variables leak between different environment sessions

### Story 5: Migration from Existing Tools
**As a** developer currently using dotenv/direnv  
**I want to** migrate my existing configuration  
**So that** I can adopt Stand without recreating all my environment files

**Acceptance Criteria:**
- I can import existing .env files
- The tool preserves my variable definitions
- Migration process completes in one command
- I can verify the imported configuration before using it

## 5. Functional Requirements

### 5.1 Environment Management

- **FR-1.1**: Users SHALL be able to initialize Stand in any directory
- **FR-1.2**: Users SHALL be able to define multiple named environments (e.g., dev, beta, prod)
- **FR-1.3**: Each environment SHALL support defining variables within the configuration file
- **FR-1.4**: Environments SHALL support inheriting from other environments using `extends`
- **FR-1.5**: Configuration SHALL support common variables shared across all environments
- **FR-1.6**: Users SHALL be able to list all available environments
- **FR-1.7**: Users SHALL be able to view environment variables with or without values
- **FR-1.8**: Users SHALL be able to view active environment variables in the current subshell

### 5.2 Environment Activation

- **FR-2.1**: Users SHALL be able to start a subshell with a specific environment
- **FR-2.2**: The subshell prompt SHALL clearly indicate the active environment
- **FR-2.3**: Users SHALL be able to execute single commands with a specific environment
- **FR-2.4**: The tool SHALL prevent nested environment activation
- **FR-2.5**: Users SHALL be able to exit an environment cleanly
- **FR-2.6**: Users SHALL be able to configure automatic exit when leaving the project directory

### 5.3 Variable Management

- **FR-3.1**: Variables SHALL follow the KEY=VALUE format
- **FR-3.2**: Variables SHALL support quoted values with spaces
- **FR-3.3**: Later variable definitions SHALL override earlier ones
- **FR-3.4**: Users SHALL be able to set temporary session variables
- **FR-3.5**: Users SHALL be able to unset variables

### 5.4 Configuration

- **FR-4.1**: Configuration SHALL use TOML format for all data including variables
- **FR-4.2**: All configuration and environment variables SHALL be stored in a single `.stand.toml` file
- **FR-4.3**: Configuration SHALL support comments using TOML syntax
- **FR-4.4**: Users SHALL be able to validate configuration syntax
- **FR-4.5**: Configuration SHALL support environment variable expansion (e.g., `${VAR}`)
- **FR-4.6**: The tool SHALL discover configuration files in order: `.stand.toml`, then `.stand/config.yaml` (legacy)
- **FR-4.7**: The tool SHALL provide deprecation warnings for legacy YAML configuration
- **FR-4.8**: The tool SHALL support migration from legacy YAML to TOML configuration

### 5.5 Shell Compatibility

- **FR-5.1**: The tool SHALL work with bash (4.0+)
- **FR-5.2**: The tool SHALL work with zsh (5.0+)
- **FR-5.3**: The tool SHALL work with fish (3.0+)
- **FR-5.4**: The tool SHALL detect the user's shell automatically
- **FR-5.5**: The tool SHALL provide appropriate prompts for each shell type

## 6. Non-Functional Requirements

### 6.1 Performance

- **NFR-1.1**: Subshell creation SHALL complete within 100ms
- **NFR-1.2**: TOML parsing and environment loading SHALL handle 100 variables in under 50ms
- **NFR-1.3**: Command execution overhead SHALL not exceed 20ms
- **NFR-1.4**: Binary size SHALL be under 10MB

### 6.2 Usability

- **NFR-2.1**: New users SHALL be productive within 5 minutes
- **NFR-2.2**: Error messages SHALL be clear and actionable
- **NFR-2.3**: Common operations SHALL require minimal typing
- **NFR-2.4**: Visual feedback SHALL use colors for clarity

### 6.3 Reliability

- **NFR-3.1**: No environment variables SHALL leak between sessions
- **NFR-3.2**: The tool SHALL handle malformed configuration gracefully
- **NFR-3.3**: Exit codes SHALL be preserved from executed commands
- **NFR-3.4**: State files SHALL be cleaned up properly

### 6.4 Security

- **NFR-4.1**: Configuration files SHALL have appropriate file permissions
- **NFR-4.2**: Sensitive `.stand.toml` files SHALL be automatically gitignored when containing secrets
- **NFR-4.3**: The tool SHALL warn about overly permissive file permissions

### 6.5 Portability

- **NFR-5.1**: The tool SHALL work on Linux (x86_64, aarch64)
- **NFR-5.2**: The tool SHALL work on macOS (Intel and Apple Silicon)
- **NFR-5.3**: The tool SHALL be distributed as a single binary
- **NFR-5.4**: No runtime dependencies SHALL be required

## 7. Constraints

- The tool must be implemented in Rust for performance and safety
- The command name must be `stand`
- Configuration files must use the `.stand.toml` filename
- The tool must not require root/admin privileges
- The tool must not modify the user's shell configuration files

## 8. Assumptions

- Users have basic command-line knowledge
- Users have one of the supported shells installed
- Projects already use environment variables for configuration
- Users want explicit control over environment switching
- Most usage will be interactive (vs automated)

## 9. Out of Scope (MVP)

- Encrypted variable storage
- Remote/cloud configuration synchronization
- Team sharing features
- Windows native shell support (PowerShell, cmd)
- GUI or web interface
- Plugin system
- Integration with secret management services

## 10. Success Criteria

### Adoption Metrics
- Users can complete initial setup in under 2 minutes
- 90% of common operations require 10 keystrokes or less
- Zero reported cases of environment variable leakage

### Quality Metrics
- Test coverage > 80%
- All commands respond in < 100ms
- Binary works on all target platforms without modification

### User Satisfaction
- Faster workflow compared to manual environment switching
- Reduced errors from wrong environment usage
- Simplified command execution with active environments

## 11. Glossary

- **Environment**: A named set of environment variables (e.g., dev, prod)
- **Subshell**: A child shell process with isolated environment variables
- **Base/Common Variables**: Variables shared across multiple environments
- **Environment File**: A file containing KEY=VALUE pairs (.env format)
- **State**: Runtime information about active environment and session