Skip to content

refactor(agent-core-v2): remove the agent RPC aggregation layer - #2871

Merged
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:refact-agent-rpc-removal
Aug 13, 2026
Merged

refactor(agent-core-v2): remove the agent RPC aggregation layer#2871
sailist merged 4 commits into
MoonshotAI:mainfrom
sailist:refact-agent-rpc-removal

Conversation

@sailist

@sailist sailist commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

agent-core-v2 had two ways to reach agent-scope behavior: a facade-style AgentRPCService (src/agent/rpc/) aggregating 12 methods, and direct domain-service calls. Every edge (klient facade, node-sdk, kap-server, kimi-inspect, test harness) had to know which track to take, and orchestration logic (session-metadata writes, telemetry, main-agent broadcast, turn-launch settlement, plugin-command expansion) lived in the RPC facade instead of its owning domain — duplicating edge-side re-implementations (node-sdk and kap-server each re-did the skill metadata write) and relying on implicit knowledge like "Promises cannot cross the klient wire".

What changed

Engine: orchestration sinks to owning domains, agent/rpc/ deleted

  • IAgentPromptService gains submit/submitSteer (engine-side {turn_id} settlement, MAIN-only session metadata); IAgentSkillService.activate returns PromptLaunchResult and writes session metadata internally; new agent-scope agent/pluginCommand/ domain owns plugin-command activation and the plugin_command.activated event.
  • IAgentPermissionModeService.setModeAndBroadcast / IAgentLoopService.cancelFromUser / IAgentFullCompactionService.cancel added; setMode and loop.cancel stay pure for their internal callers.
  • Session-metadata writes (title/lastPrompt) are unified to MAIN-agent-only across prompt/steer/skill/pluginCommand; node-sdk and kap-server drop their edge-side writes (double-write protection).
  • disabledTools leaves the prompt path entirely: the engine's submit never accepted it, and the klient facade / node-sdk prompt entries stop carrying it (v1 never consumed the field). Session tool gating stays available through IAgentToolPolicyService.setSessionDisabledTools, composed at the edge the way kap-server's prompt route does.

klient: per-domain contracts, facade API otherwise unchanged

  • agentRpcContract split into per-domain contracts (prompt/skill/loop/permissionMode/command/…); the facade re-routes to domain channels with its wire shapes unchanged (contract-parity holds).

Callers and tests

  • node-sdk, kap-server (:abortcancelFromUser), kimi-inspect, and the v2 test harness (ctx.rpc kept as a composed adapter) call domain services directly.
  • The kap-server debug-RPC prompt/plugin-command suite migrates to agent-core-v2 domain tests (test/agent/prompt/submit.test.ts, test/agent/pluginCommand/); rpc-domain tests move to their owner domains.

Externally visible: the agentRPCService debug channel is gone (per-domain channels serve the same operations); session-metadata writes are MAIN-agent-only; the klient facade and node-sdk prompt entries no longer accept disabledTools.

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.

- delete src/agent/rpc/ (AgentRPCService, IAgentRPCService, core-api,
  prompt-metadata, types) and sink each method's orchestration into its
  owning domain service
- prompt: new submit/submitSteer composing disabledTools gating,
  MAIN-only session metadata, and engine-side {turn_id} settlement
- skill: activate now returns PromptLaunchResult and writes session
  metadata internally (MAIN-only, unified across prompt/steer/skill/
  pluginCommand); node-sdk and kap-server drop their edge-side writes
- pluginCommand: new agent-scope domain owning command activation and
  the plugin_command.activated domain event
- permissionMode/loop/fullCompaction: new setModeAndBroadcast /
  cancelFromUser / cancel; setMode and loop.cancel stay pure for
  internal callers
- klient: agentRpcContract split into per-domain contracts; facade
  re-routes to domain channels with its public API unchanged
- node-sdk, kap-server, kimi-inspect and the v2 test harness now call
  domain services directly; ctx.rpc keeps its name as a composed
  adapter
- externally visible: the agentRPCService debug channel is gone and
  session metadata writes are now MAIN-agent-only (see changeset)
…domain

Prompt should not own session tool policy: submit no longer accepts or
applies disabledTools. The klient facade keeps its prompt({ disabledTools })
API and composes it edge-side — applying agentToolPolicyService
setSessionDisabledTools before calling agentPromptService.submit, the same
way kap-server's prompt route already does. Over klient, a profile-less
engine now surfaces the raw profile error instead of request.invalid.

Also restores the RPC-removal changeset, which did not make it into the
previous commit.
@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fad36dd

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 Aug 13, 2026

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

commit: fad36dd

@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: 09c6704c13

ℹ️ 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 +95 to +97
if (input.disabledTools !== undefined) {
await call(scope, 'agentToolPolicyService', 'setSessionDisabledTools', [
[...input.disabledTools],

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 Validate prompt payload before applying disabled tools

When prompt() is called with disabledTools and a malformed input payload, this first call persists the session denylist, and only the later agentPromptService.submit call validates/rejects the prompt shape. With klient validation enabled by default, a rejected prompt can still leave tools disabled for subsequent prompts; pre-validate the submit payload before mutating agentToolPolicyService so the composed facade remains atomic on caller input errors.

Useful? React with 👍 / 👎.

The prompt path no longer carries session tool gating on any surface:
the klient facade prompt() loses the disabledTools field and calls
agentPromptService.submit directly, and the node-sdk
SessionPromptRpcInput stops accepting or forwarding it (v1 always
ignored the field). Session tool gating remains available through
IAgentToolPolicyService.setSessionDisabledTools, composed at the edge
the way kap-server's prompt route does; the klient toolPolicy contract
added for facade-side composition is removed as unused.
@sailist

sailist commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: fad36dd950

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

@sailist
sailist merged commit 23e68ee into MoonshotAI:main Aug 13, 2026
15 checks passed
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