Communitygithub.com

MoonshotAI/write-tui

kimi-code 터미널 UI(apps/kimi-code/src/tui)를 작성하거나 수정할 때 사용합니다. 컴포넌트, 대화상자/선택기, 슬래시 명령어, 테마, 스트리밍 렌더링 또는 KimiTUI 컨트롤러를 다루며, 아키텍처, 새 기능 추가 위치, 테스트 배치, 테마 시스템 작동 방식, 대화상자 상호작용/시각 사양(DESIGN.md)을 포함합니다.

write-tui란 무엇인가요?

이 스킬은 kimi-code 애플리케이션의 터미널 UI(TUI) 코드를 작성하거나 수정할 때 따라야 할 전반적인 가이드라인을 제공합니다. 주요 아키텍처는 `KimiTUI` 코디네이터를 중심으로 하며, 상태 관리, 레이아웃 연결, 세션 수명 주기, 슬래시 명령어 디스패치 등을 담당합니다. 컨트롤러는 스트리밍 렌더링, 세션 이벤트 처리, 작업 브라우저 등 각 책임 영역별로 독립적으로 테스트 가능한 형태로 분리되어 있습니다. 새 기능은 그 유형에 따라 CLI 인수, 슬래시 명령어, 트랜스크립트 메시지 유형, 도구 결과 표시, 팝업/선택기 등 각각의 적절한 디렉터리와 모듈에 배치해야 하며, 테스트는 해당 기능의 기존 테스트 파일 옆에 추가해야 합니다. 테마 시스템은 `src/tui/theme/`에서 중앙 관리되며, 의미론적 색상 토큰을 사용하고, `ColorPalette`가 단일 진실 공급원입니다. 모든 대화상자나 선택기 UI는 DESIGN.md의 상호작용 및 시각 규칙을 따라야 하며, 제출 전에는 린트/포맷/테스트를 실행하고 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)

터미널 UI는 apps/kimi-code/src/tui에 있습니다. TUI 코드를 작성하기 전에 apps/kimi-code/AGENTS.md를 읽어 항상 적용되는 맵, 모듈 경계 및 하드 제약 조건(출력 가능 키 디코딩, chalk 명명된 색상 금지 등)을 확인하세요. 이 스킬은 방법론입니다: 아키텍처 방향, 기능 배치, 테스트 위치, 테마 작동 방식 및 대화상자 사양을 다룹니다.

목록 대화상자, 선택기, 입력 상자, 상태/토글 목록의 경우 상호작용 및 시각적 규칙이 표준입니다. 이 폴더에 있는 **DESIGN.md**를 읽고 제출 전에 자체 점검 목록을 따르세요.

아키텍처

KimiTUI는 상태, 레이아웃, 세션 및 대화상자를 연결하고 무거운 로직을 컨트롤러에 위임하는 코디네이터입니다.

  • src/tui/kimi-tui.ts — KimiTUI 코디네이터. state를 보유하며, 시작/종료 순서, 레이아웃/편집기 연결, 사용자 입력 진입점, 전송/대기열 관리, 세션 수명 주기 및 슬래시 명령어 핸들러 디스패치를 담당합니다. 이벤트 라우팅이나 렌더링 로직을 축적해서는 안 됩니다. 해당 로직은 컨트롤러에 있습니다.
  • src/tui/tui-state.ts — TUIState, createTUIState, createInitialAppState. 단일 전역 UI 상태 구조입니다. 새 전역 필드를 추가하기 전에 로컬 컴포넌트 상태에 속하는지 진정으로 여기에 속하는지 결정하세요.
  • src/tui/controllers/ — 독립적으로 테스트 가능한 책임 영역입니다. 각 컨트롤러는 하나의 조각을 소유합니다:
    • 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/ — UI 유형별 pi-tui 컴포넌트: chrome/ (푸터, 할 일, 환영 메시지, 로더, 디바이스 코드), dialogs/ (선택기, 승인/질문 패널, 편집기를 대체하는 설정 팝업), editor/ (입력 상자 + 멘션 제공자), media/ (이미지, diff, 코드 하이라이트), 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/.
  • 순수 유틸리티 테스트 → 해당 유틸리티 테스트 옆.
  • 작은 기능을 위해 일반적인 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 토큰 추가)은 표준이며 가드(guard)에 의해 적용됩니다. 이 규칙은 apps/kimi-code/AGENTS.md에 있습니다. 이 스킬은 메커니즘만 다룹니다.

제출 전 확인 사항

  • 변경한 파일에 대해 린트/포맷/테스트를 실행하세요.
  • 모든 대화상자/선택기/입력/토글 목록에 대해 DESIGN.md 끝에 있는 자가 점검 목록을 확인하세요.
  • 출력 가능 키 비교에는 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.

관련 스킬