session: replace timestamp-prefix IDs with UUIDv4; show first segment in acme GUI

This commit is contained in:
Ollie Agent 2026-08-01 17:26:34 +02:00
parent 0395a4a92f
commit 7403e1f5bb
3 changed files with 29 additions and 9 deletions

BIN
Ollie Executable file

Binary file not shown.

View File

@ -153,15 +153,26 @@ func (sl *sessionList) refresh() {
sl.mu.Lock()
sl.allSIDs = nil
var display strings.Builder
for _, l := range lines {
if s := strings.TrimSpace(l); s != "" {
id, _, _ := strings.Cut(s, "\t")
id, rest, _ := strings.Cut(s, "\t")
sl.allSIDs = append(sl.allSIDs, id)
short := id
if idx := strings.IndexByte(id, '-'); idx > 0 {
short = id[:idx]
}
display.WriteString(short)
if rest != "" {
display.WriteByte('\t')
display.WriteString(rest)
}
display.WriteByte('\n')
}
}
sl.mu.Unlock()
sl.win.Write("body", []byte(raw+"\n"))
sl.win.Write("body", []byte(display.String()))
sl.win.Ctl("clean")
}
@ -173,8 +184,11 @@ func (sl *sessionList) resolveFullSID(text string) string {
sl.mu.Lock()
defer sl.mu.Unlock()
for _, sid := range sl.allSIDs {
parts := strings.Split(sid, "__")
if parts[len(parts)-1] == text {
short := sid
if idx := strings.IndexByte(sid, '-'); idx > 0 {
short = sid[:idx]
}
if short == text || sid == text {
return sid
}
}
@ -238,7 +252,11 @@ func openChat(sid string) {
log.Printf("open chat %s: %v", sid, err)
return
}
winName := "ollie/sessions/" + sid
short := sid
if idx := strings.IndexByte(sid, '-'); idx > 0 {
short = sid[:idx]
}
winName := "ollie/sessions/" + short
if data, err := read9p("session/idx"); err == nil {
for _, line := range strings.Split(string(data), "\n") {
fields := strings.Split(line, "\t")

View File

@ -7,7 +7,6 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
@ -65,11 +64,14 @@ type Session struct {
saveTimer *time.Timer
}
// NewSessionID generates a unique, lexicographically sortable session identifier.
// NewSessionID generates a UUIDv4 session identifier.
func NewSessionID() string {
b := make([]byte, 3)
b := make([]byte, 16)
rand.Read(b) //nolint:errcheck
return strconv.FormatInt(time.Now().UnixNano(), 10) + "-" + fmt.Sprintf("%06x", b)
b[6] = (b[6] & 0x0f) | 0x40 // version 4
b[8] = (b[8] & 0x3f) | 0x80 // variant 10xx
return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
b[0:4], b[4:6], b[6:8], b[8:10], b[10:16])
}
// NextUncheckedStep returns the first unchecked step from plan bytes.