Communitygithub.com

MoonshotAI/agent-core-dev

用於開發 packages/agent-core-v2(DI × Scope 代理引擎)時使用——新增或修改領域服務、選擇 LifecycleScope、配置 DI 依賴、跨作用域拆分領域、擁有或遷移配置區段、以實驗性標誌門控行為、引發編碼錯誤、處理權限系統、編寫 DI/Scope 測試、將業務邏輯從 agent-core (v1) 移植到 v2、針對 v2 分類主分支提交,或透過 server-v2 暴露 v2 領域,同時保持 /api/v1 線路合約與已發佈用戶端相容。按開發階段(定向→設計→實作→測試→驗證)自包含引導,外加 v1→v2 移植、主分支提交分類和 server-v2 線路暴露的校準工作流程;每個檔案都承載其步驟的規則、範例和紅線。

agent-core-dev 是什麼?

此技能為開發者提供一個按生命週期階段組織的、自包含的指南,用於開發 `packages/agent-core-v2`——這是一個基於 DI × Scope 架構的新型代理引擎。它涵蓋了從定向到設計、實作、測試和驗證的完整過程,並包含用於將 v1 邏輯移植到 v2 以及將 v2 領域暴露於伺服器的工作流程。每個階段檔案都提供了具體的規則、範例和不可違反的「紅線」,確保一致性,例如禁止直接 `new` 帶 DI 依賴的類別、避免循環依賴以及使用編碼錯誤而非 `instanceof` 進行錯誤處理。此技能專注於使開發者無需查閱原始源文件即可高效工作,特別適合在 agent-core-v1 到 v2 的遷移或維護兩個版本共存的程式碼庫時使用。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/MoonshotAI/kimi-code/tree/main/.agents/skills/agent-core-dev

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

agent-core-dev 是做什麼的?

按生命週期階段開發 packages/agent-core-v2。此技能自包含:每個規則、配方和紅線都位於下面的階段檔案中——它不會委託給 packages/agent-core-v2/docs/。

agent-core-v2 是基於 DI × Scope 架構(packages/agent-core 的移植)的新代理引擎。所有內容都透過容器解析:一個服務宣告其身份、依賴項和生命週期;容器決定建構、每個作用域的單例、排序和釋放。階段檔案以命令式形式重述規則,以便您無需閱讀原始文件即可工作。

生命週期一覽

Orient → Design → Implement → Test → Verify
  │        │          │          │        │
  │        │          │          │        └─ lint:domain · typecheck · test · dep graph · red lines
  │        │          │          └─ test.md
  │        │          └─ implement.md (+ errors.md · flags.md · permission.md)
  │        └─ design.md
  └─ orient.md

階段是有序的,但並非嚴格線性:一個測試失敗(階段 4)揭示了錯誤的作用域,會將您送回設計(階段 2);一個 CyclicDependencyError 會將您送回 design.md §dependency-direction 和 implement.md §cycles。

工作流程

跨階段的端到端程序。在單獨閱讀階段檔案之前,請優先使用這些。

  • 校準(將 agent-core 移植到 agent-core-v2):將一個 v1 類別拆分為語義單元,修正每個單元的領域/作用域/服務/依賴項,然後遷移邏輯和測試。當任務是「將功能 X 從 v1 移動到 v2」或「將 IXxxService 移植到 v2」時使用。
  • 提交校準(針對 v2 分類 main 分支提交):給定一個 main 分支提交哈希值加上簡短說明,找出它變更的 v1 邏輯,檢查 v2 是否已經有對應的實作,將其分類(已對齊/部分/缺失/不適用),並建議最小的修復。在 kimi-code-v2-追趕-main 階段使用,一次處理一個提交;如果差距是整個領域,則升級到 align.md。
  • 伺服器校準(將 agent-core-v2 透過 server-v2 暴露):將一個 v2 領域接入 packages/kap-server,透過 /api/v2(原生)和 /api/v1(v1 相容鏡像)暴露,透過共享 @moonshot-ai/protocol 模式保持線規格與既有的 v1 合約位元組相容,並將僅 v1 的行為隔離在 <domain>Legacy 邊緣轉接器中,而不是扭曲原生的 v2 服務。當任務是「在伺服器上暴露新的 v2 服務」、「在 /api/v1 介面新增路由」或「保持 server-v2 線路與已發佈的 v1 用戶端相容」時使用。

