* feat: add OpenCode v1.1.1 version detection and permission compatibility utilities - Add opencode-version.ts: Detect installed OpenCode version and support API - Add permission-compat.ts: Compatibility layer for permission system migration - Add comprehensive tests (418 lines total) - Export new utilities from shared/index.ts 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode) * fix: update agent permission configs for OpenCode v1.1.1 compatibility - Fix document-writer: change invalid 'permission: { background_task: deny }' to 'tools: { background_task: false }' - Fix explore: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Fix oracle: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Align all agents with v1.1.1 permission system structure 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
73 lines
1.8 KiB
TypeScript
73 lines
1.8 KiB
TypeScript
import { execSync } from "child_process"
|
|
|
|
export const PERMISSION_BREAKING_VERSION = "1.1.1"
|
|
|
|
const NOT_CACHED = Symbol("NOT_CACHED")
|
|
let cachedVersion: string | null | typeof NOT_CACHED = NOT_CACHED
|
|
|
|
export function parseVersion(version: string): number[] {
|
|
const cleaned = version.replace(/^v/, "").split("-")[0]
|
|
return cleaned.split(".").map((n) => parseInt(n, 10) || 0)
|
|
}
|
|
|
|
export function compareVersions(a: string, b: string): -1 | 0 | 1 {
|
|
const partsA = parseVersion(a)
|
|
const partsB = parseVersion(b)
|
|
const maxLen = Math.max(partsA.length, partsB.length)
|
|
|
|
for (let i = 0; i < maxLen; i++) {
|
|
const numA = partsA[i] ?? 0
|
|
const numB = partsB[i] ?? 0
|
|
if (numA < numB) return -1
|
|
if (numA > numB) return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
export function isVersionGte(a: string, b: string): boolean {
|
|
return compareVersions(a, b) >= 0
|
|
}
|
|
|
|
export function isVersionLt(a: string, b: string): boolean {
|
|
return compareVersions(a, b) < 0
|
|
}
|
|
|
|
export function getOpenCodeVersion(): string | null {
|
|
if (cachedVersion !== NOT_CACHED) {
|
|
return cachedVersion
|
|
}
|
|
|
|
try {
|
|
const result = execSync("opencode --version", {
|
|
encoding: "utf-8",
|
|
timeout: 5000,
|
|
stdio: ["pipe", "pipe", "pipe"],
|
|
}).trim()
|
|
|
|
const versionMatch = result.match(/(\d+\.\d+\.\d+(?:-[\w.]+)?)/)
|
|
cachedVersion = versionMatch?.[1] ?? null
|
|
return cachedVersion
|
|
} catch {
|
|
cachedVersion = null
|
|
return null
|
|
}
|
|
}
|
|
|
|
export function supportsNewPermissionSystem(): boolean {
|
|
const version = getOpenCodeVersion()
|
|
if (!version) return true
|
|
return isVersionGte(version, PERMISSION_BREAKING_VERSION)
|
|
}
|
|
|
|
export function usesLegacyToolsSystem(): boolean {
|
|
return !supportsNewPermissionSystem()
|
|
}
|
|
|
|
export function resetVersionCache(): void {
|
|
cachedVersion = NOT_CACHED
|
|
}
|
|
|
|
export function setVersionCache(version: string | null): void {
|
|
cachedVersion = version
|
|
}
|