SKILL.md
.codex/skills/compose-kotlin-agent-skills/SKILL.md
1---2name: compose-kotlin-agent-skills3description: >4 Enterprise Android/Kotlin skill for 2026 — Kotlin 2.x K2 compiler, AGP 9, Navigation 3,5 edge-to-edge Compose, strict MVI with atomic _state.update, banned AI antipatterns.6 Jetpack Compose, Hilt, Room, KMP, CameraX/ML Kit, performance, testing. Use when writing7 Kotlin for Android, building Compose UI, MVVM/MVI architecture, debugging recomposition,8 Room DAOs, Navigation 3, coroutines, or asking "structure Android app", "ViewModel UiState",9 "collectAsStateWithLifecycle", "edge to edge", "AGP 9", "K2 compiler", "Play Store release".10license: MIT11metadata:12 author: haidrrrry13 version: "2.2.0"14 standard: agentskills.io15 platforms:16 target: ["android", "kotlin-multiplatform", "compose-multiplatform"]17 host: ["macos", "linux", "windows"]18 agent_compatibility: 2719---2021# Android & Kotlin — Enterprise Production Skill (2026)2223Authoritative Android engineering kit. Real patterns from [AnimatedClockJetpacl](https://github.com/haidrrrry/AnimatedClockJetpacl), [Authenticator](https://github.com/haidrrrry/Authenticator), [RepLock](https://github.com/haidrrrry/RepLockPushupAppBlocker).2425> **Not** an Android library, voice-assistant skill, on-device LLM SDK, or Compose UI library.26> This is **markdown for coding AIs** — clone into `.cursor/skills/` or `.claude/skills/`. See README § "What this is NOT".2728**Meta index:** [`AGENTS.md`](AGENTS.md) · **CI:** `python3 scripts/validate_skills.py`2930## Sub-Skills (Modular)3132| Skill | Path | Scope |33|-------|------|-------|34| Architecture | [`skills/android-kotlin-architecture/SKILL.md`](skills/android-kotlin-architecture/SKILL.md) | MVI/MVVM, modules, UseCases, UDF |35| Compose UI | [`skills/android-kotlin-compose/SKILL.md`](skills/android-kotlin-compose/SKILL.md) | UI, edge-to-edge, performance, motion |36| Testing | [`skills/android-kotlin-testing/SKILL.md`](skills/android-kotlin-testing/SKILL.md) | Turbine, Compose tests, Hilt fakes |3738## 2026 Toolchain — Non-Negotiable3940| Tool | Minimum | Notes |41|------|---------|-------|42| Kotlin | **2.0+** (2.1.x) | K2 compiler only — no K1 fallback |43| AGP | **9.0+** | Built-in Kotlin, new DSL defaults |44| Compose BOM | **2025.05+** | Material 3, strong skipping default |45| Navigation | **3.x** (`2.9+` artifact) | Type-safe `NavKey`, `@Serializable` routes |46| compileSdk / targetSdk | **35+** | Edge-to-edge mandatory |47| JDK | **17** | Required for AGP 9 |4849```toml50[versions]51kotlin = "2.1.20"52agp = "9.0.0"53compose-bom = "2025.05.00"54navigation = "2.9.0"55room = "2.7.1"56hilt = "2.56.2"57lifecycle = "2.9.0"58coroutines = "1.10.2"59```6061## Kotlin 2.x / K2 Compiler Constraints62631. **Enable K2** — `kotlin.compiler.execution.strategy` default; use `ksp` not `kapt` for Hilt/Room.642. **Smart casts** — prefer `when (val x = state) { is Loaded -> ... }` over unsafe `!!`.653. **Sealed hierarchy** — `sealed interface UiState` + `data object Loading : UiState` for exhaustive `when`.664. **`@JvmInline value class`** for IDs (`@JvmInline value class UserId(val raw: String)`).675. **`@Immutable` / `@Stable`** on UiState and UI models passed to Compose.686. **Explicit API** optional for libraries — `kotlin { explicitApi() }` in published modules.697. **No `!!`** except in tests with comment — use `requireNotNull` / early return.708. **`data class` copy** for state — never mutate UiState fields in place.7172```kotlin73sealed interface AccountsUiState {74 data object Loading : AccountsUiState75 data class Ready(76 val accounts: List<AccountUi>,77 val query: String = ""78 ) : AccountsUiState79 data class Error(@StringRes val messageRes: Int) : AccountsUiState80}81```8283## MVI Guardrails — Atomic State Only8485**Allowed mutation:** `_state.update { it.copy(...) }` or `_state.update { prev -> ... }`.8687**Banned in ViewModel:**8889```kotlin90// BANNED91_state.value = AccountsUiState(...) // naked assign92_state.value.accounts.add(item) // mutating list inside state93mutableStateOf / mutableStateListOf in VM // Compose scope only94viewModelScope.launch { _state.value = ... } // use update inside launch95```9697**Required pattern:**9899```kotlin100class AccountsViewModel @Inject constructor(101 private val repository: AccountsRepository102) : ViewModel() {103104 private val _state = MutableStateFlow<AccountsUiState>(AccountsUiState.Loading)105 val state: StateFlow<AccountsUiState> = _state.asStateFlow()106107 private val _effects = Channel<AccountsEffect>(Channel.BUFFERED)108 val effects: Flow<AccountsEffect> = _effects.receiveAsFlow()109110 fun onEvent(event: AccountsEvent) {111 when (event) {112 AccountsEvent.Refresh -> refresh()113 is AccountsEvent.QueryChanged -> _state.update { current ->114 when (current) {115 is AccountsUiState.Ready -> current.copy(query = event.query)116 else -> current117 }118 }119 }120 }121122 private fun refresh() {123 viewModelScope.launch {124 _state.update { AccountsUiState.Loading }125 repository.load()126 .onSuccess { list ->127 _state.update { AccountsUiState.Ready(accounts = list.map { it.toUi() }) }128 }129 .onFailure {130 _state.update { AccountsUiState.Error(R.string.error_load_failed) }131 }132 }133 }134}135```136137**UI collects:**138139```kotlin140@Composable141fun AccountsRoute(vm: AccountsViewModel = hiltViewModel()) {142 val state by vm.state.collectAsStateWithLifecycle()143 LaunchedEffect(Unit) {144 vm.effects.collect { effect -> /* one-shot: nav, snackbar */ }145 }146 AccountsScreen(state = state, onEvent = vm::onEvent)147}148```149150## Navigation 3 + Edge-to-Edge151152```kotlin153@Serializable data object Home154@Serializable data class Detail(val id: String)155156@Composable157fun AppNavHost(navController: NavHostController = rememberNavController()) {158 NavHost(navController, startDestination = Home) {159 composable<Home> { HomeScreen(onOpen = { navController.navigate(Detail(it)) }) }160 composable<Detail> { entry ->161 val route = entry.toRoute<Detail>()162 DetailScreen(id = route.id)163 }164 }165}166```167168- Routes = `@Serializable` types, not string paths169- Pass **IDs** in nav args — fetch models in destination ViewModel170- `enableEdgeToEdge()` in Activity — see compose sub-skill171172Deep dive: [`references/07-navigation.md`](references/07-navigation.md)173174## Banned Antipatterns — AI Hallucination Lookup175176Full table with WRONG/RIGHT pairs and row numbers: **[`references/00-banned-antipatterns.md`](references/00-banned-antipatterns.md)**177178Load before reviewing any agent-generated Kotlin. Compose audit checklist: [`skills/android-kotlin-compose/SKILL.md`](skills/android-kotlin-compose/SKILL.md) § REVIEW MODE.179180## Reference Routing181182| File | Topic |183|------|-------|184| `references/00-banned-antipatterns.md` | Master banned table — load first for reviews |185| `references/01-architecture.md` | Clean Arch, MVVM, modules |186| `references/02-compose-ui.md` | Composition, M3, theming |187| `references/03-animations.md` | Motion, Canvas |188| `references/04-coroutines-flow.md` | Flow, errors, cancellation |189| `references/05-hilt-di.md` | DI, scopes |190| `references/06-room-db.md` | Room, offline-first |191| `references/07-navigation.md` | Nav 3, deep links |192| `references/08-kmp-cmp.md` | KMP, expect/actual |193| `references/09-networking.md` | Ktor, JWT |194| `references/10-performance.md` | Recomposition, Coil, profiles |195| `references/11-testing.md` | Turbine, UI tests |196| `references/12-camera-mlkit.md` | CameraX, pose |197| `references/13-release-checklist.md` | R8, Play Store |198| `references/14-datastore.md` | DataStore, SP migration, encryption |199| `references/15-paging3.md` | Paging 3, RemoteMediator, asState() |200| `references/16-coil-image.md` | Coil 3.4, AsyncImage, cache |201| `references/17-accessibility.md` | TalkBack, semantics, WCAG |202| `references/18-gradle-build-logic.md` | Convention plugins, KSP, R8, baseline profiles |203| `references/19-xml-to-compose-migration.md` | XML → Compose, RxJava → Flow |204205## Platforms206207**Target (what the docs teach):** Android · Kotlin Multiplatform · Compose Multiplatform208**Host (where the docs are read):** macOS · Linux · Windows — anywhere your AI agent runs209**Agent compatibility:** 27 install guides → [`agents/README.md`](agents/README.md)210211Repo: `https://github.com/haidrrrry/compose-kotlin-agent-skills`212213## Mandatory Defaults (Summary)214215- **Strings:** `stringResource` / `@StringRes` — zero hardcoded UI text216- **State:** ViewModel `StateFlow` + `_state.update { }`217- **UI:** Stateless composables, `modifier` first optional param218- **Lists:** `LazyColumn` + keys + `contentType`219- **DI:** `@HiltViewModel` + constructor inject220- **Tests:** Fakes + Turbine — see testing sub-skill221222## Validation Before PR223224```bash225python3 scripts/validate_skills.py --strict226```227228## Anti-Rationalizations229230| Excuse | Reality |231|--------|---------|232| "UiState overkill" | `data object Loading` costs one line |233| "Keys later" | Broken scroll/focus NOW |234| "Prototype skip repo" | Prototypes ship |235| "collectAsState fine" | Background collector drains battery |236237## Examples238239| Path | Patterns |240|------|----------|241| `examples/animated-clock/` | Canvas, `rotate()`, particles |242| `examples/authenticator/` | Room Flow, `combine`, CompositionLocal theme |243