Communitygithub.com

MoonshotAI/agent-core-v2 开发技能

在开发 packages/agent-core-v2(DI × 作用域 智能体引擎)时使用——添加或修改领域服务、选择生命周期作用域、装配 DI 依赖、跨作用域拆分领域、拥有或迁移配置段、在实验性标志后控制行为、引发编码错误、处理权限系统、编写 DI/作用域测试、将业务逻辑从 agent-core (v1) 移植到 v2、对 main 分支提交进行 triage 以适配 v2、或通过 server-v2 暴露 v2 领域同时保持 /api/v1 的线缆与已发布客户端兼容。自包含指南,按开发阶段组织(定位→设计→实现→测试→验证),并包含 v1→v2 迁移、main 分支提交 triage 和 server-v2 线缆暴露的对齐工作流;每个文件都包含其步骤的规则、示例和红线。

agent-core-v2 开发技能 是什么?

该技能是 `agent-core-v2` 软件包的全面开发指南,基于 DI(依赖注入)× 作用域架构。它为开发人员提供了按阶段组织的工作流:从定位(Orient)开始理解 DI 核心概念,经过设计(Design)确定服务的作用域和依赖方向,到实现(Implement)遵循标准化的服务配方,再到测试(Test)使用正确的隔离策略,最后通过验证(Verify)确保所有红线规则被遵守。技能特别包含三个关键工作流:**对齐**工作流(align.md)用于将 v1 业务逻辑完整迁移到 v2;**提交对齐**工作流(commit-align.md)用于逐 commit 检查 v2 代码库与 main 分支的差距;**服务器对齐**工作流(server-align.md)用于通过 server-v2 安全暴露 v2 领域,同时维护与已发布 v1 客户端的向后兼容性。它支持 Claude Code、Cursor、Codex 等 AI 编码代理,并提供了 12 条全局红线,覆盖了依赖注入、作用域、错误处理、配置、标志和测试等领域,确保开发人员无需查阅源码即可应用正确的开发模式。该技能的目标是加速 `agent-core` 到 `agent-core-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-v2 开发技能 是做什么的?

按生命周期阶段开发 packages/agent-core-v2。本技能是自包含的:每条规则、配方和红线都存在于下面的阶段文件中——它不会委托给 packages/agent-core-v2/docs/。

agent-core-v2 是基于 DI × 作用域 架构构建的新智能体引擎(packages/agent-core 的移植)。所有组件都通过容器解析:服务声明其身份、依赖项和生命周期;容器决定构造、单例每作用域、排序和销毁。阶段文件以命令式形式重述规则,以便您无需阅读源文档即可工作。

生命周期概览

定位 → 设计 → 实现 → 测试 → 验证
  │        │          │          │        │
  │        │          │          │        └─ 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 §依赖方向和 implement.md §循环。

工作流

跨阶段的端到端流程。在单独阅读阶段文件之前,请先使用这些。

  • 对齐(移植 agent-core → agent-core-v2):将 v1 类拆分为语义单元,修复每个单元的领域/作用域/服务/依赖关系,然后迁移逻辑和测试。当任务为“将特性 X 从 v1 移动到 v2”或“将 IXxxService 移植到 v2”时使用。
  • 提交对齐(对 main 分支提交进行 triage 以适配 v2):给定一个 main 分支提交哈希 + 一条简短的注释,找到它更改的 v1 逻辑,检查 v2 是否已经有相应的实现,将其分类(已对齐/部分对齐/缺失/不适用),并推荐最小修复。在 kimi-code-v2-追赶-main 阶段使用,一次处理一个提交;如果差距是整个领域,则升级到 align.md。
  • 服务器对齐(通过 server-v2 暴露 agent-core-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 暴露(每作用域操作映射)以及哪些事件通过 WebSocket 流式传输;需要在什么内容上包装外观层。
  • 阶段 3——实现:标准服务配方和 DI 构建块——接口 + 身份、构造函数注入、作用域注册、Disposable、急切 vs 延迟、invokeFunction、createInstance、子作用域以及循环重构手册。
    • 主题:服务编写——文件布局、命名、契约 vs 实现内容、接口风格、构造函数/字段约定、事件、多服务领域、注释规则。
    • 主题:配置——段注册模型、App vs Session 拆分、拥有配置段、TOML 格式以及环境变量覆盖。
    • 主题:错误——共置的 XxxError、中央代码注册表、线缆序列化、边界转换。
    • 主题:标志——registerFlagDefinition、IFlagService.enabled(id)、[experimental] 配置段、解析优先级。
    • 主题:权限——可组合的责任链内核、策略注册表 + 组合器、modes/agentTypes 元数据、resolveExecution/accesses。
    • 主题:遥测——通过 ITelemetryService 发出事件、上下文传播以及追加器目标(ConsoleAppender / CloudAppender)。
  • 阶段 4——测试:通过接口解析被测系统、选择 TestInstantiationService vs createScopedTestHost、共享存根、服务组、拆卸。
  • 阶段 5——验证并提交:lint:domain、typecheck、test 以及提交前清单。

如何使用本技能

跳转到您所在的阶段,阅读该文件;每个文件都是自包含的,并以自己的红线结束。在提交前浏览下面的全局红线——它们可以捕获跨所有阶段的大部分错误。仓库的真相来源仍然是 packages/agent-core-v2/src/ 中的代码;本技能将相同的规则编码,以便您不必重新推导它们。

全局红线

跨所有阶段的不变量。每个都在相应的阶段文件中展开。

  1. 不得在构造函数带有 @IService 依赖的类上使用 new——使用 @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, …> 来伪造每会话状态。(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 进行。事实 → IBootstrapService(保持领域无关——永远不要添加 cron/标志/模型状态);会话状态 → 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).

相关技能