summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-15 11:58:01 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:41:27 +0200
commit1cdd24fbc7b45693b65b5d55e4f45c2ebc60a556 (patch)
treea623be9bdcfb78fca8185d10019c118f4ac00106
parentf6be348bf704ab3d012eec549357f5acd9c74796 (diff)
downloadopencode-1cdd24fbc7b45693b65b5d55e4f45c2ebc60a556.tar.gz
opencode-1cdd24fbc7b45693b65b5d55e4f45c2ebc60a556.zip
minor fixes
-rw-r--r--internal/app/app.go5
-rw-r--r--internal/config/config.go5
-rw-r--r--internal/llm/agent/agent-tool.go8
-rw-r--r--internal/llm/agent/agent.go17
-rw-r--r--internal/llm/agent/coder.go2
-rw-r--r--internal/llm/agent/task.go39
6 files changed, 49 insertions, 27 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
index 9f575cac3..ca23b3c40 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -48,9 +48,10 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
LSPClients: make(map[string]*lsp.Client),
}
+ app.initLSPClients(ctx)
+
var err error
app.CoderAgent, err = agent.NewCoderAgent(
-
app.Permissions,
app.Sessions,
app.Messages,
@@ -61,8 +62,6 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
return nil, err
}
- app.initLSPClients(ctx)
-
return app, nil
}
diff --git a/internal/config/config.go b/internal/config/config.go
index 1f3091ff3..f0afbdd3c 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -272,5 +272,8 @@ func Get() *Config {
// WorkingDirectory returns the current working directory from the configuration.
func WorkingDirectory() string {
- return viper.GetString("wd")
+ if cfg == nil {
+ panic("config not loaded")
+ }
+ return cfg.WorkingDir
}
diff --git a/internal/llm/agent/agent-tool.go b/internal/llm/agent/agent-tool.go
index a92ea44a4..83160bb64 100644
--- a/internal/llm/agent/agent-tool.go
+++ b/internal/llm/agent/agent-tool.go
@@ -53,7 +53,7 @@ func (b *agentTool) Run(ctx context.Context, call tools.ToolCall) (tools.ToolRes
return tools.ToolResponse{}, fmt.Errorf("session_id and message_id are required")
}
- agent, err := NewTaskAgent(b.lspClients)
+ agent, err := NewTaskAgent(b.messages, b.sessions, b.lspClients)
if err != nil {
return tools.ToolResponse{}, fmt.Errorf("error creating agent: %s", err)
}
@@ -105,9 +105,11 @@ func (b *agentTool) Run(ctx context.Context, call tools.ToolCall) (tools.ToolRes
func NewAgentTool(
Sessions session.Service,
Messages message.Service,
+ LspClients map[string]*lsp.Client,
) tools.BaseTool {
return &agentTool{
- sessions: Sessions,
- messages: Messages,
+ sessions: Sessions,
+ messages: Messages,
+ lspClients: LspClients,
}
}
diff --git a/internal/llm/agent/agent.go b/internal/llm/agent/agent.go
index 997004e12..1958111a1 100644
--- a/internal/llm/agent/agent.go
+++ b/internal/llm/agent/agent.go
@@ -4,6 +4,8 @@ import (
"context"
"errors"
"fmt"
+ "os"
+ "runtime/debug"
"strings"
"sync"
@@ -88,6 +90,21 @@ func (a *agent) Generate(ctx context.Context, sessionID string, content string)
defer func() {
if r := recover(); r != nil {
logging.ErrorPersist(fmt.Sprintf("Panic in Generate: %v", r))
+
+ // dump stack trace into a file
+ file, err := os.Create("panic.log")
+ if err != nil {
+ logging.ErrorPersist(fmt.Sprintf("Failed to create panic log: %v", err))
+ return
+ }
+
+ defer file.Close()
+
+ stackTrace := debug.Stack()
+ if _, err := file.Write(stackTrace); err != nil {
+ logging.ErrorPersist(fmt.Sprintf("Failed to write panic log: %v", err))
+ }
+
}
}()
defer a.activeRequests.Delete(sessionID)
diff --git a/internal/llm/agent/coder.go b/internal/llm/agent/coder.go
index 8eea57041..a3db6b55c 100644
--- a/internal/llm/agent/coder.go
+++ b/internal/llm/agent/coder.go
@@ -49,7 +49,7 @@ func NewCoderAgent(
tools.NewSourcegraphTool(),
tools.NewViewTool(lspClients),
tools.NewWriteTool(lspClients, permissions),
- NewAgentTool(sessions, messages),
+ NewAgentTool(sessions, messages, lspClients),
}, otherTools...,
),
)
diff --git a/internal/llm/agent/task.go b/internal/llm/agent/task.go
index 0a072044c..fca1f223f 100644
--- a/internal/llm/agent/task.go
+++ b/internal/llm/agent/task.go
@@ -8,39 +8,40 @@ import (
"github.com/kujtimiihoxha/termai/internal/llm/models"
"github.com/kujtimiihoxha/termai/internal/llm/tools"
"github.com/kujtimiihoxha/termai/internal/lsp"
+ "github.com/kujtimiihoxha/termai/internal/message"
+ "github.com/kujtimiihoxha/termai/internal/session"
)
type taskAgent struct {
- *agent
+ Service
}
-func (c *taskAgent) Generate(ctx context.Context, sessionID string, content string) error {
- return c.generate(ctx, sessionID, content)
-}
-
-func NewTaskAgent(lspClients map[string]*lsp.Client) (Service, error) {
+func NewTaskAgent(messages message.Service, sessions session.Service, lspClients map[string]*lsp.Client) (Service, error) {
model, ok := models.SupportedModels[config.Get().Model.Coder]
if !ok {
return nil, errors.New("model not supported")
}
ctx := context.Background()
- agentProvider, titleGenerator, err := getAgentProviders(ctx, model)
+
+ agent, err := NewAgent(
+ ctx,
+ sessions,
+ messages,
+ model,
+ []tools.BaseTool{
+ tools.NewGlobTool(),
+ tools.NewGrepTool(),
+ tools.NewLsTool(),
+ tools.NewSourcegraphTool(),
+ tools.NewViewTool(lspClients),
+ },
+ )
if err != nil {
return nil, err
}
+
return &taskAgent{
- agent: &agent{
- tools: []tools.BaseTool{
- tools.NewGlobTool(),
- tools.NewGrepTool(),
- tools.NewLsTool(),
- tools.NewSourcegraphTool(),
- tools.NewViewTool(lspClients),
- },
- model: model,
- agent: agentProvider,
- titleGenerator: titleGenerator,
- },
+ agent,
}, nil
}