Skip to content

refactor(agent-core-v2): drop the @moonshot-ai/protocol dependency - #1745

Merged
kermanx merged 2 commits into
mainfrom
refactor/agent-core-v2-drop-protocol
Jul 15, 2026
Merged

refactor(agent-core-v2): drop the @moonshot-ai/protocol dependency#1745
kermanx merged 2 commits into
mainfrom
refactor/agent-core-v2-drop-protocol

Conversation

@kermanx

@kermanx kermanx commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — see the problem statement below.

Problem

agent-core-v2 still depends on the hand-maintained @moonshot-ai/protocol package for three kinds of things: domain event payloads, v1 edge DTOs, and assorted leaf types. That package splits ownership of domain shapes away from the domains that produce and consume them, and the hand-maintained KimiErrorCode union can drift out of sync with the error codes domains actually register and throw.

What changed

Localize everything agent-core-v2 consumed from @moonshot-ai/protocol into the domain that owns it, and remove the package dependency:

  • Event payloads move next to their publishers (loop turn events, toolExecutor, subagent, swarm, shellCommand, mcp, externalHooks, profile, rpc, fullCompaction, stepRetry) and register on DomainEventMap from there.
  • v1 edge DTOs become zod schemas in the service contracts that back the routes (sessionFs, git, hostFolderBrowser, file, modelCatalog, auth/oauthWire, authLegacy, os/interface terminal, sessionLegacy, contextMemory wire message tree).
  • Leaf types land in their domains: ToolInputDisplay in tool, TurnEndReason in activity, UsageStatus reused from usage, the three remaining origins in contextMemory, CompactionResult inlined in fullCompaction, MCP OAuth tool-update constant in mcp/tools/auth.
  • The hand-maintained KimiErrorCode union is replaced by an ErrorCode type derived from the aggregated domain error definitions; registering the same code from two domains now throws. Codes that were thrown but never registered (workspace.not_found, validation.failed) are registered in their owning domains.
  • Drop the AgentPhase type: no producer ever wrote the field.
  • kap-server: remove a dead phase guard in the v1 broadcaster and keep the error mapping aligned with the derived codes.

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.

Localize everything agent-core-v2 consumed from @moonshot-ai/protocol
into the domain that owns it, and remove the package dependency:

- Event payloads move next to their publishers (loop turn events,
  toolExecutor, subagent, swarm, shellCommand, mcp, externalHooks,
  profile, rpc, fullCompaction, stepRetry) and register on
  DomainEventMap from there.
- v1 edge DTOs become zod schemas in the service contracts that back
  the routes (sessionFs, git, hostFolderBrowser, file, modelCatalog,
  auth/oauthWire, authLegacy, os/interface terminal, sessionLegacy,
  contextMemory wire message tree).
- Leaf types land in their domains: ToolInputDisplay in tool,
  TurnEndReason in activity, UsageStatus reused from usage, the three
  remaining origins in contextMemory, CompactionResult inlined in
  fullCompaction, MCP OAuth tool-update constant in mcp/tools/auth.
- The hand-maintained KimiErrorCode union is replaced by an ErrorCode
  type derived from the aggregated domain error definitions;
  registering the same code from two domains now throws. Codes that
  were thrown but never registered (workspace.not_found,
  validation.failed) are registered in their owning domains.
- Drop the AgentPhase type: no producer ever wrote the field.
- kap-server: remove a dead phase guard in the v1 broadcaster and keep
  the error mapping aligned with the derived codes.
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: ad46719

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 15, 2026

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

commit: ad46719

@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: 78ac6188df

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +90 to +100
declare module '#/app/event/eventBus' {
interface DomainEventMap {
'turn.started': TurnStartedEvent;
'turn.ended': TurnEndedEvent;
'turn.step.started': TurnStepStartedEvent;
'turn.step.completed': TurnStepCompletedEvent;
'turn.step.interrupted': TurnStepInterruptedEvent;
'assistant.delta': AssistantDeltaEvent;
'thinking.delta': ThinkingDeltaEvent;
'tool.call.delta': ToolCallDeltaEvent;
}

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 Load turn event augmentation from the loop barrel

When downstream code consumes DomainEvent/IEventBus through the package barrel or built declarations rather than compiling the whole src tree, this augmentation is never loaded: turnEvents.ts is neither exported from src/index.ts nor imported for side effects by loopService.ts (unlike the new toolExecutorEvents side-effect import). That makes public consumers lose the turn.*/delta event keys even though the loop still publishes them, so typed subscriptions or event switches for turn.started/assistant.delta can fail to type-check. Add a side-effect import from the loop service/barrel or export this module.

Useful? React with 👍 / 👎.

…rvice

turnEvents.ts was only reachable through type-only imports, so consumers
of the package barrel or built declarations never loaded its
DomainEventMap augmentation and lost the turn.*/delta event keys. Add a
side-effect import in loopService.ts, mirroring the toolExecutorEvents
pattern.
@kermanx
kermanx merged commit 27236bd into main Jul 15, 2026
14 checks passed
@kermanx
kermanx deleted the refactor/agent-core-v2-drop-protocol branch July 15, 2026 08:03
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.

1 participant