Skip to content

feat(kap-server): include host product in instance registry and /api/v1/meta - #5045

Merged
wbxl2000 merged 1 commit into
mainfrom
feat/kap-instance-product
Nov 18, 2026
Merged

wbxl2000 merged 1 commit into
mainfrom
feat/kap-instance-product

Conversation

@wbxl2000

Copy link
Copy Markdown
Collaborator

Requirement or Bug

当 Kimi Code Desktop 与 CLI(kimi web / kimi rc)在同一台机器上同时运行时,两者都会在 ~/.kimi-code/server/instances/*.json 下注册本地 KAP 实例。此前注册文件仅记录 server_id、pid、host、port、started_at、heartbeat_at 与内核 host_version,本地调用方无法直接区分哪个实例来自桌面端(kimi-code-desktop)、哪个来自命令行(kimi-code-cli)。本 PR 将 startServer 已接收的 opts.hostIdentity.productName 落入 instances/*.json 与 GET /api/v1/meta 的可选字段 product,使本地 Agent 与脚本可直接识别宿主类型(例如优先连接正在运行的桌面端)。

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

startServer(opts) 入参中原本已携带必填的 opts.hostIdentity.productName(桌面端传入 "kimi-code-desktop",CLI 传入 "kimi-code-cli"),无需改动任何上游客户端即可在 kap-server 内直接透传到实例注册表与 /api/v1/meta。

interface ServerInstanceDisk {
  server_id: string;
  pid: number;
  host: string;
  port: number;
  started_at: number;
  heartbeat_at: number;
  host_version?: string;
  product?: string;
}
  • packages/kap-server/src/instanceRegistry.ts、src/start.ts:ServerInstanceInfo 与磁盘序列化新增可选字段 product(非空字符串时写入与还原),startServer 注册实例时传入 opts.hostIdentity.productName。
  • packages/kap-server/src/protocol/rest-meta.ts、src/routes/meta.ts、src/routes/registerApiV1Routes.ts:GET /api/v1/meta 响应新增可选字段 product,透传 opts.hostIdentity.productName;HOST_API_LEVEL 保持 1(纯增量可选响应字段,旧版客户端与新版服务端双向兼容),同步更新 apiSurface.snapshot.test.ts 的契约摘要。

Behavior Changes and Affected Users

行为 改动前 改动后 依赖旧行为的人群 退路
~/.kimi-code/server/instances/*.json 实例元数据 不含 product 字段 新增可选字符串字段 product(如 "kimi-code-desktop"、"kimi-code-cli");旧版写入的无 product 文件仍正常解析 读取 instances/*.json 的本地 CLI、外部 KAP Agent 与脚本 旧字段完整保留;新增字段为可选字段,忽略未知字段的读取方不受影响
GET /api/v1/meta 响应 data 不含 product 字段 新增可选字段 data.product 消费 /api/v1/meta 的 Desktop / Web(code-app)及外部 KAP 客户端 旧字段完整保留,纯增量可选字段
  • 受影响模块:packages/kap-server
  • 测试覆盖:packages/kap-server/test/instanceRegistry.test.ts(覆盖 product 磁盘读写、listLive 还原及 startServer 注入)、packages/kap-server/test/meta.test.ts(覆盖 /api/v1/meta 返回 data.product)、packages/kap-server/test/apiSurface.snapshot.test.ts(契约摘要与快照校验通过)。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 08a6397

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T09:48:26.586920Z 08a6397 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 18, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@08a6397
npx https://pkg.pr.new/@moonshot-ai/kimi-code@08a6397

commit: 08a6397

@wbxl2000
wbxl2000 merged commit baa7b4b into main Nov 18, 2026
17 checks passed
@wbxl2000
wbxl2000 deleted the feat/kap-instance-product branch November 18, 2026 11:54
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants