MCPcopy
hub / github.com/Doorman11991/smallcode / exportToMarkdown

Function exportToMarkdown

src/session/share.js:14–35  ·  view source on GitHub ↗

* Export a session to a markdown file. * Output is redacted to strip secrets that may appear in messages.

(session, outputPath)

Source from the content-addressed store, hash-verified

12 * Output is redacted to strip secrets that may appear in messages.
13 */
14function exportToMarkdown(session, outputPath) {
15 const safe = redactValue(session);
16 let md = `# SmallCode Session: ${safe.title || 'Untitled'}\n\n`;
17 md += `**Model:** ${safe.model}\n`;
18 md += `**Date:** ${safe.createdAt}\n`;
19 md += `**Messages:** ${(safe.messages || []).length}\n\n`;
20 md += `---\n\n`;
21
22 for (const msg of (safe.messages || [])) {
23 const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
24 if (msg.role === 'user') {
25 md += `## You\n\n${content}\n\n`;
26 } else if (msg.role === 'assistant') {
27 md += `## AI\n\n${content}\n\n`;
28 } else if (msg.role === 'tool') {
29 md += `> Tool: ${(content || '').slice(0, 200)}\n\n`;
30 }
31 }
32
33 fs.writeFileSync(outputPath, md, { mode: 0o600 });
34 return outputPath;
35}
36
37/**
38 * Export session as a GitHub Gist (requires gh CLI).

Callers 2

exportToGistFunction · 0.85
commands.jsFile · 0.85

Calls 1

redactValueFunction · 0.50

Tested by

no test coverage detected