20-sep: infra global - OmniRoute watchdog + plugin OpenCode + changelog sobremesa/portatil

This commit is contained in:
juanminsanz
2026-09-20 11:59:56 +02:00
commit 49bdf1ac76
8 changed files with 806 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<#
.SYNOPSIS
Instala en el equipo actual la infraestructura global de OmniRoute + OpenCode.
.DESCRIPTION
1. Copia el plugin global `omniroute-bootstrap.ts` a la carpeta de plugins de OpenCode
(~/.config/opencode/plugins/). Asi OpenCode relanza OmniRoute al arrancar, en
cualquier repositorio.
2. Registra/actualiza la tarea programada `OmniRoute Watchdog` apuntando al vigilante
canonico de este repo (INFRAESTRUCTURA).
3. Arranca la tarea.
No requiere administrador. Idempotente: se puede re-ejecutar tras un git pull.
.NOTES
Repo: INFRAESTRUCTURA.
#>
[CmdletBinding()]
param(
[switch]$NoStart
)
$ErrorActionPreference = 'Stop'
$RepoRoot = Split-Path -Parent $PSScriptRoot
$TaskName = 'OmniRoute Watchdog'
$PwshExe = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
$Watchdog = Join-Path $RepoRoot 'omniroute\omniroute_watchdog.ps1'
$PluginSrc = Join-Path $RepoRoot 'opencode\omniroute-bootstrap.ts'
$PluginDir = Join-Path $env:USERPROFILE '.config\opencode\plugins'
$PluginDst = Join-Path $PluginDir 'omniroute-bootstrap.ts'
$UserId = "$env:USERDOMAIN\$env:USERNAME"
Write-Host '== Instalando infraestructura global (OmniRoute + OpenCode) ==' -ForegroundColor Cyan
# 1) Plugin global de OpenCode ---------------------------------------------
if (-not (Test-Path $PluginDir)) { New-Item -ItemType Directory -Force -Path $PluginDir | Out-Null }
Copy-Item -LiteralPath $PluginSrc -Destination $PluginDst -Force
Write-Host " - Plugin global instalado en $PluginDst" -ForegroundColor Green
# 2) Tarea programada ------------------------------------------------------
if (-not (Test-Path $Watchdog)) { throw "No se encuentra el vigilante: $Watchdog" }
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
Write-Host ' - Eliminando tarea anterior...' -ForegroundColor Yellow
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
}
$Action = New-ScheduledTaskAction `
-Execute $PwshExe `
-Argument "-NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File `"$Watchdog`"" `
-WorkingDirectory $env:USERPROFILE
$Trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$Settings = New-ScheduledTaskSettingsSet `
-AllowStartIfOnBatteries `
-DontStopIfGoingOnBatteries `
-StartWhenAvailable `
-RestartCount 999 `
-RestartInterval (New-TimeSpan -Minutes 1) `
-MultipleInstances IgnoreNew
$Settings.ExecutionTimeLimit = 'PT0S'
$Settings.Hidden = $true
$Principal = New-ScheduledTaskPrincipal -UserId $UserId -LogonType Interactive -RunLevel Limited
Register-ScheduledTask `
-TaskName $TaskName `
-Action $Action `
-Trigger $Trigger `
-Settings $Settings `
-Principal $Principal `
-Description 'Arranca y vigila OmniRoute (localhost:20128) al iniciar sesion. Autocuracion.' `
-Force | Out-Null
Write-Host " - Tarea '$TaskName' registrada -> $Watchdog" -ForegroundColor Green
# 3) Arrancar --------------------------------------------------------------
if (-not $NoStart) {
Start-ScheduledTask -TaskName $TaskName
Write-Host ' - Vigilante arrancado.' -ForegroundColor Yellow
}
Write-Host ''
Write-Host 'Listo. Comprobar:' -ForegroundColor Cyan
Write-Host " Get-ScheduledTask -TaskName '$TaskName' | Get-ScheduledTaskInfo"
Write-Host " Get-Content `"$env:USERPROFILE\.omniroute\watchdog.log`" -Tail 20"