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

Function runLifecycle

apps/kimi-code/src/cli/sub/server/lifecycle.ts:159–197  ·  view source on GitHub ↗
(
  deps: LifecycleCommandDeps,
  json: boolean,
  body: (mgr: ServiceManager) => Promise<Record<string, unknown>>,
)

Source from the content-addressed store, hash-verified

157}
158
159async function runLifecycle(
160 deps: LifecycleCommandDeps,
161 json: boolean,
162 body: (mgr: ServiceManager) => Promise<Record<string, unknown>>,
163): Promise<void> {
164 try {
165 const mgr = deps.resolveManager();
166 const result = await body(mgr);
167 if (json) {
168 deps.stdout.write(`${JSON.stringify(result)}\n`);
169 return;
170 }
171 deps.stdout.write(formatHuman(result));
172 } catch (error) {
173 if (error instanceof ServiceUnavailableError || error instanceof ServiceUnsupportedError) {
174 const payload = {
175 ok: false,
176 action: error instanceof ServiceUnavailableError ? 'unavailable' : 'unsupported',
177 platform: error.platform,
178 message: error.message,
179 };
180 if (json) {
181 deps.stdout.write(`${JSON.stringify(payload)}\n`);
182 } else {
183 deps.stderr.write(`${error.message}\n`);
184 }
185 process.exit(2);
186 return;
187 }
188 if (json) {
189 deps.stdout.write(
190 `${JSON.stringify({ ok: false, message: error instanceof Error ? error.message : String(error) })}\n`,
191 );
192 } else {
193 deps.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
194 }
195 process.exit(1);
196 }
197}
198
199function formatHuman(result: Record<string, unknown>): string {
200 const rawAction = result['action'];

Callers 1

addLifecycleCommandsFunction · 0.85

Calls 4

formatHumanFunction · 0.85
resolveManagerMethod · 0.80
writeMethod · 0.65
exitMethod · 0.65

Tested by

no test coverage detected