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

Function handleExportMdCommand

apps/kimi-code/src/tui/commands/session.ts:90–132  ·  view source on GitHub ↗
(host: SlashCommandHost, args: string)

Source from the content-addressed store, hash-verified

88}
89
90export async function handleExportMdCommand(host: SlashCommandHost, args: string): Promise<void> {
91 const session = host.session;
92 if (session === undefined) {
93 host.showError(NO_ACTIVE_SESSION_MESSAGE);
94 return;
95 }
96
97 host.showStatus('Exporting session as Markdown…');
98 try {
99 const context = await session.getContext();
100 if (context.history.length === 0) {
101 host.showError('No messages to export.');
102 return;
103 }
104
105 const now = new Date();
106 const shortId = session.id.slice(0, 8);
107 const timestamp = now.toISOString().replaceAll(/[-:]/g, '').replace(/T/, '-').slice(0, 15);
108 const defaultName = `kimi-export-${shortId}-${timestamp}.md`;
109
110 const trimmedArgs = args.trim();
111 const outputPath = trimmedArgs.length > 0
112 ? resolve(trimmedArgs)
113 : resolve(host.state.appState.workDir, defaultName);
114
115 const md = buildExportMarkdown({
116 sessionId: session.id,
117 workDir: host.state.appState.workDir,
118 history: context.history,
119 tokenCount: context.tokenCount,
120 now,
121 });
122
123 await mkdir(dirname(outputPath), { recursive: true });
124 await writeFile(outputPath, md, 'utf-8');
125
126 const linked = toTerminalHyperlink(outputPath, pathToFileURL(outputPath).href);
127 host.showNotice(`Exported ${String(context.history.length)} messages`, linked);
128 } catch (error) {
129 const msg = formatErrorMessage(error);
130 host.showError(`Failed to export session: ${msg}`);
131 }
132}
133
134export async function handleExportDebugZipCommand(host: SlashCommandHost): Promise<void> {
135 const session = host.session;

Callers 1

Calls 10

buildExportMarkdownFunction · 0.90
toTerminalHyperlinkFunction · 0.90
formatErrorMessageFunction · 0.90
showErrorMethod · 0.65
showStatusMethod · 0.65
showNoticeMethod · 0.65
resolveFunction · 0.50
mkdirFunction · 0.50
writeFileFunction · 0.50
getContextMethod · 0.45

Tested by

no test coverage detected