Files
alan 95362134aa session export: write only session.html, retire the markdown export
A stage's session was exported twice, as session.md and session.html, and both
files were presented. It is now one html file; the markdown export is retired.

- internal/stage/session_export.go: ExportSession renders and writes exactly one
  file, session.html, via writeSessionFile; renderSessionMarkdown and its helpers
  are gone; SessionExportResult carries HTML/HTMLBytes only. The source read, the
  8 MiB source / 2 MiB rendered bounds, the truncation banner, the
  never-overwrite rule and the honest empty-session handling are unchanged.
- internal/protocol/runs.go: SessionExport drops markdown/markdown_bytes (a
  record written before the change still decodes; unknown fields are ignored),
  and adds LegacySessionMarkdownArtifact with RunStep.PresentedArtifacts(), the
  one Go rule that hides the retired session.md from every artifact listing.
- internal/server/runner.go: evidence.Markdown/MarkdownBytes are no longer copied.
- internal/tui: the artifacts panel, the recorded count and the per-visit summary
  derive from PresentedArtifacts(), so the terminal never lists session.md.
- web/src/app.js: the spike's renderArtifacts applies the same filter.
- android: the Session section is the html export alone in a WebView — SessionView,
  the Markdown/HTML toggle and the session markdown path are removed;
  presentedArtifacts(step) filters the retired session.md out of the per-visit
  gallery, the run gallery and its count, the verdict/selection lists and the
  timeline indicator; data/protocol SessionExport drops the markdown fields.
- Tests pin the single html file, prove no session.md is written and that a
  pre-existing one is neither overwritten nor presented, and prove a legacy
  export record still loads and its session.md is hidden.

The legacy session.md of an older run stays on disk (dated evidence); it is only
no longer produced and no longer presented.

Checks (macOS, Go 1.24, Android Gradle 8.11.1, 18 Oct 2026): gofmt -l . prints
nothing; go build ./... && go vet ./... clean; go test ./internal/... ./cmd/...
-> 19 packages ok, 0 failures; node --check web/src/app.js ok and node --test
web/test -> 20/20; gradle --offline --no-daemon :app:assembleDebug
:app:testDebugUnitTest -> BUILD SUCCESSFUL.

Packaged references checked: internal/author/skill/references/delivery.md and
operations.md both described the session.md+session.html pair, so both are
updated here to describe the single session.html export and the retired, hidden
session.md. README.md and internal/author/skill/SKILL.md carry no session.md
reference and install.go's managed inventory is unchanged (no reference added or
removed). docs/notes/session-html-only.md records the remaining stale shared
documentation (docs/stage-artifacts.md, docs/app-integration-verification.md) for
the docs-fold writer; shared docs are not edited by this item.
2026-10-18 10:06:49 +01:00

155 lines
4.9 KiB
Go

