MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / AcpServer

Class AcpServer

packages/acp-adapter/src/server.ts:130–925  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128 * push `session/update` chunks back to the client.
129 */
130export class AcpServer implements Agent {
131 private negotiated: AcpVersionSpec | undefined;
132 private clientCapabilities: ClientCapabilities | undefined;
133 private readonly sessions = new Map<string, AcpSession>();
134 private readonly agentInfo: Implementation | undefined;
135 private readonly terminalAuthEnv: Readonly<Record<string, string>> | undefined;
136 private readonly terminalAuthLegacyCommand: string | undefined;
137 private readonly resolveSlashCommands: (
138 session: Session,
139 ) => Promise<ResolvedSlashCommands>;
140 /**
141 * Lazily-built inner {@link Kaos} (a {@link LocalKaos}) used as the
142 * delegate target for every {@link AcpKaos} this server hands out.
143 * One per server (not per session) so we don't re-probe the
144 * environment for every `session/new` call.
145 */
146 private innerKaos: Kaos | undefined = undefined;
147
148 constructor(
149 private readonly harness: KimiHarness,
150 private readonly conn?: AgentSideConnection | undefined,
151 opts?: {
152 agentInfo?: Implementation;
153 /**
154 * Env vars to advertise in `authMethods[0].env` so the `kimi login`
155 * subprocess the client spawns (via `terminal-auth`) lands its
156 * token under the same data root the ACP server uses. Intended for
157 * sandboxed test setups (e.g. `{ KIMI_CODE_HOME: '/tmp/...' }`);
158 * leave undefined in production so the advertised env stays empty.
159 */
160 terminalAuthEnv?: Readonly<Record<string, string>>;
161 /**
162 * Absolute binary path advertised in `_meta['terminal-auth'].command`
163 * for clients that don't yet honor the first-class
164 * `AuthMethodTerminal` (Zed without `AcpBetaFeatureFlag`, JetBrains
165 * plugin). Clients on this legacy path spawn `<command> login`
166 * directly. Defaults to undefined (the `_meta` fallback is omitted).
167 */
168 terminalAuthLegacyCommand?: string;
169 /**
170 * Slash commands to advertise in the one-shot
171 * `available_commands_update` pushed immediately after each
172 * `session/new`, `session/load`, and `session/resume`. Accepts
173 * either a static array, or a resolver called once per session
174 * (with the just-created `Session`) so per-session sources like
175 * `session.listSkills()` can be merged in. When omitted, the
176 * adapter falls back to an empty list.
177 *
178 * Returning a {@link SlashCommandsSnapshot} (`{ commands, skillCommandMap }`)
179 * additionally lets {@link AcpSession.prompt} intercept
180 * `/skill:<name> ...` inputs at the adapter boundary and route
181 * them to {@link Session.activateSkill} instead of forwarding the
182 * raw slash text — matching the TUI's slash-command behavior so
183 * skill activations don't fall back to model-driven Bash
184 * exploration of `~/.kimi-code/skills/`.
185 */
186 slashCommands?: SlashCommandsResolver;
187 },

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected