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 // Add MCP servers
102 schema["properties"].(map[string]any)["mcpServers"] = map[string]any{
103 "type": "object",
104 "description": "Model Control Protocol server configurations",
105 "additionalProperties": map[string]any{
106 "type": "object",
107 "description": "MCP server configuration",
108 "properties": map[string]any{
109 "command": map[string]any{
110 "type": "string",
111 "description": "Command to execute for the MCP server",
112 },
113 "env": map[string]any{
114 "type": "array",
115 "description": "Environment variables for the MCP server",
116 "items": map[string]any{
117 "type": "string",
118 },
119 },
120 "args": map[string]any{
121 "type": "array",
122 "description": "Command arguments for the MCP server",
123 "items": map[string]any{
124 "type": "string",
125 },
126 },
127 "type": map[string]any{
128 "type": "string",
129 "description": "Type of MCP server",
130 "enum": []string{"stdio", "sse"},
131 "default": "stdio",
132 },
133 "url": map[string]any{
134 "type": "string",
135 "description": "URL for SSE type MCP servers",
136 },
137 "headers": map[string]any{
138 "type": "object",
139 "description": "HTTP headers for SSE type MCP servers",
140 "additionalProperties": map[string]any{
141 "type": "string",
142 },
143 },
144 },
145 "required": []string{"command"},
146 },
147 }
148
149 // Add providers
150 providerSchema := map[string]any{
151 "type": "object",
152 "description": "LLM provider configurations",
153 "additionalProperties": map[string]any{
154 "type": "object",
155 "description": "Provider configuration",
156 "properties": map[string]any{
157 "apiKey": map[string]any{
158 "type": "string",
159 "description": "API key for the provider",
160 },
161 "disabled": map[string]any{
162 "type": "boolean",
163 "description": "Whether the provider is disabled",
164 "default": false,
165 },
166 },
167 },
168 }
169
170 // Add known providers
171 knownProviders := []string{
172 string(models.ProviderAnthropic),
173 string(models.ProviderOpenAI),
174 string(models.ProviderGemini),
175 string(models.ProviderGROQ),
176 string(models.ProviderBedrock),
177 string(models.ProviderAzure),
178 }
179
180 providerSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["provider"] = map[string]any{
181 "type": "string",
182 "description": "Provider type",
183 "enum": knownProviders,
184 }
185
186 schema["properties"].(map[string]any)["providers"] = providerSchema
187
188 // Add agents
189 agentSchema := map[string]any{
190 "type": "object",
191 "description": "Agent configurations",
192 "additionalProperties": map[string]any{
193 "type": "object",
194 "description": "Agent configuration",
195 "properties": map[string]any{
196 "model": map[string]any{
197 "type": "string",
198 "description": "Model ID for the agent",
199 },
200 "maxTokens": map[string]any{
201 "type": "integer",
202 "description": "Maximum tokens for the agent",
203 "minimum": 1,
204 },
205 "reasoningEffort": map[string]any{
206 "type": "string",
207 "description": "Reasoning effort for models that support it (OpenAI, Anthropic)",
208 "enum": []string{"low", "medium", "high"},
209 },
210 },
211 "required": []string{"model"},
212 },
213 }
214
215 // Add model enum
216 modelEnum := []string{}
217 for modelID := range models.SupportedModels {
218 modelEnum = append(modelEnum, string(modelID))
219 }
220 agentSchema["additionalProperties"].(map[string]any)["properties"].(map[string]any)["model"].(map[string]any)["enum"] = modelEnum
221
222 // Add specific agent properties
223 agentProperties := map[string]any{}
224 knownAgents := []string{
225 string(config.AgentCoder),
226 string(config.AgentTask),
227 string(config.AgentTitle),
228 }
229
230 for _, agentName := range knownAgents {
231 agentProperties[agentName] = map[string]any{
232 "$ref": "#/definitions/agent",
233 }
234 }
235
236 // Create a combined schema that allows both specific agents and additional ones
237 combinedAgentSchema := map[string]any{
238 "type": "object",
239 "description": "Agent configurations",
240 "properties": agentProperties,
241 "additionalProperties": agentSchema["additionalProperties"],
242 }
243
244 schema["properties"].(map[string]any)["agents"] = combinedAgentSchema
245 schema["definitions"] = map[string]any{
246 "agent": agentSchema["additionalProperties"],
247 }
248
249 // Add LSP configuration
250 schema["properties"].(map[string]any)["lsp"] = map[string]any{
251 "type": "object",
252 "description": "Language Server Protocol configurations",
253 "additionalProperties": map[string]any{
254 "type": "object",
255 "description": "LSP configuration for a language",
256 "properties": map[string]any{
257 "disabled": map[string]any{
258 "type": "boolean",
259 "description": "Whether the LSP is disabled",
260 "default": false,
261 },
262 "command": map[string]any{
263 "type": "string",
264 "description": "Command to execute for the LSP server",
265 },
266 "args": map[string]any{
267 "type": "array",
268 "description": "Command arguments for the LSP server",
269 "items": map[string]any{
270 "type": "string",
271 },
272 },
273 "options": map[string]any{
274 "type": "object",
275 "description": "Additional options for the LSP server",
276 },
277 },
278 "required": []string{"command"},
279 },
280 }
281
282 return schema
283}