Communitygithub.com

MoonshotAI/write-tui

kimi-code のターミナルUI(apps/kimi-code/src/tui)の作成・修正時に使用します。コンポーネント、ダイアログ/セレクター、スラッシュコマンド、テーマ、ストリーミングレンダリング、KimiTUIコントローラーをカバーします。アーキテクチャ、新機能の追加場所、テスト配置、テーマシステムの仕組み、およびダイアログの操作/ビジュアル仕様(DESIGN.md)を説明します。

write-tui とは?

このスキルは、kimi-codeアプリケーションのターミナルUI(TUI)を開発・保守するための詳細なガイドです。`apps/kimi-code/src/tui` ディレクトリ内のコードベースを理解し、正しい場所に新しい機能を追加し、適切なテスト配置を行い、一貫したテーマシステムを適用するための包括的な手順を提供します。アーキテクチャは `KimiTUI` コーディネーターを中心に構成され、コントローラーがイベントルーティングやレンダリングロジックを担当し、コマンド、コンポーネント、ユーティリティがそれぞれ独立した責務を持ちます。また、ダイアログやセレクターなどのインタラクションには `DESIGN.md` に定義された視覚的・操作的ルールがあり、これに従うことが必須です。カラートークンは `src/tui/theme/colors.ts` の `ColorPalette` が唯一の情報源であり、変更時は複数のミラーを同期する必要があります。このスキルは主に Claude Code や Codex などの AI エージェント向けに設計されており、コーディング前にこれらのガイドラインを参照することで、安定性と一貫性を保ちながら TUI 開発を効率的に進めることができます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/MoonshotAI/kimi-code/tree/main/.agents/skills/write-tui

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Write TUI(apps/kimi-code)

ターミナルUIは apps/kimi-code/src/tui にあります。TUIコードを書く前に、apps/kimi-code/AGENTS.md を読んで、常時有効なマップ、モジュール境界、およびハード制約(printable-keyデコード、chalkの名前付き色の禁止など)を確認してください。このスキルはハウツーです:アーキテクチャの方向性、機能の配置、テスト配置、テーマの仕組み、およびダイアログ仕様について説明します。

リストダイアログ、セレクター、入力ボックス、ステータス/トグルリストについては、操作と視覚のルールが規範的です — このフォルダ内の DESIGN.md を参照し、提出前にそのセルフチェックリストに従ってください。

アーキテクチャ

KimiTUI はコーディネーターであり、状態、レイアウト、セッション、ダイアログを結びつけ、重いロジックをコントローラーに委譲します。

  • src/tui/kimi-tui.ts — KimiTUI コーディネーター。state を保持し、起動/停止の順序、レイアウト/エディターの配線、ユーザー入力のエントリ、送信/キューイング、セッションライフサイクル、およびスラッシュコマンドハンドラーのディスパッチを担当します。イベントルーティングやレンダリングロジックを蓄積すべきではありません — それらはコントローラーにあります。
  • src/tui/tui-state.ts — TUIState、createTUIState、createInitialAppState。単一のグローバルUI状態の形状。新しいグローバルフィールドを追加する前に、それが本当にここに属するのか、それともローカルコンポーネントの状態に属するのかを判断してください。
  • src/tui/controllers/ — 独立してテスト可能な責務。各コントローラーは1つのスライスを所有します:
    • session-event-handler.ts — SDKセッションイベントをルーティング(handleEvent ディスパッチ + イベントごとの handleXxx)。具体的なイベント処理はここに記述し、KimiTUI には記述しません。
    • streaming-ui.ts — ストリーミングレンダリング:アシスタントデルタ、思考、ツール呼び出し/結果、圧縮、サブエージェント、バックグラウンドエージェント、トランスクリプト集約。
    • session-replay.ts — 再開/リプレイのオーケストレーション;リプレイレコードを同じライブレンダリングフックに通します。ステートレスなリプレイ解析/制限/プロジェクションヘルパーは src/tui/utils/message-replay.ts に属します。
    • tasks-browser.ts — タスクブラウザコントローラー。
    • editor-keyboard.ts — エディターのキーボード処理、終了ショートカット、外部エディター、クリップボード画像。
    • auth-flow.ts — ログイン/認証のオーケストレーション(refreshConfigAfterLogin など)。
  • src/tui/commands/ — スラッシュコマンドの宣言、解析、順序付け、および動的スキルコマンド生成。解析と型のみ;実行は KimiTUI のスラッシュコマンドハンドラーセクションからディスパッチされ、複雑な実行は utils または焦点を絞ったコンポーネントに委譲されます。
  • src/tui/components/ — pi-tui コンポーネント(UIタイプ別):chrome/(フッター、TODO、ウェルカム、ローダー、デバイスコード)、dialogs/(セレクター、承認/質問パネル、エディターを置き換える設定ポップアップ)、editor/(入力ボックス + メンションプロバイダー)、media/(画像、差分、コードハイライト)、messages/(トランスクリプトブロック + ツールレンダラー)、panes/(アクティビティ、キュー)。
  • src/tui/reverse-rpc/ — SDKの承認/質問コールバックをUIパネルデータに、ユーザーの選択をSDK応答に変換します。
  • src/tui/theme/ — テーマ、カラートークン、スタイルヘルパー、pi-tui マークダウンテーマ、端末背景検出。色の唯一の情報源。
  • src/tui/utils/ — TUI専用ユーティリティ(TUIState またはコンポーネントが必要)。アプリ全体でUIに依存しないヘルパーは src/utils/ にあります。

