feat(tui,server,config): live config editor + artifact viewer
Two operator features over the existing WebSocket protocol, plus a tui-go nav fix. Config editor (g / palette "config"): - core:config gains a thin registry stack: OrchestrationKnobs ([orchestration] block), CorrexConfigWriter (round-trip TOML serializer; parseToml(write(c))==c), ConfigHolder (AtomicReference live config), and EditableConfig (allowlist of editable fields + patch applier; security fields are absent so they can never be patched). - ConfigService validates -> persists (atomic temp+move) -> swaps the holder -> rebuilds config-derived services. Live-apply is scoped to safe seams: stage timeout, compaction threshold (now a supplier), router knobs (routerFacade rebuild), and personalization/project toggles all take effect on the next session/turn; in-flight sessions keep the config they started with. server.host/port are persisted + badged "restart required", not hot-swapped. - Protocol: GetConfig / UpdateConfig / ConfigSnapshot; TUI overlay with type-aware editing (bool toggle, enum cycle, inline int/string edit) and save. Artifact viewer (v / palette "artifacts"): - Server assembles a session's artifacts from the event log and resolves bytes from the CAS store (StreamQueries.listArtifacts) — a replay-neutral snapshot read. TUI overlay lists artifacts and shows scrollable content. tui-go fix: workflow failure no longer clears selectedID (which yanked the user to the list); listNav lands on the first session when nothing is selected instead of wrapping to a random one. Config is not event-sourced (it lives in TOML); editing stays outside the log.
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
"github.com/correx/tui-go/internal/protocol"
|
||||
)
|
||||
|
||||
// openConfig opens the config editor and requests the current config from the server.
|
||||
func (m *Model) openConfig() {
|
||||
m.overlay = OverlayConfig
|
||||
m.configIndex = 0
|
||||
m.configEditing = false
|
||||
m.configEditBuf = ""
|
||||
m.configError = ""
|
||||
if len(m.configFields) == 0 {
|
||||
m.configLoading = true
|
||||
}
|
||||
m.client.Send(protocol.GetConfig())
|
||||
}
|
||||
|
||||
// handleConfigKey owns every key while the config overlay is open. In edit mode it captures the
|
||||
// value being typed; otherwise it navigates fields, stages edits, and saves.
|
||||
func (m Model) handleConfigKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if m.configEditing {
|
||||
switch k.Type {
|
||||
case tea.KeyEsc:
|
||||
m.configEditing = false
|
||||
m.configEditBuf = ""
|
||||
case tea.KeyEnter:
|
||||
if m.configIndex >= 0 && m.configIndex < len(m.configFields) {
|
||||
m.configStaged[m.configFields[m.configIndex].Key] = m.configEditBuf
|
||||
}
|
||||
m.configEditing = false
|
||||
m.configEditBuf = ""
|
||||
case tea.KeyBackspace:
|
||||
if n := len(m.configEditBuf); n > 0 {
|
||||
m.configEditBuf = m.configEditBuf[:n-1]
|
||||
}
|
||||
case tea.KeyRunes, tea.KeySpace:
|
||||
m.configEditBuf += string(k.Runes)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case k.Type == tea.KeyEsc || runeIs(k, "g"):
|
||||
m.overlay = OverlayNone
|
||||
case k.Type == tea.KeyUp || runeIs(k, "k"):
|
||||
if m.configIndex > 0 {
|
||||
m.configIndex--
|
||||
}
|
||||
case k.Type == tea.KeyDown || runeIs(k, "j"):
|
||||
if m.configIndex < len(m.configFields)-1 {
|
||||
m.configIndex++
|
||||
}
|
||||
case k.Type == tea.KeyEnter || k.Type == tea.KeySpace:
|
||||
m = m.actOnConfigField()
|
||||
case runeIs(k, "s"):
|
||||
if len(m.configStaged) > 0 {
|
||||
m.client.Send(protocol.UpdateConfig(m.configStaged))
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// actOnConfigField applies the type-appropriate action to the selected field: toggle a bool,
|
||||
// cycle an enum, or begin inline editing for numeric/string fields.
|
||||
func (m Model) actOnConfigField() Model {
|
||||
if m.configIndex < 0 || m.configIndex >= len(m.configFields) {
|
||||
return m
|
||||
}
|
||||
f := m.configFields[m.configIndex]
|
||||
switch f.Type {
|
||||
case "BOOL":
|
||||
if m.currentConfigValue(f) == "true" {
|
||||
m.configStaged[f.Key] = "false"
|
||||
} else {
|
||||
m.configStaged[f.Key] = "true"
|
||||
}
|
||||
case "ENUM":
|
||||
m.configStaged[f.Key] = cycleEnum(f.Options, m.currentConfigValue(f))
|
||||
default: // INT, LONG, DOUBLE, STRING
|
||||
m.configEditing = true
|
||||
m.configEditBuf = m.currentConfigValue(f)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// currentConfigValue returns the staged edit for a field if present, else the server value.
|
||||
func (m Model) currentConfigValue(f protocol.ConfigFieldDto) string {
|
||||
if v, ok := m.configStaged[f.Key]; ok {
|
||||
return v
|
||||
}
|
||||
return f.Value
|
||||
}
|
||||
|
||||
// cycleEnum returns the option after cur (wrapping); falls back to the first option.
|
||||
func cycleEnum(options []string, cur string) string {
|
||||
if len(options) == 0 {
|
||||
return cur
|
||||
}
|
||||
for i, o := range options {
|
||||
if o == cur {
|
||||
return options[(i+1)%len(options)]
|
||||
}
|
||||
}
|
||||
return options[0]
|
||||
}
|
||||
|
||||
func (m Model) configModal() string {
|
||||
t := m.theme
|
||||
w := m.modalWidth()
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(m.titleLine("config"))
|
||||
if n := len(m.configStaged); n > 0 {
|
||||
b.WriteString(mbg(t, " ("+itoa(n)+" unsaved)", t.P.Warn))
|
||||
}
|
||||
b.WriteString("\n\n")
|
||||
|
||||
if m.configLoading && len(m.configFields) == 0 {
|
||||
b.WriteString(mbg(t, " loading…", t.P.Faint) + "\n")
|
||||
b.WriteString("\n" + modalHints(t, [][2]string{{"esc", "close"}}))
|
||||
return t.Overlay.Width(w).Render(b.String())
|
||||
}
|
||||
if m.configError != "" {
|
||||
b.WriteString(lipgloss.NewStyle().Foreground(t.P.Bad).Background(t.P.BgPanel).Render(" ▲ "+truncate(m.configError, w-8)) + "\n\n")
|
||||
}
|
||||
if len(m.configRestart) > 0 {
|
||||
b.WriteString(mbg(t, " saved · restart required: "+strings.Join(m.configRestart, ", "), t.P.Warn) + "\n\n")
|
||||
}
|
||||
|
||||
// Windowed field list, keeping the selected row in view.
|
||||
bodyH := m.height*70/100 - 6
|
||||
if bodyH < 4 {
|
||||
bodyH = 4
|
||||
}
|
||||
off := 0
|
||||
if len(m.configFields) > bodyH {
|
||||
off = m.configIndex - bodyH/2
|
||||
if off < 0 {
|
||||
off = 0
|
||||
}
|
||||
if off > len(m.configFields)-bodyH {
|
||||
off = len(m.configFields) - bodyH
|
||||
}
|
||||
}
|
||||
end := off + bodyH
|
||||
if end > len(m.configFields) {
|
||||
end = len(m.configFields)
|
||||
}
|
||||
for i := off; i < end; i++ {
|
||||
b.WriteString(m.configRow(i) + "\n")
|
||||
}
|
||||
|
||||
b.WriteString("\n" + modalHints(t, [][2]string{
|
||||
{"↑↓", "select"}, {"enter", "edit/toggle"}, {"s", "save"}, {"g/esc", "close"},
|
||||
}))
|
||||
return t.Overlay.Width(w).Render(b.String())
|
||||
}
|
||||
|
||||
// configRow renders one field line: marker, key, current value (with edit caret / staged mark).
|
||||
func (m Model) configRow(i int) string {
|
||||
t := m.theme
|
||||
f := m.configFields[i]
|
||||
_, staged := m.configStaged[f.Key]
|
||||
|
||||
marker := mbg(t, " ", t.P.BgPanel)
|
||||
keyFg := t.P.Fg
|
||||
if i == m.configIndex {
|
||||
marker = lipgloss.NewStyle().Foreground(t.P.Accent).Background(t.P.BgPanel).Render("▸ ")
|
||||
keyFg = t.P.FgStrong
|
||||
}
|
||||
|
||||
var valStr string
|
||||
if m.configEditing && i == m.configIndex {
|
||||
caret := lipgloss.NewStyle().Foreground(t.P.Accent).Background(t.P.BgPanel).Render("▏")
|
||||
valStr = lipgloss.NewStyle().Foreground(t.P.FgStrong).Background(t.P.BgPanel).Render(m.configEditBuf) + caret
|
||||
} else {
|
||||
valFg := t.P.Accent2
|
||||
if staged {
|
||||
valFg = t.P.Warn
|
||||
}
|
||||
val := m.currentConfigValue(f)
|
||||
if staged {
|
||||
val = "*" + val
|
||||
}
|
||||
valStr = lipgloss.NewStyle().Foreground(valFg).Background(t.P.BgPanel).Render(val)
|
||||
}
|
||||
|
||||
row := marker +
|
||||
lipgloss.NewStyle().Foreground(keyFg).Background(t.P.BgPanel).Render(padRaw(f.Key, 42)) + " " + valStr
|
||||
if f.RestartRequired {
|
||||
row += lipgloss.NewStyle().Foreground(t.P.Faint).Background(t.P.BgPanel).Render(" (restart)")
|
||||
}
|
||||
return row
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/correx/tui-go/internal/protocol"
|
||||
)
|
||||
|
||||
func configModel() Model {
|
||||
m := NewModel(nil)
|
||||
m.width, m.height = 120, 40
|
||||
m.theme = NewTheme(SoftBlue)
|
||||
m.overlay = OverlayConfig
|
||||
m.configFields = []protocol.ConfigFieldDto{
|
||||
{Key: "project.enabled", Type: "BOOL", Value: "false"},
|
||||
{Key: "tui.theme", Type: "ENUM", Value: "dark", Options: []string{"dark", "light", "soft-blue"}},
|
||||
{Key: "router.generation.max_tokens", Type: "INT", Value: "512"},
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func TestConfigToggleBoolStagesFlippedValue(t *testing.T) {
|
||||
m := configModel()
|
||||
updated, _ := m.handleConfigKey(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if m.configStaged["project.enabled"] != "true" {
|
||||
t.Fatalf("want staged project.enabled=true, got %q", m.configStaged["project.enabled"])
|
||||
}
|
||||
out := m.configModal()
|
||||
if !strings.Contains(out, "project.enabled") {
|
||||
t.Fatalf("modal missing field key:\n%s", out)
|
||||
}
|
||||
if !strings.Contains(out, "*true") {
|
||||
t.Fatalf("modal missing staged marker for flipped value:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigEnumCycles(t *testing.T) {
|
||||
m := configModel()
|
||||
m.configIndex = 1 // tui.theme
|
||||
updated, _ := m.handleConfigKey(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if m.configStaged["tui.theme"] != "light" {
|
||||
t.Fatalf("want staged tui.theme=light (next after dark), got %q", m.configStaged["tui.theme"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigIntEditCommitsBuffer(t *testing.T) {
|
||||
m := configModel()
|
||||
m.configIndex = 2 // router.generation.max_tokens
|
||||
// Enter edit mode.
|
||||
updated, _ := m.handleConfigKey(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if !m.configEditing {
|
||||
t.Fatalf("expected edit mode after enter on INT field")
|
||||
}
|
||||
// Clear the seeded buffer and type a new value.
|
||||
m.configEditBuf = ""
|
||||
for _, r := range "1024" {
|
||||
updated, _ = m.handleConfigKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
|
||||
m = updated.(Model)
|
||||
}
|
||||
updated, _ = m.handleConfigKey(tea.KeyMsg{Type: tea.KeyEnter})
|
||||
m = updated.(Model)
|
||||
if m.configEditing {
|
||||
t.Fatalf("expected edit mode to end after commit")
|
||||
}
|
||||
if m.configStaged["router.generation.max_tokens"] != "1024" {
|
||||
t.Fatalf("want staged max_tokens=1024, got %q", m.configStaged["router.generation.max_tokens"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSnapshotClearsStagedOnCleanReply(t *testing.T) {
|
||||
m := configModel()
|
||||
m.configStaged["project.enabled"] = "true"
|
||||
m.applyServer(protocol.ServerMessage{
|
||||
Type: protocol.TypeConfigSnapshot,
|
||||
ConfigFields: []protocol.ConfigFieldDto{{Key: "project.enabled", Type: "BOOL", Value: "true"}},
|
||||
})
|
||||
if len(m.configStaged) != 0 {
|
||||
t.Fatalf("expected staged edits cleared on clean snapshot, got %v", m.configStaged)
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@ const (
|
||||
OverlayDiff
|
||||
OverlayToolPalette
|
||||
OverlayModels
|
||||
OverlayArtifacts
|
||||
OverlayConfig
|
||||
)
|
||||
|
||||
// RouterEntry is one line in a session's conversation transcript.
|
||||
@@ -188,6 +190,23 @@ type Model struct {
|
||||
diffScrollOffset int
|
||||
eventStripShown bool
|
||||
|
||||
// artifact viewer (OverlayArtifacts) — populated by the artifact.list response
|
||||
artifacts []protocol.ArtifactDto
|
||||
artifactsFor string // sessionId the current listing belongs to
|
||||
artifactsIndex int
|
||||
artifactScroll int
|
||||
artifactsLoading bool
|
||||
|
||||
// config editor (OverlayConfig) — populated by the config.snapshot response
|
||||
configFields []protocol.ConfigFieldDto
|
||||
configIndex int
|
||||
configStaged map[string]string // key -> edited value, pending save
|
||||
configEditing bool // true while typing a value into configEditBuf
|
||||
configEditBuf string
|
||||
configError string
|
||||
configRestart []string // keys from the last save that need a restart
|
||||
configLoading bool
|
||||
|
||||
// command palette
|
||||
paletteFilter string
|
||||
paletteIndex int
|
||||
@@ -214,6 +233,7 @@ func NewModel(client *ws.Client) Model {
|
||||
history: map[string][]string{},
|
||||
historyIndex: -1,
|
||||
routerMessages: map[string][]RouterEntry{},
|
||||
configStaged: map[string]string{},
|
||||
chatMode: ChatModeChat,
|
||||
providerType: "LOCAL",
|
||||
snapshotPhase: true,
|
||||
|
||||
@@ -39,6 +39,10 @@ func (m Model) renderOverlay(base string) string {
|
||||
return m.center(m.toolPaletteModal())
|
||||
case OverlayModels:
|
||||
return m.center(m.modelsModal())
|
||||
case OverlayArtifacts:
|
||||
return m.center(m.artifactsModal())
|
||||
case OverlayConfig:
|
||||
return m.center(m.configModal())
|
||||
}
|
||||
return base
|
||||
}
|
||||
@@ -414,6 +418,137 @@ func (m Model) modelsModal() string {
|
||||
return m.center(modal)
|
||||
}
|
||||
|
||||
// artifactListRows is the number of artifact entries shown in the list portion of
|
||||
// the viewer (the rest of the modal height goes to the selected artifact's content).
|
||||
func (m Model) artifactListRows() int {
|
||||
n := len(m.artifacts)
|
||||
if n > 6 {
|
||||
n = 6
|
||||
}
|
||||
if n < 1 {
|
||||
n = 1
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
// artifactContentBodyH is the number of content lines visible for the selected artifact.
|
||||
func (m Model) artifactContentBodyH() int {
|
||||
h := m.height*70/100 - m.artifactListRows() - 7 // title, blanks, content header, hints
|
||||
if h < 3 {
|
||||
h = 3
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// artifactContentLines splits the selected artifact's content into display lines.
|
||||
func (m Model) artifactContentLines() []string {
|
||||
if m.artifactsIndex < 0 || m.artifactsIndex >= len(m.artifacts) {
|
||||
return nil
|
||||
}
|
||||
c := m.artifacts[m.artifactsIndex].Content
|
||||
if c == nil {
|
||||
return []string{"(no content stored)"}
|
||||
}
|
||||
return strings.Split(strings.ReplaceAll(*c, "\r\n", "\n"), "\n")
|
||||
}
|
||||
|
||||
// artifactContentMaxScroll keeps the last page of content anchored to the body bottom.
|
||||
func (m Model) artifactContentMaxScroll() int {
|
||||
max := len(m.artifactContentLines()) - m.artifactContentBodyH()
|
||||
if max < 0 {
|
||||
max = 0
|
||||
}
|
||||
return max
|
||||
}
|
||||
|
||||
func (m Model) artifactsModal() string {
|
||||
t := m.theme
|
||||
w := m.modalWidth()
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString(m.titleLine("artifacts"))
|
||||
if len(m.artifacts) > 0 {
|
||||
b.WriteString(mbg(t, " ("+itoa(m.artifactsIndex+1)+"/"+itoa(len(m.artifacts))+")", t.P.Faint))
|
||||
}
|
||||
b.WriteString("\n\n")
|
||||
|
||||
if m.artifactsLoading {
|
||||
b.WriteString(mbg(t, " loading…", t.P.Faint) + "\n")
|
||||
b.WriteString("\n" + modalHints(t, [][2]string{{"esc", "close"}}))
|
||||
return t.Overlay.Width(w).Render(b.String())
|
||||
}
|
||||
if len(m.artifacts) == 0 {
|
||||
b.WriteString(mbg(t, " no artifacts for this session", t.P.Faint) + "\n")
|
||||
b.WriteString("\n" + modalHints(t, [][2]string{{"esc", "close"}}))
|
||||
return t.Overlay.Width(w).Render(b.String())
|
||||
}
|
||||
|
||||
// Windowed artifact list, keeping the selected row in view.
|
||||
rows := m.artifactListRows()
|
||||
off := 0
|
||||
if len(m.artifacts) > rows {
|
||||
off = m.artifactsIndex - rows/2
|
||||
if off < 0 {
|
||||
off = 0
|
||||
}
|
||||
if off > len(m.artifacts)-rows {
|
||||
off = len(m.artifacts) - rows
|
||||
}
|
||||
}
|
||||
end := off + rows
|
||||
if end > len(m.artifacts) {
|
||||
end = len(m.artifacts)
|
||||
}
|
||||
for i := off; i < end; i++ {
|
||||
a := m.artifacts[i]
|
||||
marker := mbg(t, " ", t.P.BgPanel)
|
||||
idFg := t.P.Fg
|
||||
if i == m.artifactsIndex {
|
||||
marker = lipgloss.NewStyle().Foreground(t.P.Accent).Background(t.P.BgPanel).Render("▸ ")
|
||||
idFg = t.P.FgStrong
|
||||
}
|
||||
row := marker +
|
||||
lipgloss.NewStyle().Foreground(idFg).Background(t.P.BgPanel).Render(padRaw(shortID(a.ArtifactID), 14)) + " " +
|
||||
mbg(t, padRaw(a.StageID, 18), t.P.Accent2) + " " +
|
||||
mbg(t, a.Phase, t.P.Faint)
|
||||
b.WriteString(row + "\n")
|
||||
}
|
||||
|
||||
// Selected artifact content, scrollable with PgUp/PgDn.
|
||||
lines := m.artifactContentLines()
|
||||
bodyH := m.artifactContentBodyH()
|
||||
coff := m.artifactScroll
|
||||
if coff > m.artifactContentMaxScroll() {
|
||||
coff = m.artifactContentMaxScroll()
|
||||
}
|
||||
if coff < 0 {
|
||||
coff = 0
|
||||
}
|
||||
b.WriteString(mbg(t, " ── content", t.P.Faint))
|
||||
if len(lines) > bodyH {
|
||||
b.WriteString(mbg(t, " ("+itoa(coff+1)+"-"+itoa(min(coff+bodyH, len(lines)))+"/"+itoa(len(lines))+")", t.P.Faint))
|
||||
}
|
||||
b.WriteString("\n")
|
||||
cend := coff + bodyH
|
||||
if cend > len(lines) {
|
||||
cend = len(lines)
|
||||
}
|
||||
for i := coff; i < cend; i++ {
|
||||
b.WriteString(mbg(t, " "+truncate(lines[i], w-6), t.P.Fg) + "\n")
|
||||
}
|
||||
|
||||
b.WriteString("\n" + modalHints(t, [][2]string{{"↑↓", "select"}, {"PgUp/Dn", "scroll"}, {"v/esc", "close"}}))
|
||||
return t.Overlay.Width(w).Render(b.String())
|
||||
}
|
||||
|
||||
// shortID trims a long artifact id for the list column while staying identifiable.
|
||||
func shortID(id string) string {
|
||||
if len(id) <= 14 {
|
||||
return id
|
||||
}
|
||||
return id[:13] + "…"
|
||||
}
|
||||
|
||||
func tierColor(t Theme, tier int) lipgloss.Color {
|
||||
switch {
|
||||
case tier >= 3:
|
||||
|
||||
@@ -137,9 +137,6 @@ func (m *Model) applyServer(msg protocol.ServerMessage) {
|
||||
if s := m.session(msg.SessionID); s != nil {
|
||||
s.Active = false
|
||||
}
|
||||
if msg.SessionID == m.selectedID {
|
||||
m.selectedID = ""
|
||||
}
|
||||
case protocol.TypeStageStarted:
|
||||
if s := m.session(msg.SessionID); s != nil {
|
||||
s.CurrentStage = msg.StageID
|
||||
@@ -277,6 +274,28 @@ func (m *Model) applyServer(msg protocol.ServerMessage) {
|
||||
m.gpuTotalMB = msg.GpuMemoryTotalMb
|
||||
m.gpuUtil = msg.GpuUtilizationPct
|
||||
m.ramMB = msg.ProcessRssMb
|
||||
case protocol.TypeArtifactList:
|
||||
m.artifacts = msg.Artifacts
|
||||
m.artifactsFor = msg.SessionID
|
||||
m.artifactsLoading = false
|
||||
m.artifactScroll = 0
|
||||
if m.artifactsIndex >= len(m.artifacts) {
|
||||
m.artifactsIndex = 0
|
||||
}
|
||||
case protocol.TypeConfigSnapshot:
|
||||
m.configFields = msg.ConfigFields
|
||||
m.configRestart = msg.ConfigRestartRequired
|
||||
m.configLoading = false
|
||||
if msg.ConfigError != nil {
|
||||
m.configError = *msg.ConfigError
|
||||
} else {
|
||||
// A clean snapshot means the staged edits were accepted (or this is a fresh fetch).
|
||||
m.configError = ""
|
||||
m.configStaged = map[string]string{}
|
||||
}
|
||||
if m.configIndex >= len(m.configFields) {
|
||||
m.configIndex = 0
|
||||
}
|
||||
}
|
||||
|
||||
// Background-update badge for non-selected sessions.
|
||||
@@ -290,7 +309,8 @@ func sessionIDOf(msg protocol.ServerMessage) string {
|
||||
case protocol.TypeStageManifest, protocol.TypeSnapshotComplete,
|
||||
protocol.TypeProtocolError, protocol.TypeProviderStatus,
|
||||
protocol.TypeWorkflowList, protocol.TypeRouterResponse,
|
||||
protocol.TypeModelChanged, protocol.TypeModelList, protocol.TypeResourceStatus:
|
||||
protocol.TypeModelChanged, protocol.TypeModelList, protocol.TypeResourceStatus,
|
||||
protocol.TypeArtifactList, protocol.TypeConfigSnapshot:
|
||||
return ""
|
||||
default:
|
||||
return msg.SessionID
|
||||
|
||||
@@ -167,6 +167,10 @@ func (m Model) handleNormalKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.overlayEventIdx = 0
|
||||
case "t":
|
||||
m.overlay = OverlayToolPalette
|
||||
case "v":
|
||||
m.openArtifacts()
|
||||
case "g":
|
||||
m.openConfig()
|
||||
case "m":
|
||||
m.openModelsOverlay()
|
||||
case "w":
|
||||
@@ -340,6 +344,10 @@ func (m Model) autoApprove() (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
func (m Model) handleOverlayKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
// Config overlay owns all its keys (esc cancels an in-progress edit rather than closing).
|
||||
if m.overlay == OverlayConfig {
|
||||
return m.handleConfigKey(k)
|
||||
}
|
||||
if k.Type == tea.KeyEsc {
|
||||
m.overlay = OverlayNone
|
||||
return m, nil
|
||||
@@ -376,6 +384,29 @@ func (m Model) handleOverlayKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if runeIs(k, "t") {
|
||||
m.overlay = OverlayNone
|
||||
}
|
||||
case OverlayArtifacts:
|
||||
switch {
|
||||
case k.Type == tea.KeyUp || runeIs(k, "k"):
|
||||
if m.artifactsIndex > 0 {
|
||||
m.artifactsIndex--
|
||||
m.artifactScroll = 0
|
||||
}
|
||||
case k.Type == tea.KeyDown || runeIs(k, "j"):
|
||||
if m.artifactsIndex < len(m.artifacts)-1 {
|
||||
m.artifactsIndex++
|
||||
m.artifactScroll = 0
|
||||
}
|
||||
case k.Type == tea.KeyPgUp:
|
||||
if m.artifactScroll > 0 {
|
||||
m.artifactScroll--
|
||||
}
|
||||
case k.Type == tea.KeyPgDown:
|
||||
if m.artifactScroll < m.artifactContentMaxScroll() {
|
||||
m.artifactScroll++
|
||||
}
|
||||
case runeIs(k, "v"):
|
||||
m.overlay = OverlayNone
|
||||
}
|
||||
case OverlayModels:
|
||||
switch {
|
||||
case k.Type == tea.KeyUp || runeIs(k, "k"):
|
||||
@@ -401,6 +432,23 @@ func (m Model) handleOverlayKey(k tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// openArtifacts opens the artifact viewer for the selected session and requests its
|
||||
// artifacts from the server. No-op when no session is selected.
|
||||
func (m *Model) openArtifacts() {
|
||||
if m.selectedID == "" {
|
||||
return
|
||||
}
|
||||
m.overlay = OverlayArtifacts
|
||||
m.artifactsIndex = 0
|
||||
m.artifactScroll = 0
|
||||
// Reuse a cached listing only if it's for this session; otherwise show a loading state.
|
||||
if m.artifactsFor != m.selectedID {
|
||||
m.artifacts = nil
|
||||
m.artifactsLoading = true
|
||||
}
|
||||
m.client.Send(protocol.ListArtifacts(m.selectedID))
|
||||
}
|
||||
|
||||
// openModelsOverlay opens the model picker, pre-selecting the resident model.
|
||||
func (m *Model) openModelsOverlay() {
|
||||
m.overlay = OverlayModels
|
||||
@@ -452,6 +500,8 @@ func paletteCommands() []paletteCmd {
|
||||
{"tools", "tool palette", "tools for the current stage"},
|
||||
{"models", "swap model", "pick / pin the local model"},
|
||||
{"events", "event inspector", "browse the event stream"},
|
||||
{"artifacts", "view artifacts", "browse this session's artifacts"},
|
||||
{"config", "edit config", "view / change correx settings"},
|
||||
{"mode", "toggle mode", "switch chat / steering"},
|
||||
{"cancel", "cancel session", "stop the selected session"},
|
||||
{"back", "back to list", "leave the current session"},
|
||||
@@ -486,6 +536,10 @@ func (m Model) execPalette(id string) (tea.Model, tea.Cmd) {
|
||||
case "events":
|
||||
m.overlay = OverlayEventInspector
|
||||
m.overlayEventIdx = 0
|
||||
case "artifacts":
|
||||
m.openArtifacts()
|
||||
case "config":
|
||||
m.openConfig()
|
||||
case "mode":
|
||||
m.cycleChatMode()
|
||||
case "cancel":
|
||||
@@ -683,6 +737,13 @@ func (m *Model) listNav(dir int) {
|
||||
break
|
||||
}
|
||||
}
|
||||
// No current selection (e.g. nothing entered yet): start at the first
|
||||
// session rather than wrapping off the end into an arbitrary entry.
|
||||
if idx < 0 {
|
||||
m.selectedID = list[0].ID
|
||||
m.wfIndex = -1
|
||||
return
|
||||
}
|
||||
n := idx + dir
|
||||
if n < 0 {
|
||||
n = len(list) - 1
|
||||
|
||||
Reference in New Issue
Block a user