68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
/**
|
|
* OmniRoute Bootstrap — plugin GLOBAL de OpenCode
|
|
*
|
|
* Objetivo: que al arrancar OpenCode (en CUALQUIER repositorio) se asegure de que
|
|
* OmniRoute esta levantado en localhost:20128, lanzando el vigilante en modo `-Once`.
|
|
*
|
|
* No depende de ningun repositorio: vive en la config global de OpenCode
|
|
* (~/.config/opencode/plugins/) y el vigilante canonico esta en el repo INFRAESTRUCTURA.
|
|
*
|
|
* Instalacion: `scripts/instalar_global.ps1` (copia este fichero a la carpeta global
|
|
* de plugins de OpenCode y registra la tarea de arranque).
|
|
*
|
|
* Nota: el vigilante ya corre como tarea programada al iniciar sesion; este plugin es
|
|
* la red de seguridad para cuando OpenCode arranca sin que el vigilante este vivo.
|
|
*/
|
|
|
|
import type { Plugin } from "@opencode-ai/plugin"
|
|
import { spawn } from "node:child_process"
|
|
import { existsSync } from "node:fs"
|
|
|
|
// --- Configuracion ---------------------------------------------------------
|
|
|
|
// Vigilante canonico (repo INFRAESTRUCTURA). Se puede sobreescribir con OMNIROUTE_WATCHDOG.
|
|
const WATCHDOG =
|
|
process.env.OMNIROUTE_WATCHDOG ??
|
|
`${process.env.USERPROFILE}\\Documents\\Github\\INFRAESTRUCTURA\\omniroute\\omniroute_watchdog.ps1`
|
|
|
|
const POWERSHELL =
|
|
process.env.SystemRoot
|
|
? `${process.env.SystemRoot}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
|
|
: "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
|
|
|
|
// Evita lanzar el vigilante mas de una vez por proceso de OpenCode.
|
|
let launched = false
|
|
|
|
function ensureOmniRoute(): void {
|
|
if (launched) return
|
|
launched = true
|
|
try {
|
|
if (!existsSync(WATCHDOG)) return
|
|
const child = spawn(
|
|
POWERSHELL,
|
|
[
|
|
"-NoProfile",
|
|
"-NonInteractive",
|
|
"-ExecutionPolicy",
|
|
"Bypass",
|
|
"-WindowStyle",
|
|
"Hidden",
|
|
"-File",
|
|
WATCHDOG,
|
|
"-Once",
|
|
],
|
|
{ detached: true, stdio: "ignore", windowsHide: true },
|
|
)
|
|
child.unref()
|
|
} catch {
|
|
// Silencioso: el arranque de OpenCode no debe romperse por OmniRoute.
|
|
}
|
|
}
|
|
|
|
// --- Plugin ----------------------------------------------------------------
|
|
|
|
export const OmniRouteBootstrap: Plugin = async () => {
|
|
ensureOmniRoute()
|
|
return {}
|
|
}
|