Files
weichenandCursor 6bc1b08540 Record sessions as an append-only entry tree
Why: Linear transcripts cannot fork, and compaction rewrote history, so resume and branch navigation had nothing to point at.
Evidence: go test -count=1 ./runtime/session/
Impact: Load still returns the model-visible path, including old one-message-per-line files. Compaction appends a summary entry instead of truncating the file.
Refs: feature/pi-headless N1
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 10:08:04 +00:00

33 lines
791 B
Go

package session
import (
"fmt"
"html"
"os"
"strings"
)
// ExportHTML writes the active branch as a standalone HTML document.
func (s *Store) ExportHTML(path string) error {
msgs, err := s.Load()
if err != nil {
return err
}
var b strings.Builder
b.WriteString("<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>")
title := s.Name()
if title == "" {
title = "session"
}
b.WriteString(html.EscapeString(title))
b.WriteString("</title></head><body>\n")
for _, m := range msgs {
fmt.Fprintf(&b, "<article data-role=\"%s\"><h2>%s</h2><pre>%s</pre></article>\n",
html.EscapeString(string(m.Role)),
html.EscapeString(string(m.Role)),
html.EscapeString(m.Content))
}
b.WriteString("</body></html>\n")
return os.WriteFile(path, []byte(b.String()), 0o644)
}