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

Function resolvePromptSession

apps/kimi-code/src/cli/run-prompt.ts:258–350  ·  view source on GitHub ↗
(
  harness: KimiHarness,
  opts: CLIOptions,
  workDir: string,
  defaultModel: string | undefined,
  stderr: PromptOutput,
  setRestorePermission: (restorePermission: () => Promise<void>) => void,
)

Source from the content-addressed store, hash-verified

256}
257
258async function resolvePromptSession(
259 harness: KimiHarness,
260 opts: CLIOptions,
261 workDir: string,
262 defaultModel: string | undefined,
263 stderr: PromptOutput,
264 setRestorePermission: (restorePermission: () => Promise<void>) => void,
265): Promise<ResolvedPromptSession> {
266 if (opts.session !== undefined) {
267 const sessions = await harness.listSessions({ sessionId: opts.session, workDir });
268 const target = sessions[0];
269 if (target === undefined) {
270 throw new Error(`Session "${opts.session}" not found.`);
271 }
272 if (resolve(target.workDir) !== resolve(workDir)) {
273 stderr.write(
274 `${chalk.hex('#E8A838')(
275 `Session "${opts.session}" was created under a different directory.\n` +
276 ` cd "${target.workDir}" && kimi -r ${opts.session}`,
277 )}\n\n`,
278 );
279 throw new Error(
280 `Session "${opts.session}" was created under a different directory.`,
281 );
282 }
283 const session = await harness.resumeSession({
284 id: opts.session,
285 additionalDirs: opts.addDirs?.length ? opts.addDirs : undefined,
286 });
287 const status = await session.getStatus();
288 const restorePermission = await forcePromptPermission(
289 session,
290 status.permission,
291 setRestorePermission,
292 );
293 if (opts.model !== undefined) {
294 await session.setModel(opts.model);
295 }
296 installHeadlessHandlers(session);
297 return {
298 session,
299 resumed: true,
300 restorePermission,
301 telemetryModel: configuredModel(opts.model, status.model, defaultModel),
302 goalModel: configuredModel(opts.model, status.model),
303 };
304 }
305
306 if (opts.continue) {
307 const sessions = await harness.listSessions({ workDir });
308 const previous = sessions[0];
309 if (previous !== undefined) {
310 const session = await harness.resumeSession({
311 id: previous.id,
312 additionalDirs: opts.addDirs?.length ? opts.addDirs : undefined,
313 });
314 const status = await session.getStatus();
315 const restorePermission = await forcePromptPermission(

Callers 1

runPromptFunction · 0.85

Calls 11

forcePromptPermissionFunction · 0.85
installHeadlessHandlersFunction · 0.85
configuredModelFunction · 0.85
requireConfiguredModelFunction · 0.85
listSessionsMethod · 0.65
writeMethod · 0.65
getStatusMethod · 0.65
createSessionMethod · 0.65
resolveFunction · 0.50
resumeSessionMethod · 0.45
setModelMethod · 0.45

Tested by

no test coverage detected