Generates type-safe Tuple utilities for Kotlin/KMP projects by copying pre-built example files and adjusting package names.
Usage
Before generating code, confirm the following with the user in a single message.
Confirmation Items
- Target module (for multi-module projects, which module to generate into)
- Analyze the project structure and suggest a candidate module
- Ask the user to confirm or specify a different module
- Package name and output directory
- Infer from the module's existing package structure and suggest a candidate
- Ask the user to confirm or specify a different package name
- Maximum Tuple size (default: 20)
- Ask: "Generate Tuple0–Tuple20 (default)? Enter a different number to change."
- File types to generate (default: all)
- Let the user select (multiple choice):
-
Tuple.kt+TupleFactory.kt— Tuple data classes and tupleOf factories (required, always generated) -
TupleToList.kt—toList()extension functions -
AbstractTupleSerializer.kt+TupleSerializer.kt— KSerializer for kotlinx.serialization -
AwaitAll.kt— Type-safe awaitAll -
AllNotNullOrNull.kt— allNotNullOrNull utility
-
- Let the user select (multiple choice):
Skipping Confirmation
When the user's intent is clear, skip the confirmation and proceed directly with default settings:
- "by default" / "with default settings" / "with default settings"
- "with everything included" / "generate all" / "generate all"
- Arguments explicitly specify target module, package, and options
Processing of ARGUMENTS
When the skill ARGUMENTS receives parameters:
- The value of ARGUMENTS is treated as the default value (used for estimating the target module, package name, options, etc.)
- If there is a value explicitly specified in the user message,prioritize the user message do so
- If ARGUMENTS and the user message conflict, follow the specification in the user message
Output Directory Detection
Detect the source set directory based on the module type:
| Module type | Source directory pattern |
|---|---|
| Kotlin Multiplatform (commonMain) | <module>/src/commonMain/kotlin/ |
| JVM / Android (main) | <module>/src/main/kotlin/ or <module>/src/main/java/ |
| Single-module project | src/main/kotlin/ or src/main/java/ |
Detection steps:
- Check
build.gradle.kts/build.gradlefor KMP plugin (kotlin("multiplatform")) or JVM/Android plugin - Look for existing
src/commonMain/kotlin,src/main/kotlin, orsrc/main/javadirectories - Append the package path (e.g.,
com.example.tuple→com/example/tuple/)
Example Confirmation Message
I'll generate Tuple utilities. Let me confirm the following:
1. Target module: **shared** (detected)
→ Enter a different module name if needed
2. Package: `com.example.tuple` (detected)
Output: `shared/src/commonMain/kotlin/com/example/tuple/`
→ Enter a different package name if needed
3. Max Tuple size: **20** (default)
→ Enter a number to change
4. Files to generate:
- [x] Tuple.kt + TupleFactory.kt (required)
- [x] TupleToList.kt (toList() conversion)
- [x] AbstractTupleSerializer.kt + TupleSerializer.kt (kotlinx.serialization support)
- [x] AwaitAll.kt (type-safe awaitAll)
- [x] AllNotNullOrNull.kt (null-safety utility)
→ Uncheck any you don't need
OK to proceed?
Generation Method: Copy from Example
This skill ships pre-built example files under example/src/commonMain/kotlin/com/example/tuple/.
Do NOT generate code from scratch. Instead, copy example files and adjust them.
Step-by-step
- Determine the absolute path of the example directory relative to this skill's location:
- Example files:
<skill_dir>/example/src/commonMain/kotlin/com/example/tuple/
- Example files:
- Check for existing Tuple definitions in the target module:
- Search for
data class Tuplein<module>/src/ - Additionally, search for Tuple-related directories:
find <module>/src -type d -name "tuple*"to enumerate package directories - If found, ask the user whether to: overwrite, use a different package, or cancel
- Keep the detection results because they will be used in the completion message of Step 10
- Search for
- Create the target output directory (if not exists)
- Copy selected files from the example directory to the target output directory using Bash
cp- Always copy:
Tuple.kt,TupleFactory.kt - Copy if selected:
TupleToList.kt,AbstractTupleSerializer.kt+TupleSerializer.kt,AwaitAll.kt,AllNotNullOrNull.kt - When selecting all files:
cp <EXAMPLE_DIR>/*.kt <TARGET_DIR>/may be copied all at once with - When selecting some: Copy only the selected files individually (
cp *.ktis not used because it includes unselected files)
- Always copy:
- Replace package name in all copied files using Bash
sed:
Also replace import statements if the package is used in imports:sed -i '' 's/package com\.example\.tuple/package <USER_PACKAGE>/g' <TARGET_DIR>/*.ktsed -i '' 's/import com\.example\.tuple\./import <USER_PACKAGE>./g' <TARGET_DIR>/*.kt - If max Tuple size < 20: Read each copied file and remove Tuple definitions beyond N.
- Each file has clearly separated blocks per Tuple size — remove lines for Tuple(N+1) through Tuple20
- If max Tuple size > 20: Read the reference
.mdfiles to understand the pattern, then extend the copied files.- Reference files: tuple-to-list.md, tuple-serializer.md, await-all.md, all-not-null-or-null.md
- Verify and add dependencies in
build.gradle.kts: Check dependencies, and add any that are missing. If you add any, notify the user.- If TupleSerializer.kt is included:
kotlinx-serializationplugin is not configured →build.gradle.ktsadd to (refer to the official documentation and add using the correct configuration method)kotlinx-serialization-jsondependency is not configured →commonMain.dependencies(KMP) ordependencies(JVM/Android)
- If AwaitAll.kt is included:
kotlinx-coroutines-coredependency is not configured → add similarly
- If TupleSerializer.kt is included:
- Build verification: Run a compile check to ensure the generated files have no errors:
- KMP:
./gradlew :<module>:compileKotlinJvm - Android:
./gradlew :<module>:compileDebugKotlin - If errors occur, fix them before completing
- KMP:
- Completion message — Output according to the following template:
## 生成完了 **パッケージ**: `<package>` **出力先**: `<output_dir>` ### 生成ファイル - Tuple.kt - TupleFactory.kt - ... ### 依存関係 - [変更なし / 追加: kotlinx-serialization plugin, kotlinx-serialization-json, ...] ### 既存 Tuple パッケージ - [なし / `<package1>`, `<package2>`, ... — 不要であれば削除を検討してください] ### ビルド結果 - [SUCCESS / FAILED — エラー内容]- The existing Tuple packages detected in Step 2 (results of both text search and directory search) must be reported
Why This Approach
- The example files contain ~2,600 lines of repetitive Kotlin code (Tuple0–Tuple20)
- Copying and
sed-replacing is far more efficient than generating from scratch - Minimizes context consumption and eliminates generation errors