Skip to content

feat(acp): report Kimi account usage - #2716

Open
daniel20060210 wants to merge 2 commits into
MoonshotAI:mainfrom
daniel20060210:codex/kimi-account-usage
Open

feat(acp): report Kimi account usage#2716
daniel20060210 wants to merge 2 commits into
MoonshotAI:mainfrom
daniel20060210:codex/kimi-account-usage

Conversation

@daniel20060210

Copy link
Copy Markdown

Related Issue

Resolve #2483

Problem

Kimi Code 的 ACP 目前只传输对话和工具事件,没有把 Coding Plan 的额度窗口或 API Key 计费模式暴露给客户端。客户端因此无法在账号状态区域展示真实用量,也无法区分 Coding Plan 与 API Usage Billing。

What changed

  • 在会话打开和主 Agent 每轮结束后发送标准 ACP usage_update
  • 保留标准 used / size 上下文字段,并在 _meta.kimiCode 中附加 coding_plan / api_key 计费模式
  • Coding Plan 额度由 Kimi runtime 自己读取并按会话缓存一分钟;API Key 永不进入通知
  • 增加 Coding Plan、API Key、缓存和会话初始化回归测试
  • 同步中英文 ACP 文档,并为 @moonshot-ai/kimi-code 添加 patch changeset

验证:

  • vitest run packages/acp-adapter/test:37 个测试文件、328 个测试通过
  • tsc -p packages/acp-adapter/tsconfig.json --noEmit
  • pnpm --filter @moonshot-ai/kimi-code run build

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • 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 Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 65f1dce

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

@daniel20060210
daniel20060210 deleted the codex/kimi-account-usage branch August 7, 2026 05:42
@daniel20060210
daniel20060210 restored the codex/kimi-account-usage branch August 7, 2026 08:07
@daniel20060210 daniel20060210 reopened this Aug 7, 2026
@daniel20060210
daniel20060210 marked this pull request as ready for review August 7, 2026 08:07

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65f1dceda6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

DEFAULT_MODE_ID,
);
this.scheduleAvailableCommandsUpdate(session.id);
void acpSession.emitUsageReport();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add account usage reporting to the default ACP server

The new reporting is wired only into @moonshot-ai/acp-adapter, but apps/kimi-code/src/cli/sub/acp.ts:40-44 routes ordinary kimi acp invocations to @moonshot-ai/acp-server; this adapter is used only when KIMI_CODE_LEGACY_FLAG is enabled. The default server's emitUsageUpdate() still sends context fields without _meta.kimiCode, so nearly all users will not receive the advertised account usage. Implement the metadata and opening update in packages/acp-server as well, or route the default command through this implementation.

Useful? React with 👍 / 👎.

Comment on lines +333 to +337
const billingMode =
providerId === 'managed:kimi-code' && provider?.oauth !== undefined
? 'coding_plan'
: typeof provider?.apiKey === 'string' && provider.apiKey.length > 0
? 'api_key'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize API keys supplied through the provider env table

In the legacy adapter, a Kimi provider configured with [providers.<name>.env] KIMI_API_KEY = "..." is valid and is resolved by providerValue(provider.apiKey, provider.env, 'KIMI_API_KEY') in packages/agent-core/src/session/provider-manager.ts, but this classification checks only provider.apiKey. For that supported configuration the session is actually API-key billed while _meta.kimiCode is omitted entirely; resolve the credential using the same precedence without serializing its value.

Useful? React with 👍 / 👎.

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.

ACP: expose managed account quota (5h / weekly) on usage frames

1 participant