Skip to content
Open
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
6 changes: 4 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"build": "tsup",
"build:watch": "tsup --watch --outDir npm/dist --onSuccess 'echo ✅ Types rebuilt to npm/dist'",
"npm:publish": "node scripts/publish-npm.cjs",
"clean": "rimraf dist .turbo"
"clean": "rimraf dist .turbo",
"generate:schema": "tsx scripts/generate-roomodes-schema.ts"
},
"dependencies": {
"zod": "3.25.76"
Expand All @@ -31,6 +32,7 @@
"@types/node": "^24.1.0",
"globals": "^16.3.0",
"tsup": "^8.4.0",
"vitest": "^3.2.3"
"vitest": "^3.2.3",
"zod-to-json-schema": "^3.25.1"
}
}
83 changes: 83 additions & 0 deletions packages/types/scripts/generate-roomodes-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Generates the JSON Schema for .roomodes configuration files from the Zod
* schemas defined in packages/types/src/mode.ts.
*
* This ensures the schema stays in sync with the TypeScript types. Run via:
* pnpm --filter @roo-code/types generate:schema
*
* The output is written to schemas/roomodes.json at the repository root.
*/

import * as fs from "fs"
import * as path from "path"
import { fileURLToPath } from "url"
import { zodToJsonSchema } from "zod-to-json-schema"
import { z } from "zod"

import { toolGroups, deprecatedToolGroups } from "../src/tool.js"
import { groupOptionsSchema, modeConfigSchema } from "../src/mode.js"

// ---------------------------------------------------------------------------
// 1. Build a ToolGroup enum that includes deprecated groups so existing
// configs still validate.
// ---------------------------------------------------------------------------
const allToolGroups = [...toolGroups, ...deprecatedToolGroups] as [string, ...string[]]
const allToolGroupsSchema = z.enum(allToolGroups)

// ---------------------------------------------------------------------------
// 2. Build a GroupEntry schema that uses the extended tool group list.
// ---------------------------------------------------------------------------
const groupEntrySchema = z.union([allToolGroupsSchema, z.tuple([allToolGroupsSchema, groupOptionsSchema])])

// ---------------------------------------------------------------------------
// 3. Build the RuleFile schema (used during import/export but not part of
// the core Zod types).
// ---------------------------------------------------------------------------
const ruleFileSchema = z.object({
relativePath: z.string(),
content: z.string().optional(),
})

// ---------------------------------------------------------------------------
// 4. Build an extended ModeConfig schema that includes rulesFiles and uses
// the extended groups (with deprecated entries).
// ---------------------------------------------------------------------------
const exportedModeConfigSchema = modeConfigSchema.omit({ groups: true }).extend({
groups: z.array(groupEntrySchema),
rulesFiles: z.array(ruleFileSchema).optional(),
})

// ---------------------------------------------------------------------------
// 5. Build the top-level .roomodes schema.
// ---------------------------------------------------------------------------
const roomodesSchema = z
.object({
customModes: z.array(exportedModeConfigSchema),
})
.strict()

// ---------------------------------------------------------------------------
// 6. Convert to JSON Schema (draft-07).
// ---------------------------------------------------------------------------
const jsonSchema = zodToJsonSchema(roomodesSchema, {
$refStrategy: "none",
target: "jsonSchema7",
}) as Record<string, unknown>

// ---------------------------------------------------------------------------
// 7. Add metadata.
// ---------------------------------------------------------------------------
jsonSchema["$id"] = "https://github.com/RooCodeInc/Roo-Code/blob/main/schemas/roomodes.json"
jsonSchema["title"] = "Roo Code Custom Modes"
jsonSchema["description"] = "Schema for .roomodes configuration files used by Roo Code to define custom modes."

// ---------------------------------------------------------------------------
// 8. Write to disk.
// ---------------------------------------------------------------------------
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(__dirname, "../../..")
const outPath = path.join(repoRoot, "schemas", "roomodes.json")
fs.mkdirSync(path.dirname(outPath), { recursive: true })
fs.writeFileSync(outPath, JSON.stringify(jsonSchema, null, "\t") + "\n", "utf-8")

