agentleFS
wrinfotelwrinfotel/verified-android-skills/skills/kmp-fundamentals/SKILL.md

kmp-fundamentals

Skill0 starsChanged 35 days agoMITView on GitHub

Kotlin Multiplatform fundamentals: source-set discipline, expect/actual placement and balance, and multiplatform dependency choices. Use when writing or reviewing code in commonMain/platform source sets, adding expect declarations, or migrating shared logic to KMP. Core rules have machine checks in checks/.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 2 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    After ANY expect/actual or source-set edit, run the Verification step (bottom of this file).

    line 15
  2. Very specific:

    MUST keep common source sets (commonMain, commonTest) free of platform SDK imports: android.*, java.* / javax.*, com.android.*, …

    line 21
  3. Very specific:

    MUST declare expect in the common source set and actual in each platform-specific source set, in the same package — never the reverse.

    line 55
  4. Very specific:

    Every expect declaration MUST have an actual in every declared platform source set.

    line 78
  5. Very specific:

    Prefer not needing expect/actual at all: "rely on standard language constructs wherever possible" — a common interface with platform …

    line 83
  6. Very specific:

    Add dependencies per source set: commonMain.dependencies { } for shared code, androidMain.dependencies { } for Android-only.

    line 108
  7. Very specific:

    No deterministic check covers dependency wiring.

    line 118
  8. Very specific:

    Run after every KMP-related edit (from the module's src root, i.e.

    line 123
  9. Distinctive:

    All three must pass (exit 0) before declaring the task done.

    line 132

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

KMP Fundamentals

Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY expect/actual or source-set edit, run the Verification step (bottom of this file). The checks give pre-compile feedback in seconds — the compiler stays the ground truth.

1. Source-set discipline — no platform APIs in common

MUST keep common source sets (commonMain, commonTest) free of platform SDK imports: android.*, java.* / javax.*, com.android.*, com.google.android.*, androidx.activity.*, and Kotlin/Native platform.*. Common code compiles to every target, where those SDKs do not exist ("you can't use the java.io.File dependency from the common code").

WRONG:

// commonMain/.../Greeting.kt
import java.io.File

fun greeting() {
    File("greeting.txt").writeText("Hello, Multiplatform!")
}

RIGHT:

// commonMain/.../Greeting.kt
import kotlinx.io.files.Path

fun greeting() {
    // use a multiplatform library (kotlinx-io, Ktor, kotlinx-datetime, ...)
}

androidx.compose.* / material3 and other Compose Multiplatform artifacts are intentionally NOT flagged: they ship a common API. Shared platform- family code (e.g. Apple APIs) belongs in intermediate source sets (appleMain), not in commonMain.

2. expect/actual placement

MUST declare expect in the common source set and actual in each platform-specific source set, in the same package — never the reverse.

WRONG:

// androidMain/.../Platform.android.kt
expect fun androidApiLevel(): Int        // expect belongs in commonMain

// commonMain/.../Platform.kt
actual fun logTag(): String = "shared"   // actual belongs in a platform set

RIGHT:

// commonMain/.../Platform.kt
expect fun androidApiLevel(): Int

// androidMain/.../Platform.android.kt
actual fun androidApiLevel(): Int = Build.VERSION.SDK_INT

3. expect/actual balance — and prefer interfaces

Every expect declaration MUST have an actual in every declared platform source set; an actual without a matching expect does not compile. The check below verifies the name balance across the whole module before you build.

Prefer not needing expect/actual at all: "rely on standard language constructs wherever possible" — a common interface with platform implementations (wired by DI or a small expect/actual factory) beats expect class. Expected/actual classes are Beta and recommended only for inheriting platform classes.

WRONG:

// commonMain
expect class Logger() {
    fun log(message: String)
}

RIGHT:

// commonMain
interface Logger {
    fun log(message: String)
}
expect fun buildLogger(): Logger   // actualized per platform or via DI

4. Dependencies & libraries (review-verified)

  • Add dependencies per source set: commonMain.dependencies { } for shared code, androidMain.dependencies { } for Android-only.
  • In common code prefer multiplatform libraries — kotlinx-coroutines, kotlinx-datetime, kotlinx-io, Ktor client, kotlinx.serialization — over platform APIs.
  • Platform-only libraries (Guava, Spring, Room desktop variants) go to the corresponding platform source set.
  • Tests mirror sources: commonTest compiles to all targets; use kotlin.test there, platform frameworks only in platform test sets.

No deterministic check covers dependency wiring; verify against references/kmp.md.

Verification

Run after every KMP-related edit (from the module's src root, i.e. the parent of commonMain/androidMain/...):

bash <skill-dir>/checks/check_no_platform_imports_in_common.sh <src-root>
bash <skill-dir>/checks/check_expect_actual_placement.sh       <src-root>
bash <skill-dir>/checks/check_expect_actual_balance.sh         <src-root>

All three must pass (exit 0) before declaring the task done. Checks are deterministic file-level heuristics; per-target actual coverage and signature matching are the compiler's job — the balance check catches the forgotten platform file before you pay for a build.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.