Skip to content

feat(klient): contract-driven facade with http/ipc/memory transports - #1768

Merged
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:feat/klient-facade
Jul 16, 2026
Merged

feat(klient): contract-driven facade with http/ipc/memory transports#1768
sailist merged 2 commits into
MoonshotAI:mainfrom
sailist:feat/klient-facade

Conversation

@sailist

@sailist sailist commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

None — the problem is explained below.

Problem

@moonshot-ai/klient accumulated several overlapping client implementations (channel, client, httpChannel, wsChannel, wsKlient, proxy) with no shared contract: each transport re-implemented method routing in its own way, payloads were not validated at the boundary, and there was no single façade over the kap-server surface. Meanwhile the e2e suites lived in a separate packages/server-e2e workspace that had to be kept in sync with the klient by hand.

What changed

1. Contract-driven klient facade

  • Added zod-validated contract sections (global / session / agent) under packages/klient/src/contract, and a facade exposing global.*, session(id).*, agent(id).* with zod validation on every call.
  • Transport is selected once at creation via subpath entries (@moonshot-ai/klient/http|ipc|memory); all three return the same Klient shape.
  • Klient-level typed event forwarding is layered on top of the contract.
  • Dropped the legacy channel / client / httpChannel / wsChannel / wsKlient / proxy implementations.

2. Absorbed server-e2e into the klient test suites

  • Moved the packages/server-e2e scenarios into packages/klient/test/e2e: dual-backend session/agent suites (in-memory + in-process server), /api/v2 wire tests, and the legacy /api/v1 live suites, plus the docker e2e runner.
  • Removed the packages/server-e2e workspace (and its flake.nix entries) so e2e coverage evolves next to the client it tests.
  • Added contract conformance helpers so the same assertions run against every transport.

3. Exposed model registry / catalog on kap-server v2

  • Registered the model registry and catalog services on the kap-server v2 RPC surface (src/transport/channelRegistry.ts) so klient consumers can query available models through the contract.

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.

- add zod-validated contract sections (global/session/agent) under
  src/contract and a facade exposing global.*, session(id).*, agent(id).*
- select transport once at creation via subpath entries
  (@moonshot-ai/klient/http|ipc|memory); drop legacy channel/client/
  httpChannel/wsChannel/wsKlient/proxy implementations
- absorb packages/server-e2e into packages/klient test/e2e suites
  (dual-backend, legacy v1, v2 wire) and remove the server-e2e workspace
- expose model registry and catalog services on kap-server v2 RPC surface
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fc55640

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@moonshot-ai/kap-server Minor
@moonshot-ai/kimi-code Patch
@moonshot-ai/klient Minor

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 16, 2026

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

commit: fc55640

@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: a8761b00a3

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

update: (patch) => call(scope, 'sessionMetadata', 'update', [patch]) as Promise<void>,
setArchived: (archived) =>
call(scope, 'sessionMetadata', 'setArchived', [archived]) as Promise<void>,
status: () => call(scope, 'sessionActivity', 'status', []) as Promise<SessionStatus>,

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 the missing sessionActivity service before exposing status

This new facade method routes session.status() to a sessionActivity v2 service, but that service does not exist in agent-core-v2 and is not exposed by packages/kap-server/src/transport/channelRegistry.ts (repo-wide rg "ISessionActivity|sessionActivity" only finds the new klient references and tests). As a result, HTTP callers get an unknown service: sessionActivity response for every klient.session(id).status() call, and the memory transport also imports a non-existent @moonshot-ai/agent-core-v2/session/sessionActivity/sessionActivity module. Either add/register the service or remove/remap this facade method.

Useful? React with 👍 / 👎.

The engine retired its sessionActivity service in MoonshotAI#1751 (session busy is
now derived from agent activity views), but the facade still called the
deleted wire channel and imported the deleted engine module, breaking
typecheck and every klient suite at import time.

- drop the sessionActivity contract/registry entries and mirror the
  agentActivityView service instead (agent scope)
- compose session status() client-side from the pending interaction lists
  and each agent's agentActivityView, keeping the retired service's
  precedence and typing SessionStatus locally in the facade
- replace the deleted-channel call in the v2 smoke suite with a
  sessionInteractionService probe
- fix the legacy image-file suite to wait with the harness's
  waitForSessionBusy
@sailist
sailist merged commit 4cffd73 into MoonshotAI:main Jul 16, 2026
14 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 16, 2026
sailist added a commit that referenced this pull request Jul 16, 2026
The klient facade PR landed with its release notes planned for a later
feature release; removing the two pending changesets so the next release
does not pick up version bumps and changelog entries for it.
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 19, 2026
…oonshotAI#1768)

* feat(klient): contract-driven facade with http/ipc/memory transports

- add zod-validated contract sections (global/session/agent) under
  src/contract and a facade exposing global.*, session(id).*, agent(id).*
- select transport once at creation via subpath entries
  (@moonshot-ai/klient/http|ipc|memory); drop legacy channel/client/
  httpChannel/wsChannel/wsKlient/proxy implementations
- absorb packages/server-e2e into packages/klient test/e2e suites
  (dual-backend, legacy v1, v2 wire) and remove the server-e2e workspace
- expose model registry and catalog services on kap-server v2 RPC surface

* fix(klient): derive session status from agentActivityView

The engine retired its sessionActivity service in MoonshotAI#1751 (session busy is
now derived from agent activity views), but the facade still called the
deleted wire channel and imported the deleted engine module, breaking
typecheck and every klient suite at import time.

- drop the sessionActivity contract/registry entries and mirror the
  agentActivityView service instead (agent scope)
- compose session status() client-side from the pending interaction lists
  and each agent's agentActivityView, keeping the retired service's
  precedence and typing SessionStatus locally in the facade
- replace the deleted-channel call in the v2 smoke suite with a
  sessionInteractionService probe
- fix the legacy image-file suite to wait with the harness's
  waitForSessionBusy
ywh114 pushed a commit to ywh114/kimi-code that referenced this pull request Jul 19, 2026
MoonshotAI#1775)

The klient facade PR landed with its release notes planned for a later
feature release; removing the two pending changesets so the next release
does not pick up version bumps and changelog entries for it.
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