console.log(`Generated ${path.relative(repoRoot, outPath)}`)
54 changes: 54 additions & 0 deletions packages/types/src/__tests__/roomodes-schema-sync.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { describe, it, expect } from "vitest"
import * as fs from "fs"
import * as path from "path"
import { fileURLToPath } from "url"
import { zodToJsonSchema } from "zod-to-json-schema"
import { z } from "zod"

import { toolGroups, deprecatedToolGroups } from "../tool.js"
import { groupOptionsSchema, modeConfigSchema } from "../mode.js"

/**
* This test verifies that the checked-in schemas/roomodes.json matches what
* would be generated from the current Zod schemas. If this test fails, run:
*
* pnpm --filter @roo-code/types generate:schema
*
* to regenerate the schema file.
*/
describe("roomodes schema sync", () => {
it("should match the dynamically generated schema from Zod types", () => {
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const schemaPath = path.resolve(__dirname, "../../../../schemas/roomodes.json")
const checkedIn = JSON.parse(fs.readFileSync(schemaPath, "utf-8"))

// Reproduce the same generation logic as scripts/generate-roomodes-schema.ts
const allToolGroups = [...toolGroups, ...deprecatedToolGroups] as [string, ...string[]]
const allToolGroupsSchema = z.enum(allToolGroups)
const groupEntrySchema = z.union([allToolGroupsSchema, z.tuple([allToolGroupsSchema, groupOptionsSchema])])
const ruleFileSchema = z.object({
relativePath: z.string(),
content: z.string().optional(),
})
const exportedModeConfigSchema = modeConfigSchema.omit({ groups: true }).extend({
groups: z.array(groupEntrySchema),
rulesFiles: z.array(ruleFileSchema).optional(),
})
const roomodesSchema = z
.object({
customModes: z.array(exportedModeConfigSchema),
})
.strict()

const generated = zodToJsonSchema(roomodesSchema, {
$refStrategy: "none",
target: "jsonSchema7",
}) as Record<string, unknown>

generated["$id"] = "https://github.com/RooCodeInc/Roo-Code/blob/main/schemas/roomodes.json"
generated["title"] = "Roo Code Custom Modes"
generated["description"] = "Schema for .roomodes configuration files used by Roo Code to define custom modes."

expect(checkedIn).toEqual(generated)
})
})
43 changes: 43 additions & 0 deletions pnpm-lock.yaml

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

96 changes: 96 additions & 0 deletions schemas/roomodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"type": "object",
"properties": {
"customModes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"slug": {
"type": "string",
"pattern": "^[a-zA-Z0-9-]+$"
},
"name": {
"type": "string",
"minLength": 1
},
"roleDefinition": {
"type": "string",
"minLength": 1
},
"whenToUse": {
"type": "string"
},
"description": {
"type": "string"
},
"customInstructions": {
"type": "string"
},
"source": {
"type": "string",
"enum": ["global", "project"]
},
"groups": {
"type": "array",
"items": {
"anyOf": [
{
"type": "string",
"enum": ["read", "edit", "command", "mcp", "modes", "browser"]
},
{
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": [
{
"type": "string",
"enum": ["read", "edit", "command", "mcp", "modes", "browser"]
},
{
"type": "object",
"properties": {
"fileRegex": {
"type": "string"
},
"description": {
"type": "string"
}
},
"additionalProperties": false
}
]
}
]
}
},
"rulesFiles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"relativePath": {
"type": "string"
},
"content": {
"type": "string"
}
},
"required": ["relativePath"],
"additionalProperties": false
}
}
},
"required": ["slug", "name", "roleDefinition", "groups"],
"additionalProperties": false
}
}
},
"required": ["customModes"],
"additionalProperties": false,
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://github.com/RooCodeInc/Roo-Code/blob/main/schemas/roomodes.json",
"title": "Roo Code Custom Modes",
"description": "Schema for .roomodes configuration files used by Roo Code to define custom modes."
}
Loading
Loading