From dcce2468a00e2f1aeb5e7c60a2be0900503fbbc8 Mon Sep 17 00:00:00 2001 From: luckyyzh Date: Mon, 3 Aug 2026 19:04:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=A1=E5=88=92=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E5=85=81=E8=AE=B8=E7=94=B5=E6=B1=A0=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=EF=BC=88=E7=AC=94=E8=AE=B0=E6=9C=AC=E4=B8=8D=E6=8F=92?= =?UTF-8?q?=E7=94=B5=20Queued=20=E4=B8=8D=E5=90=AF=E5=8A=A8=EF=BC=89+=20We?= =?UTF-8?q?b=20=E4=BB=BB=E5=8A=A1=E6=80=BB=E6=98=AF=E8=A6=86=E7=9B=96?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/local-tools/pi-agent-public.ps1 | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/data/local-tools/pi-agent-public.ps1 b/data/local-tools/pi-agent-public.ps1 index 1418b65..92f2fe2 100644 --- a/data/local-tools/pi-agent-public.ps1 +++ b/data/local-tools/pi-agent-public.ps1 @@ -36,20 +36,21 @@ if ([string]::IsNullOrWhiteSpace($publicUrl)) { } function Ensure-Tasks { - # Web supervisor 任务:必需,自动注册(相对路径,新机器可直接用) - if (-not (Get-ScheduledTask -TaskName $webTaskName -ErrorAction SilentlyContinue)) { - Write-Host " 注册计划任务 $webTaskName ..." - $supervisorPath = Join-Path $PSScriptRoot 'pi-agent-web-supervisor.ps1' - # 单引号拼接避免转义歧义(`\" 不是 PowerShell 转义引号) - $argument = '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File "' + $supervisorPath + '"' - $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $argument -WorkingDirectory $projectRoot - $trigger = New-ScheduledTaskTrigger -AtLogOn - $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable ` - -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) ` - -ExecutionTimeLimit ([TimeSpan]::Zero) - Register-ScheduledTask -TaskName $webTaskName -Action $action -Trigger $trigger ` - -Settings $settings -Description 'Pi Agent Integrated Web supervisor' -Force | Out-Null - } + # Web supervisor 任务:必需,总是用最新定义覆盖注册(-Force 不中断运行中的实例) + Write-Host " 注册/更新计划任务 $webTaskName ..." + $supervisorPath = Join-Path $PSScriptRoot 'pi-agent-web-supervisor.ps1' + # 单引号拼接避免转义歧义(`\" 不是 PowerShell 转义引号) + $argument = '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy Bypass -WindowStyle Hidden -File "' + $supervisorPath + '"' + $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $argument -WorkingDirectory $projectRoot + $trigger = New-ScheduledTaskTrigger -AtLogOn + # 显式允许电池运行(默认 DisallowStartIfOnBatteries=True 会导致笔记本不插电时任务 Queued 不启动) + $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable ` + -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) ` + -ExecutionTimeLimit ([TimeSpan]::Zero) ` + -DisallowStartIfOnBatteries:$false -StopIfGoingOnBatteries:$false + # -Force 总是用最新定义覆盖(含设置修正),不中断已运行实例 + Register-ScheduledTask -TaskName $webTaskName -Action $action -Trigger $trigger ` + -Settings $settings -Description 'Pi Agent Integrated Web supervisor' -Force | Out-Null # Tunnel 任务:可选,仅在配置了 PI_AGENT_TUNNEL_COMMAND 时注册;-NoTunnel 明确跳过 if ($NoTunnel) { @@ -67,7 +68,8 @@ function Ensure-Tasks { $trigger = New-ScheduledTaskTrigger -AtLogOn $settings = New-ScheduledTaskSettingsSet -StartWhenAvailable ` -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) ` - -ExecutionTimeLimit ([TimeSpan]::Zero) + -ExecutionTimeLimit ([TimeSpan]::Zero) ` + -DisallowStartIfOnBatteries:$false -StopIfGoingOnBatteries:$false Register-ScheduledTask -TaskName $tunnelTaskName -Action $action -Trigger $trigger ` -Settings $settings -Description 'Pi Agent Integrated public tunnel' -Force | Out-Null }