# How to Build the @moonshot-ai/acp-adapter Package in the kimi-code Monorepo

> Learn how to build the acp-adapter package within the kimi-code monorepo. Follow simple commands to compile and prepare your package for use.

- Repository: [Moonshot AI/kimi-code](https://github.com/MoonshotAI/kimi-code)
- Tags: how-to-guide
- Published: 2026-08-14

---

**Run `pnpm --filter @moonshot-ai/acp-adapter run build` after installing workspace dependencies with `pnpm install`.**

The **acp-adapter** package (`@moonshot-ai/acp-adapter`) serves as the ACP (Agent Client Protocol) integration layer for the [MoonshotAI/kimi-code](https://github.com/MoonshotAI/kimi-code) repository. This guide walks through building the package from source, including prerequisites, build commands, and verification steps based on the actual monorepo structure.

## Prerequisites for Building acp-adapter

Before building, ensure your environment meets the requirements enforced by the root [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json):

- **Node.js ≥ 24.15.0** — specified in the `"engines"` field
- **pnpm ≥ 10.33.0** — the workspace manager required for monorepo operations

Without these versions, `pnpm install` will fail with engine compatibility errors.

## Install Workspace Dependencies

The acp-adapter package depends on several internal packages within the kimi-code monorepo:

- `@agentclientprotocol/sdk`
- `@moonshot-ai/agent-core`
- `@moonshot-ai/kaos`
- `@moonshot-ai/kimi-code-sdk`

Install all workspace dependencies from the repository root:

```bash
pnpm install

```

This single command installs every package across the monorepo, including the transitive dependencies needed by acp-adapter.

## Build the acp-adapter Package

The package's [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json) ([`packages/acp-adapter/package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/acp-adapter/package.json)) defines a minimal build pipeline:

```json
"scripts": {
  "build": "tsdown"
}

```

The **tsdown** compiler transpiles TypeScript sources into the `dist/` folder. You can build acp-adapter in two equivalent ways:

### Option 1: Using pnpm Filter (Recommended)

```bash
pnpm --filter @moonshot-ai/acp-adapter run build

```

### Option 2: Direct Directory Build

```bash
cd packages/acp-adapter
pnpm run build

```

Both commands produce identical output under `packages/acp-adapter/dist`.

## Build Output Structure

After a successful build, the `dist/` directory contains:

| File | Purpose |
|------|---------|
| `dist/index.mjs` | Runtime JavaScript entry point |
| `dist/index.d.mts` | TypeScript declaration file |

These files are referenced by the package's `"exports"` field, allowing other packages (such as the `kimi-code` CLI) to import `@moonshot-ai/acp-adapter` cleanly.

## Optional Verification Steps

### Type Checking

Validate TypeScript definitions without emitting:

```bash
pnpm --filter @moonshot-ai/acp-adapter run typecheck

```

### Testing

Execute the Vitest test suite:

```bash
pnpm --filter @moonshot-ai/acp-adapter run test

```

> **Note:** The acp-adapter package currently has no unit tests, but the workspace test runner will include any future tests added to `packages/acp-adapter`.

## Programmatic Build Example

For CI/CD pipelines or automation scripts:

```ts
// build-acp-adapter.ts
import { execSync } from 'child_process';

// Install workspace dependencies (one-time)
execSync('pnpm install', { stdio: 'inherit', cwd: '/path/to/kimi-code' });

// Build only acp-adapter
execSync('pnpm --filter @moonshot-ai/acp-adapter run build', {
  stdio: 'inherit',
  cwd: '/path/to/kimi-code',
});

```

## Key Source Files

Understanding these files helps debug build issues or extend the package:

- **[`packages/acp-adapter/package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/acp-adapter/package.json)** — Declares the `build` script and internal dependencies
- **[`packages/acp-adapter/src/index.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/acp-adapter/src/index.ts)** — Public entry point re-exported after compilation
- **[`packages/acp-adapter/vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/acp-adapter/vitest.config.ts)** — Test runner configuration
- **`flake.nix`** — Nix workspace integration (lines 65–92)

## Complete CLI Workflow

```bash

# One-time setup

git clone https://github.com/MoonshotAI/kimi-code.git
cd kimi-code
pnpm install

# Build acp-adapter

pnpm --filter @moonshot-ai/acp-adapter run build

# Optional verification

pnpm --filter @moonshot-ai/acp-adapter run typecheck
pnpm --filter @moonshot-ai/acp-adapter run test

# Verify output

ls packages/acp-adapter/dist/

```

## Summary

- **Prerequisites:** Node.js ≥ 24.15.0 and pnpm ≥ 10.33.0
- **Dependency installation:** Run `pnpm install` from the repository root
- **Build command:** `pnpm --filter @moonshot-ai/acp-adapter run build`
- **Build tool:** tsdown compiles to `packages/acp-adapter/dist/`
- **Output files:** `index.mjs` (runtime) and `index.d.mts` (types)
- **Optional checks:** `typecheck` and `test` scripts for validation

## Frequently Asked Questions

### What is the acp-adapter package used for?

The acp-adapter package provides ACP (Agent Client Protocol) server functionality for the kimi-code ecosystem. It bridges the kimi-code CLI with ACP-compatible agents, enabling standardized agent communication as defined in the repository's architecture.

### Why does the build use tsdown instead of tsc?

The `tsdown` tool is configured in [`packages/acp-adapter/package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/acp-adapter/package.json) as the build compiler. While the analysis does not specify tsdown's advantages, it is the designated build tool for this package and produces the required ESM output in the `dist/` directory.

### Can I build acp-adapter without building the entire monorepo?

Yes. The `pnpm --filter` flag isolates the build to acp-adapter only. However, you must still run `pnpm install` from the root first to install shared workspace dependencies that acp-adapter imports.

### Where does the built output go?

Compiled files are written to `packages/acp-adapter/dist/`. The entry point `dist/index.mjs` and type declarations `dist/index.d.mts` are what consuming packages import when they reference `@moonshot-ai/acp-adapter`.