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

Function registerAcpCommand

apps/kimi-code/src/cli/sub/acp.ts:38–126  ·  view source on GitHub ↗
(parent: Command)

Source from the content-addressed store, hash-verified

36import { runLoginFlow } from './login-flow';
37
38export function registerAcpCommand(parent: Command): void {
39 parent
40 .command('acp')
41 .description('Run kimi-code as an Agent Client Protocol (ACP) server over stdio.')
42 .option(
43 '--login',
44 'Run the device-code login flow then exit (entry point for ACP terminal-auth).',
45 false,
46 )
47 .action(async (opts: { login?: boolean }) => {
48 if (opts.login === true) {
49 await runLoginFlow();
50 return;
51 }
52 const identity = createKimiCodeHostIdentity();
53 const harness = createKimiHarness({
54 identity,
55 uiMode: 'acp',
56 });
57 // Forward `KIMI_CODE_HOME` (if set) into `authMethods[0].env` so the
58 // `kimi login` subprocess clients spawn for terminal-auth writes its
59 // token under the same data root the ACP server reads from. Used for
60 // sandboxed test setups (Zed's `agent_servers.*.env.KIMI_CODE_HOME =
61 // /tmp/...`). Production runs leave the env unset and the field stays
62 // empty.
63 const sandboxHome = process.env[KIMI_CODE_HOME_ENV];
64 const terminalAuthEnv =
65 sandboxHome !== undefined && sandboxHome.length > 0
66 ? { [KIMI_CODE_HOME_ENV]: sandboxHome }
67 : undefined;
68 // Legacy `_meta.terminal-auth` fallback for clients that don't yet
69 // honor the first-class `type:'terminal'` (Zed without the
70 // AcpBetaFeatureFlag, current JetBrains plugin, etc.). `command` is
71 // the absolute path to this very binary (`process.argv[1]`) so the
72 // client can spawn it with `args:['login']` for the top-level
73 // `kimi login` subcommand — matches kimi-cli `acp/server.py:77-96`.
74 const legacyCommand = process.argv[1];
75 const builtinCommands: AvailableCommand[] = (ACP_BUILTIN_SLASH_COMMANDS as readonly AvailableCommand[]).map((cmd) => ({
76 name: cmd.name,
77 description: cmd.description,
78 input: cmd.input,
79 }));
80 // Skills are session-scoped (per-cwd config), so we defer the
81 // listSkills() call until the adapter hands us the just-created
82 // Session — mirrors opencode's per-directory snapshot. A
83 // listSkills() failure degrades to builtins-only so a broken
84 // skill source never blanks the palette.
85 const resolveSlashCommands = async (
86 session: Session,
87 ): Promise<SlashCommandsSnapshot> => {
88 let skills: readonly SkillSummary[] = [];
89 try {
90 skills = await session.listSkills();
91 } catch {
92 skills = [];
93 }
94 // `buildSkillSlashCommands` already returns both views — the
95 // palette entries (advertised via `available_commands_update`)

Callers 2

acp.test.tsFile · 0.90
createProgramFunction · 0.90

Calls 7

runLoginFlowFunction · 0.90
runAcpServerFunction · 0.90
getVersionFunction · 0.90
createKimiHarnessFunction · 0.85
exitMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected