* Export a session to a markdown file. * Output is redacted to strip secrets that may appear in messages.
(session, outputPath)
| 12 | * Output is redacted to strip secrets that may appear in messages. |
| 13 | */ |
| 14 | function 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). |
no test coverage detected