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

Function handlePsCommand

apps/kimi-code/src/cli/sub/server/ps.ts:54–78  ·  view source on GitHub ↗
(opts: { json?: boolean })

Source from the content-addressed store, hash-verified

52}
53
54async function handlePsCommand(opts: { json?: boolean }): Promise<void> {
55 const lock = getLiveLock();
56 if (!lock) {
57 throw new Error(
58 'No running Kimi server. Start one with `kimi server run` or `kimi web`.',
59 );
60 }
61
62 const origin = serverOrigin(lockConnectHost(lock), lock.port);
63 if (!(await isServerHealthy(origin, HEALTH_TIMEOUT_MS))) {
64 throw new Error(`Kimi server at ${origin} is not responding.`);
65 }
66
67 // The `/api/v1/connections` route is gated by bearer auth (M5.1). Read the
68 // persistent token; a clear error here means the server has never been
69 // started (no token file yet) or the token file was removed.
70 const token = resolveServerToken(getDataDir());
71 const connections = await fetchConnections(origin, token);
72
73 if (opts.json) {
74 process.stdout.write(`${JSON.stringify(connections, null, 2)}\n`);
75 return;
76 }
77 process.stdout.write(formatTable(connections));
78}
79
80async function fetchConnections(origin: string, token: string): Promise<ConnectionInfo[]> {
81 const controller = new AbortController();

Callers 1

registerPsCommandFunction · 0.85

Calls 9

getLiveLockFunction · 0.90
serverOriginFunction · 0.90
lockConnectHostFunction · 0.90
isServerHealthyFunction · 0.90
resolveServerTokenFunction · 0.90
getDataDirFunction · 0.90
fetchConnectionsFunction · 0.85
formatTableFunction · 0.85
writeMethod · 0.65

Tested by

no test coverage detected