| 13 | let rpcGeneration = 0; |
| 14 | |
| 15 | function getStorageDir(): string { |
| 16 | // Plugin v0.16+ uses the shared cortexkit/magic-context path so OpenCode |
| 17 | // and Pi can share state. The TUI just needs to point its RPC client at |
| 18 | // the same storage directory the server plugin uses for the lock-file |
| 19 | // discovery convention. |
| 20 | const dataDir = process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share"); |
| 21 | return path.join(dataDir, "cortexkit", "magic-context"); |
| 22 | } |
| 23 | |
| 24 | /** Initialize the RPC client. Call once on TUI startup. */ |
| 25 | export function initRpcClient(directory: string): void { |