Skip to content

Commit 7adbfec

Browse files
feat: add correct JSON schema for .roomodes configuration files (#11791)
Co-authored-by: Roo Code <roomote@roocode.com>
1 parent 9cfaf38 commit 7adbfec

File tree

7 files changed

+690
-2
lines changed

7 files changed

+690
-2
lines changed

packages/types/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"build": "tsup",
2121
"build:watch": "tsup --watch --outDir npm/dist --onSuccess 'echo ✅ Types rebuilt to npm/dist'",
2222
"npm:publish": "node scripts/publish-npm.cjs",
23-
"clean": "rimraf dist .turbo"
23+
"clean": "rimraf dist .turbo",
24+
"generate:schema": "tsx scripts/generate-roomodes-schema.ts"
2425
},
2526
"dependencies": {
2627
"ai-sdk-provider-poe": "2.0.18",
@@ -32,6 +33,8 @@
3233
"@types/node": "^24.1.0",
3334
"globals": "^16.3.0",
3435
"tsup": "^8.4.0",
35-
"vitest": "^3.2.3"
36+
"ajv": "^8.18.0",
37+
"vitest": "^3.2.3",
38+
"zod-to-json-schema": "^3.25.1"
3639
}
3740
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Generates the JSON Schema for .roomodes configuration files from the Zod
3+
* schemas defined in packages/types/src/mode.ts.
4+
*
5+
* This ensures the schema stays in sync with the TypeScript types. Run via:
6+
* pnpm --filter @roo-code/types generate:schema
7+
*
8+
* The output is written to schemas/roomodes.json at the repository root.
9+
*/
10+
11+
import * as fs from "fs"
12+
import * as path from "path"
13+
import { fileURLToPath } from "url"
14+
15+
import { generateRoomodesJsonSchema } from "../src/roomodes-schema.js"
16+
17+
const jsonSchema = generateRoomodesJsonSchema()
18+
19+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
20+
const repoRoot = path.resolve(__dirname, "../../..")
21+
const outPath = path.join(repoRoot, "schemas", "roomodes.json")
22+
fs.mkdirSync(path.dirname(outPath), { recursive: true })
23+
fs.writeFileSync(outPath, JSON.stringify(jsonSchema, null, "\t") + "\n", "utf-8")
24+
25+
console.log(`Generated ${path.relative(repoRoot, outPath)}`)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, it, expect } from "vitest"
2+
import * as fs from "fs"
3+
import * as path from "path"
4+
import { fileURLToPath } from "url"
5+
6+
import { generateRoomodesJsonSchema } from "../roomodes-schema.js"
7+
8+
/**
9+
* This test verifies that the checked-in schemas/roomodes.json matches what
10+
* would be generated from the current Zod schemas. If this test fails, run:
11+
*
12+
* pnpm --filter @roo-code/types generate:schema
13+
*
14+
* to regenerate the schema file.
15+
*/
16+
describe("roomodes schema sync", () => {
17+
it("should match the dynamically generated schema from Zod types", () => {
18+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
19+
const schemaPath = path.resolve(__dirname, "../../../../schemas/roomodes.json")
20+
const checkedIn = JSON.parse(fs.readFileSync(schemaPath, "utf-8"))
21+
22+
const generated = generateRoomodesJsonSchema()
23+
24+
expect(checkedIn).toEqual(generated)
25+
})
26+
})

0 commit comments

Comments
 (0)