|
| 1 | + |
| 2 | + |
| 3 | +# tuSSHi AI Coding Guidelines |
| 4 | + |
| 5 | +This document defines the coding standards, architectural decisions, and practices for the tuSSHi codebase. Every AI assistant and developer working on this project **must** adhere strictly to these rules. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## 1. Universal Principles |
| 10 | + |
| 11 | +### 1.1 Comments & Documentation |
| 12 | +- **No Inline Comments**: Do not write comments within function bodies to explain syntax, control flow, or standard actions. If logic is complex, rewrite it to be self-documenting or extract it into a descriptive helper function. |
| 13 | +- **Redundant Comments Ban**: Comments that echo the code syntax (e.g., `counter++ // increment counter`) are strictly forbidden. |
| 14 | +- **Allowed Comments**: |
| 15 | + - Package/Library-level docstrings and standard Go package documentation. |
| 16 | + - Standard API documentation on public interfaces/functions/types. |
| 17 | + - High-level `// Why:` comments explaining non-obvious architecture or constraints. |
| 18 | + - Actionable `// TODO:` comments explaining shortcuts taken or rough edges, including what should be done in the future. |
| 19 | +- **Style**: Keep short comments lowercase. Use capital letters only for multi-line contextual explanations. |
| 20 | +- **Self-Debates**: Never start self-debates in comments or code. |
| 21 | + |
| 22 | +### 1.2 Function & File Design |
| 23 | +- **Single Responsibility (SOLID)**: Every function must do exactly one thing and do it right. If a function performs multiple operations, break it down. |
| 24 | +- **DRY (Don't Repeat Yourself)**: Generalized utilities must be extracted. Never duplicate logic or functions. |
| 25 | +- **Function Names**: The name must clearly reflect the function's single action. Avoid generic names or names with "And" (which signals multiple responsibilities). |
| 26 | +- **File Length Limit**: A strict ceiling of **300 lines per file**. If a file exceeds this: |
| 27 | + - Decouple, group, and split into sub-modules or logical extensions unless structurally impossible. |
| 28 | + - **Important for AI**: Ask the developer for permission before performing a major file split/refactoring. Do not do it autonomously. |
| 29 | +- **Clean Code**: No dead, unused, or commented-out code. Use named constants instead of magic numbers. |
| 30 | + |
| 31 | +### 1.3 Development & Workflows |
| 32 | +- **Test Guard**: **NEVER** execute test suites natively (`go test` or `just test`, etc.) unless explicitly instructed by the developer. |
| 33 | +- **Linter & Formatter Integrity**: Never bypass formatters or linters. Before presenting or pushing code, formatting and linting checks must pass cleanly. |
| 34 | +- **AI Tooling Constraints**: |
| 35 | + - AI assistants must **never** run git commits or push changes under any circumstance. Commits are reserved exclusively for human execution. |
| 36 | + - AI assistants must **never** begin execution of an implementation plan without explicit authorization/approval from the developer. A plan is a plan until the human developer explicitly says "go ahead". |
| 37 | +- **Commit Format**: All commit messages must follow the `action(part): description` format. |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## 2. Go (TUI & SSH Connection Manager) |
| 42 | + |
| 43 | +### 2.1 Tooling & Verification |
| 44 | +- **Formatting**: Format using standard Go tools via: |
| 45 | + ```bash |
| 46 | + just fmt |
| 47 | + ``` |
| 48 | +- **Linting**: Lint using the standard linter suite via: |
| 49 | + ```bash |
| 50 | + just lint |
| 51 | + ``` |
| 52 | + All code must strictly pass `gofmt` and `golangci-lint` default rules (including `errcheck`, `govet`, `staticcheck`, and `revive`). |
| 53 | + |
| 54 | +### 2.2 Structural Rules & Architecture |
| 55 | +- **Folder Structure**: Follow the Standard Go Project Layout: |
| 56 | + - `/cmd` -> Application entry points (main.go). |
| 57 | + - `/internal` -> Private application/business logic (e.g., config handling, TUI layout/views/components, SSH file parsing); absolute ban on external package exposure. |
| 58 | + - `/pkg` -> Explicitly exportable, reusable utility packages. |
| 59 | +- **TUI Architecture**: |
| 60 | + - The application is built using the Bubble Tea framework (Model-View-Update pattern). |
| 61 | + - UI components (under `/internal/tui/components`) should be clean, modular, and self-contained. |
| 62 | + - Theme configurations, colors, and layout borders are defined centrally using `lipgloss` under `/internal/tui/style` and `/internal/tui/theme`. Use these existing styles and tokens instead of hardcoding styles inline. |
| 63 | + - Forms and text inputs should utilize standard components or `github.com/charmbracelet/huh` where appropriate. |
| 64 | +- **SSH Configuration Management**: |
| 65 | + - Manage the primary source of truth (`~/.ssh/config` or alternative config paths) losslessly using the AST-based parser (`github.com/kevinburke/ssh_config`). |
| 66 | + - Do not overwrite configuration files destructively; preserve comments, custom spacing, and formatting. |
| 67 | +- **Implicit Interfaces**: Leverage Go's implicit interface implementation. Do not define interfaces before they are actually needed by consumers. |
| 68 | +- **Error & Logging**: |
| 69 | + - Return early with errors. Avoid deeply nested conditional blocks (e.g., write `if err != nil { return err }` instead of deep nesting). |
| 70 | + - Avoid writing manual logging workarounds. If structured logs or diagnostics are needed, use standard CLI reporting patterns or log outputs. |
| 71 | + |
| 72 | +### 2.3 Testing |
| 73 | +- **Unit Testing**: |
| 74 | + - Use `t.Run` to group subtests. |
| 75 | + - Name test files explicitly matching target: `xxx_test.go`. |
| 76 | + - Use `stretchr/testify/assert` consistently. |
| 77 | + - Keep test components mocked where necessary to avoid real filesystem mutations unless specifically testing lossless filesystem writes. |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## 3. Verification Commands Reference |
| 82 | + |
| 83 | +Run the following commands within their respective targets to ensure compliance (note: tests should only be run when explicitly instructed): |
| 84 | + |
| 85 | +| Action | Command | Description | |
| 86 | +|---|---|---| |
| 87 | +| **Format** | `just fmt` | Formats all Go files using `gofmt` | |
| 88 | +| **Lint / Analyze** | `just lint` | Runs `golangci-lint` on the project | |
| 89 | +| **Run Application**| `just run` | Runs the TUI application directly | |
| 90 | +| **Test Run** | `go test ./...` | Runs the test suite (**Only if explicitly instructed**) | |
0 commit comments