コントローラーまたは KimiTUI のセクションが大きくなり続ける場合は、純粋関数、状態投影、プレゼンテーションコンポーネントをファイルを拡張するのではなく、対応するディレクトリに分割してください。

新機能の配置

機能の種類によって配置場所が決まります:

  • CLI引数 → src/cli/commands.ts / src/cli/options.ts、src/cli/run-shell.ts を介してTUIに渡されます。CLIはセッションを直接操作することはありません。
  • CLIサブコマンド → src/cli/sub/、非対話型のみ;@moonshot-ai/kimi-code-sdk を介してコアに到達します。
  • スラッシュコマンド → src/tui/commands/ で宣言/解析/型付け;KimiTUI のスラッシュコマンドハンドラーセクションに実行エントリを追加;複雑なロジックは utils または焦点を絞ったコンポーネントに委譲します。
  • スキル派生コマンド → buildSkillSlashCommands / スキルコマンドマップにフック;単一のスキルをハードコーディングしないでください。
  • トランスクリプトメッセージタイプ → src/tui/types.ts で形状を定義、components/messages/ コンポーネントを追加/拡張、トランスクリプトビルダーにレンダラーを登録します。
  • ツール結果表示 → components/messages/tool-renderers/registry.ts とレンダラーを拡張;ToolCallComponent 内に分岐を積み重ねないでください。
  • ポップアップ / セレクター → components/dialogs/、mountEditorReplacement 経由でマウント;DESIGN.md に従ってください。SDKコールバックによってトリガーされる場合は、reverse-rpc/ にアダプター/コントローラー/ハンドラーが必要かどうかを確認してください。
  • SDKイベント処理 → session-event-handler.ts の handleEvent にディスパッチを追加し、対応する handleXxx を追加します。
  • ストリーミングレンダリング → controllers/streaming-ui.ts。
  • セッション開始 / 再開動作 → KimiTUI のセッション管理セクション;リプレイ動作 → controllers/session-replay.ts、ライブレンダリングパスを再利用。
  • ステータスバー / アクティビティ / キュー → chrome/footer、panes/activity、panes/queue、および対応する updateXxx。
  • 設定オプション → src/tui/config.ts で読み取り/書き込み + スキーマ、次に設定UI;saveTuiConfig を介して永続化(コンポーネントが設定ファイルを直接書き込むことはありません)。
  • 定数 → 共有CLI/TUIの非コピー定数は src/constant/;TUI専用の非コピー定数は src/tui/constant/。コンポーネントローカルのコピー、オプションラベル、ヘルプテキスト、ダイアログのタイトル/フッターはコンポーネントの隣に配置 — コピーをグローバルモジュールに集中化しないでください。
  • 一般的な機能 → TUI状態に依存しない → src/utils/;TUI状態またはコンポーネントに依存する → src/tui/utils/。

テスト配置

  • コンポーネントの動作テストは、既存のコンポーネントのテストの隣に配置します(test/tui/components/...)。
  • コマンド解析テスト → test/tui/commands/。
  • reverse-rpcテスト → test/tui/reverse-rpc/。
  • 純粋ユーティリティテスト → 対応する utils テストの隣。
  • 小さな機能を追加するためだけに汎用的な some-feature.test.ts を作成しないでください;最も近い既存のテストファイルを拡張してください。

テーマシステムの仕組み

テーマは src/tui/theme/ の下で一元管理されます:

  • colors.ts — 意味論的トークン:ColorPalette、darkColors、lightColors。
  • styles.ts — ColorPalette 上に構築された共通のchalkヘルパー。
  • pi-tui-theme.ts — マークダウン/pi-tuiテーマ設定。
  • terminal-background.ts — 自動解決に使用される端末背景検出。
  • bundle.ts — colors、styles、markdownTheme を KimiTUIThemeBundle にパックします。
  • index.ts / detect.ts — テーマタイプと自動/ダーク/ライトの解決。

カラートークンセットを同期した状態に保ってください。 colors.ts の ColorPalette はカラートークンの唯一の情報源です。トークンを追加、名前変更、削除する場合は、同じ変更でそのミラーを更新してください:カスタムテーマのJSONスキーマ(apps/kimi-code/src/tui/theme/theme-schema.json)、カスタムテーマドキュメントのトークンテーブル(docs/en/customization/themes.md および docs/zh/customization/themes.md)、および custom-theme ビルトインスキルのトークンテーブル(packages/agent-core/src/skill/builtin/custom-theme.md)。