package tui
import (
"fmt"
"strings"
"git.a-wan.net/alan/pipelines/internal/protocol"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)
func fileChangesSummary(step protocol.RunStep) string {
if step.FileChanges == nil {
if step.Status == "running" {
return "File changes · capture pending"
}
return "File changes · not recorded for this visit"
}
c := step.FileChanges
if c.Status == "unavailable" {
return "File changes · capture unavailable"
}
label := fmt.Sprintf("File changes · %d observed files", len(c.Files))
if len(c.Files) == 0 {
label = "File changes · no changes observed"
}
if c.Status == "partial" {
label += " · partial capture"
}
return label + " · d view diff"
}
func artifactsSummary(step protocol.RunStep) string {
artifacts := step.PresentedArtifacts()
if len(artifacts) == 0 {
if step.Status == "running" {
return "Artifacts · capture pending"
}
return "Artifacts · not recorded for this visit"
}
label := fmt.Sprintf("Artifacts · %d recorded", len(artifacts))
if step.ArtifactsSkipped > 0 || step.ArtifactsTruncated > 0 {
label += " · partial capture"
}
return label
}
// HumanBytes renders a byte size with binary units. It is the one byte
// formatter shared by the TUI and the CLI, so sizes never diverge.
func HumanBytes(size int64) string {
const unit = 1024
if size < unit {
return fmt.Sprintf("%d B", size)
}
div, exp := int64(unit), 0
for value := size / unit; value >= unit; value /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(size)/float64(div), "KMGTPE"[exp])
}
// artifactCaptureNotes lists the partial-capture notes for one visit: one line
// per non-zero excluded/omitted count, and nothing when the capture was
// complete. A visit with no recorded artifacts yields no notes, mirroring the
// app's artifactCaptureNotes, so notes never accompany an empty-state summary.
func artifactCaptureNotes(step protocol.RunStep) []string {
if len(step.PresentedArtifacts()) == 0 {
return nil
}
var notes []string
if step.ArtifactsSkipped > 0 {
notes = append(notes, fmt.Sprintf("%d files excluded from artifact capture.", step.ArtifactsSkipped))
}
if step.ArtifactsTruncated > 0 {
notes = append(notes, fmt.Sprintf("%d files omitted by artifact capture limits.", step.ArtifactsTruncated))
}
return notes
}
func diffHighlight(line string) string {
line = ansi.Strip(line)
line = strings.ReplaceAll(strings.ReplaceAll(line, "\t", " "), "\r", "␍")
line = strings.Map(func(r rune) rune {
if r < 32 || r == 127 {
return '�'
}
return r
}, line)
style := lipgloss.NewStyle()
switch {
case strings.HasPrefix(line, "--- "), strings.HasPrefix(line, "+++ "):
style = style.Foreground(themeMuted).Bold(true)
case strings.HasPrefix(line, "@@"):
style = style.Foreground(themeAccent).Bold(true)
case strings.HasPrefix(line, "+"):
style = style.Foreground(lipgloss.Color("2"))
case strings.HasPrefix(line, "-"):
style = style.Foreground(lipgloss.Color("1"))
case strings.HasPrefix(line, "\\ "):
style = style.Foreground(themeMuted)
}
return style.Render(line)
}
// HighlightDiff also sanitizes untrusted source before terminal rendering.
func HighlightDiff(patch string) string {
lines := strings.Split(strings.TrimSuffix(patch, "\n"), "\n")
for i, line := range lines {
lines[i] = diffHighlight(line)
}
return strings.Join(lines, "\n")
}
func stageDiffLines(step protocol.RunStep) []string {
c := step.FileChanges
if c == nil {
return []string{fileChangesSummary(step)}
}
lines := []string{fileChangesSummary(step), "Observed workspace changes during this visit; not proof of exclusive authorship."}
if c.Scope != "" {
lines = append(lines, c.Scope)
}
if c.Diagnostic != "" {
lines = append(lines, lipgloss.NewStyle().Foreground(themeError).Render(ansi.Strip(c.Diagnostic)))
}
if c.Skipped > 0 {
lines = append(lines, fmt.Sprintf("%d files excluded from capture.", c.Skipped))
}
if c.Omitted > 0 {
lines = append(lines, fmt.Sprintf("%d additional changed files omitted by capture limits.", c.Omitted))
}
for _, file := range c.Files {
lines = append(lines, "", lipgloss.NewStyle().Bold(true).Render(fmt.Sprintf("%s · %q", file.Kind, file.Path)))
if file.BeforeMode != file.AfterMode {
lines = append(lines, fmt.Sprintf("Mode: %s → %s", file.BeforeMode, file.AfterMode))
}
if file.Binary {
lines = append(lines, "Binary file changed · contents not displayed.")
}
if file.Patch != "" {
for _, line := range strings.Split(strings.TrimSuffix(file.Patch, "\n"), "\n") {
lines = append(lines, diffHighlight(line))
}
}
if file.Truncated {
lines = append(lines, lipgloss.NewStyle().Foreground(themeMuted).Render("Patch omitted or truncated by capture limits."))
}
if !file.Binary && file.Patch == "" && !file.Truncated {
lines = append(lines, "No text hunk · empty file or file-mode change.")
}
}
return lines
}