summaryrefslogtreecommitdiffhomepage
path: root/internal/app
diff options
context:
space:
mode:
authorKujtim Hoxha <[email protected]>2025-04-16 20:06:23 +0200
committerKujtim Hoxha <[email protected]>2025-04-21 13:42:00 +0200
commitbbfa60c787f2ec459f1689b9a650ddbec9693ed9 (patch)
treef7f2aa31c460c8cc22ec40cc299c386277152241 /internal/app
parent76b4065f17b87a63092acfd98c997bab53700b35 (diff)
downloadopencode-bbfa60c787f2ec459f1689b9a650ddbec9693ed9.tar.gz
opencode-bbfa60c787f2ec459f1689b9a650ddbec9693ed9.zip
reimplement agent,provider and add file history
Diffstat (limited to 'internal/app')
-rw-r--r--internal/app/app.go17
-rw-r--r--internal/app/lsp.go19
2 files changed, 20 insertions, 16 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
index ca23b3c40..1c16ccc11 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -7,6 +7,7 @@ import (
"sync"
"time"
+ "github.com/kujtimiihoxha/termai/internal/config"
"github.com/kujtimiihoxha/termai/internal/db"
"github.com/kujtimiihoxha/termai/internal/history"
"github.com/kujtimiihoxha/termai/internal/llm/agent"
@@ -20,7 +21,7 @@ import (
type App struct {
Sessions session.Service
Messages message.Service
- Files history.Service
+ History history.Service
Permissions permission.Service
CoderAgent agent.Service
@@ -43,7 +44,7 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
app := &App{
Sessions: sessions,
Messages: messages,
- Files: files,
+ History: files,
Permissions: permission.NewPermissionService(),
LSPClients: make(map[string]*lsp.Client),
}
@@ -51,11 +52,17 @@ func New(ctx context.Context, conn *sql.DB) (*App, error) {
app.initLSPClients(ctx)
var err error
- app.CoderAgent, err = agent.NewCoderAgent(
- app.Permissions,
+ app.CoderAgent, err = agent.NewAgent(
+ config.AgentCoder,
app.Sessions,
app.Messages,
- app.LSPClients,
+ agent.CoderAgentTools(
+ app.Permissions,
+ app.Sessions,
+ app.Messages,
+ app.History,
+ app.LSPClients,
+ ),
)
if err != nil {
logging.Error("Failed to create coder agent", err)
diff --git a/internal/app/lsp.go b/internal/app/lsp.go
index 4e0568f07..4a762f1a1 100644
--- a/internal/app/lsp.go
+++ b/internal/app/lsp.go
@@ -22,16 +22,17 @@ func (app *App) initLSPClients(ctx context.Context) {
// createAndStartLSPClient creates a new LSP client, initializes it, and starts its workspace watcher
func (app *App) createAndStartLSPClient(ctx context.Context, name string, command string, args ...string) {
// Create a specific context for initialization with a timeout
- initCtx, initCancel := context.WithTimeout(context.Background(), 30*time.Second)
- defer initCancel()
// Create the LSP client
- lspClient, err := lsp.NewClient(initCtx, command, args...)
+ lspClient, err := lsp.NewClient(ctx, command, args...)
if err != nil {
logging.Error("Failed to create LSP client for", name, err)
return
+
}
+ initCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
+ defer cancel()
// Initialize with the initialization context
_, err = lspClient.InitializeLSPClient(initCtx, config.WorkingDirectory())
if err != nil {
@@ -64,14 +65,10 @@ func (app *App) createAndStartLSPClient(ctx context.Context, name string, comman
// runWorkspaceWatcher executes the workspace watcher for an LSP client
func (app *App) runWorkspaceWatcher(ctx context.Context, name string, workspaceWatcher *watcher.WorkspaceWatcher) {
defer app.watcherWG.Done()
- defer func() {
- if r := recover(); r != nil {
- logging.Error("LSP client crashed", "client", name, "panic", r)
-
- // Try to restart the client
- app.restartLSPClient(ctx, name)
- }
- }()
+ defer logging.RecoverPanic("LSP-"+name, func() {
+ // Try to restart the client
+ app.restartLSPClient(ctx, name)
+ })
workspaceWatcher.WatchWorkspace(ctx, config.WorkingDirectory())
logging.Info("Workspace watcher stopped", "client", name)