適用/切り替えフロー:

  • UIエントリ:ThemeSelectorComponent → handleThemeCommand → applyThemeChoice。
  • 実際の適用ステップは KimiTUI.applyTheme:state.theme、state.appState.theme を更新し、コンポーネントにパレットの更新を通知します。
  • saveTuiConfig を介して選択を永続化 — コンポーネントが設定ファイルを直接書き込んではいけません。

ハードカラールール(chalkの名前付き色の禁止、コントラスト比、モジュールトップレベルのキャッシュされたスタイル関数の禁止、色を考案する前に ColorPalette トークンを追加)は規範的であり、ガードによって強制されます — それらは apps/kimi-code/AGENTS.md にあります。このスキルはメカニズムのみをカバーします。

提出前に

  • 変更したファイルに対して lint / format / test を実行してください。
  • ダイアログ/セレクター/入力/トグルリストについては、DESIGN.md の最後にあるセルフチェックリストを一通り確認してください。
  • printable-key比較には printableChar()(CIガード)、色には chalk.hex(colors.<token>)(CIガード)を使用してください。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

MoonshotAI/agent-core-dev

Use when developing in packages/agent-core-v2 (the DI × Scope agent engine) — adding or modifying a domain Service, choosing a LifecycleScope, wiring DI dependencies, splitting a domain across scopes, owning or migrating a config section, gating behavior behind an experimental flag, raising coded errors, working on the permission system, writing DI/Scope tests, porting business logic from agent-core (v1) to v2, triaging a main-branch commit against v2, or exposing a v2 domain over server-v2 while keeping the /api/v1 wire contract compatible with released clients. Self-contained guide organized by development stage (orient → design → implement → test → verify) plus align workflows for v1→v2 migration, main-branch commit triage, and server-v2 wire exposure; each file carries the rules, examples, and red lines for its step.

MoonshotAI/agent-core-review

Use ONLY for code review and test write/review guidance in `packages/agent-core-v2` (the DI × Scope agent engine). Does NOT apply to the legacy `packages/agent-core` or to any other package — for those, do not load this skill. Groups the review and testing lenses used for agent-core-v2 — `slop` (single-level-of-abstraction / layered error-handling review, invoked only on explicit request) and `test` (contract-driven per-test rules for both authoring and reviewing tests). Apply the sub-skill that matches the task; do not apply `slop` unprompted.

MoonshotAI/consolidate

Apply an approved sub-skill grouping by moving user-specified skills into a parent bundle, with timestamped backups of every modified directory.

MoonshotAI/gen-changesets

Use when generating changesets in the kimi-code repository, including package bump selection, internal package and CLI bundle handling, bump levels, major confirmation, and English changelog wording.

MoonshotAI/gen-docs

Update Kimi Code CLI user documentation after meaningful code changes that affect product behavior or user experience.

MoonshotAI/kimi-datasource

Universal data-source assistant. Use this skill when the user wants external structured data such as stocks, financial reports, technical indicators, A-share/HK/US markets, global macroeconomics, Chinese enterprise registry information, arXiv papers, Google Scholar results, or Chinese laws/regulations and judicial cases. This plugin exposes tools via MCP server `plugin-kimi-datasource_data`; call them in the flow `mcp__plugin-kimi-datasource_data__get_data_source_desc` → `mcp__plugin-kimi-datasource_data__call_data_source_tool`.

MoonshotAI/pre-changelog

Use before merging a kimi-code release PR to preview the user-facing CLI changelog in Chinese. Reads the changelog that changesets pre-generated in the release PR, then reuses sync-changelog's strip / classify / translate logic to render a Chinese preview. Writes no files.

MoonshotAI/review

Analyze the available skill set and recommend candidate groups that could be consolidated into sub-skill bundles. Read-only — proposes a plan, does not move files.

MoonshotAI/slop

Invoke only when the user explicitly asks to review code through the "single level of abstraction / layered error handling" lens — a function does only its own layer's business logic while errors are handled above or below. The agent reports detections, raw-count measurements, and move directions. Apply only when the user explicitly requests this lens.

MoonshotAI/sub-skill

Discover and reorganize the skill inventory into hierarchical sub-skill bundles. Use when the user asks to review, group, or consolidate skills into a parent bundle.

MoonshotAI/sync-changelog

Use after a release succeeds, when maintainers need to sync apps/kimi-code/CHANGELOG.md into docs/en/release-notes/changelog.md and docs/zh/release-notes/changelog.md, then open a PR on a dedicated branch.

MoonshotAI/test

Use when writing or reviewing tests, or when asked how to write a good single test. Encodes the per-test rules behind the "test the contract / responsibility, not the implementation" principle — name and structure one behavior per `it`, drive through the public surface, stub only true external boundaries, control time and config via documented knobs, and keep tests clear, isolated, and refactor-resilient. The same rules drive both authoring (write mode) and auditing existing tests (review mode).

MoonshotAI/translate-docs

Translate and sync bilingual user documentation between docs/zh/ and docs/en/ following the source-of-truth rules in docs/AGENTS.md.

関連スキル