Browse Source

wip: refactoring tui

adamdottv 9 months ago
parent
commit
2a132f86d6
4 changed files with 15 additions and 173 deletions
  1. 0 102
      MISSING_API_FEATURES.md
  2. 13 29
      internal/tui/components/chat/message.go
  3. 2 28
      internal/tui/components/chat/messages.go
  4. 0 14
      sqlc.yaml

+ 0 - 102
MISSING_API_FEATURES.md

@@ -1,102 +0,0 @@
-# Missing API Features for TypeScript Backend
-
-This document tracks features that need to be implemented in the TypeScript backend to support the existing Go TUI functionality.
-
-## Current API Endpoints Available
-- `/session_create` - Create a new session
-- `/session_share` - Share a session
-- `/session_messages` - Get messages for a session
-- `/session_list` - List all sessions
-- `/session_chat` - Send a chat message (with SSE streaming response)
-- `/event` - SSE event stream (currently only supports `storage.write` events)
-
-## Missing Features
-
-### Session Management
-- [ ] Session deletion
-- [ ] Session renaming/updating title
-- [ ] Session compaction/summarization
-- [ ] Session export/import
-
-### Message Management
-- [ ] Message editing
-- [ ] Message deletion
-- [ ] Message retrieval by ID
-- [ ] Message search/filtering
-- [ ] System messages support
-
-### Agent/LLM Features
-- [ ] Model selection/switching
-- [ ] Tool invocation support
-- [ ] Agent state management (busy/idle)
-- [ ] Cancel ongoing generation
-- [ ] Token usage tracking per message
-- [ ] Custom prompts/system messages
-
-### File/Attachment Support
-- [ ] File attachments in messages
-- [ ] Image attachments
-- [ ] Code snippet attachments
-- [ ] Attachment storage/retrieval
-
-### LSP Integration
-- [ ] LSP server discovery
-- [ ] LSP diagnostics
-- [ ] LSP code actions
-- [ ] LSP hover information
-- [ ] LSP references
-- [ ] LSP workspace symbols
-
-### Configuration
-- [ ] Model configuration
-- [ ] API key management
-- [ ] Theme preferences
-- [ ] User preferences storage
-
-### Permissions
-- [ ] File system access permissions
-- [ ] Command execution permissions
-- [ ] Network access permissions
-
-### Status/Notifications
-- [ ] Status message broadcasting
-- [ ] Error notifications
-- [ ] Progress indicators
-
-### History
-- [ ] Command history
-- [ ] Search history
-- [ ] Recent files/folders
-
-### Events (SSE)
-Currently only `storage.write` is supported. Missing events:
-- [ ] `session.created`
-- [ ] `session.updated`
-- [ ] `session.deleted`
-- [ ] `message.created`
-- [ ] `message.updated`
-- [ ] `message.deleted`
-- [ ] `agent.status` (busy/idle)
-- [ ] `tool.invoked`
-- [ ] `tool.result`
-- [ ] `error`
-- [ ] `status` (info/warning/error messages)
-- [ ] `lsp.diagnostics`
-- [ ] `permission.requested`
-- [ ] `permission.granted`
-- [ ] `permission.denied`
-
-### Database/Storage
-- [ ] Message persistence
-- [ ] Session persistence
-- [ ] File tracking
-- [ ] Log storage
-
-### Pubsub/Real-time Updates
-- [ ] Publish message events when messages are created/updated via API
-- [ ] Agent busy/idle status updates
-
-### Misc
-- [ ] Health check endpoint
-- [ ] Version endpoint
-- [ ] Metrics/telemetry

+ 13 - 29
internal/tui/components/chat/message.go

@@ -16,10 +16,10 @@ import (
 	"github.com/sst/opencode/internal/tui/styles"
 	"github.com/sst/opencode/internal/tui/styles"
 	"github.com/sst/opencode/internal/tui/theme"
 	"github.com/sst/opencode/internal/tui/theme"
 	"github.com/sst/opencode/pkg/client"
 	"github.com/sst/opencode/pkg/client"
+	"golang.org/x/text/cases"
+	"golang.org/x/text/language"
 )
 )
 
 
-type uiMessageType int
-
 const (
 const (
 	maxResultHeight = 10
 	maxResultHeight = 10
 )
 )
