summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-29 15:22:25 -0500
committeradamdottv <[email protected]>2025-05-29 15:22:25 -0500
commit1c01ee48340c524af9223fac43f21d3a545e4583 (patch)
treef33bde056ef0d65828f15a9199ad0b910f65d74f /cmd
parent005d6e0bde9a42e2bebee7b712b0fe9a7be23499 (diff)
downloadopencode-1c01ee48340c524af9223fac43f21d3a545e4583.tar.gz
opencode-1c01ee48340c524af9223fac43f21d3a545e4583.zip
wip: refactoring tui
Diffstat (limited to 'cmd')
-rw-r--r--cmd/root.go20
-rw-r--r--cmd/schema/README.md65
-rw-r--r--cmd/schema/main.go337
3 files changed, 5 insertions, 417 deletions
diff --git a/cmd/root.go b/cmd/root.go
index f9a55babe..85258d591 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -13,7 +13,6 @@ import (
zone "github.com/lrstanley/bubblezone"
"github.com/spf13/cobra"
"github.com/sst/opencode/internal/config"
- "github.com/sst/opencode/internal/logging"
"github.com/sst/opencode/internal/pubsub"
"github.com/sst/opencode/internal/tui"
"github.com/sst/opencode/internal/tui/app"
@@ -107,9 +106,9 @@ to assist developers in writing, debugging, and understanding code directly from
// Set up message handling for the TUI
go func() {
defer tuiWg.Done()
- defer logging.RecoverPanic("TUI-message-handler", func() {
- attemptTUIRecovery(program)
- })
+ // defer logging.RecoverPanic("TUI-message-handler", func() {
+ // attemptTUIRecovery(program)
+ // })
for {
select {
@@ -157,15 +156,6 @@ to assist developers in writing, debugging, and understanding code directly from
},
}
-// attemptTUIRecovery tries to recover the TUI after a panic
-func attemptTUIRecovery(program *tea.Program) {
- slog.Info("Attempting to recover TUI after panic")
-
- // We could try to restart the TUI or gracefully exit
- // For now, we'll just quit the program to avoid further issues
- program.Quit()
-}
-
func setupSubscriber[T any](
ctx context.Context,
wg *sync.WaitGroup,
@@ -176,7 +166,7 @@ func setupSubscriber[T any](
wg.Add(1)
go func() {
defer wg.Done()
- defer logging.RecoverPanic(fmt.Sprintf("subscription-%s", name), nil)
+ // defer logging.RecoverPanic(fmt.Sprintf("subscription-%s", name), nil)
subCh := subscriber(ctx)
if subCh == nil {
@@ -224,7 +214,7 @@ func setupSubscriptions(app *app.App, parentCtx context.Context) (chan tea.Msg,
waitCh := make(chan struct{})
go func() {
- defer logging.RecoverPanic("subscription-cleanup", nil)
+ // defer logging.RecoverPanic("subscription-cleanup", nil)
wg.Wait()
close(waitCh)
}()
diff --git a/cmd/schema/README.md b/cmd/schema/README.md
deleted file mode 100644
index e448ea0cb..000000000
--- a/cmd/schema/README.md
+++ /dev/null
@@ -1,65 +0,0 @@
-# OpenCode Configuration Schema Generator
-
-This tool generates a JSON Schema for the OpenCode configuration file. The schema can be used to validate configuration files and provide autocompletion in editors that support JSON Schema.
-
-## Usage
-
-```bash
-go run cmd/schema/main.go > opencode-schema.json
-```
-
-This will generate a JSON Schema file that can be used to validate configuration files.
-
-## Schema Features
-
-The generated schema includes:
-
-- All configuration options with descriptions
-- Default values where applicable
-- Validation for enum values (e.g., model IDs, provider types)
-- Required fields
-- Type checking
-
-## Using the Schema
-
-You can use the generated schema in several ways:
-
-1. **Editor Integration**: Many editors (VS Code, JetBrains IDEs, etc.) support JSON Schema for validation and autocompletion. You can configure your editor to use the generated schema for `.opencode.json` files.
-
-2. **Validation Tools**: You can use tools like [jsonschema](https://github.com/Julian/jsonschema) to validate your configuration files against the schema.
-
-3. **Documentation**: The schema serves as documentation for the configuration options.
-
-## Example Configuration
-
-Here's an example configuration that conforms to the schema:
-
-```json
-{
- "data": {
- "directory": ".opencode"
- },
- "debug": false,
- "providers": {
- "anthropic": {
- "apiKey": "your-api-key"
- }
- },
- "agents": {
- "primary": {
- "model": "claude-3.7-sonnet",
- "maxTokens": 5000,
- "reasoningEffort": "medium"
- },
- "task": {
- "model": "claude-3.7-sonnet",
- "maxTokens": 5000
- },
- "title": {
- "model": "claude-3.7-sonnet",
- "maxTokens": 80
- }
- }
-}
-```
-
diff --git a/cmd/schema/main.go b/cmd/schema/main.go
deleted file mode 100644
index 854dbfe7c..000000000
--- a/cmd/schema/main.go
+++ /dev/null
@@ -1,337 +0,0 @@
-package main
-
-import (
- "encoding/json"
- "fmt"
- "os"
-
- "github.com/sst/opencode/internal/config"
- "github.com/sst/opencode/internal/llm/models"
-)
-
-// JSONSchemaType represents a JSON Schema type
-type JSONSchemaType struct {
- Type string `json:"type,omitempty"`
- Description string `json:"description,omitempty"`
- Properties map[string]any `json:"properties,omitempty"`
- Required []string `json:"required,omitempty"`
- AdditionalProperties any `json:"additionalProperties,omitempty"`
- Enum []any `json:"enum,omitempty"`
- Items map[string]any `json:"items,omitempty"`
- OneOf []map[string]any `json:"oneOf,omitempty"`
- AnyOf []map[string]any `json:"anyOf,omitempty"`
- Default any `json:"default,omitempty"`
-}
-
-func main() {
- schema := generateSchema()
-
- // Pretty print the schema
- encoder := json.NewEncoder(os.Stdout)
- encoder.SetIndent("", " ")
- if err := encoder.Encode(schema); err != nil {
- fmt.Fprintf(os.Stderr, "Error encoding schema: %v\n", err)
- os.Exit(1)
- }
-}
-
-func generateSchema() map[string]any {
- schema := map[string]any{
- "$schema": "http://json-schema.org/draft-07/schema#",
- "title": "OpenCode Configuration",
- "description": "Configuration schema for the OpenCode application",
- "type": "object",
- "properties": map[string]any{},
- }
-
- // Add Data configuration
- schema["properties"].(map[string]any)["data"] = map[string]any{
- "type": "object",
- "description": "Storage configuration",
- "properties": map[string]any{
- "directory": map[string]any{
- "type": "string",
- "description": "Directory where application data is stored",
- "default": ".opencode",
- },
- },
- "required": []string{"directory"},
- }
-
- // Add working directory
- schema["properties"].(map[string]any)["wd"] = map[string]any{
- "type": "string",
- "description": "Working directory for the application",
- }
-
- // Add debug flags
- schema["properties"].(map[string]any)["debug"] = map[string]any{
- "type": "boolean",
- "description": "Enable debug mode",
- "default": false,
- }
-
- schema["properties"].(map[string]any)["debugLSP"] = map[string]any{
- "type": "boolean",
- "description": "Enable LSP debug mode",
- "default": false,
- }
-
- schema["properties"].(map[string]any)["contextPaths"] = map[string]any{
- "type": "array",
- "description": "Context paths for the application",
- "items": map[string]any{
- "type": "string",
- },
- "default": []string{
- ".github/copilot-instructions.md",
- ".cursorrules",
- ".cursor/rules/",
- "CLAUDE.md",
- "CLAUDE.local.md",
- "opencode.md",
- "opencode.local.md",
- "OpenCode.md",
- "OpenCode.local.md",
- "OPENCODE.md",
- "OPENCODE.local.md",
- },
- }
-
- schema["properties"].(map[string]any)["tui"] = map[string]any{
- "type": "object",
- "description": "Terminal User Interface configuration",
- "properties": map[string]any{
- "theme": map[string]any{
- "type": "string",
- "description": "TUI theme name",
- "default": "opencode",
- "enum": []string{
- "opencode",
- "ayu",
- "catppuccin",
- "dracula",
- "flexoki",
- "gruvbox",
- "monokai",
- "onedark",
- "tokyonight",
- "tron",
- "custom",
- },
- },
- "customTheme": map[string]any{
- "type": "object",
- "description": "Custom theme color definitions",
- "additionalProperties": map[string]any{
- "oneOf": []map[string]any{
- {
- "type": "string",
- "pattern": "^#[0-9a-fA-F]{6}$",
- },
- {
- "type": "object",
- "properties": map[string]any{
- "dark": map[string]any{
- "type": "string",
- "pattern": "^#[0-9a-fA-F]{6}$",
- },
- "light": map[string]any{
- "type": "string",
- "pattern": "^#[0-9a-fA-F]{6}$",
- },
- },
- "required": []string{"dark", "light"},
- "additionalProperties": false,
- },
- },
- },
- },
- },
- }
-
- // Add MCP servers
- schema["properties"].(map[string]any)["mcpServers"] = map[string]any{
- "type": "object",
- "description": "Model Control Protocol server configurations",
- "additionalProperties": map[string]any{
- "type": "object",
- "description": "MCP server configuration",
- "properties": map[string]any{
- "command": map[string]any{
- "type": "string",
- "description": "Command to execute for the MCP server",
- },
- "env": map[string]any{
- "type": "array",
- "description": "Environment variables for the MCP server",
- "items": map[string]any{
- "type": "string",
- },
- },
- "args": map[string]any{
- "type": "array",
- "description": "Command arguments for the MCP server",
- "items": map[string]any{
- "type": "string",
- },
- },
- "type": map[string]any{
- "type": "string",
- "description": "Type of MCP server",
- "enum": []string{"stdio", "sse"},
- "default": "stdio",
- },
- "url": map[string]any{
- "type": "string",
- "description": "URL for SSE type MCP servers",
- },
- "headers": map[string]any{
- "type": "object",
- "description": "HTTP headers for SSE type MCP servers",
- "additionalProperties": map[string]any{
- "type": "string",
- },
- },
- },
- "required": []string{"command"},
- },
- }
-
- // Add providers
- providerSchema := map[string]any{
- "type": "object",
- "description": "LLM provider configurations",
- "additionalProperties": map[string]any{
- "type": "object",
- "description": "Provider configuration",
- "properties": map[string]any{
- "apiKey": map[string]any{
- "type": "string",
- "description": "API key for the provider",
- },
- "disabled": map[string]any{
- "type": "boolean",
- "description": "Whether the provider is disabled",
- "default": false,
- },
- },
- },
- }
-
- // Add known providers
- knownProviders := []string{
- string(models.ProviderAnthropic),
- string(models.ProviderOpenAI),
- string(models.ProviderGemini),
- string(models.ProviderGROQ),
- string(models.ProviderOpenRouter),
- string(models.ProviderBedrock),
- string(models.ProviderAzure),
- string(models.ProviderVertexAI),
- }
-
- providerSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["provider"] = map[string]any{
- "type": "string",
- "description": "Provider type",
- "enum": knownProviders,
- }
-
- schema["properties"].(map[string]any)["providers"] = providerSchema
-
- // Add agents
- agentSchema := map[string]any{
- "type": "object",
- "description": "Agent configurations",
- "additionalProperties": map[string]any{
- "type": "object",
- "description": "Agent configuration",
- "properties": map[string]any{
- "model": map[string]any{
- "type": "string",
- "description": "Model ID for the agent",
- },
- "maxTokens": map[string]any{
- "type": "integer",
- "description": "Maximum tokens for the agent",
- "minimum": 1,
- },
- "reasoningEffort": map[string]any{
- "type": "string",
- "description": "Reasoning effort for models that support it (OpenAI, Anthropic)",
- "enum": []string{"low", "medium", "high"},
- },
- },
- "required": []string{"model"},
- },
- }
-
- // Add model enum
- modelEnum := []string{}
- for modelID := range models.SupportedModels {
- modelEnum = append(modelEnum, string(modelID))
- }
- agentSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["model"].(map[string]any)["enum"] = modelEnum
-
- // Add specific agent properties
- agentProperties := map[string]any{}
- knownAgents := []string{
- string(config.AgentPrimary),
- string(config.AgentTask),
- string(config.AgentTitle),
- }
-
- for _, agentName := range knownAgents {
- agentProperties[agentName] = map[string]any{
- "$ref": "#/definitions/agent",
- }
- }
-
- // Create a combined schema that allows both specific agents and additional ones
- combinedAgentSchema := map[string]any{
- "type": "object",
- "description": "Agent configurations",
- "properties": agentProperties,
- "additionalProperties": agentSchema["additionalProperties"],
- }
-
- schema["properties"].(map[string]any)["agents"] = combinedAgentSchema
- schema["definitions"] = map[string]any{
- "agent": agentSchema["additionalProperties"],
- }
-
- // Add LSP configuration
- schema["properties"].(map[string]any)["lsp"] = map[string]any{
- "type": "object",
- "description": "Language Server Protocol configurations",
- "additionalProperties": map[string]any{
- "type": "object",
- "description": "LSP configuration for a language",
- "properties": map[string]any{
- "disabled": map[string]any{
- "type": "boolean",
- "description": "Whether the LSP is disabled",
- "default": false,
- },
- "command": map[string]any{
- "type": "string",
- "description": "Command to execute for the LSP server",
- },
- "args": map[string]any{
- "type": "array",
- "description": "Command arguments for the LSP server",
- "items": map[string]any{
- "type": "string",
- },
- },
- "options": map[string]any{
- "type": "object",
- "description": "Additional options for the LSP server",
- },
- },
- "required": []string{"command"},
- },
- }
-
- return schema
-}