1package main
2
3import (
4 "encoding/json"
5 "fmt"
6 "os"
7
8 "github.com/opencode-ai/opencode/internal/config"
9 "github.com/opencode-ai/opencode/internal/llm/models"
10)
11
12// JSONSchemaType represents a JSON Schema type
13type JSONSchemaType struct {
14 Type string `json:"type,omitempty"`
15 Description string `json:"description,omitempty"`
16 Properties map[string]any `json:"properties,omitempty"`
17 Required []string `json:"required,omitempty"`
18 AdditionalProperties any `json:"additionalProperties,omitempty"`
19 Enum []any `json:"enum,omitempty"`
20 Items map[string]any `json:"items,omitempty"`
21 OneOf []map[string]any `json:"oneOf,omitempty"`
22 AnyOf []map[string]any `json:"anyOf,omitempty"`
23 Default any `json:"default,omitempty"`
24}
25
26func main() {
27 schema := generateSchema()
28
29 // Pretty print the schema
30 encoder := json.NewEncoder(os.Stdout)
31 encoder.SetIndent("", " ")
32 if err := encoder.Encode(schema); err != nil {
33 fmt.Fprintf(os.Stderr, "Error encoding schema: %v\n", err)
34 os.Exit(1)
35 }
36}
37
38func generateSchema() map[string]any {
39 schema := map[string]any{
40 "$schema": "http://json-schema.org/draft-07/schema#",
41 "title": "OpenCode Configuration",
42 "description": "Configuration schema for the OpenCode application",
43 "type": "object",
44 "properties": map[string]any{},
45 }
46
47 // Add Data configuration
48 schema["properties"].(map[string]any)["data"] = map[string]any{
49 "type": "object",
50 "description": "Storage configuration",
51 "properties": map[string]any{
52 "directory": map[string]any{
53 "type": "string",
54 "description": "Directory where application data is stored",
55 "default": ".opencode",
56 },
57 },
58 "required": []string{"directory"},
59 }
60
61 // Add working directory
62 schema["properties"].(map[string]any)["wd"] = map[string]any{
63 "type": "string",
64 "description": "Working directory for the application",
65 }
66
67 // Add debug flags
68 schema["properties"].(map[string]any)["debug"] = map[string]any{
69 "type": "boolean",
70 "description": "Enable debug mode",
71 "default": false,
72 }
73
74 schema["properties"].(map[string]any)["debugLSP"] = map[string]any{
75 "type": "boolean",
76 "description": "Enable LSP debug mode",
77 "default": false,
78 }
79
80 schema["properties"].(map[string]any)["contextPaths"] = map[string]any{
81 "type": "array",
82 "description": "Context paths for the application",
83 "items": map[string]any{
84 "type": "string",
85 },
86 "default": []string{
87 ".github/copilot-instructions.md",
88 ".cursorrules",
89 ".cursor/rules/",
90 "CLAUDE.md",
91 "CLAUDE.local.md",
92 "opencode.md",
93 "opencode.local.md",
94 "OpenCode.md",
95 "OpenCode.local.md",
96 "OPENCODE.md",
97 "OPENCODE.local.md",
98 },
99 }
100
101 schema["properties"].(map[string]any)["tui"] = map[string]any{
102 "type": "object",
103 "description": "Terminal User Interface configuration",
104 "properties": map[string]any{
105 "theme": map[string]any{
106 "type": "string",
107 "description": "TUI theme name",
108 "default": "opencode",
109 "enum": []string{
110 "opencode",
111 "catppuccin",
112 "dracula",
113 "flexoki",
114 "gruvbox",
115 "monokai",
116 "onedark",
117 "tokyonight",
118 "tron",
119 },
120 },
121 },
122 }
123
124 // Add MCP servers
125 schema["properties"].(map[string]any)["mcpServers"] = map[string]any{
126 "type": "object",
127 "description": "Model Control Protocol server configurations",
128 "additionalProperties": map[string]any{
129 "type": "object",
130 "description": "MCP server configuration",
131 "properties": map[string]any{
132 "command": map[string]any{
133 "type": "string",
134 "description": "Command to execute for the MCP server",
135 },
136 "env": map[string]any{
137 "type": "array",
138 "description": "Environment variables for the MCP server",
139 "items": map[string]any{
140 "type": "string",
141 },
142 },
143 "args": map[string]any{
144 "type": "array",
145 "description": "Command arguments for the MCP server",
146 "items": map[string]any{
147 "type": "string",
148 },
149 },
150 "type": map[string]any{
151 "type": "string",
152 "description": "Type of MCP server",
153 "enum": []string{"stdio", "sse"},
154 "default": "stdio",
155 },
156 "url": map[string]any{
157 "type": "string",
158 "description": "URL for SSE type MCP servers",
159 },
160 "headers": map[string]any{
161 "type": "object",
162 "description": "HTTP headers for SSE type MCP servers",
163 "additionalProperties": map[string]any{
164 "type": "string",
165 },
166 },
167 },
168 "required": []string{"command"},
169 },
170 }
171
172 // Add providers
173 providerSchema := map[string]any{
174 "type": "object",
175 "description": "LLM provider configurations",
176 "additionalProperties": map[string]any{
177 "type": "object",
178 "description": "Provider configuration",
179 "properties": map[string]any{
180 "apiKey": map[string]any{
181 "type": "string",
182 "description": "API key for the provider",
183 },
184 "disabled": map[string]any{
185 "type": "boolean",
186 "description": "Whether the provider is disabled",
187 "default": false,
188 },
189 },
190 },
191 }
192
193 // Add known providers
194 knownProviders := []string{
195 string(models.ProviderAnthropic),
196 string(models.ProviderOpenAI),
197 string(models.ProviderGemini),
198 string(models.ProviderGROQ),
199 string(models.ProviderOpenRouter),
200 string(models.ProviderBedrock),
201 string(models.ProviderAzure),
202 }
203
204 providerSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["provider"] = map[string]any{
205 "type": "string",
206 "description": "Provider type",
207 "enum": knownProviders,
208 }
209
210 schema["properties"].(map[string]any)["providers"] = providerSchema
211
212 // Add agents
213 agentSchema := map[string]any{
214 "type": "object",
215 "description": "Agent configurations",
216 "additionalProperties": map[string]any{
217 "type": "object",
218 "description": "Agent configuration",
219 "properties": map[string]any{
220 "model": map[string]any{
221 "type": "string",
222 "description": "Model ID for the agent",
223 },
224 "maxTokens": map[string]any{
225 "type": "integer",
226 "description": "Maximum tokens for the agent",
227 "minimum": 1,
228 },
229 "reasoningEffort": map[string]any{
230 "type": "string",
231 "description": "Reasoning effort for models that support it (OpenAI, Anthropic)",
232 "enum": []string{"low", "medium", "high"},
233 },
234 },
235 "required": []string{"model"},
236 },
237 }
238
239 // Add model enum
240 modelEnum := []string{}
241 for modelID := range models.SupportedModels {
242 modelEnum = append(modelEnum, string(modelID))
243 }
244 agentSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["model"].(map[string]any)["enum"] = modelEnum
245
246 // Add specific agent properties
247 agentProperties := map[string]any{}
248 knownAgents := []string{
249 string(config.AgentCoder),
250 string(config.AgentTask),
251 string(config.AgentTitle),
252 }
253
254 for _, agentName := range knownAgents {
255 agentProperties[agentName] = map[string]any{
256 "$ref": "#/definitions/agent",
257 }
258 }
259
260 // Create a combined schema that allows both specific agents and additional ones
261 combinedAgentSchema := map[string]any{
262 "type": "object",
263 "description": "Agent configurations",
264 "properties": agentProperties,
265 "additionalProperties": agentSchema["additionalProperties"],
266 }
267
268 schema["properties"].(map[string]any)["agents"] = combinedAgentSchema
269 schema["definitions"] = map[string]any{
270 "agent": agentSchema["additionalProperties"],
271 }
272
273 // Add LSP configuration
274 schema["properties"].(map[string]any)["lsp"] = map[string]any{
275 "type": "object",
276 "description": "Language Server Protocol configurations",
277 "additionalProperties": map[string]any{
278 "type": "object",
279 "description": "LSP configuration for a language",
280 "properties": map[string]any{
281 "disabled": map[string]any{
282 "type": "boolean",
283 "description": "Whether the LSP is disabled",
284 "default": false,
285 },
286 "command": map[string]any{
287 "type": "string",
288 "description": "Command to execute for the LSP server",
289 },
290 "args": map[string]any{
291 "type": "array",
292 "description": "Command arguments for the LSP server",
293 "items": map[string]any{
294 "type": "string",
295 },
296 },
297 "options": map[string]any{
298 "type": "object",
299 "description": "Additional options for the LSP server",
300 },
301 },
302 "required": []string{"command"},
303 },
304 }
305
306 return schema
307}