@@ -12,15 +12,23 @@ import { join } from "node:path"
1212
1313import {
1414 AGENTS_TARGET_DIR ,
15+ checkVersionCompatibility ,
1516 createLogger ,
1617 getAgentsSourceDir ,
1718 getErrorMessage ,
1819 getPackageRoot ,
1920 parseCliFlags ,
21+ parseFrontmatter ,
2022 retryOnTransientError ,
2123 validateAgentContent ,
2224} from "./src/paths.mjs"
2325
26+ /**
27+ * Mock OpenCode version for compatibility checking.
28+ * In production, this would be obtained from the OpenCode CLI or environment.
29+ */
30+ const OPENCODE_VERSION = "0.1.0"
31+
2432const packageRoot = getPackageRoot ( import . meta. url )
2533const AGENTS_SOURCE_DIR = getAgentsSourceDir ( packageRoot )
2634
@@ -52,14 +60,33 @@ const logger = createLogger(VERBOSE)
5260const verbose = logger . verbose
5361
5462/**
55- * Validates an agent file by reading and validating its content.
63+ * Validates an agent file by reading and validating its content,
64+ * including version compatibility checking.
5665 *
5766 * @param {string } filePath - Path to the agent file to validate
5867 * @returns {{ valid: boolean, error?: string } } Validation result with optional error message
5968 */
6069function validateAgentFile ( filePath ) {
6170 const content = readFileSync ( filePath , "utf-8" )
62- return validateAgentContent ( content )
71+ const contentValidation = validateAgentContent ( content )
72+ if ( ! contentValidation . valid ) {
73+ return contentValidation
74+ }
75+
76+ // Check version compatibility from frontmatter
77+ const frontmatter = parseFrontmatter ( content )
78+ if ( frontmatter . found && frontmatter . fields . requires ) {
79+ const requiresVersion = frontmatter . fields . requires
80+ const isCompatible = checkVersionCompatibility ( requiresVersion , OPENCODE_VERSION )
81+ if ( ! isCompatible ) {
82+ return {
83+ valid : false ,
84+ error : `Incompatible OpenCode version: requires ${ requiresVersion } , but current version is ${ OPENCODE_VERSION } ` ,
85+ }
86+ }
87+ }
88+
89+ return { valid : true }
6390}
6491
6592/**
0 commit comments