refactor(agent-core-v2): drop the @moonshot-ai/protocol dependency - #1745
Conversation
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.
|
commit: |
There was a problem hiding this comment.
💡 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".
| 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; | ||
| } |
There was a problem hiding this comment.
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.
Related Issue
No linked issue — see the problem statement below.
Problem
agent-core-v2still depends on the hand-maintained@moonshot-ai/protocolpackage 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-maintainedKimiErrorCodeunion can drift out of sync with the error codes domains actually register and throw.What changed
Localize everything
agent-core-v2consumed from@moonshot-ai/protocolinto the domain that owns it, and remove the package dependency:DomainEventMapfrom there.ToolInputDisplayin tool,TurnEndReasonin activity,UsageStatusreused from usage, the three remaining origins in contextMemory,CompactionResultinlined in fullCompaction, MCP OAuth tool-update constant in mcp/tools/auth.KimiErrorCodeunion is replaced by anErrorCodetype 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.AgentPhasetype: no producer ever wrote the field.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.