階段

  • 階段 1 — 定向:DI 黑箱(身份/依賴項/生命週期)、四個 LifecycleScope 層級及其可見性,以及檔案頭註釋慣例。在接觸業務程式碼之前閱讀。
  • 階段 2 — 設計服務:選擇作用域、跨作用域拆分領域、選擇呼叫風格(直接呼叫 vs 事件 vs 鉤子)以及直接依賴項。在編碼之前決定內容的位置以及誰知道誰。
    • 主題:領域邊界 vs 作用域——避免 session / agent / turn 變成上帝物件;資料所有權測試及其拆分結論。
    • 主題:持久化層——三層 Store → Storage → backend 模型,按存取模式命名 Store,以及業務程式碼應依賴哪一層。
    • 主題:邊緣暴露——resource:action + WS 事件——哪些服務透過 /api/v2 暴露(每個作用域的動作對映)以及哪些事件透過 WS 串流;哪些內容應包裝在 Facade 中。
  • 階段 3 — 實作:標準服務配方和 DI 建構區塊——介面 + 身份、建構子注入、作用域註冊、Disposable、急切與延遲、invokeFunction、createInstance、子作用域以及循環重構腳本。
    • 主題:服務編寫——檔案佈局、命名、合約與實作內容、介面風格、建構子/欄位慣例、事件、多服務領域、註解規則。
    • 主題:設定——區段註冊模型、App 與 Session 拆分、擁有設定區段、TOML 格式以及環境變數覆蓋。
    • 主題:錯誤——共置的 XxxError、中央程式碼註冊表、線序列化、邊界轉換。
    • 主題:功能標誌——registerFlagDefinition、IFlagService.enabled(id)、[experimental] 設定區段、解析優先級。
    • 主題:權限——可組合的責任鏈核心、政策註冊表 + 組合器、modes/agentTypes 元資料、resolveExecution/accesses。
    • 主題:遙測——透過 ITelemetryService 發出事件、上下文傳播以及附加器目的地(ConsoleAppender / CloudAppender)。
  • 階段 4 — 測試:透過介面解析受測系統,選擇 TestInstantiationService 與 createScopedTestHost、共享樁、服務群組、拆卸。
  • 階段 5 — 驗證並提交:lint:domain、typecheck、test 以及提交前檢查清單。

如何使用此技能

跳轉到您所在的階段並閱讀該檔案;每個檔案都是自包含的,並以自身的紅線結尾。在提交前略讀下面的全域紅線——它們能捕捉跨所有階段的大多數錯誤。儲存庫的真實來源是 packages/agent-core-v2/src/ 中的程式碼;此技能將相同的規則編纂成文,以便您無需重新推導。

全域紅線

跨所有階段不變的約束。每個約束在所指出的階段檔案中有更詳細的說明。

  1. 禁止 new 一個建構子帶有 @IService 依賴項的類別——應使用 @IX 或 accessor.get(IX) 注入。(implement.md)
  2. @IX 僅裝飾建構子參數;參數順序取決於建構方式(createInstance 為靜態優先,作用域服務為 @IX 優先)。(service-authoring.md)
  3. 介面和實作都攜帶 _serviceBrand;createDecorator 的名稱必須全域唯一。(implement.md)
  4. 父作用域永遠不應依賴子作用域——短期對象可以注入長期對象,反之則不行。(orient.md)
  5. 禁止循環依賴——應重構(提取第三個服務/使用事件/重新設定作用域);不要使用 Delayed 來中斷循環。(design.md, implement.md)
  6. ServicesAccessor 僅在 invokeFunction 期間有效——切勿將其儲存起來用於非同步操作。(implement.md)
  7. 作用域應遵循狀態身份——不要在 App 作用域使用 Map<sessionId, …> 來模擬每 session 的狀態。(design.md)
  8. 基礎層永遠不應知道上層;業務程式碼永遠不應依賴邊緣層(gateway/rpc)。(design.md)
  9. 拋出編碼錯誤;集中註冊錯誤碼;在線路上根據 code 進行分支,永遠不要使用 instanceof。(errors.md)
  10. 使用通過 registerFlagDefinition 貢獻並透過 IFlagService.enabled(id) 解析的功能標誌來門控未發佈的行為;禁止使用臨時的環境變數切換。(flags.md)
  11. 測試應透過介面解析受測系統;共享樁應位於 test/ 目錄下,永遠不應放在 src/。(test.md)
  12. 設定是偏好註冊表:只有可持久化、有模式且面向使用者/操作員的偏好才應放入 IConfigService。領域特定的設定(包括僅環境的操作切換)應透過 registerSection + envOverlay 進行。事實(Facts)→ IBootstrapService(保持領域無關——永遠不要新增 cron/flags/模型狀態);session 狀態 → Session 作用域;常量 → 程式碼。業務領域永遠不應直接呼叫 IBootstrapService.getEnv()。(config.md)

Individual skills in this repo

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

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.

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).

相關技能