Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.

Commit 1cdd24f

Browse files
committed
minor fixes
1 parent f6be348 commit 1cdd24f

File tree

6 files changed

+49
-27
lines changed

6 files changed

+49
-27
lines changed

internal/app/app.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
4848
LSPClients: make(map[string]*lsp.Client),
4949
}
5050

51+
app.initLSPClients(ctx)
52+
5153
var err error
5254
app.CoderAgent, err = agent.NewCoderAgent(
53-
5455
app.Permissions,
5556
app.Sessions,
5657
app.Messages,
@@ -61,8 +62,6 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
6162
return nil, err
6263
}
6364

64-
app.initLSPClients(ctx)
65-
6665
return app, nil
6766
}
6867

internal/config/config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,8 @@ func Get() *Config {
272272

273273
// WorkingDirectory returns the current working directory from the configuration.
274274
func WorkingDirectory() string {
275-
return viper.GetString("wd")
275+
if cfg == nil {
276+
panic("config not loaded")
277+
}
278+
return cfg.WorkingDir
276279
}

internal/llm/agent/agent-tool.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (b *agentTool) Run(ctx context.Context, call tools.ToolCall) (tools.ToolRes
5353
return tools.ToolResponse{}, fmt.Errorf("session_id and message_id are required")
5454
}
5555

56-
agent, err := NewTaskAgent(b.lspClients)
56+
agent, err := NewTaskAgent(b.messages, b.sessions, b.lspClients)
5757
if err != nil {
5858
return tools.ToolResponse{}, fmt.Errorf("error creating agent: %s", err)
5959
}
@@ -105,9 +105,11 @@ func (b *agentTool) Run(ctx context.Context, call tools.ToolCall) (tools.ToolRes
105105
func NewAgentTool(
106106
Sessions session.Service,
107107
Messages message.Service,
108+
LspClients map[string]*lsp.Client,
108109
) tools.BaseTool {
109110
return &agentTool{
110-
sessions: Sessions,
111-
messages: Messages,
111+
sessions: Sessions,
112+
messages: Messages,
113+
lspClients: LspClients,
112114
}
113115
}

internal/llm/agent/agent.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"os"
8+
"runtime/debug"
79
"strings"
810
"sync"
911

@@ -88,6 +90,21 @@ func (a *agent) Generate(ctx context.Context, sessionID string, content string)
8890
defer func() {
8991
if r := recover(); r != nil {
9092
logging.ErrorPersist(fmt.Sprintf("Panic in Generate: %v", r))
93+
94+
// dump stack trace into a file
95+
file, err := os.Create("panic.log")
96+
if err != nil {
97+
logging.ErrorPersist(fmt.Sprintf("Failed to create panic log: %v", err))
98+
return
99+
}
100+
101+
defer file.Close()
102+
103+
stackTrace := debug.Stack()
104+
if _, err := file.Write(stackTrace); err != nil {
105+
logging.ErrorPersist(fmt.Sprintf("Failed to write panic log: %v", err))
106+
}
107+
91108
}
92109
}()
93110
defer a.activeRequests.Delete(sessionID)

internal/llm/agent/coder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCoderAgent(
4949
tools.NewSourcegraphTool(),
5050
tools.NewViewTool(lspClients),
5151
tools.NewWriteTool(lspClients, permissions),
52-
NewAgentTool(sessions, messages),
52+
NewAgentTool(sessions, messages, lspClients),
5353
}, otherTools...,
5454
),
5555
)

internal/llm/agent/task.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,40 @@ import (
88
"github.com/kujtimiihoxha/termai/internal/llm/models"
99
"github.com/kujtimiihoxha/termai/internal/llm/tools"
1010
"github.com/kujtimiihoxha/termai/internal/lsp"
11+
"github.com/kujtimiihoxha/termai/internal/message"
12+
"github.com/kujtimiihoxha/termai/internal/session"
1113
)
1214

1315
type taskAgent struct {
14-
*agent
16+
Service
1517
}
1618

17-
func (c *taskAgent) Generate(ctx context.Context, sessionID string, content string) error {
18-
return c.generate(ctx, sessionID, content)
19-
}
20-
21-
func NewTaskAgent(lspClients map[string]*lsp.Client) (Service, error) {
19+
func NewTaskAgent(messages message.Service, sessions session.Service, lspClients map[string]*lsp.Client) (Service, error) {
2220
model, ok := models.SupportedModels[config.Get().Model.Coder]
2321
if !ok {
2422
return nil, errors.New("model not supported")
2523
}
2624

2725
ctx := context.Background()
28-
agentProvider, titleGenerator, err := getAgentProviders(ctx, model)
26+
27+
agent, err := NewAgent(
28+
ctx,
29+
sessions,
30+
messages,
31+
model,
32+
[]tools.BaseTool{
33+
tools.NewGlobTool(),
34+
tools.NewGrepTool(),
35+
tools.NewLsTool(),
36+
tools.NewSourcegraphTool(),
37+
tools.NewViewTool(lspClients),
38+
},
39+
)
2940
if err != nil {
3041
return nil, err
3142
}
43+
3244
return &taskAgent{
33-
agent: &agent{
34-
tools: []tools.BaseTool{
35-
tools.NewGlobTool(),
36-
tools.NewGrepTool(),
37-
tools.NewLsTool(),
38-
tools.NewSourcegraphTool(),
39-
tools.NewViewTool(lspClients),
40-
},
41-
model: model,
42-
agent: agentProvider,
43-
titleGenerator: titleGenerator,
44-
},
45+
agent,
4546
}, nil
4647
}

0 commit comments

Comments
 (0)