Communitygithub.com

MoonshotAI/write-tui

Use when writing or modifying the kimi-code terminal UI in apps/kimi-code/src/tui — components, dialogs/selectors, slash commands, themes, streaming render, or the KimiTUI controllers. Covers the architecture, where new features go, test placement, the theme system mechanics, and the dialog interaction/visual spec (DESIGN.md).

write-tui とは?

write-tui is a Claude Code agent skill that use when writing or modifying the kimi-code terminal UI in apps/kimi-code/src/tui — components, dialogs/selectors, slash commands, themes, streaming render, or the KimiTUI controllers. Covers the architecture, where new features go, test placement, the theme system mechanics, and the dialog interaction/visual spec (DESIGN.md).

対応~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)

The terminal UI lives in apps/kimi-code/src/tui. Before writing TUI code, read apps/kimi-code/AGENTS.md for the always-on map, module boundaries, and hard constraints (printable-key decoding, no chalk named colors, etc.). This skill is the how-to: architecture orientation, feature routing, test placement, theme mechanics, and the dialog spec.

For any list dialog, selector, input box, or status/toggle list, the interaction and visual rules are normative — see DESIGN.md in this folder and follow its self-check list before submitting.

Architecture

KimiTUI is a coordinator that wires state, layout, session, and dialogs together and delegates heavy logic to controllers.

  • src/tui/kimi-tui.ts — the KimiTUI coordinator. Holds state, owns startup/shutdown order, layout/editor wiring, user-input entry, sending/queueing, session lifecycle, and the slash-command handler dispatch. It should not accumulate event-routing or rendering logic — those live in controllers.
  • src/tui/tui-state.tsTUIState, createTUIState, createInitialAppState. The single global UI state shape. Before adding a new global field, decide whether it truly belongs here vs. local component state.
  • src/tui/controllers/ — the independently-testable responsibilities. Each controller owns one slice:
    • session-event-handler.ts — routes SDK session events (handleEvent dispatch + the per-event handleXxx). Concrete event handling goes here, not in KimiTUI.
    • streaming-ui.ts — streaming render: assistant delta, thinking, tool call / result, compaction, subagent, background agent, transcript aggregation.
    • session-replay.ts — resume/replay orchestration; drives replay records through the same live render hooks. Stateless replay parsing/limiting/projection helpers belong in src/tui/utils/message-replay.ts.
    • tasks-browser.ts — the tasks browser controller.
    • editor-keyboard.ts — editor keyboard handling, exit shortcuts, external editor, clipboard image.
    • auth-flow.ts — login/auth orchestration (refreshConfigAfterLogin, etc.).
  • src/tui/commands/ — slash-command declaration, parsing, ordering, and dynamic skill-command generation. Parsing and types only; execution is dispatched from KimiTUI's slash-command handler section, and complex execution sinks into utils or focused components.
  • src/tui/components/ — pi-tui components by UI type: chrome/ (footer, todo, welcome, loader, device code), dialogs/ (selectors, approval/question panels, settings popups that replace the editor), editor/ (input box + mention provider), media/ (image, diff, code highlight), messages/ (transcript blocks + tool-renderers), panes/ (activity, queue).
  • src/tui/reverse-rpc/ — adapts SDK approval/question callbacks into UI panel data and the user's choice back into an SDK response.
  • src/tui/theme/ — themes, color tokens, style helpers, pi-tui markdown theme, terminal-background detection. The single source of truth for color.
  • src/tui/utils/ — TUI-only utilities (need TUIState or a component). App-wide, UI-independent helpers go in src/utils/.

When a controller or KimiTUI section keeps growing, split pure functions, state projections, and presentation components into the matching directory rather than expanding the file.

Where new features go

