Skip to content
Merged
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
7 changes: 5 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,8 @@
"@types/node": "^24.1.0",
"globals": "^16.3.0",
"tsup": "^8.4.0",
"vitest": "^3.2.3"
"ajv": "^8.18.0",
"vitest": "^3.2.3",
"zod-to-json-schema": "^3.25.1"
}
}
25 changes: 25 additions & 0 deletions packages/types/scripts/generate-roomodes-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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 { generateRoomodesJsonSchema } from "../src/roomodes-schema.js"

const jsonSchema = generateRoomodesJsonSchema()

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)}`)
26 changes: 26 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,26 @@
import { describe, it, expect } from "vitest"
import * as fs from "fs"
import * as path from "path"
import { fileURLToPath } from "url"

import { generateRoomodesJsonSchema } from "../roomodes-schema.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"))

const generated = generateRoomodesJsonSchema()

expect(checkedIn).toEqual(generated)
})
})
Loading
Loading