Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions custom-mode-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/ModeConfig",
"definitions": {
"ModeConfig": {
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"roleDefinition": {
"type": "string",
"minLength": 1
},
"customInstructions": {
"type": "string"
},
"groups": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string",
"enum": ["read", "edit", "browser", "command", "mcp", "modes"]
},
{
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
"enum": ["read", "edit", "browser", "command", "mcp", "modes"]
},
{
"type": "object",
"properties": {
"fileRegex": {
"type": "string"
},
"description": {
"type": "string"
}
},
"additionalProperties": false
}
]
},
{
"type": "object",
"properties": {
"group": {
"type": "string",
"enum": ["read", "edit", "browser", "command", "mcp", "modes"]
},
"fileRegex": {
"type": "string"
},
"description": {
"type": "string"
}
},
"required": ["group"],
"additionalProperties": false
}
]
},
"description": "Tool groups that are allowed in this mode. Recommended syntax: { group: \"read\" } or { group: \"edit\", options: { fileRegex: \"\\\\.md$\", description: \"Markdown files\" } }."
}
},
"required": ["name", "roleDefinition", "groups"],
"additionalProperties": false
}
},
"title": "Roo Code Mode Configuration",
"description": "Schema for Roo Code mode configuration YAML files. Supports object-based syntax for group entries."
}
50 changes: 34 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@
"@mistralai/mistralai": "^1.3.6",
"@modelcontextprotocol/sdk": "^1.7.0",
"@types/clone-deep": "^4.0.4",
"@types/js-yaml": "^4.0.9",
"@types/pdf-parse": "^1.1.4",
"@types/tmp": "^0.2.6",
"@types/turndown": "^5.0.5",
Expand All @@ -426,6 +427,7 @@
"i18next": "^24.2.2",
"isbinaryfile": "^5.0.2",
"js-tiktoken": "^1.0.19",
"js-yaml": "^4.1.0",
"mammoth": "^1.8.0",
"monaco-vscode-textmate-theme-converter": "^0.1.7",
"node-ipc": "^12.0.0",
Expand All @@ -450,7 +452,7 @@
"tree-sitter-wasms": "^0.1.11",
"turndown": "^7.2.0",
"web-tree-sitter": "^0.22.6",
"zod": "^3.23.8"
"zod": "^3.24.1"
},
"devDependencies": {
"@changesets/cli": "^2.27.10",
Expand Down Expand Up @@ -484,6 +486,7 @@
"tsup": "^8.4.0",
"tsx": "^4.19.3",
"typescript": "^5.4.5",
"zod-to-json-schema": "^3.24.5",
"zod-to-ts": "^1.2.0"
},
"lint-staged": {
Expand Down
59 changes: 59 additions & 0 deletions scripts/generate-mode-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as fs from "fs/promises"
import * as path from "path"
import { zodToJsonSchema } from "zod-to-json-schema"
import { modeConfigInputSchema } from "../src/modeSchemas"

/**
* Generate a JSON schema from the Zod schema for mode configurations
*
* This script generates a JSON schema that supports both the original syntax (v1)
* and the new object-based syntax (v2) for mode configuration.
*
* V1 syntax (tuple-based):
* - Simple format: "read"
* - With options: ["edit", { fileRegex: "\\.md$", description: "Markdown files" }]
*
* V2 syntax (object-based):
* - Simple format: { group: "read" }
* - With options: { group: "edit", options: { fileRegex: "\\.md$", description: "Markdown files" } }
*/
async function generateModeSchema() {
// Convert the Zod schema to a JSON schema
const jsonSchema = zodToJsonSchema(modeConfigInputSchema, {
$refStrategy: "none",
name: "ModeConfig",
})

// Add schema metadata
const schemaWithMetadata = {
$schema: "http://json-schema.org/draft-07/schema#",
...jsonSchema,
title: "Roo Code Mode Configuration",
description: "Schema for Roo Code mode configuration YAML files",
}

// Add additional documentation about the syntax options
schemaWithMetadata.description =
"Schema for Roo Code mode configuration YAML files. Supports object-based syntax for group entries."

// Add documentation to the groups property in the schema
// Cast to any to avoid TypeScript errors with the schema structure
const schema = schemaWithMetadata as any
if (schema.definitions?.ModeConfig?.properties?.groups) {
schema.definitions.ModeConfig.properties.groups.description =
'Tool groups that are allowed in this mode. Recommended syntax: { group: "read" } or ' +
'{ group: "edit", options: { fileRegex: "\\\\.md$", description: "Markdown files" } }.'
}

// Write the schema to a file
const schemaPath = path.join(__dirname, "..", "custom-mode-schema.json")
await fs.writeFile(schemaPath, JSON.stringify(schemaWithMetadata, null, 2), "utf-8")

console.log(`JSON schema generated at: ${schemaPath}`)
}

// Run the script
generateModeSchema().catch((error) => {
console.error("Error generating schema:", error)
process.exit(1)
})
Loading