Skip to content

refactor(protocol): remove package and relocate wire types into agent-core-v2 - #3646

Merged
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:refact-171-09-08-remove-protocol-package
Sep 8, 2026
Merged

refactor(protocol): remove package and relocate wire types into agent-core-v2#3646
sailist merged 1 commit into
MoonshotAI:mainfrom
sailist:refact-171-09-08-remove-protocol-package

Conversation

@sailist

@sailist sailist commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Internal refactor; no linked issue.

Problem

packages/protocol (@moonshot-ai/protocol) was the legacy shared REST + WS wire-schema package. After kap-server became the serving daemon, it kept its own diverged fork of the protocol under kap-server/src/protocol/, leaving the standalone package as a stale, mostly dead copy: its zod schemas had no runtime consumers, and several of its types (ToolInputDisplay, CompactionResult, UsageStatus, TurnEndReason, …) already existed in agent-core-v2, with the engine importing the protocol copy instead of its own. Four packages still depended on it, almost entirely type-only.

What changed

  • agent-core-v2 now owns the wire types. The 54 v1 wire event interfaces and their supporting types (TaskInfo, KimiErrorCode, wire Session/Workspace/MessageContent/ConfigResponse, …) moved from packages/protocol/src/events.ts into their respective domain files (agent/loop/turnEvents.ts, agent/toolExecutor/toolExecutorEvents.ts, agent/fullCompaction/compactionOps.ts, agent/task/types.ts, app/sessionLegacy/sessionProtocol.ts, app/config/configEvents.ts, new app/workspace/workspaceProtocol.ts, new agent/prompt/messageContent.ts, errors.ts, …). Types the engine already had are reused, not duplicated. A new src/events.ts holds the AgentEvent/Event unions (same 54 members as before). MCP_OAUTH_AUTHORIZATION_URL_TOOL_UPDATE moved to tool/toolContract.ts. The engine's own two imports were flipped to its local tool/toolInputDisplay.ts.
  • node-sdk imports those types from agent-core-v2 deep paths; its public API (43 re-exported types + the const) is unchanged, enforced by the existing exhaustive-switch contract test.
  • klient's compile-time parity checks now assert against agent-core-v2 types; the live-server e2e harness takes v1 REST/WS DTOs from their actual owners — kap-server's protocol layer (new ./protocol/* subpath export) and engine wire schemas (os/interface/terminal, llm-adapter/model/catalog, app/authLegacy, app/file, app/hostFolderBrowser, app/sessionLegacy).
  • acp-server imports the same types from agent-core-v2.
  • kap-server exposes ./protocol/*; the terminal create-request compat schema (runtime_id optional) moved from an inline route definition into protocol/rest-terminal.ts (wire unchanged).
  • packages/protocol deleted, including its now-dead zod schemas and ToolResultDisplay/VOLATILE_EVENT_TYPES (kap-server already has live copies). flake.nix and changeset docs updated.

Verified: per-package typechecks, full-repo pnpm typecheck, node-sdk build + api-extractor (public dts unchanged), acp-server 149/149 tests, klient e2e (live suites skip without KIMI_SERVER_URL), full vitest suite on Linux CI-equivalent host.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: the issue must have a maintainer's /approve).
  • 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.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 107b464

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 Sep 8, 2026

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

commit: 107b464

@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: 70cf49c534

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

type: 'tool_result';
tool_call_id: string;
output: unknown;
is_error?: boolean | undefined;

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 Remove redundant undefined from optional properties

Declare this as is_error?: boolean rather than is_error?: boolean | undefined. The same prohibited pattern is repeated across the newly added MessageContent, config, and session protocol interfaces, so update all of those optional properties consistently.

AGENTS.md reference: AGENTS.md:L55-L57

Useful? React with 👍 / 👎.

@sailist
sailist force-pushed the refact-171-09-08-remove-protocol-package branch from 70cf49c to 107b464 Compare September 8, 2026 09:26

@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: 107b4643a0

ℹ️ 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 +240 to +242
export interface TurnStartedEvent extends Omit<TurnStartedPayload, 'agentId'> {
readonly type: 'turn.started';
}

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 Preserve legacy background-task turn origins

When SDK consumers handle a replayed or legacy turn.started event whose origin is { kind: 'background_task', ... }, this type now inherits agent-core-v2's PromptOrigin, which omits that variant even though the SDK still publicly exports BackgroundTaskOrigin and includes it in its own PromptOrigin. Updating the SDK therefore makes existing exhaustive origin handlers fail to compile or incorrectly treat a valid legacy event as impossible; keep the wire-specific origin union rather than deriving this event directly from the engine payload.

AGENTS.md reference: AGENTS.md:L22-L22

Useful? React with 👍 / 👎.

Comment on lines +1 to 3
import { describe, expect, it } from 'vitest';

import {
APIConnectionError,
APIProviderRateLimitError,
APIStatusError,
} from '#/llm-adapter/contract/errors';
import { emptyUsage } from '#human/llm/usage';
import { IEventBus } from '#/app/event/eventBus';
import { retryBackoffDelays } from '#/_base/utils/retry';

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 Restore the step-retry integration coverage

This protocol relocation deletes all loop-level retry tests from this file—including finite retry limits, retryability classification, cancellation during backoff, persisted wire events, and per-turn budget reset—while leaving only backoff arithmetic, and no equivalent cases were relocated elsewhere under packages/agent-core-v2/test. That unrelated deletion allows regressions in the still-active retry path in loopService.ts to pass CI, so retain or relocate these tests as part of this focused refactor.

AGENTS.md reference: AGENTS.md:L12-L12

Useful? React with 👍 / 👎.

@sailist
sailist merged commit 9188d03 into MoonshotAI:main Sep 8, 2026
15 checks passed
arrrrny added a commit to arrrrny/kimi-code-sync that referenced this pull request Sep 9, 2026
Sync 147 upstream commits onto the fork. Notable upstream changes:
- Remove the protocol package and relocate wire types into
  agent-core-v2/src/events.ts (MoonshotAI#3646)
- Absorb stepRetry into the LLM requester turn state machine (already
  followed in the 2026-09-07 sync)
- NotifyUser tool + mid-turn update panel (MoonshotAI#3524)
- HEIC/HEIF/BMP image support (MoonshotAI#3649), resumable large file reads
  (MoonshotAI#3645), reasoning_details round-trip (MoonshotAI#3492), zstd updater
  manifests (MoonshotAI#3669)

Conflict resolutions (all by hand, fork features preserved):
- package.json: drop the empty simple-git-hooks block (upstream cleanup;
  not a fork feature).
- docs/config-manifest.toml: take the union, then regenerate with
  pnpm gen:config-manifest (33 sections, fork sections intact).
- test/agent/stepRetry/stepRetry.test.ts: keep upstream's slimmed
  retryBackoffDelays test — the fork had deleted the old fat version
  when stepRetry was absorbed; the util is fork-used code with no other
  coverage.
- protocol/src/events.ts: accept upstream's package removal; the fork's
  compaction.started model/model_display fields already auto-merged
  into their new home (agent/fullCompaction/compactionOps.ts). No source
  still imports @moonshot-ai/protocol.

Merge follow-ups:
- Regenerate state/wire/config manifests; freshness tests pass.
- node-sdk update-all-session-models flag test: drop the v1-engine
  parity half (legacy agent-core v1 is removed upstream); keep the v2
  registration pin.
- Fix pre-existing lint errors in merge-touched files so the
  lint-staged pre-commit gate passes: unused imports/variables
  (sdk-rpc-client-v2.ts, tui/commands/config.ts,
  check-import-boundaries.mjs), floating promises (sdk-rpc-client-v2.ts,
  fullCompaction.test.ts).
- Add compactionOps.ts (model_display) to .github/FORK_OWNED_FILES so
  the relocated compaction-model fields are guard-listed.

Verification:
- pnpm run typecheck green; pnpm run lint at fork baseline (no new
  findings vs pre-merge HEAD).
- FORK_OWNED_FILES markers all resolve.
- Fork suites pass: TUI commands + session CLI (75 tests),
  x-opencode-session (7), update-all-session-models flag, oauth
  openai-compatible.
- fullCompaction.test.ts: 2 failures, both pre-existing at pre-merge
  HEAD (baseline had 5; upstream's macOS stabilization fixed 3.
EOF
)
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