Agent Skills
› chrisbanes/skills
› kotlin-api-design
kotlin-api-design
GitHub指导 Kotlin API 设计,涵盖函数归属、值类、数据类及多平台边界决策。通过明确领域语义和最小化抽象,优化成员/扩展函数选择,处理原生 SDK 隔离与 Compose 稳定性,确保公共接口清晰且符合领域语言。
触发场景
Kotlin 函数归属决策
API 设计审查
多平台代码边界划分
安装
npx skills add chrisbanes/skills --skill kotlin-api-design -g -y
SKILL.md
Frontmatter
{
"name": "kotlin-api-design",
"description": "Use when designing or reviewing Kotlin function ownership, member or extension functions, factories, single-field domain types, value classes, data classes, Kotlin Multiplatform expect\/actual declarations, or platform service boundaries."
}
Kotlin API design
Core principle
Place behavior, types, and platform seams where their meaning is clearest to callers; use the smallest public abstraction that preserves domain language and platform independence.
Procedure
- Name the domain concept, its owning type or module, and the callers that need to depend on it.
- Choose function ownership before adding an extension, factory, helper, or service layer.
- Represent a single-field domain concept with the smallest type that preserves its semantic and interop contract.
- Keep shared code semantic; put native SDK and platform details behind an interface or a narrowly justified expect/actual boundary.
- Read the focused reference for every material API decision below.
- Finish when the public surface states domain intent, platform details remain at leaves, and callers do not depend on convenience abstractions with no clear owner.
Topic router
| Signal | Read |
|---|---|
| Member vs top-level, extension, factory, service, or receiver choice | Function ownership |
Primitive obsession, one-field domain type, @JvmInline value class, data class, interop, or Compose stability |
Value classes |
| Source sets, platform services, native SDKs, files, sensors, permissions, Compose Multiplatform interop, or expect/actual | Multiplatform boundaries |
| Branching and guard-condition shape | Kotlin control flow |
RED/GREEN agent scenarios
- RED adds an extension on
Stringto hide repository behavior. GREEN gives the behavior a domain owner or service with a meaningful dependency boundary. - Novel case: shared UI needs a platform permission service. GREEN preserves a semantic shared contract and places platform SDK calls at the native leaf.
- Counterexample: an internal helper has one obvious owning class. GREEN keeps it a member instead of extracting a factory or value type for ceremony.
版本历史
- 2026.8.5 当前 2026-08-16 02:44