@@ -149,7 +149,8 @@ func renderAssistantMessage(
 			switch toolInvocation.(type) {
 			switch toolInvocation.(type) {
 			case client.MessageToolInvocationToolCall:
 			case client.MessageToolInvocationToolCall:
 				toolCall := toolInvocation.(client.MessageToolInvocationToolCall)
 				toolCall := toolInvocation.(client.MessageToolInvocationToolCall)
-				toolName := toolName(toolCall.ToolName)
+				toolName := renderToolName(toolCall.ToolName)
+
 				var toolArgs []string
 				var toolArgs []string
 				toolMap, _ := convertToMap(toolCall.Args)
 				toolMap, _ := convertToMap(toolCall.Args)
 				for _, arg := range toolMap {
 				for _, arg := range toolMap {
@@ -166,7 +167,7 @@ func renderAssistantMessage(
 
 
 			case client.MessageToolInvocationToolResult:
 			case client.MessageToolInvocationToolResult:
 				toolInvocationResult := toolInvocation.(client.MessageToolInvocationToolResult)
 				toolInvocationResult := toolInvocation.(client.MessageToolInvocationToolResult)
-				toolName := toolName(toolInvocationResult.ToolName)
+				toolName := renderToolName(toolInvocationResult.ToolName)
 				var toolArgs []string
 				var toolArgs []string
 				toolMap, _ := convertToMap(toolInvocationResult.Args)
 				toolMap, _ := convertToMap(toolInvocationResult.Args)
 				for _, arg := range toolMap {
 				for _, arg := range toolMap {
@@ -258,35 +259,18 @@ func findToolResponse(toolCallID string, futureMessages []message.Message) *mess
 	return nil
 	return nil
 }
 }
 
 
-func toolName(name string) string {
+func renderToolName(name string) string {
 	switch name {
 	switch name {
 	// case agent.AgentToolName:
 	// case agent.AgentToolName:
 	// 	return "Task"
 	// 	return "Task"
-	case tools.BashToolName:
-		return "Bash"
-	case tools.EditToolName:
-		return "Edit"
-	case tools.FetchToolName:
-		return "Fetch"
-	case tools.GlobToolName:
-		return "Glob"
-	case tools.GrepToolName:
-		return "Grep"
-	case tools.LSToolName:
+	case "ls":
 		return "List"
 		return "List"
-	case tools.ViewToolName:
-		return "View"
-	case tools.WriteToolName:
-		return "Write"
-	case tools.PatchToolName:
-		return "Patch"
-	case tools.BatchToolName:
-		return "Batch"
+	default:
+		return cases.Title(language.English).String(name)
 	}
 	}
-	return name
 }
 }
 
 
-func getToolAction(name string) string {
+func renderToolAction(name string) string {
 	switch name {
 	switch name {
 	// case agent.AgentToolName:
 	// case agent.AgentToolName:
 	// 	return "Preparing prompt..."
 	// 	return "Preparing prompt..."
@@ -570,7 +554,7 @@ func renderToolResponse(toolCall message.ToolCall, response message.ToolResult,
 
 
 		var toolCalls []string
 		var toolCalls []string
 		for i, result := range batchResult.Results {
 		for i, result := range batchResult.Results {
-			toolName := toolName(result.ToolName)
+			toolName := renderToolName(result.ToolName)
 
 
 			// Format the tool input as a string
 			// Format the tool input as a string
 			inputStr := string(result.ToolInput)
 			inputStr := string(result.ToolInput)
@@ -628,11 +612,11 @@ func renderToolMessage(
 
 
 	response := findToolResponse(toolCall.ID, allMessages)
 	response := findToolResponse(toolCall.ID, allMessages)
 	toolNameText := baseStyle.Foreground(t.TextMuted()).
 	toolNameText := baseStyle.Foreground(t.TextMuted()).
-		Render(fmt.Sprintf("%s: ", toolName(toolCall.Name)))
+		Render(fmt.Sprintf("%s: ", renderToolName(toolCall.Name)))
 
 
 	if !toolCall.Finished {
 	if !toolCall.Finished {
 		// Get a brief description of what the tool is doing
 		// Get a brief description of what the tool is doing
-		toolAction := getToolAction(toolCall.Name)
+		toolAction := renderToolAction(toolCall.Name)
 
 
 		progressText := baseStyle.
 		progressText := baseStyle.
 			Width(width - 2 - lipgloss.Width(toolNameText)).
 			Width(width - 2 - lipgloss.Width(toolNameText)).

+ 2 - 28
internal/tui/components/chat/messages.go

@@ -23,7 +23,6 @@ type messagesCmp struct {
 	app              *app.App
 	app              *app.App
 	width, height    int
 	width, height    int
 	viewport         viewport.Model
 	viewport         viewport.Model
-	currentMsgID     string
 	spinner          spinner.Model
 	spinner          spinner.Model
 	rendering        bool
 	rendering        bool
 	attachments      viewport.Model
 	attachments      viewport.Model
@@ -63,8 +62,6 @@ func (m *messagesCmp) Init() tea.Cmd {
 }
 }
 
 
 func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
-	// m.renderView()
-
 	var cmds []tea.Cmd
 	var cmds []tea.Cmd
 	switch msg := msg.(type) {
 	switch msg := msg.(type) {
 	case dialog.ThemeChangedMsg:
 	case dialog.ThemeChangedMsg:
@@ -72,16 +69,12 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		return m, nil
 		return m, nil
 	case ToggleToolMessagesMsg:
 	case ToggleToolMessagesMsg:
 		m.showToolMessages = !m.showToolMessages
 		m.showToolMessages = !m.showToolMessages
-		// Clear the cache to force re-rendering of all messages
-		// m.cachedContent = make(map[string]cacheItem)
 		m.renderView()
 		m.renderView()
 		return m, nil
 		return m, nil
 	case state.SessionSelectedMsg:
 	case state.SessionSelectedMsg:
 		cmd := m.Reload(msg)
 		cmd := m.Reload(msg)
 		return m, cmd
 		return m, cmd
 	case state.SessionClearedMsg:
 	case state.SessionClearedMsg:
-		// m.messages = make([]message.Message, 0)
-		m.currentMsgID = ""
 		m.rendering = false
 		m.rendering = false
 		return m, nil
 		return m, nil
 	case tea.KeyMsg:
 	case tea.KeyMsg:
@@ -119,17 +112,10 @@ func (m *messagesCmp) renderView() {
 	for _, msg := range m.app.Messages {
 	for _, msg := range m.app.Messages {
 		switch msg.Role {
 		switch msg.Role {
 		case client.User:
 		case client.User:
-			content := renderUserMessage(
-				msg,
-				m.width,
-			)
+			content := renderUserMessage(msg, m.width)
 			messages = append(messages, content+"\n")
 			messages = append(messages, content+"\n")
 		case client.Assistant:
 		case client.Assistant:
-			content := renderAssistantMessage(
-				msg,
-				m.width,
-				m.showToolMessages,
-			)
+			content := renderAssistantMessage(msg, m.width, m.showToolMessages)
 			messages = append(messages, content+"\n")
 			messages = append(messages, content+"\n")
 		}
 		}
 	}
 	}
@@ -328,18 +314,6 @@ func (m *messagesCmp) GetSize() (int, int) {
 }
 }
 
 
 func (m *messagesCmp) Reload(session *session.Session) tea.Cmd {
 func (m *messagesCmp) Reload(session *session.Session) tea.Cmd {
-	// messages := m.app.Messages
-	// messages, err := m.app.MessagesOLD.List(context.Background(), session.ID)
-	// if err != nil {
-	// 	status.Error(err.Error())
-	// 	return nil
-	// }
-	// m.messages = messages
-
-	if len(m.app.Messages) > 0 {
-		m.currentMsgID = m.app.Messages[len(m.app.Messages)-1].Id
-	}
-	// delete(m.cachedContent, m.currentMsgID)
 	m.rendering = true
 	m.rendering = true
 	return func() tea.Msg {
 	return func() tea.Msg {
 		m.renderView()
 		m.renderView()

+ 0 - 14
sqlc.yaml

@@ -1,14 +0,0 @@
-version: "2"
-sql:
-  - engine: "sqlite"
-    schema: "internal/db/migrations"
-    queries: "internal/db/sql"
-    gen:
-      go:
-        package: "db"
-        out: "internal/db"
-        emit_json_tags: true
-        emit_prepared_queries: true
-        emit_interface: true
-        emit_exact_table_names: false
-        emit_empty_slices: true