|
| 1 | +# AGENTS.md — AudioType |
| 2 | + |
| 3 | +> Guidelines for AI coding agents working in this repository. |
| 4 | +
|
| 5 | +## Project Overview |
| 6 | + |
| 7 | +AudioType is a **native macOS menu bar app** for voice-to-text. Users hold the `fn` key to record, release to transcribe via Groq's Whisper API, and the result is typed into the focused app. It runs as an `LSUIElement` (no dock icon), built with Swift Package Manager (not Xcode projects). |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Debug build (used during development) |
| 13 | +swift build |
| 14 | + |
| 15 | +# Release build |
| 16 | +swift build -c release |
| 17 | + |
| 18 | +# Build + create .app bundle (debug) |
| 19 | +make app |
| 20 | + |
| 21 | +# Full dev cycle: kill running app, reset Accessibility, rebuild, install to /Applications, launch |
| 22 | +make dev |
| 23 | + |
| 24 | +# Clean all build artifacts |
| 25 | +make clean |
| 26 | +``` |
| 27 | + |
| 28 | +**There is no Xcode project.** The app is built entirely via `Package.swift` + `Makefile`. Do not create `.xcodeproj` or `.xcworkspace` files. |
| 29 | + |
| 30 | +## Lint |
| 31 | + |
| 32 | +```bash |
| 33 | +# Run SwiftLint (must pass before merge — CI blocks on failure) |
| 34 | +swiftlint lint AudioType |
| 35 | + |
| 36 | +# Format code with swift-format |
| 37 | +swift-format -i -r AudioType |
| 38 | + |
| 39 | +# Install lint tools |
| 40 | +make setup |
| 41 | +``` |
| 42 | + |
| 43 | +SwiftLint config is in `.swiftlint.yml`. Key rules: |
| 44 | +- **`force_cast`** is an error — always use `as?` with guard/if-let |
| 45 | +- **`opening_brace`** — opening braces must be on the same line, preceded by a space |
| 46 | +- `trailing_whitespace`, `line_length`, `function_body_length`, `file_length`, `type_body_length` are **disabled** |
| 47 | +- See `.swiftlint.yml` for the full opt-in rule list |
| 48 | + |
| 49 | +## Tests |
| 50 | + |
| 51 | +```bash |
| 52 | +# Run all tests |
| 53 | +swift test |
| 54 | + |
| 55 | +# Run a single test (by filter) |
| 56 | +swift test --filter TestClassName |
| 57 | +swift test --filter TestClassName/testMethodName |
| 58 | +``` |
| 59 | + |
| 60 | +Note: the test target may be empty. CI runs `swift test` with `continue-on-error: true`. |
| 61 | + |
| 62 | +## CI Pipeline |
| 63 | + |
| 64 | +CI runs on every push/PR to `main` (`.github/workflows/ci.yml`): |
| 65 | +1. **Lint** — `swiftlint lint AudioType` (must pass; blocks Build and Test) |
| 66 | +2. **Build** — `swift build` (debug) + `swift build -c release` + `make app` + codesign verify |
| 67 | +3. **Test** — `swift test` (soft failure allowed) |
| 68 | + |
| 69 | +Releases (`.github/workflows/release.yml`) trigger on `v*` tags and produce `AudioType.dmg` + `AudioType.zip`. |
| 70 | + |
| 71 | +## Project Structure |
| 72 | + |
| 73 | +``` |
| 74 | +AudioType/ |
| 75 | + App/ # App entry point, menu bar controller, transcription orchestration |
| 76 | + AudioTypeApp.swift # @main, AppDelegate, onboarding flow |
| 77 | + MenuBarController.swift # NSStatusItem, state-driven icon tinting, overlay windows |
| 78 | + TranscriptionManager.swift # State machine (idle→recording→processing→idle/error) |
| 79 | + Core/ # Business logic |
| 80 | + AudioRecorder.swift # AVAudioEngine capture, PCM→16kHz resampling, RMS level |
| 81 | + GroqEngine.swift # Groq Whisper API client, WAV encoding, multipart upload |
| 82 | + HotKeyManager.swift # CGEventTap for fn key hold detection |
| 83 | + TextInserter.swift # CGEvent keyboard simulation to type into focused app |
| 84 | + TextPostProcessor.swift # Post-transcription corrections (tech terms, punctuation) |
| 85 | + UI/ # SwiftUI views |
| 86 | + RecordingOverlay.swift # Floating waveform (recording) / thinking dots (processing) |
| 87 | + OnboardingView.swift # First-launch permission + API key setup |
| 88 | + SettingsView.swift # API key, model picker, permissions, launch-at-login |
| 89 | + Theme.swift # Brand color system (coral palette, adaptive dark/light) |
| 90 | + Utilities/ |
| 91 | + Permissions.swift # Microphone + Accessibility permission helpers |
| 92 | + KeychainHelper.swift # File-based secret storage (Application Support, 0600 perms) |
| 93 | + Resources/ |
| 94 | + Assets.xcassets/ # Asset catalog (currently empty) |
| 95 | +Resources/ |
| 96 | + Info.plist # Bundle config (LSUIElement, mic usage description) |
| 97 | + AppIcon.icns # App icon (coral gradient) |
| 98 | +``` |
| 99 | + |
| 100 | +## Code Style |
| 101 | + |
| 102 | +### Imports |
| 103 | +- Sort alphabetically: `import AppKit`, `import Foundation`, `import SwiftUI` |
| 104 | +- Use specific submodule imports where appropriate: `import os.log` (not `import os`) |
| 105 | +- Only import what the file actually uses |
| 106 | + |
| 107 | +### Formatting |
| 108 | +- **2-space indentation** (no tabs) |
| 109 | +- Opening braces on the **same line** as the declaration |
| 110 | +- No trailing whitespace (rule disabled in linter, but keep it clean) |
| 111 | +- Use `// MARK: -` sections to organize classes (`// MARK: - Private`, `// MARK: - Transcription`) |
| 112 | + |
| 113 | +### Types & Naming |
| 114 | +- **Classes** for stateful objects with reference semantics: `TranscriptionManager`, `AudioRecorder` |
| 115 | +- **Enums** for namespaced constants and error types: `AudioTypeTheme`, `GroqEngineError`, `KeychainHelper` |
| 116 | +- **Structs** for SwiftUI views: `RecordingOverlay`, `SettingsView` |
| 117 | +- camelCase for properties/methods, PascalCase for types |
| 118 | +- Identifier names: min 1 char, max 50 chars; `x`, `y`, `i`, `j`, `k` are allowed |
| 119 | + |
| 120 | +### Error Handling |
| 121 | +- Define domain-specific error enums conforming to `Error, LocalizedError` |
| 122 | +- Provide human-readable `errorDescription` for every case |
| 123 | +- Use `do/catch` or `try?` — never `try!` |
| 124 | +- Never force-cast (`as!`) — use `as?` with guard/if-let |
| 125 | +- Errors shown to user go through `TranscriptionState.error(String)` |
| 126 | + |
| 127 | +### Patterns Used |
| 128 | +- **Singleton**: `TranscriptionManager.shared`, `TextPostProcessor.shared`, `AudioLevelMonitor.shared` |
| 129 | +- **`@MainActor`** on `TranscriptionManager` — all state mutations on main thread |
| 130 | +- **NotificationCenter** for decoupled state communication (`transcriptionStateChanged`, `audioLevelChanged`) |
| 131 | +- **`@Published` + ObservableObject** for SwiftUI reactivity |
| 132 | +- **Closures** for callbacks: `HotKeyManager(callback:)`, `audioRecorder.onLevelUpdate` |
| 133 | +- **`os.log` Logger** with subsystem `"com.audiotype"` — use per-class categories |
| 134 | + |
| 135 | +### Colors & Theming |
| 136 | +All colors live in `AudioType/UI/Theme.swift` (`AudioTypeTheme` enum). Never use hardcoded color literals in views. The palette: |
| 137 | +- **Coral** `#FF6B6B` — brand color, waveform bars, accents, checkmarks |
| 138 | +- **Amber** `#FFB84D` — processing state (thinking dots, menu bar icon) |
| 139 | +- **Recording red** `#FF4D4D` — menu bar icon while recording |
| 140 | +- Adaptive variants for dark mode (coralLight, amberLight) |
| 141 | + |
| 142 | +### Menu Bar Icon States |
| 143 | +- **Idle**: SF Symbol `waveform.circle.fill`, `isTemplate = true` (follows OS appearance) |
| 144 | +- **Recording**: same symbol, tinted `nsRecordingRed`, `isTemplate = false` |
| 145 | +- **Processing**: `ellipsis.circle.fill`, tinted `nsAmber`, `isTemplate = false` |
| 146 | +- **Error**: `exclamationmark.triangle.fill`, tinted `.systemRed` |
| 147 | + |
| 148 | +### Security |
| 149 | +- API keys stored in `~/Library/Application Support/AudioType/.secrets` with `0600` permissions |
| 150 | +- Never commit `.env`, credentials, or API keys |
| 151 | +- Audio is recorded in-memory only — never written to disk |
| 152 | + |
| 153 | +## App Bundle |
| 154 | +The `.app` bundle is assembled by `make app` (not Xcode): |
| 155 | +- Binary: `.build/debug/AudioType` → `AudioType.app/Contents/MacOS/AudioType` |
| 156 | +- Plist: `Resources/Info.plist` → `AudioType.app/Contents/Info.plist` |
| 157 | +- Icon: `Resources/AppIcon.icns` → `AudioType.app/Contents/Resources/AppIcon.icns` |
| 158 | +- Ad-hoc codesigned: `codesign --force --deep --sign -` |
| 159 | + |
| 160 | +When updating the version, change **both** `CFBundleVersion` and `CFBundleShortVersionString` in `Resources/Info.plist` **and** the display string in `SettingsView.swift`. |
0 commit comments