@@ -14,12 +14,15 @@ import { join } from "node:path";
1414
1515import { parseCompartmentOutput } from "@magic-context/core/hooks/magic-context/compartment-parser" ;
1616import { detectConflicts } from "@magic-context/core/shared/conflict-detector" ;
17- import {
18- getOpenCodeCacheDir ,
19- getProjectMagicContextHistorianDir ,
20- } from "@magic-context/core/shared/data-path" ;
17+ import { getProjectMagicContextHistorianDir } from "@magic-context/core/shared/data-path" ;
2118import { parse as parseJsonc } from "comment-json" ;
2219import { getOpenCodeVersion , isOpenCodeInstalled } from "./opencode-helpers" ;
20+ import {
21+ getOpenCodePluginCacheRoots ,
22+ getOpenCodePluginPackageJsonPaths ,
23+ OPENCODE_PLUGIN_ENTRY_WITH_VERSION ,
24+ OPENCODE_PLUGIN_NAME ,
25+ } from "./opencode-plugin-cache" ;
2326import {
2427 type ConfigPaths ,
2528 detectConfigPaths ,
@@ -28,9 +31,6 @@ import {
2831} from "./paths" ;
2932import { sanitizeConfigValue , sanitizeDiagnosticText , sanitizePathString } from "./redaction" ;
3033
31- const PLUGIN_NAME = "@cortexkit/opencode-magic-context" ;
32- const PLUGIN_ENTRY_WITH_VERSION = `${ PLUGIN_NAME } @latest` ;
33-
3434export interface DiagnosticReport {
3535 timestamp : string ;
3636 platform : string ;
@@ -216,24 +216,20 @@ function getSelfVersion(): string {
216216}
217217
218218function getPluginCacheInfo ( ) : { path : string ; cached ?: string ; latest ?: string } {
219- const path = join ( getOpenCodeCacheDir ( ) , "packages" , PLUGIN_ENTRY_WITH_VERSION ) ;
219+ const [ path = "" ] = getOpenCodePluginCacheRoots ( ) ;
220220 let cached : string | undefined ;
221- try {
222- const installedPkgPath = join (
223- path ,
224- "node_modules" ,
225- "@cortexkit" ,
226- "opencode-magic-context" ,
227- "package.json" ,
228- ) ;
229- if ( existsSync ( installedPkgPath ) ) {
230- const pkg = JSON . parse ( readFileSync ( installedPkgPath , "utf-8" ) ) as {
231- version ?: unknown ;
232- } ;
233- cached = typeof pkg . version === "string" ? pkg . version : undefined ;
221+ for ( const installedPkgPath of getOpenCodePluginPackageJsonPaths ( ) ) {
222+ try {
223+ if ( existsSync ( installedPkgPath ) ) {
224+ const pkg = JSON . parse ( readFileSync ( installedPkgPath , "utf-8" ) ) as {
225+ version ?: unknown ;
226+ } ;
227+ cached = typeof pkg . version === "string" ? pkg . version : undefined ;
228+ if ( cached ) break ;
229+ }
230+ } catch {
231+ cached = undefined ;
234232 }
235- } catch {
236- cached = undefined ;
237233 }
238234 return { path, cached, latest : getSelfVersion ( ) } ;
239235}
@@ -283,8 +279,9 @@ function configHasPluginEntry(config: Record<string, unknown> | null): boolean {
283279 const plugins = Array . isArray ( config ?. plugin ) ? config . plugin : [ ] ;
284280 return plugins . some ( ( entry ) => {
285281 if ( typeof entry !== "string" ) return false ;
286- if ( entry === PLUGIN_NAME ) return true ;
287- if ( entry . startsWith ( `${ PLUGIN_NAME } @` ) ) return true ;
282+ if ( entry === OPENCODE_PLUGIN_NAME ) return true ;
283+ if ( entry === OPENCODE_PLUGIN_ENTRY_WITH_VERSION ) return true ;
284+ if ( entry . startsWith ( `${ OPENCODE_PLUGIN_NAME } @` ) ) return true ;
288285 // Local dev paths
289286 if ( entry . includes ( "opencode-magic-context" ) ) return true ;
290287 return false ;
0 commit comments