The feature type decides the landing spot:

  • CLI argumentssrc/cli/commands.ts / src/cli/options.ts, passed into the TUI via src/cli/run-shell.ts. The CLI never operates on the session directly.
  • CLI subcommandssrc/cli/sub/, non-interactive only; reach core via @moonshot-ai/kimi-code-sdk.
  • Slash commands → declare/parse/type under src/tui/commands/; add the execution entry in KimiTUI's slash-command handler section; sink complex logic into utils or a focused component.
  • Skill-derived commands → hook into buildSkillSlashCommands / the skill command map; do not hard-code a single skill.
  • Transcript message types → define the shape in src/tui/types.ts, add/extend a components/messages/ component, register the renderer in the transcript builder.
  • Tool-result display → extend components/messages/tool-renderers/registry.ts and the renderer; do not stack branches inside ToolCallComponent.
  • Popup / selectorcomponents/dialogs/, mounted via mountEditorReplacement; follow DESIGN.md. If triggered by an SDK callback, check whether reverse-rpc/ needs an adapter/controller/handler.
  • SDK event handling → add the dispatch in session-event-handler.ts's handleEvent, then the matching handleXxx.
  • Streaming rendercontrollers/streaming-ui.ts.
  • Session start / resume behavior → the session-management section of KimiTUI; replay behavior → controllers/session-replay.ts, reusing live render paths.
  • Status bar / activity / queuechrome/footer, panes/activity, panes/queue, and the matching updateXxx.
  • Configuration option → read/write + schema in src/tui/config.ts, then the settings UI; persist through saveTuiConfig (a component never writes the config file itself).
  • Constants → shared CLI/TUI non-copy constants in src/constant/; TUI-only non-copy constants in src/tui/constant/. Component-local copy, option labels, help text, dialog titles/footers stay next to their component — do not centralize copy into a global module.
  • General capability → no TUI-state dependency → src/utils/; depends on TUI state or a component → src/tui/utils/.

Test placement

  • Component behavior tests sit next to the component's existing tests (test/tui/components/...).
  • Command parsing tests → test/tui/commands/.
  • reverse-rpc tests → test/tui/reverse-rpc/.
  • Pure utility tests → next to the corresponding utils tests.
  • Do not create a generic some-feature.test.ts just to land a small feature; extend the nearest existing test file.

Theme system mechanics

Themes are managed centrally under src/tui/theme/:

  • colors.ts — semantic tokens: ColorPalette, darkColors, lightColors.
  • styles.ts — common chalk helpers built on top of ColorPalette.
  • pi-tui-theme.ts — the markdown/pi-tui theme config.
  • terminal-background.ts — terminal background detection used by auto resolution.
  • bundle.ts — packs colors, styles, markdownTheme into a KimiTUIThemeBundle.
  • index.ts / detect.ts — theme type and auto/dark/light resolution.

Keep the color-token set in sync. ColorPalette in colors.ts is the source of truth for color tokens. When you add, rename, or remove one, update its mirrors in the same change: the custom-theme JSON schema (apps/kimi-code/src/tui/theme/theme-schema.json), the token tables in the custom-theme docs (docs/en/customization/themes.md and docs/zh/customization/themes.md), and the token table in the custom-theme built-in skill (packages/agent-core/src/skill/builtin/custom-theme.md).

Apply / switch flow:

  • UI entry: ThemeSelectorComponenthandleThemeCommandapplyThemeChoice.
  • The real apply step is KimiTUI.applyTheme: it updates state.theme, state.appState.theme, and notifies components to refresh their palette.
  • Persist the choice through saveTuiConfig — a component must not write the config file itself.

The hard color rules (no chalk named colors, contrast ratios, no module-top-level cached styled functions, add a ColorPalette token before inventing a color) are normative and guard-enforced — they live in apps/kimi-code/AGENTS.md. This skill only covers the mechanics.

Before you submit

  • Run lint / format / test on the files you changed.
  • For any dialog/selector/input/toggle list, walk the self-check list at the end of DESIGN.md.
  • Keep printableChar() for printable-key comparisons (CI guard) and chalk.hex(colors.<token>) for color (CI guard).

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.

関連スキル