mirror of
https://github.com/stablyai/orca.git
synced 2026-10-07 16:02:29 +00:00
Retain complete status plugin files during replacement, symlinks and existing permissions, including legacy Windows directory permission recovery. Fixes #24121. Continues #24131; permission-recovery review credited to pullfrog. Co-authored-by: Ahmed Nagy <ahmednagy25t@gmail.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import { mkdirSync } from 'node:fs'
|
|
import {
|
|
writeCanonicalOpenCodePluginAtomically,
|
|
writeOverlayOpenCodePluginAtomically
|
|
} from './opencode-plugin-atomic-write'
|
|
import { join } from 'node:path'
|
|
import {
|
|
isInstalledOpenCodePluginCurrent,
|
|
isOverlayOpenCodePluginCurrent
|
|
} from './opencode-installed-plugin'
|
|
|
|
/**
|
|
* Directory holding the TUI copy of a status plugin file. OpenCode 2 loads a
|
|
* `tui` entrypoint only from a plugins/ subdirectory, and OpenCode 1 loads only
|
|
* plugins/*.js files, so this entry is invisible to 1.x.
|
|
*/
|
|
export function openCodeTuiPluginDirName(pluginFileName: string): string {
|
|
return `${pluginFileName.replace(/\.js$/, '')}-tui`
|
|
}
|
|
|
|
/**
|
|
* Install the TUI copy beside the server plugin file. The same module serves
|
|
* both: its setup() tells a TUI context from a server context. Call it before
|
|
* writing the server file, which decides at load whether to stand down.
|
|
*/
|
|
export function writeOpenCodeTuiPlugin(
|
|
pluginsDir: string,
|
|
pluginFileName: string,
|
|
source: string,
|
|
ownership: 'canonical' | 'overlay' = 'canonical'
|
|
): void {
|
|
const dir = join(pluginsDir, openCodeTuiPluginDirName(pluginFileName))
|
|
const entry = join(dir, 'tui.js')
|
|
const isCurrent =
|
|
ownership === 'canonical' ? isInstalledOpenCodePluginCurrent : isOverlayOpenCodePluginCurrent
|
|
if (isCurrent(entry, source)) {
|
|
return
|
|
}
|
|
mkdirSync(dir, { recursive: true })
|
|
const write =
|
|
ownership === 'canonical'
|
|
? writeCanonicalOpenCodePluginAtomically
|
|
: writeOverlayOpenCodePluginAtomically
|
|
write(entry, source)
|
|
}
|