The open source coding agent.
TypeScript
wip: refactoring tui
adamdottvca87b2806f4a
diff --git a/packages/tui/cmd/root.go b/packages/tui/cmd/root.goindex 6f0c00f3093..d952fc3a3dc 100644--- a/packages/tui/cmd/root.go+++ b/packages/tui/cmd/root.go@@ -16,7 +16,6 @@ import ("github.com/sst/opencode/internal/pubsub""github.com/sst/opencode/internal/tui""github.com/sst/opencode/internal/tui/app"- "github.com/sst/opencode/internal/version")var rootCmd = &cobra.Command{@@ -26,16 +25,6 @@ var rootCmd = &cobra.Command{It provides an interactive chat interface with AI capabilities, code analysis, and LSP integrationto assist developers in writing, debugging, and understanding code directly from the terminal.`,RunE: func(cmd *cobra.Command, args []string) error {- // If the help flag is set, show the help message- if cmd.Flag("help").Changed {- cmd.Help()- return nil- }- if cmd.Flag("version").Changed {- fmt.Println(version.Version)- return nil- }-// Setup logging// file, err := os.OpenFile("debug.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)// if err != nil {diff --git a/packages/tui/internal/format/format.go b/packages/tui/internal/format/format.godeleted file mode 100644index 321f5c10266..00000000000--- a/packages/tui/internal/format/format.go+++ /dev/null@@ -1,46 +0,0 @@-package format--import (- "encoding/json"- "fmt"-)--// OutputFormat represents the format for non-interactive mode output-type OutputFormat string--const (- // TextFormat is plain text output (default)- TextFormat OutputFormat = "text"-- // JSONFormat is output wrapped in a JSON object- JSONFormat OutputFormat = "json"-)--// IsValid checks if the output format is valid-func (f OutputFormat) IsValid() bool {- return f == TextFormat || f == JSONFormat-}--// String returns the string representation of the output format-func (f OutputFormat) String() string {- return string(f)-}--// FormatOutput formats the given content according to the specified format-func FormatOutput(content string, format OutputFormat) (string, error) {- switch format {- case TextFormat:- return content, nil- case JSONFormat:- jsonData := map[string]string{- "response": content,- }- jsonBytes, err := json.MarshalIndent(jsonData, "", " ")- if err != nil {- return "", fmt.Errorf("failed to marshal JSON: %w", err)- }- return string(jsonBytes), nil- default:- return "", fmt.Errorf("unsupported output format: %s", format)- }-}diff --git a/packages/tui/internal/format/format_test.go b/packages/tui/internal/format/format_test.godeleted file mode 100644index 04054a7c497..00000000000--- a/packages/tui/internal/format/format_test.go+++ /dev/null@@ -1,90 +0,0 @@-package format--import (- "testing"-)--func TestOutputFormat_IsValid(t *testing.T) {- t.Parallel()-- tests := []struct {- name string- format OutputFormat- want bool- }{- {- name: "text format",- format: TextFormat,- want: true,- },- {- name: "json format",- format: JSONFormat,- want: true,- },- {- name: "invalid format",- format: "invalid",- want: false,- },- }-- for _, tt := range tests {- tt := tt- t.Run(tt.name, func(t *testing.T) {- t.Parallel()- if got := tt.format.IsValid(); got != tt.want {- t.Errorf("OutputFormat.IsValid() = %v, want %v", got, tt.want)- }- })- }-}--func TestFormatOutput(t *testing.T) {- t.Parallel()-- tests := []struct {- name string- content string- format OutputFormat- want string- wantErr bool- }{- {- name: "text format",- content: "test content",- format: TextFormat,- want: "test content",- wantErr: false,- },- {- name: "json format",- content: "test content",- format: JSONFormat,- want: "{\n \"response\": \"test content\"\n}",- wantErr: false,- },- {- name: "invalid format",- content: "test content",- format: "invalid",- want: "",- wantErr: true,- },- }-- for _, tt := range tests {- tt := tt- t.Run(tt.name, func(t *testing.T) {- t.Parallel()- got, err := FormatOutput(tt.content, tt.format)- if (err != nil) != tt.wantErr {- t.Errorf("FormatOutput() error = %v, wantErr %v", err, tt.wantErr)- return- }- if got != tt.want {- t.Errorf("FormatOutput() = %v, want %v", got, tt.want)- }- })- }-}diff --git a/packages/tui/internal/tui/components/chat/chat.go b/packages/tui/internal/tui/components/chat/chat.goindex 2fabea43d6c..ebebac25299 100644--- a/packages/tui/internal/tui/components/chat/chat.go+++ b/packages/tui/internal/tui/components/chat/chat.go@@ -10,7 +10,6 @@ import ("github.com/sst/opencode/internal/tui/app""github.com/sst/opencode/internal/tui/styles""github.com/sst/opencode/internal/tui/theme"- "github.com/sst/opencode/internal/version")type SendMsg struct {@@ -97,7 +96,7 @@ func logo(width int) string {versionText := baseStyle.Foreground(t.TextMuted()).- Render(version.Version)+ Render("v0.0.1") // TODO: get version from serverreturn baseStyle.Bold(true).diff --git a/packages/tui/internal/tui/components/core/status.go b/packages/tui/internal/tui/components/core/status.goindex ce9cddf0dcd..fd47a5701c7 100644--- a/packages/tui/internal/tui/components/core/status.go+++ b/packages/tui/internal/tui/components/core/status.go@@ -145,9 +145,6 @@ func formatTokensAndCost(tokens float32, contextWindow float32, cost float32) stfunc (m statusCmp) View() string {t := theme.CurrentTheme()- // modelID := config.Get().Agents[config.AgentPrimary].Model- // model := models.SupportedModels[modelID]-// Initialize the help widgetstatus := getHelpWidget("")diff --git a/packages/tui/internal/version/version.go b/packages/tui/internal/version/version.godeleted file mode 100644index 69fd5282b2c..00000000000--- a/packages/tui/internal/version/version.go+++ /dev/null@@ -1,25 +0,0 @@-package version--import "runtime/debug"--// Build-time parameters set via -ldflags-var Version = "unknown"--// A user may install pug using `go install github.com/sst/opencode@latest`.-// without -ldflags, in which case the version above is unset. As a workaround-// we use the embedded build version that *is* set when using `go install` (and-// is only set for `go install` and not for `go build`).-func init() {- info, ok := debug.ReadBuildInfo()- if !ok {- // < go v1.18- return- }- mainVersion := info.Main.Version- if mainVersion == "" || mainVersion == "(devel)" {- // bin not built using `go install`- return- }- // bin built using `go install`- Version = mainVersion-}