Skip to content

Commit eaf3b00

Browse files
committed
feat(postinstall): validate agent requires field against OpenCode version
Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent f3e236c commit eaf3b00

File tree

2 files changed

+585
-2
lines changed

2 files changed

+585
-2
lines changed

postinstall.mjs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ import { join } from "node:path"
1212

1313
import {
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+
2432
const packageRoot = getPackageRoot(import.meta.url)
2533
const AGENTS_SOURCE_DIR = getAgentsSourceDir(packageRoot)
2634

@@ -52,14 +60,33 @@ const logger = createLogger(VERBOSE)
5260
const 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
*/
6069
function 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

Comments
 (0)