Skip to content

refactor(kap-server): drop the @moonshot-ai/protocol dependency - #1755

Merged
kermanx merged 2 commits into
mainfrom
refactor/kap-server-drop-protocol
Jul 15, 2026
Merged

refactor(kap-server): drop the @moonshot-ai/protocol dependency#1755
kermanx merged 2 commits into
mainfrom
refactor/kap-server-drop-protocol

Conversation

@kermanx

@kermanx kermanx commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — this is the second half of the decoupling landed in #1745.

Problem

After #1745 removed @moonshot-ai/protocol from the engine, the v2 server was the last link in the engine → server → UI chain still built on the v1-era shared schema package. The schemas the server speaks fall into two kinds: contracts the engine's own services already own (fs, oauth, terminal, session/messages DTOs…), and shapes only the v1 transport needs (envelope, numeric error codes, REST endpoint schemas, the WS/asyncapi catalog). Both should live with their owners instead of in a shared package.

What changed

  • Engine-owned contracts are imported from agent-core-v2 leaf paths (sessionFs, git, hostFolderBrowser, auth, authLegacy, terminal, file, modelCatalog, contextMemory, sessionLegacy).
  • v1-only shapes move into a new local kap-server/src/protocol tree that keeps the established vocabulary: envelope, the numeric ErrorCode table, request-id, pagination, the session/workspace/goal/approval/question/task/tool/skill models, all rest-* endpoint schemas, and the ws-control / asyncapi / event-zod / display catalog (ported field-for-field; v1 quirks preserved deliberately).
  • The v1 WS event stream is recomposed locally: transport/ws/v1/events.ts builds the Event union from the engine's DomainEvent plus the v1-only synthesized frames; AgentPhase moves into the legacyStatus projection; volatile classification is owned by the broadcaster module.
  • The engine files carrying v1 wire DTOs keep the protocol vocabulary too: sessionProtocol, oauthProtocol, protocolMessage.
  • Tests re-point to the same local/engine sources; the agent-core-dev skill docs get minimal updates for the new schema/error-code homes.
  • @moonshot-ai/protocol is removed from kap-server's dependencies. The protocol package itself, agent-core (v1), and server-e2e are untouched — server-e2e keeps validating responses against the original protocol schemas, acting as a drift oracle.

Verification: /openapi.json and /asyncapi.json captured before and after are byte-identical; kap-server typecheck and test suite match main's baseline (only the pre-existing boot/lock/workspaceFs environment flakes).

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.

Re-source every schema/type the server imported from
@moonshot-ai/protocol, and remove the package dependency:

- Contracts the engine owns come from agent-core-v2 leaf paths
  (sessionFs, git, hostFolderBrowser, auth/oauthWire, authLegacy,
  terminal, file, modelCatalog, contextMemory wireMessage,
  sessionLegacy sessionWire).
- Shapes only the v1 transport needs move into a local
  kap-server/src/wire tree: envelope, numeric ErrorCode table,
  request-id, pagination, session/workspace/goal/approval/question/
  task/tool/skill models, all rest-* endpoint schemas, the ws-control
  catalog, asyncapi, the event zod catalog, and display.
- The v1 WS event stream is recomposed locally:
  transport/ws/v1/events.ts builds the Event union from the engine's
  DomainEvent plus the v1-only synthesized frames, AgentPhase moves
  into the legacyStatus projection, and isVolatileEventType is owned
  by the broadcaster module.
- Tests re-point to the same local/engine sources; the server-align
  and errors skill docs now describe the new schema ownership.

/openapi.json and /asyncapi.json are byte-identical before and after;
the only test failures are the pre-existing boot/lock/workspaceFs
environment flakes also present on main.
@changeset-bot

changeset-bot Bot commented Jul 15, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2895095

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

@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@2895095
npx https://pkg.pr.new/@moonshot-ai/kimi-code@2895095

commit: 2895095

Rename kap-server/src/wire to src/protocol: the v1 wire schemas keep
their established name in their new home instead of introducing a
second term that collides with the engine's wire journal domain.

Apply the same vocabulary in the engine: sessionWire, oauthWire, and
wireMessage become sessionProtocol, oauthProtocol, and
protocolMessage (matching the existing toProtocolMessage naming).

Keep the agent-core-dev skill doc edits minimal: only the lines whose
schema/error-code home changed are updated.
@kermanx
kermanx merged commit 4f99114 into main Jul 15, 2026
15 checks passed
@kermanx
kermanx deleted the refactor/kap-server-drop-protocol branch July 15, 2026 14:40
@github-actions github-actions Bot mentioned this pull request Jul 15, 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.

1 participant