# Dev Cheat Sheet

Concise command reference for day-to-day work across Git, Python, Rust, Node, Tauri, and .NET.

Use this as a practical command sheet, not as a full tutorial.

## Table of Contents 📑

- [Setup](#setup)
- [Git](#git)
- [PAQ-Next (Advanced Compression)](#paq-next-advanced-compression)
- [Python](#python)
- [Node and npm](#node-and-npm)
- [Rust](#rust)
- [Tauri v2](#tauri-v2)
- [Dotnet and CSharp](#dotnet-and-csharp)
- [Common Output Folder Pattern](#common-output-folder-pattern)
- [Docker](#docker)
- [Useful Cleanup Commands](#useful-cleanup-commands)
- [Recommended Habits](#recommended-habits)
- [Workflows and SDT DevTool](#workflows-and-sdt-devtool)

## Setup

### Setup w64devkit for C++ (PAQ-Next)

```powershell
$env:PATH = "f:\w64devkit\w64devkit\bin;" + $env:PATH
```

Adds GCC/G++ and Unix tools to the current PowerShell session.

### Probe toolchain availability

```powershell
python scripts/diag.py probe --tool dotnet --json
python scripts/diag.py probe --tool python --json
python scripts/diag.py probe --tool node --json
python scripts/diag.py probe --tool npm --json
python scripts/diag.py probe --tool cargo --json
python scripts/diag.py probe --tool tauri --json
python scripts/diag.py probe --tool git --json
```

Checks if required tools are in the current path.

### Shell bootstrap (doctor)

```powershell
python scripts/dev_shell.py doctor
```

Analyzes the environment and reports missing components or configuration errors.

[Back to Top](#dev-cheat-sheet)

## Git

### Check where you are

```powershell
git status --short --branch
git remote -v
git branch -vv

# See which files are ignored by git
git clean -nd
```

### Stashing

```powershell
git stash push -m "Description"
git stash pop
git stash drop # Discard
git stash clear # Wipe all stashes
```

### Remotes & Pushing - THE FLAGS

```powershell
# Safer 'force push' (fails if remote has moved)
git push --force-with-lease

# Push all branches and all tags at once
git push --all
git push --tags

# Delete a remote branch
git push origin --delete branch-name

# Set upstream for current branch (first push)
git push -u origin branch-name
```

### History & Analysis

```powershell
# Graphical log in terminal
git log --graph --oneline --decorate --all

# Search commit messages
git log --grep="bug fix"

# Find which commit introduced a string
git log -S "secret_key"

# See changes per line (last change for every line)
git blame file_path.py
```

### Git Repository Cleanup

```powershell
# Fast cleanup of untracked files
git clean -fd

# Prune stale remote tracking branches
git fetch origin --prune
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

## PAQ-Next (Advanced Compression)

### Compile PAQ-Next (C++)

```powershell
# Add toolchain first (if not in path)
$env:PATH = "f:\w64devkit\w64devkit\bin;" + $env:PATH

# Build from root of src-paq-next/
g++ -O3 -mavx2 -Iinclude cli/main.cpp src/archiver.cpp -o paq_next_cli.exe
```

Compiles with AVX2 optimizations and include-path support.

### Run PAQ-Next Compression

```powershell
# Compress a folder
.\paq_next_cli.exe c <source_folder>

# Compress a folder to a specific file
.\paq_next_cli.exe c <source_folder> <output_name>.paq

# Extract an archive
.\paq_next_cli.exe x <archive>.paq <destination_folder>
```

[Back to Top](#dev-cheat-sheet)

## Python

### Package Management - THE FLAGS

```powershell
# Install from requirements with upgrades
pip install -r requirements.txt --upgrade

# Install without saving to cache (Great for CI/Low disk)
pip install -r requirements.txt --no-cache-dir

# Target a specific directory
pip install -t ./lib <package>

# Search local packages for a string
pip list | Select-String "crypto"

# See everything about a package
pip show <package-name>
```

### Quality & Performance

```powershell
# Parallel testing
pip install pytest-xdist
pytest -n auto # Use all CPU cores

# Benchmark a script
python -m cProfile -s time script.py
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

## Node and npm

### Dependency Management - THE FLAGS

```powershell
# Force install (when versions conflict)
npm install --force

# Ignore peer dependency errors (Common in React)
npm install --legacy-peer-deps

# Production only (Skip devDependencies)
npm install --production

# Deep security audit and auto-fix
npm audit fix --force
```

### Scripts & Performance

```powershell
# Build with specific log level
npm run build --loglevel silent

# Pass custom flags directly to a script
npm run dev -- --host 0.0.0.0 --port 3000
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

## Rust

### Essential Workflow - THE FLAGS

```powershell
# Fast check (Skip code generation)
cargo check --all-targets --all-features

# Build with specific features enabled
cargo build --features "feature-a,feature-b"

# Build without default features
cargo build --no-default-features

# Cross-compilation (Requires target in toolchain)
cargo build --target x86_64-apple-darwin
cargo build --target aarch64-unknown-linux-gnu
```

### Diagnostics & Performance

```powershell
# See exactly why a build is slow
cargo build --timings

# Run specific test by name/substring
cargo test test_function_name

# Open local docs for all dependencies
cargo doc --open --no-deps
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

## Tauri v2

### Initialize Mobile (REQUIRED for first run)

```powershell
# This creates the android/ios project folders in src-tauri/gen
npm run tauri android init
npm run tauri ios init
```

### Desktop Builds - THE FLAGS

```powershell
# Fast build (Binary only)
npm run tauri build -- --no-bundle

# Explicit config file (Great for multi-env)
npm run tauri build -- --config path/to/config.json

# Verbose output for debugging packaging
npm run tauri build -- --verbose
```

### Mobile Builds

```powershell
# Debug mode on Android device (or Emulator)
npm run tauri android dev

# Production APK/AAB generation
npm run tauri android build -- --target aarch64
```

### Troubleshooting

```powershell
# System diagnostic report
npm run tauri info
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

### Frontend-only build

```powershell
npm run build
```

Builds the web frontend assets (the `dist/` folder) without launching or packaging the desktop app.

## Dotnet and CSharp

### Restore & Build - THE FLAGS

```powershell
# Restore from specific NuGet source
dotnet restore --source https://api.nuget.org/v3/index.json

# Build without restoring (Great for build script repetition)
dotnet build --no-restore

# Build with minimal output (Keep it clean)
dotnet build --verbosity quiet # or minimal, normal, detailed, diagnostic
```

### Run & Watch

```powershell
# Run with custom environment variables
$env:ASPNETCORE_ENVIRONMENT="Development"; dotnet run

# Watch with specific project filter
dotnet watch --project Project.csproj
```

### Advanced Publishing

```powershell
# Single-File for Linux (Self-Contained)
dotnet publish -c Release -r linux-x64 --self-contained true `
  -p:PublishSingleFile=true `
  -p:IncludeNativeLibrariesForSelfExtract=true `
  -o ./output/linux-x64-single

# Ready-To-Run (R2R) - Fast startup at the cost of size
dotnet publish -c Release -o ./output -p:PublishReadyToRun=true
```

### Tools

```powershell
# Install a dotnet tool globally
dotnet tool install -g <tool-name>
```

&nbsp;
[🔼 Back to Top](#dev-cheat-sheet)

## Common Output Folder Pattern

Use explicit output folders so results are easy to find and easy to clean up.

```powershell
./output/
./output/win-x64/
./output/win-x64-single/
./output/linux-x64/
./output/linux-x64-single/
```

[Back to Top](#dev-cheat-sheet)

## Docker

### Build & Run

```powershell
docker build -t app-name .
docker run -p 8080:80 app-name
```

### Docker System Cleanup

```powershell
docker system prune -a # Wipe everything unused
docker container prune
docker image prune
```

[Back to Top](#dev-cheat-sheet)

## Useful Cleanup Commands

### Remove Node artifacts

```powershell
Remove-Item -Recurse -Force .\node_modules
Remove-Item -Recurse -Force .\dist
```

### Remove Rust / Tauri artifacts

```powershell
Remove-Item -Recurse -Force .\src-tauri\target
```

### Remove .NET artifacts (Deep clean)

```powershell
Get-ChildItem -Include bin,obj,output -Recurse | Remove-Item -Recurse -Force
```

### Remove Python artifacts

```powershell
Remove-Item -Recurse -Force .\.venv
Get-ChildItem -Include __pycache__ -Recurse | Remove-Item -Recurse -Force
```

[Back to Top](#dev-cheat-sheet)

## Recommended Habits

Before any risky Git action:

```powershell
git status --short --branch
git branch backup/pre-risk
git tag pre-risk-YYYY-MM-DD
git fetch origin --prune
```

Before publishing builds:

```powershell
npm run build
cargo test
dotnet test
```

Adjust to the stack used by the current project.

[Back to Top](#dev-cheat-sheet)

## Workflows and SDT DevTool

### Build / Run SDT (DevTool)

```powershell
# Quick build
python scripts/dotnet-min.py build

# Standard run
dotnet run --project DevTool.csproj
```

### Route & Workflow Verification

```powershell
# Static check
python scripts/verify-workflow-routes.py --project-root .

# Headless execution test
python scripts/verify-workflow-routes.py --project-root . --workflow build --workflow tauri --execute --env-profile dev
```

### Build & Sync Output

```powershell
# Publish web assets + app
python scripts/publish-app.py --target web

# Publish specific projects
python scripts/publish-sidecar.py --project path/to/sidecar.csproj
python scripts/publish-webgateway.py --project path/to/gateway.csproj

# Sync all results to central output/
python scripts/sync-output.py
```

### Database Migration Gate

```powershell
python scripts/migration-gate.py
```

### NuGet / Node Cleanup

```powershell
# NuGet cache export
python scripts/nuget-export-cache.py --output-zip cache-export.zip

# Clean node_modules safely
python scripts/npm-clean.py --working-dir .
```

[Back to Top](#dev-cheat-sheet)
