new-feature
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-14
- Stars
- ★ 0
- Forks
- 0
02 资源文件 1
- 参考文档manifest.yaml766 B
03 SKILL.md 正文
New Feature Skill
Scaffolds a feature for a Kotlin Multiplatform / Compose Multiplatform project as an api + impl
Gradle module pair, wired into the nav graph and DI.
Before generating, read .claude/rules/kmp/feature-structure.md (layout),
.claude/rules/kmp/architecture.md (MVI contract, error handling),
.claude/rules/kmp/navigation.md and .claude/rules/kmp/localization.md. If an existing feature is
already in the repo, read it and match it exactly — the rules describe the shape, the existing
feature is the ground truth for this project's package names and Gradle conventions.
When NOT to use this skill
This skill writes files. It runs only when the user wants a feature scaffolded and has a name for it. If they are still deciding what to build, hand off and stop:
- Exploring what the feature should be →
idea-brainstormer - Choosing an approach or comparing designs →
solution-designer - Splitting a feature into tasks →
task-decomposer - Only asking how KMP source sets or
expect/actualwork →kmp-multiplatform-specialist
Inputs
- Feature name in PascalCase (
Logs,Settings,OrderDetail). The module path is the lowercase name (feature/logs/), the package is the lowercase name. - If the user gave no name, ask for it and stop until provided. Do not invent one.
Mode
Decide before writing anything:
- New feature (default) — create the
api+implmodule pair. - Extra screen in an existing feature — the user named a feature that already exists. Create only
the screen package inside that feature's
impl, plus its route in that feature'sapi, its Koin registration and its test. Create no new Gradle modules, edit nosettings.gradle.kts.
If it is ambiguous which mode applies, ask. Do not guess.
Procedure
-
Confirm scope. Restate the feature name, the mode, and the exact list of files you will create or edit. Wait for confirmation. Create nothing outside that list.
-
Locate the conventions. Read
settings.gradle.kts,gradle/libs.versions.toml, one existingfeature/*/impl/build.gradle.kts(if any) andcomposeAppDI + nav files. Reuse the project's existing plugin aliases, convention plugins and version-catalog entries. Never introduce a new dependency or a hardcoded version when the catalog already has one. If the project has no feature module yet, say so and derive the build files fromcomposeApp— do not copy them blindly. -
Create
feature/<name>/api(new-feature mode only):build.gradle.kts— KMP + serialization only. No Compose, no Koin, no Ktor.<Name>Key.kt—@Serializable @Keep data object <Name>Key : NavKey(or adata classwhen the screen takes arguments). Both annotations are required: R8 reaches keys reflectively and drops an unmarked one in release builds only.- The feature's
SerializersModulecontribution —polymorphic(NavKey::class) { subclass(<Name>Key::class, <Name>Key.serializer()) }. Without it the back stack does not restore on iOS, desktop or web; Android is the only target that can fall back to reflection, so omitting it passes every Android test. - Nothing else goes in
api. - Navigation 2 project (the repo uses
NavHost/navigation-compose2.x): name the file<Name>Route.kt, write@Serializable @Keep data object <Name>Routewith noNavKeysupertype and noSerializersModule, and add afun NavController.navigateTo<Name>(...)extension. Match what step 2 found — never introduce Nav 3 into a Nav 2 project.
-
Create
feature/<name>/impl(new-feature mode only):build.gradle.kts— depends onfeature/<name>/api,core/designsystemand whatevercore/*it needs; Compose Multiplatform, Koin, ViewModel, coroutines.- Declare the resources package explicitly, or every generated import will be wrong — the default
is derived from the root project name and the module path, not from your Kotlin package:
compose.resources { packageOfResClass = "<pkg>.feature.<name>.impl.generated.resources" }
-
Write the screen package under
impl/src/commonMain/kotlin/<pkg>/feature/<name>/ui/:<Name>UiState.kt— one@Immutable data classplus its sealed status/error types. No Compose imports beyond the stability annotation.<Name>Intent.kt—sealed interface <Name>Intentcovering every user action.<Name>Effect.kt—sealed interface <Name>Effectfor one-shot outcomes only (navigation, transient messages). Omit the file entirely if the screen has none; do not create an empty type.<Name>ViewModel.kt— extends the project'sMviViewModel<State, Intent, Effect>base. If the project has no base class yet, create it once incore/exactly as specified inarchitecture.mdand say so in your summary. Constructor takes its dependencies plus the injected dispatcher andCoroutineExceptionHandler. ImplementsonIntentwith an exhaustivewhen. No public method other thanonIntent.<Name>Screen.kt—<Name>Route(resolves the ViewModel withkoinViewModel(), collects state withcollectAsStateWithLifecycle, collects effects lifecycle-aware) plus a stateless<Name>Screen(state, onIntent)that onlywhen-dispatches toviewcomponents/.viewcomponents/— oneinternalcomposable per file, stateless and hoisted. At minimum a loading, an error and a content view. Light + dark@Previewnext to each non-trivial view.
-
Write the domain and data layers under
impl/src/commonMain/kotlin/<pkg>/feature/<name>/only for what the screen actually needs:domain/model/,domain/repository/<Name>Repository.kt(interface).data/<Name>RepositoryImpl.kt,data/remote/dto/with the DTO→model mapping at the boundary.- Add a UseCase only if the escalation trigger in
architecture.mdapplies. A pass-through UseCase is a violation, not a placeholder.
-
Add strings to
impl/src/commonMain/composeResources/values/strings.xmland to every other locale folder the project ships (e.g.values-uk/). Every user-facing string goes here — no literal in a composable. Error text stays a sealed type mapped to a resource by a@Composablelabel function at the screen root. -
Register DI —
impl/.../di/<Name>Module.kt:val <name>Module = module { // constructor DSL: bind<T>() inside the lambda, from org.koin.core.module.dsl singleOf(::<Name>RepositoryImpl) { bind<<Name>Repository>() } viewModelOf(::<Name>ViewModel) // Nav 3: the feature contributes its entry builder here, so composeApp never names it. single<EntryProviderInstaller>(named("<name>")) { { <name>Entries(get()) } } }Then add
<name>Moduleto the aggregated module list incomposeApp. Plain Koin DSL — do not introduce Koin Annotations or KSP. -
Wire navigation — the feature owns its entries;
composeAppcomposes features, not screens. Writefun EntryProviderScope<NavKey>.<name>Entries(navigator: Navigator)inimpl/.../ui/<Name>Navigation.ktwith oneentry<<Name>Key> { }per screen of this feature, passing navigation lambdas down. Adding a screen must not require an edit tocomposeApp— if it does, the graph has become a switchboard (seenavigation.md). If it is a top-level destination, register it in the destination list and add its label to every locale file.Navigation 2 project: the same shape one level down — write
fun NavGraphBuilder.<name>Graph(...)withcomposable<<Name>Route> { }entries and call it from the existingNavHost. Never create a secondNavHostor a secondNavDisplay.Either way: do not add a
selectedDestinationfield, a navigation state holder, or an effect that mirrors a stored selection onto the back stack. Selection is derived from the back stack. -
Register the modules (new-feature mode only) — add
include(":feature:<name>:api")andinclude(":feature:<name>:impl")tosettings.gradle.kts, and add theimpldependency tocomposeApp/build.gradle.kts. -
Add the test —
impl/src/commonTest/.../<Name>ViewModelTest.kt: hand-written fakes (no MockK incommonTest), injected test dispatcher,runTest,advanceUntilIdle, driven only throughonIntent. Cover the success path and each error branch. -
Build and verify — run the project's build and test commands (typically
./gradlew buildand./gradlew :feature:<name>:impl:allTests). Report the real output. Fix compile and test failures before finishing.
Do NOT
- Do NOT put anything except the destination key and its
SerializersModulecontribution (Nav 2: the route and its navigation extension) infeature/<name>/api. - Do NOT store the selected destination anywhere. It is derived from the back stack.
- Do NOT make one feature's
impldepend on another feature'simpl. - Do NOT expose
MutableStateFlow, the raw effectChannel, or any public method besidesonIntentfrom the ViewModel. - Do NOT use
MutableSharedFlowfor effects, or swallow exceptions in an emptycatch. - Do NOT add a dependency that is not in the version catalog without telling the user first.
- Do NOT touch files outside the confirmed list — no drive-by refactors of existing features.
- Do NOT commit. Leave that to the user or the
commit/finish-taskskills.
Error handling
- Feature name missing or not PascalCase → ask for it and stop.
- Module path already exists → stop and report. Ask whether the user meant the extra-screen mode.
- No
settings.gradle.kts, or the project is not KMP → stop and report; this skill does not bootstrap a project. - The project has no
core/designsystemor no MVI base class → say exactly what is missing and what you propose to create, then wait. Do not silently invent a parallel convention. - Build or tests fail → report the actual error output. Never claim success on a red build.
Example
/new-feature Logs on a project whose package is com.example.app creates:
settings.gradle.kts + include(":feature:logs:api"), (":feature:logs:impl")
feature/logs/api/build.gradle.kts
feature/logs/api/src/commonMain/kotlin/com/example/app/feature/logs/api/LogsKey.kt
feature/logs/impl/build.gradle.kts
feature/logs/impl/src/commonMain/kotlin/com/example/app/feature/logs/
ui/LogsScreen.kt ui/LogsViewModel.kt ui/LogsUiState.kt ui/LogsIntent.kt ui/LogsEffect.kt
ui/LogsNavigation.kt
ui/viewcomponents/LogsLoading.kt LogsErrorState.kt LogsContent.kt
domain/model/LogEntry.kt domain/repository/LogsRepository.kt
data/LogsRepositoryImpl.kt
di/LogsModule.kt
feature/logs/impl/src/commonMain/composeResources/values/strings.xml
feature/logs/impl/src/commonMain/composeResources/values-uk/strings.xml
feature/logs/impl/src/commonTest/kotlin/com/example/app/feature/logs/ui/LogsViewModelTest.kt
composeApp/… + composable<LogsRoute> entry, + logsModule
Expected outcome: ./gradlew build succeeds and :feature:logs:impl:allTests passes with the new
ViewModel test green.
Related Skills
kmp-multiplatform-specialist—expect/actual, source sets, target configuration, KMP Gradle DSLkotlin-specialist— coroutines, Flow, sealed classes, idiomatic Kotlindependency-injection-architecture— Koin fundamentals and layer boundariesunit-testing-kotlin— general Kotlin testing practicecommit/finish-task— committing the result
04 同仓库更多 Skills
universal-skill
暂无简介
notion-skill
暂无简介
inline-frontmatter-skill
Hand-authored description that already lives in the body and must not be double-wrapped.
universal-skill
暂无简介
notion-skill
暂无简介
write-a-skill
暂无简介