Skip to content

refactor: centralize main agent id constant #45

@CoutinhoTTS

Description

@CoutinhoTTS

Summary

Centralize the main agent id (main) so runtime code does not duplicate the literal across agent-core, node-sdk, and apps/kimi-code.

Motivation

The main agent id is currently treated as a shared protocol/identity value, but it is defined or hard-coded in multiple places. For example:

  • packages/node-sdk/src/rpc.ts defines a local MAIN_AGENT_ID
  • packages/node-sdk/src/session.ts defines a local MAIN_AGENT_ID
  • packages/agent-core/src/session/rpc.ts checks agentId === 'main'
  • apps/kimi-code has its own TUI-level MAIN_AGENT_ID

This makes future changes error-prone because the value is part of the SDK/core communication contract.

Proposed Change

Define MAIN_AGENT_ID once in agent-core and reuse it across the runtime code:

  • Export MAIN_AGENT_ID from packages/agent-core/src/agent/index.ts
  • Use it in agent-core session/rpc code instead of hard-coded 'main'
  • Import it in node-sdk from @moonshot-ai/agent-core
  • Re-export it from @moonshot-ai/kimi-code-sdk
  • Let apps/kimi-code consume it through the SDK boundary instead of importing agent-core directly

Scope

This is an internal refactor. It should not change runtime behavior.

Validation

Expected validation:

  • pnpm --filter @moonshot-ai/agent-core typecheck
  • pnpm --filter @moonshot-ai/kimi-code-sdk typecheck
  • pnpm --filter @moonshot-ai/kimi-code typecheck

If this direction sounds reasonable, I’d be happy to submit a PR to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions