diff options
| author | Dax <[email protected]> | 2025-09-01 17:15:49 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-01 17:15:49 -0400 |
| commit | f993541e0b538388969defc94d08c3a7af5ef873 (patch) | |
| tree | ae9898664175faf69583e0bbb1b10135c645d798 /packages/tui/cmd | |
| parent | e2df3eb44dc8b032f74ed0273a53be5f83aaab13 (diff) | |
| download | opencode-f993541e0b538388969defc94d08c3a7af5ef873.tar.gz opencode-f993541e0b538388969defc94d08c3a7af5ef873.zip | |
Refactor to support multiple instances inside single opencode process (#2360)
This release has a bunch of minor breaking changes if you are using opencode plugins or sdk
1. storage events have been removed (we might bring this back but had some issues)
2. concept of `app` is gone - there is a new concept called `project` and endpoints to list projects and get the current project
3. plugin receives `directory` which is cwd and `worktree` which is where the root of the project is if it's a git repo
4. the session.chat function has been renamed to session.prompt in sdk. it no longer requires model to be passed in (model is now an object)
5. every endpoint takes an optional `directory` parameter to operate as though opencode is running in that directory
Diffstat (limited to 'packages/tui/cmd')
| -rw-r--r-- | packages/tui/cmd/opencode/main.go | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/packages/tui/cmd/opencode/main.go b/packages/tui/cmd/opencode/main.go index f1473e8ba..22841fc89 100644 --- a/packages/tui/cmd/opencode/main.go +++ b/packages/tui/cmd/opencode/main.go @@ -2,7 +2,6 @@ package main import ( "context" - "encoding/json" "io" "log/slog" "os" @@ -19,6 +18,7 @@ import ( "github.com/sst/opencode/internal/clipboard" "github.com/sst/opencode/internal/tui" "github.com/sst/opencode/internal/util" + "golang.org/x/sync/errgroup" ) var Version = "dev" @@ -37,14 +37,6 @@ func main() { url := os.Getenv("OPENCODE_SERVER") - appInfoStr := os.Getenv("OPENCODE_APP_INFO") - var appInfo opencode.App - err := json.Unmarshal([]byte(appInfoStr), &appInfo) - if err != nil { - slog.Error("Failed to unmarshal app info", "error", err) - os.Exit(1) - } - stat, err := os.Stdin.Stat() if err != nil { slog.Error("Failed to stat stdin", "error", err) @@ -73,17 +65,43 @@ func main() { option.WithBaseURL(url), ) - // Fetch agents from the /agent endpoint - agentsPtr, err := httpClient.App.Agents(context.Background()) + var agents []opencode.Agent + var path *opencode.Path + var project *opencode.Project + + batch := errgroup.Group{} + + batch.Go(func() error { + result, err := httpClient.Project.Current(context.Background(), opencode.ProjectCurrentParams{}) + if err != nil { + return err + } + project = result + return nil + }) + + batch.Go(func() error { + result, err := httpClient.Agent.List(context.Background(), opencode.AgentListParams{}) + if err != nil { + return err + } + agents = *result + return nil + }) + + batch.Go(func() error { + result, err := httpClient.Path.Get(context.Background(), opencode.PathGetParams{}) + if err != nil { + return err + } + path = result + return nil + }) + + err = batch.Wait() if err != nil { - slog.Error("Failed to fetch agents", "error", err) - os.Exit(1) - } - if agentsPtr == nil { - slog.Error("No agents returned from server") - os.Exit(1) + panic(err) } - agents := *agentsPtr ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -91,7 +109,7 @@ func main() { logger := slog.New(apiHandler) slog.SetDefault(logger) - slog.Debug("TUI launched", "app", appInfoStr, "agents_count", len(agents), "url", url) + slog.Debug("TUI launched") go func() { err = clipboard.Init() @@ -101,7 +119,7 @@ func main() { }() // Create main context for the application - app_, err := app.New(ctx, version, appInfo, agents, httpClient, model, prompt, agent, sessionID) + app_, err := app.New(ctx, version, project, path, agents, httpClient, model, prompt, agent, sessionID) if err != nil { panic(err) } @@ -118,12 +136,9 @@ func main() { signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT) go func() { - stream := httpClient.Event.ListStreaming(ctx) + stream := httpClient.Event.ListStreaming(ctx, opencode.EventListParams{}) for stream.Next() { evt := stream.Current().AsUnion() - if _, ok := evt.(opencode.EventListResponseEventStorageWrite); ok { - continue - } program.Send(evt) } if err := stream.Err(); err != nil { |
