okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffauffeat(api)!: migrate daemon and clients to protocol 361c43ca

main
828 B30 linesraw
1// Package presentation formats session metadata for terminal displays.
2package presentation
3
4import (
5	"fmt"
6	"regexp"
7	"time"
8)
9
10var sanitizerRegex = regexp.MustCompile(`[\p{Cc}\x{202a}-\x{202e}\x{2066}-\x{2069}]`)
11
12// SessionText replaces control characters and direction overrides in session metadata.
13func SessionText(text string) string { return sanitizerRegex.ReplaceAllString(text, " ") }
14
15func AssistantAge(timestamp *int64, now time.Time) string {
16	if timestamp == nil {
17		return "time unknown"
18	}
19	elapsedSeconds := max(0, now.Unix()-*timestamp)
20	if elapsedSeconds < 60 {
21		return "just now"
22	}
23	if elapsedSeconds < 3600 {
24		return fmt.Sprintf("%dm ago", elapsedSeconds/60)
25	}
26	if elapsedSeconds < 86400 {
27		return fmt.Sprintf("%dh ago", elapsedSeconds/3600)
28	}
29	return fmt.Sprintf("%dd ago", elapsedSeconds/86400)
30}