Kotlin Tuple Utility Generation Skill
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):
Skipping Confirmation
When the user's intent is clear, skip the confirmation and proceed directly with default settings:
- "デフォルトで" / "デフォルト設定で" / "with default settings"
- "全部入りで" / "全部生成して" / "generate all"
- Arguments explicitly specify target module, package, and options
ARGUMENTS の処理
スキルが ARGUMENTS パラメータを受け取った場合:
- ARGUMENTS の値は デフォルト値 として扱う(対象モジュール、パッケージ名、オプション等の推定に使用)
- ユーザメッセージで明示的に指定された値がある場合は、ユーザメッセージを優先 する
- ARGUMENTS とユーザメッセージが矛盾する場合は、ユーザメッセージの指定に従う
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.gradle for KMP plugin (kotlin("multiplatform")) or JVM/Android plugin
- Look for existing
src/commonMain/kotlin, src/main/kotlin, or src/main/java directories
- 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/
- Check for existing Tuple definitions in the target module:
- Search for
data class Tuple in <module>/src/
- Additionally, search for Tuple-related directories:
find <module>/src -type d -name "tuple*" でパッケージディレクトリを列挙
- If found, ask the user whether to: overwrite, use a different package, or cancel
- 検出結果は Step 10 の完了メッセージで使用するため保持しておくこと
- 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
- 全ファイル選択時:
cp <EXAMPLE_DIR>/*.kt <TARGET_DIR>/ でまとめてコピーしてよい
- 一部選択時: 選択されたファイルのみ個別にコピーする(
cp *.kt は未選択ファイルも含むため使わない)
- Replace package name in all copied files using Bash
sed:sed -i '' 's/package com\.example\.tuple/package <USER_PACKAGE>/g' <TARGET_DIR>/*.kt
Also replace import statements if the package is used in imports:sed -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
.md files to understand the pattern, then extend the copied files.
- Verify and add dependencies in
build.gradle.kts:
依存関係を確認し、不足している場合は追加する。追加した場合はユーザに通知すること。
- If TupleSerializer.kt is included:
kotlinx-serialization plugin が未設定 → build.gradle.kts に追加(公式ドキュメントを参照して正しい設定方法で追加)
kotlinx-serialization-json dependency が未設定 → commonMain.dependencies(KMP)または dependencies(JVM/Android)に追加
- If AwaitAll.kt is included:
kotlinx-coroutines-core dependency が未設定 → 同様に追加
- 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
- Completion message — 以下のテンプレートに従って出力する:
## 生成完了
**パッケージ**: `<package>`
**出力先**: `<output_dir>`
### 生成ファイル
- Tuple.kt
- TupleFactory.kt
- ...
### 依存関係
- [変更なし / 追加: kotlinx-serialization plugin, kotlinx-serialization-json, ...]
### 既存 Tuple パッケージ
- [なし / `<package1>`, `<package2>`, ... — 不要であれば削除を検討してください]
### ビルド結果
- [SUCCESS / FAILED — エラー内容]
- Step 2 で検出した既存 Tuple パッケージ(テキスト検索・ディレクトリ検索の両方の結果)を 必ず 報告する
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
1---2name: kotlin-tuple-23description: "Generates type-safe Tuple utilities (Tuple0–Tuple20) for Kotlin and Kotlin Multiplatform projects. Creates Tuple data classes, tupleOf factories, toList conversion, KSerializer for kotlinx.serialization, type-safe awaitAll, and allNotNullOrNull in one go. Use when requested: \"add Tuple\", \"generate tupleOf\", \"type-safe Tuple\", \"type-safe awaitAll\", \"add allNotNullOrNull\", \"await multiple Deferred with type safety\", \"null-check multiple nullable values at once\". For Kotlin/KMP projects where Pair/Triple is not enough for multi-element grouping."4---56# Kotlin Tuple Utility Generation Skill78Generates type-safe Tuple utilities for Kotlin/KMP projects by copying pre-built example files and adjusting package names.910## Usage1112Before generating code, confirm the following with the user in **a single message**.1314### Confirmation Items15161. **Target module** (for multi-module projects, which module to generate into)17 - Analyze the project structure and suggest a candidate module18 - Ask the user to confirm or specify a different module192. **Package name and output directory**20 - Infer from the module's existing package structure and suggest a candidate21 - Ask the user to confirm or specify a different package name223. **Maximum Tuple size** (default: 20)23 - Ask: "Generate Tuple0–Tuple20 (default)? Enter a different number to change."244. **File types to generate** (default: all)25 - Let the user select (multiple choice):26 - [x] `Tuple.kt` + `TupleFactory.kt` — Tuple data classes and tupleOf factories (required, always generated)27 - [x] `TupleToList.kt` — `toList()` extension functions28 - [x] `AbstractTupleSerializer.kt` + `TupleSerializer.kt` — KSerializer for kotlinx.serialization29 - [x] `AwaitAll.kt` — Type-safe awaitAll30 - [x] `AllNotNullOrNull.kt` — allNotNullOrNull utility3132### Skipping Confirmation3334When the user's intent is clear, skip the confirmation and proceed directly with default settings:35- "デフォルトで" / "デフォルト設定で" / "with default settings"36- "全部入りで" / "全部生成して" / "generate all"37- Arguments explicitly specify target module, package, and options3839### ARGUMENTS の処理4041スキルが `ARGUMENTS` パラメータを受け取った場合:42- ARGUMENTS の値は **デフォルト値** として扱う(対象モジュール、パッケージ名、オプション等の推定に使用)43- ユーザメッセージで明示的に指定された値がある場合は、**ユーザメッセージを優先** する44- ARGUMENTS とユーザメッセージが矛盾する場合は、ユーザメッセージの指定に従う4546### Output Directory Detection4748Detect the source set directory based on the module type:4950| Module type | Source directory pattern |51|---|---|52| Kotlin Multiplatform (commonMain) | `<module>/src/commonMain/kotlin/` |53| JVM / Android (main) | `<module>/src/main/kotlin/` or `<module>/src/main/java/` |54| Single-module project | `src/main/kotlin/` or `src/main/java/` |5556Detection steps:571. Check `build.gradle.kts` / `build.gradle` for KMP plugin (`kotlin("multiplatform")`) or JVM/Android plugin582. Look for existing `src/commonMain/kotlin`, `src/main/kotlin`, or `src/main/java` directories593. Append the package path (e.g., `com.example.tuple` → `com/example/tuple/`)6061### Example Confirmation Message6263```64I'll generate Tuple utilities. Let me confirm the following:65661. Target module: **shared** (detected)67 → Enter a different module name if needed68692. Package: `com.example.tuple` (detected)70 Output: `shared/src/commonMain/kotlin/com/example/tuple/`71 → Enter a different package name if needed72733. Max Tuple size: **20** (default)74 → Enter a number to change75764. Files to generate:77 - [x] Tuple.kt + TupleFactory.kt (required)78 - [x] TupleToList.kt (toList() conversion)79 - [x] AbstractTupleSerializer.kt + TupleSerializer.kt (kotlinx.serialization support)80 - [x] AwaitAll.kt (type-safe awaitAll)81 - [x] AllNotNullOrNull.kt (null-safety utility)82 → Uncheck any you don't need8384OK to proceed?85```8687## Generation Method: Copy from Example8889This skill ships pre-built example files under `example/src/commonMain/kotlin/com/example/tuple/`.90**Do NOT generate code from scratch.** Instead, copy example files and adjust them.9192### Step-by-step93941. Determine the absolute path of the example directory relative to this skill's location:95 - Example files: `<skill_dir>/example/src/commonMain/kotlin/com/example/tuple/`962. **Check for existing Tuple definitions** in the target module:97 - Search for `data class Tuple` in `<module>/src/`98 - Additionally, search for Tuple-related directories: `find <module>/src -type d -name "tuple*"` でパッケージディレクトリを列挙99 - If found, ask the user whether to: overwrite, use a different package, or cancel100 - 検出結果は Step 10 の完了メッセージで使用するため保持しておくこと1013. Create the target output directory (if not exists)1024. **Copy selected files** from the example directory to the target output directory using Bash `cp`103 - Always copy: `Tuple.kt`, `TupleFactory.kt`104 - Copy if selected: `TupleToList.kt`, `AbstractTupleSerializer.kt` + `TupleSerializer.kt`, `AwaitAll.kt`, `AllNotNullOrNull.kt`105 - **全ファイル選択時**: `cp <EXAMPLE_DIR>/*.kt <TARGET_DIR>/` でまとめてコピーしてよい106 - **一部選択時**: 選択されたファイルのみ個別にコピーする(`cp *.kt` は未選択ファイルも含むため使わない)1075. **Replace package name** in all copied files using Bash `sed`:108 ```bash109 sed -i '' 's/package com\.example\.tuple/package <USER_PACKAGE>/g' <TARGET_DIR>/*.kt110 ```111 Also replace import statements if the package is used in imports:112 ```bash113 sed -i '' 's/import com\.example\.tuple\./import <USER_PACKAGE>./g' <TARGET_DIR>/*.kt114 ```1156. **If max Tuple size < 20**: Read each copied file and remove Tuple definitions beyond N.116 - Each file has clearly separated blocks per Tuple size — remove lines for Tuple(N+1) through Tuple201177. **If max Tuple size > 20**: Read the reference `.md` files to understand the pattern, then extend the copied files.118 - Reference files: [tuple-to-list.md](./tuple-to-list.md), [tuple-serializer.md](./tuple-serializer.md), [await-all.md](./await-all.md), [all-not-null-or-null.md](./all-not-null-or-null.md)1198. **Verify and add dependencies** in `build.gradle.kts`:120 依存関係を確認し、不足している場合は追加する。追加した場合はユーザに通知すること。121 - If TupleSerializer.kt is included:122 - `kotlinx-serialization` plugin が未設定 → `build.gradle.kts` に追加(公式ドキュメントを参照して正しい設定方法で追加)123 - `kotlinx-serialization-json` dependency が未設定 → `commonMain.dependencies`(KMP)または `dependencies`(JVM/Android)に追加124 - If AwaitAll.kt is included:125 - `kotlinx-coroutines-core` dependency が未設定 → 同様に追加1269. **Build verification**: Run a compile check to ensure the generated files have no errors:127 - KMP: `./gradlew :<module>:compileKotlinJvm`128 - Android: `./gradlew :<module>:compileDebugKotlin`129 - If errors occur, fix them before completing13010. **Completion message** — 以下のテンプレートに従って出力する:131 ```132 ## 生成完了133134 **パッケージ**: `<package>`135 **出力先**: `<output_dir>`136137 ### 生成ファイル138 - Tuple.kt139 - TupleFactory.kt140 - ...141142 ### 依存関係143 - [変更なし / 追加: kotlinx-serialization plugin, kotlinx-serialization-json, ...]144145 ### 既存 Tuple パッケージ146 - [なし / `<package1>`, `<package2>`, ... — 不要であれば削除を検討してください]147148 ### ビルド結果149 - [SUCCESS / FAILED — エラー内容]150 ```151 - Step 2 で検出した既存 Tuple パッケージ(テキスト検索・ディレクトリ検索の両方の結果)を **必ず** 報告する152153### Why This Approach154155- The example files contain ~2,600 lines of repetitive Kotlin code (Tuple0–Tuple20)156- Copying and `sed`-replacing is far more efficient than generating from scratch157- Minimizes context consumption and eliminates generation errors