summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-12 09:44:56 -0500
committeradamdottv <[email protected]>2025-05-12 09:44:56 -0500
commitdfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c (patch)
treeebf8123a492626a31b7767b18a60594879cd70b0
parented9fba99c9e230094ed5d468c88f81469d60c911 (diff)
downloadopencode-dfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c.tar.gz
opencode-dfe5fd8d970f76af9db0a7bf9a1e6f0bc01a291c.zip
wip: refactoring
-rw-r--r--cmd/root.go2
-rw-r--r--internal/app/app.go60
-rw-r--r--internal/llm/agent/agent-tool.go2
-rw-r--r--internal/llm/agent/agent.go22
-rw-r--r--internal/llm/agent/mcp-tools.go1
-rw-r--r--internal/llm/tools/bash.go1
-rw-r--r--internal/llm/tools/edit.go27
-rw-r--r--internal/llm/tools/fetch.go1
-rw-r--r--internal/llm/tools/patch.go5
-rw-r--r--internal/llm/tools/write.go3
-rw-r--r--internal/logging/logging.go7
-rw-r--r--internal/session/session.go7
-rw-r--r--internal/tui/components/chat/list.go8
-rw-r--r--internal/tui/components/chat/sidebar.go2
-rw-r--r--internal/tui/components/core/status.go5
-rw-r--r--internal/tui/components/dialog/session.go4
-rw-r--r--internal/tui/components/logs/table.go7
-rw-r--r--internal/tui/page/chat.go2
-rw-r--r--internal/tui/tui.go6
19 files changed, 97 insertions, 75 deletions
diff --git a/cmd/root.go b/cmd/root.go
index 7bf8485f4..1b8c4c574 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -42,7 +42,7 @@ to assist developers in writing, debugging, and understanding code directly from
// Setup logging
lvl := new(slog.LevelVar)
- logger := slog.New(slog.NewTextHandler(logging.NewWriter(), &slog.HandlerOptions{
+ logger := slog.New(slog.NewTextHandler(logging.NewSlogWriter(), &slog.HandlerOptions{
Level: lvl,
}))
slog.SetDefault(logger)
diff --git a/internal/app/app.go b/internal/app/app.go
index 42de24548..283b311c8 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -10,7 +10,6 @@ import (
"log/slog"
"github.com/opencode-ai/opencode/internal/config"
- "github.com/opencode-ai/opencode/internal/db"
"github.com/opencode-ai/opencode/internal/history"
"github.com/opencode-ai/opencode/internal/llm/agent"
"github.com/opencode-ai/opencode/internal/logging"
@@ -42,30 +41,44 @@ type App struct {
}
func New(ctx context.Context, conn *sql.DB) (*App, error) {
- q := db.New(conn)
- loggingService := logging.NewService(q)
- sessionService := session.NewService(q)
- messageService := message.NewService(q)
- historyService := history.NewService(q, conn)
- permissionService := permission.NewPermissionService()
- statusService := status.NewService()
-
- // Initialize logging service
- logging.InitManager(loggingService)
-
- // Initialize session manager
- session.InitManager(sessionService)
-
- // Initialize status service
- status.InitManager(statusService)
+ err := logging.InitService(conn)
+ if err != nil {
+ slog.Error("Failed to initialize logging service", "error", err)
+ return nil, err
+ }
+ err = session.InitService(conn)
+ if err != nil {
+ slog.Error("Failed to initialize session service", "error", err)
+ return nil, err
+ }
+ err = message.InitService(conn)
+ if err != nil {
+ slog.Error("Failed to initialize message service", "error", err)
+ return nil, err
+ }
+ err = history.InitService(conn)
+ if err != nil {
+ slog.Error("Failed to initialize history service", "error", err)
+ return nil, err
+ }
+ err = permission.InitService()
+ if err != nil {
+ slog.Error("Failed to initialize permission service", "error", err)
+ return nil, err
+ }
+ err = status.InitService()
+ if err != nil {
+ slog.Error("Failed to initialize status service", "error", err)
+ return nil, err
+ }
app := &App{
- Logs: loggingService,
- Sessions: sessionService,
- Messages: messageService,
- History: historyService,
- Permissions: permissionService,
- Status: statusService,
+ Logs: logging.GetService(),
+ Sessions: session.GetService(),
+ Messages: message.GetService(),
+ History: history.GetService(),
+ Permissions: permission.GetService(),
+ Status: status.GetService(),
LSPClients: make(map[string]*lsp.Client),
}
@@ -75,7 +88,6 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
// Initialize LSP clients in the background
go app.initLSPClients(ctx)
- var err error
app.CoderAgent, err = agent.NewAgent(
config.AgentCoder,
app.Sessions,
diff --git a/internal/llm/agent/agent-tool.go b/internal/llm/agent/agent-tool.go
index 713b0690d..d451eafed 100644
--- a/internal/llm/agent/agent-tool.go
+++ b/internal/llm/agent/agent-tool.go
@@ -91,7 +91,7 @@ func (b *agentTool) Run(ctx context.Context, call tools.ToolCall) (tools.ToolRes
parentSession.PromptTokens += updatedSession.PromptTokens
parentSession.CompletionTokens += updatedSession.CompletionTokens
- _, err = b.sessions.Save(ctx, parentSession)
+ _, err = b.sessions.Update(ctx, parentSession)
if err != nil {
return tools.ToolResponse{}, fmt.Errorf("error saving parent session: %s", err)
}
diff --git a/internal/llm/agent/agent.go b/internal/llm/agent/agent.go
index 295ac4654..f6f816256 100644
--- a/internal/llm/agent/agent.go
+++ b/internal/llm/agent/agent.go
@@ -156,7 +156,7 @@ func (a *agent) generateTitle(ctx context.Context, sessionID string, content str
}
session.Title = title
- _, err = a.sessions.Save(ctx, session)
+ _, err = a.sessions.Update(ctx, session)
return err
}
@@ -459,7 +459,7 @@ out:
func (a *agent) finishMessage(ctx context.Context, msg *message.Message, finishReson message.FinishReason) {
msg.AddFinish(finishReson)
- _ = a.messages.Update(ctx, *msg)
+ _, _ = a.messages.Update(ctx, *msg)
}
func (a *agent) processEvent(ctx context.Context, sessionID string, assistantMsg *message.Message, event provider.ProviderEvent) error {
@@ -477,13 +477,16 @@ func (a *agent) processEvent(ctx context.Context, sessionID string, assistantMsg
switch event.Type {
case provider.EventThinkingDelta:
assistantMsg.AppendReasoningContent(event.Content)
- return a.messages.Update(ctx, *assistantMsg)
+ _, err := a.messages.Update(ctx, *assistantMsg)
+ return err
case provider.EventContentDelta:
assistantMsg.AppendContent(event.Content)
- return a.messages.Update(ctx, *assistantMsg)
+ _, err := a.messages.Update(ctx, *assistantMsg)
+ return err
case provider.EventToolUseStart:
assistantMsg.AddToolCall(*event.ToolCall)
- return a.messages.Update(ctx, *assistantMsg)
+ _, err := a.messages.Update(ctx, *assistantMsg)
+ return err
// TODO: see how to handle this
// case provider.EventToolUseDelta:
// tm := time.Unix(assistantMsg.UpdatedAt, 0)
@@ -495,7 +498,8 @@ func (a *agent) processEvent(ctx context.Context, sessionID string, assistantMsg
// }
case provider.EventToolUseStop:
assistantMsg.FinishToolCall(event.ToolCall.ID)
- return a.messages.Update(ctx, *assistantMsg)
+ _, err := a.messages.Update(ctx, *assistantMsg)
+ return err
case provider.EventError:
if errors.Is(event.Error, context.Canceled) {
status.Info(fmt.Sprintf("Event processing canceled for session: %s", sessionID))
@@ -506,7 +510,7 @@ func (a *agent) processEvent(ctx context.Context, sessionID string, assistantMsg
case provider.EventComplete:
assistantMsg.SetToolCalls(event.Response.ToolCalls)
assistantMsg.AddFinish(event.Response.FinishReason)
- if err := a.messages.Update(ctx, *assistantMsg); err != nil {
+ if _, err := a.messages.Update(ctx, *assistantMsg); err != nil {
return fmt.Errorf("failed to update message: %w", err)
}
return a.TrackUsage(ctx, sessionID, a.provider.Model(), event.Response.Usage)
@@ -540,7 +544,7 @@ func (a *agent) TrackUsage(ctx context.Context, sessionID string, model models.M
sess.CompletionTokens += usage.OutputTokens
sess.PromptTokens += usage.InputTokens
- _, err = a.sessions.Save(ctx, sess)
+ _, err = a.sessions.Update(ctx, sess)
if err != nil {
return fmt.Errorf("failed to save session: %w", err)
}
@@ -691,7 +695,7 @@ func (a *agent) CompactSession(ctx context.Context, sessionID string) error {
session.SummarizedAt = currentTime
// Save the updated session
- _, err = a.sessions.Save(ctx, session)
+ _, err = a.sessions.Update(ctx, session)
if err != nil {
return fmt.Errorf("failed to save session with summary: %w", err)
}
diff --git a/internal/llm/agent/mcp-tools.go b/internal/llm/agent/mcp-tools.go
index 9966b99d9..a6a21d028 100644
--- a/internal/llm/agent/mcp-tools.go
+++ b/internal/llm/agent/mcp-tools.go
@@ -86,6 +86,7 @@ func (b *mcpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolRes
}
permissionDescription := fmt.Sprintf("execute %s with the following parameters: %s", b.Info().Name, params.Input)
p := b.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: config.WorkingDirectory(),
diff --git a/internal/llm/tools/bash.go b/internal/llm/tools/bash.go
index 7231e1d2a..eb27026e5 100644
--- a/internal/llm/tools/bash.go
+++ b/internal/llm/tools/bash.go
@@ -268,6 +268,7 @@ func (b *bashTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error)
}
if !isSafeReadOnly {
p := b.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: config.WorkingDirectory(),
diff --git a/internal/llm/tools/edit.go b/internal/llm/tools/edit.go
index 44787f525..df5c94290 100644
--- a/internal/llm/tools/edit.go
+++ b/internal/llm/tools/edit.go
@@ -37,7 +37,7 @@ type EditResponseMetadata struct {
type editTool struct {
lspClients map[string]*lsp.Client
permissions permission.Service
- files history.Service
+ history history.Service
}
const (
@@ -95,7 +95,7 @@ func NewEditTool(lspClients map[string]*lsp.Client, permissions permission.Servi
return &editTool{
lspClients: lspClients,
permissions: permissions,
- files: files,
+ history: files,
}
}
@@ -202,6 +202,7 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -224,14 +225,14 @@ func (e *editTool) createNewFile(ctx context.Context, filePath, content string)
}
// File can't be in the history so we create a new file history
- _, err = e.files.Create(ctx, sessionID, filePath, "")
+ _, err = e.history.Create(ctx, sessionID, filePath, "")
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
}
// Add the new content to the file history
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, content)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, content)
if err != nil {
// Log error but don't fail the operation
slog.Debug("Error creating file history version", "error", err)
@@ -313,6 +314,7 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -335,9 +337,9 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
}
// Check if file exists in history
- file, err := e.files.GetByPathAndSession(ctx, filePath, sessionID)
+ file, err := e.history.GetLatestByPathAndSession(ctx, filePath, sessionID)
if err != nil {
- _, err = e.files.Create(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.Create(ctx, sessionID, filePath, oldContent)
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
@@ -345,13 +347,13 @@ func (e *editTool) deleteContent(ctx context.Context, filePath, oldString string
}
if file.Content != oldContent {
// User Manually changed the content store an intermediate version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, oldContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
}
// Store the new version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, "")
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, "")
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
@@ -433,6 +435,7 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
permissionPath = rootDir
}
p := e.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -455,9 +458,9 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
}
// Check if file exists in history
- file, err := e.files.GetByPathAndSession(ctx, filePath, sessionID)
+ file, err := e.history.GetLatestByPathAndSession(ctx, filePath, sessionID)
if err != nil {
- _, err = e.files.Create(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.Create(ctx, sessionID, filePath, oldContent)
if err != nil {
// Log error but don't fail the operation
return ToolResponse{}, fmt.Errorf("error creating file history: %w", err)
@@ -465,13 +468,13 @@ func (e *editTool) replaceContent(ctx context.Context, filePath, oldString, newS
}
if file.Content != oldContent {
// User Manually changed the content store an intermediate version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, oldContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, oldContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
}
// Store the new version
- _, err = e.files.CreateVersion(ctx, sessionID, filePath, newContent)
+ _, err = e.history.CreateVersion(ctx, sessionID, filePath, newContent)
if err != nil {
slog.Debug("Error creating file history version", "error", err)
}
diff --git a/internal/llm/tools/fetch.go b/internal/llm/tools/fetch.go
index 863532a0b..d2ab148b9 100644
--- a/internal/llm/tools/fetch.go
+++ b/internal/llm/tools/fetch.go
@@ -122,6 +122,7 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
}
p := t.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: config.WorkingDirectory(),
diff --git a/internal/llm/tools/patch.go b/internal/llm/tools/patch.go
index e0c0bf5bc..d70e6a451 100644
--- a/internal/llm/tools/patch.go
+++ b/internal/llm/tools/patch.go
@@ -193,6 +193,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
dir := filepath.Dir(path)
patchDiff, _, _ := diff.GenerateDiff("", *change.NewContent, path)
p := p.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: dir,
@@ -220,6 +221,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
patchDiff, _, _ := diff.GenerateDiff(currentContent, newContent, path)
dir := filepath.Dir(path)
p := p.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: dir,
@@ -239,6 +241,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
dir := filepath.Dir(path)
patchDiff, _, _ := diff.GenerateDiff(*change.OldContent, "", path)
p := p.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: dir,
@@ -313,7 +316,7 @@ func (p *patchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
totalRemovals += removals
// Update history
- file, err := p.files.GetByPathAndSession(ctx, absPath, sessionID)
+ file, err := p.files.GetLatestByPathAndSession(ctx, absPath, sessionID)
if err != nil && change.Type != diff.ActionAdd {
// If not adding a file, create history entry for existing file
_, err = p.files.Create(ctx, sessionID, absPath, oldContent)
diff --git a/internal/llm/tools/write.go b/internal/llm/tools/write.go
index 617d69c29..d826b3a49 100644
--- a/internal/llm/tools/write.go
+++ b/internal/llm/tools/write.go
@@ -167,6 +167,7 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
permissionPath = rootDir
}
p := w.permissions.Request(
+ ctx,
permission.CreatePermissionRequest{
SessionID: sessionID,
Path: permissionPath,
@@ -189,7 +190,7 @@ func (w *writeTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
}
// Check if file exists in history
- file, err := w.files.GetByPathAndSession(ctx, filePath, sessionID)
+ file, err := w.files.GetLatestByPathAndSession(ctx, filePath, sessionID)
if err != nil {
_, err = w.files.Create(ctx, sessionID, filePath, oldContent)
if err != nil {
diff --git a/internal/logging/logging.go b/internal/logging/logging.go
index d669d485d..0ef5f0f28 100644
--- a/internal/logging/logging.go
+++ b/internal/logging/logging.go
@@ -18,7 +18,6 @@ import (
"github.com/google/uuid"
"github.com/opencode-ai/opencode/internal/db"
"github.com/opencode-ai/opencode/internal/pubsub"
- // "github.com/opencode-ai/opencode/internal/status"
)
type Log struct {
@@ -220,6 +219,7 @@ func (sw *slogWriter) Write(p []byte) (n int, err error) {
logEntry.Attributes[key] = value
}
}
+
if d.Err() != nil {
return len(p), fmt.Errorf("logfmt.ScanRecord: %w", d.Err())
}
@@ -231,6 +231,11 @@ func (sw *slogWriter) Write(p []byte) (n int, err error) {
// Create log entry via the service (non-blocking or handle error appropriately)
// Using context.Background() as this is a low-level logging write.
go func(le Log) { // Run in a goroutine to avoid blocking slog
+ if globalLoggingService == nil {
+ // If the logging service is not initialized, log the message to stderr
+ // fmt.Fprintf(os.Stderr, "ERROR [logging.slogWriter]: logging service not initialized\n")
+ return
+ }
if err := Create(context.Background(), le); err != nil {
// Log internal error using a more primitive logger to avoid loops
fmt.Fprintf(os.Stderr, "ERROR [logging.slogWriter]: failed to persist log: %v\n", err)
diff --git a/internal/session/session.go b/internal/session/session.go
index 933df8117..e377bfd21 100644
--- a/internal/session/session.go
+++ b/internal/session/session.go
@@ -12,7 +12,6 @@ import (
"github.com/opencode-ai/opencode/internal/pubsub"
)
-// Session represents a conversation session.
type Session struct {
ID string
ParentSessionID string
@@ -27,16 +26,12 @@ type Session struct {
UpdatedAt int64
}
-// --- Events ---
-
const (
EventSessionCreated pubsub.EventType = "session_created"
EventSessionUpdated pubsub.EventType = "session_updated"
EventSessionDeleted pubsub.EventType = "session_deleted"
)
-// --- Service Definition ---
-
type Service interface {
pubsub.Subscriber[Session]
@@ -77,8 +72,6 @@ func GetService() Service {
return globalSessionService
}
-// --- Service Methods ---
-
func (s *service) Create(ctx context.Context, title string) (Session, error) {
s.mu.Lock()
defer s.mu.Unlock()
diff --git a/internal/tui/components/chat/list.go b/internal/tui/components/chat/list.go
index 55f76c342..f749f6b05 100644
--- a/internal/tui/components/chat/list.go
+++ b/internal/tui/components/chat/list.go
@@ -110,7 +110,7 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.viewport.GotoBottom()
case pubsub.Event[message.Message]:
needsRerender := false
- if msg.Type == pubsub.CreatedEvent {
+ if msg.Type == message.EventMessageCreated {
if msg.Payload.SessionID == m.session.ID {
messageExists := false
@@ -142,7 +142,7 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
}
- } else if msg.Type == pubsub.UpdatedEvent && msg.Payload.SessionID == m.session.ID {
+ } else if msg.Type == message.EventMessageUpdated && msg.Payload.SessionID == m.session.ID {
for i, v := range m.messages {
if v.ID == msg.Payload.ID {
m.messages[i] = msg.Payload
@@ -155,8 +155,8 @@ func (m *messagesCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if needsRerender {
m.renderView()
if len(m.messages) > 0 {
- if (msg.Type == pubsub.CreatedEvent) ||
- (msg.Type == pubsub.UpdatedEvent && msg.Payload.ID == m.messages[len(m.messages)-1].ID) {
+ if (msg.Type == message.EventMessageCreated) ||
+ (msg.Type == message.EventMessageUpdated && msg.Payload.ID == m.messages[len(m.messages)-1].ID) {
m.viewport.GotoBottom()
}
}
diff --git a/internal/tui/components/chat/sidebar.go b/internal/tui/components/chat/sidebar.go
index a66249b36..50c9ee567 100644
--- a/internal/tui/components/chat/sidebar.go
+++ b/internal/tui/components/chat/sidebar.go
@@ -59,7 +59,7 @@ func (m *sidebarCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.loadModifiedFiles(ctx)
}
case pubsub.Event[session.Session]:
- if msg.Type == pubsub.UpdatedEvent {
+ if msg.Type == session.EventSessionUpdated {
if m.session.ID == msg.Payload.ID {
m.session = msg.Payload
}
diff --git a/internal/tui/components/core/status.go b/internal/tui/components/core/status.go
index 84e0be42b..5de0b852e 100644
--- a/internal/tui/components/core/status.go
+++ b/internal/tui/components/core/status.go
@@ -65,13 +65,13 @@ func (m statusCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case chat.SessionClearedMsg:
m.session = session.Session{}
case pubsub.Event[session.Session]:
- if msg.Type == pubsub.UpdatedEvent {
+ if msg.Type == session.EventSessionUpdated {
if m.session.ID == msg.Payload.ID {
m.session = msg.Payload
}
}
case pubsub.Event[status.StatusMessage]:
- if msg.Type == pubsub.CreatedEvent {
+ if msg.Type == status.EventStatusPublished {
statusMsg := statusMessage{
Level: msg.Payload.Level,
Message: msg.Payload.Message,
@@ -308,4 +308,3 @@ func NewStatusCmp(lspClients map[string]*lsp.Client) StatusCmp {
return statusComponent
}
-
diff --git a/internal/tui/components/dialog/session.go b/internal/tui/components/dialog/session.go
index 174e4bed9..d49af82f8 100644
--- a/internal/tui/components/dialog/session.go
+++ b/internal/tui/components/dialog/session.go
@@ -93,7 +93,7 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if len(s.sessions) > 0 {
selectedSession := s.sessions[s.selectedIdx]
// Update the session manager with the selected session
- session.SetCurrentSession(selectedSession.ID)
+ // session.SetCurrentSession(selectedSession.ID)
return s, util.CmdHandler(SessionSelectedMsg{
Session: selectedSession,
})
@@ -111,7 +111,7 @@ func (s *sessionDialogCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (s *sessionDialogCmp) View() string {
t := theme.CurrentTheme()
baseStyle := styles.BaseStyle()
-
+
if len(s.sessions) == 0 {
return baseStyle.Padding(1, 2).
Border(lipgloss.RoundedBorder()).
diff --git a/internal/tui/components/logs/table.go b/internal/tui/components/logs/table.go
index e7fc4ea70..4a9eb06a4 100644
--- a/internal/tui/components/logs/table.go
+++ b/internal/tui/components/logs/table.go
@@ -9,7 +9,6 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/opencode-ai/opencode/internal/logging"
"github.com/opencode-ai/opencode/internal/pubsub"
- "github.com/opencode-ai/opencode/internal/session"
"github.com/opencode-ai/opencode/internal/tui/components/chat"
"github.com/opencode-ai/opencode/internal/tui/layout"
"github.com/opencode-ai/opencode/internal/tui/theme"
@@ -49,7 +48,7 @@ func (i *tableCmp) fetchLogs() tea.Cmd {
var logs []logging.Log
var err error
- sessionId := session.CurrentSessionID()
+ sessionId := "" //session.CurrentSessionID()
// Limit the number of logs to improve performance
const logLimit = 100
@@ -85,7 +84,7 @@ func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case pubsub.Event[logging.Log]:
// Only handle created events
- if msg.Type == pubsub.CreatedEvent {
+ if msg.Type == logging.EventLogCreated {
// Add the new log to our list
i.logs = append([]logging.Log{msg.Payload}, i.logs...)
// Keep the list at a reasonable size
@@ -105,7 +104,7 @@ func (i *tableCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
t, cmd := i.table.Update(msg)
cmds = append(cmds, cmd)
i.table = t
-
+
// Only send selected log message when selection changes
selectedRow := i.table.SelectedRow()
if selectedRow != nil {
diff --git a/internal/tui/page/chat.go b/internal/tui/page/chat.go
index 46609fdd0..378575f4d 100644
--- a/internal/tui/page/chat.go
+++ b/internal/tui/page/chat.go
@@ -137,7 +137,7 @@ func (p *chatPage) sendMessage(text string, attachments []message.Attachment) te
p.session = newSession
// Update the current session in the session manager
- session.SetCurrentSession(newSession.ID)
+ // session.SetCurrentSession(newSession.ID)
cmd := p.setSidebar()
if cmd != nil {
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index ddc574328..4e5782353 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -212,11 +212,11 @@ func (a appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg.Action {
case dialog.PermissionAllow:
- a.app.Permissions.Grant(msg.Permission)
+ a.app.Permissions.Grant(context.Background(), msg.Permission)
case dialog.PermissionAllowForSession:
- a.app.Permissions.GrantPersistant(msg.Permission)
+ a.app.Permissions.GrantPersistant(context.Background(), msg.Permission)
case dialog.PermissionDeny:
- a.app.Permissions.Deny(msg.Permission)
+ a.app.Permissions.Deny(context.Background(), msg.Permission)
}
a.showPermissions = false
return a, cmd