@@ -250,20 +250,12 @@ public sealed class BeautiCodeToggle : Control {
250250
251251$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot " ..\.." )).Path
252252$HostScript = Join-Path $PSScriptRoot " session-host.mjs"
253- $CodexLaunchScript = Join-Path $RepoRoot " scripts\codex-launch.ps1"
254253$ReleaseManifest = Join-Path $RepoRoot " release-manifest.json"
255254$BundledNode = Join-Path $RepoRoot " runtime\node.exe"
256255$coreDist = Join-Path $RepoRoot " packages\core\dist\index.js"
257256$adapterFolder = if ($TargetHost -eq " dsh" ) { " adapter-dsh" } else { " adapter-codex" }
258257$adapterDist = Join-Path $RepoRoot (" packages\{0}\dist\index.js" -f $adapterFolder )
259258
260- if ($TargetHost -eq " codex" ) {
261- if (-not (Test-Path - LiteralPath $CodexLaunchScript - PathType Leaf)) {
262- throw " 缺少 Codex 启动脚本:$CodexLaunchScript "
263- }
264- . $CodexLaunchScript
265- }
266-
267259if ($NodePath ) {
268260 if (-not (Test-Path - LiteralPath $NodePath - PathType Leaf)) {
269261 throw (" 未找到 Node.js 可执行文件:{0}" -f $NodePath )
@@ -633,68 +625,6 @@ function Get-BcThemeName {
633625 }
634626}
635627
636- function Find-ChatGptExe {
637- if ($script :cachedChatGptExe -and (Test-Path - LiteralPath $script :cachedChatGptExe )) {
638- return $script :cachedChatGptExe
639- }
640- $script :cachedChatGptExe = Find-BcCodexExecutable
641- return $script :cachedChatGptExe
642- }
643-
644- function Start-ChatGptDesktop {
645- param ([int ]$CdpPort = 9335 )
646- $errors = New-Object System.Collections.ArrayList
647- try {
648- $result = Start-BcCodexWithCdp - CdpPort $CdpPort
649- if ($result.Method -eq " appx" ) {
650- [void ]$errors.Add (" Store launch may ignore custom CDP arguments; beautiCode will keep discovering the host." )
651- }
652- return $true
653- } catch {
654- [void ]$errors.Add ((" Codex launch: {0}" -f $_.Exception.Message ))
655- }
656- throw (" 无法启动 ChatGPT/Codex:{0}" -f ([string ]::Join(" | " , @ ($errors ))))
657- }
658-
659- function Stop-ChatGptDesktop {
660- $targets = @ (Get-BcCodexMainProcesses )
661- if ($targets.Count -eq 0 ) { return $true }
662-
663- $answer = [System.Windows.Forms.MessageBox ]::Show(
664- $L.RestartConfirm ,
665- $L.AppName ,
666- [System.Windows.Forms.MessageBoxButtons ]::YesNo,
667- [System.Windows.Forms.MessageBoxIcon ]::Warning,
668- [System.Windows.Forms.MessageBoxDefaultButton ]::Button2
669- )
670- if ($answer -ne [System.Windows.Forms.DialogResult ]::Yes) {
671- Show-Tip - Title $L.AppName - Text $L.RestartCancelled - Icon Info
672- return $false
673- }
674-
675- # Shared helper: CloseMainWindow first, then a non-force Stop-Process.
676- if (Stop-BcCodexGracefully - WaitSeconds 5 ) { return $true }
677-
678- $answer = [System.Windows.Forms.MessageBox ]::Show(
679- $L.ForceCloseConfirm ,
680- $L.AppName ,
681- [System.Windows.Forms.MessageBoxButtons ]::YesNo,
682- [System.Windows.Forms.MessageBoxIcon ]::Warning,
683- [System.Windows.Forms.MessageBoxDefaultButton ]::Button2
684- )
685- if ($answer -ne [System.Windows.Forms.DialogResult ]::Yes) {
686- Show-Tip - Title $L.AppName - Text $L.RestartCancelled - Icon Info
687- return $false
688- }
689-
690- if (Stop-BcCodexForcefully - WaitSeconds 3 ) { return $true }
691-
692- $remaining = @ (Get-BcCodexMainProcesses )
693- throw (" 无法停止 ChatGPT/Codex 进程:{0}" -f (
694- [string ]::Join(" , " , @ ($remaining | ForEach-Object { $_.Process.Id }))
695- ))
696- }
697-
698628function Test-BcCdpPort ([int ]$CdpPort ) {
699629 if ($CdpPort -le 0 ) { return $false }
700630 # Cheap TCP first — avoids 1s HTTP timeout on closed ports.
@@ -722,11 +652,6 @@ function Test-BcCdpPort([int]$CdpPort) {
722652 }
723653}
724654
725- function Test-ChatGptRunning {
726- $procs = @ (Get-Process - Name " ChatGPT" , " Codex" - ErrorAction SilentlyContinue)
727- return ($procs.Count -gt 0 )
728- }
729-
730655function Wait-BcCdpReady {
731656 param (
732657 [int ]$PreferredPort = 0 ,
@@ -824,12 +749,10 @@ function Ensure-BcDshReady {
824749 return $true
825750}
826751
827- # Ensure ChatGPT/Codex is up with loopback CDP, then re-publish the active
828- # (default) background. Used by tray "应用或重新应用".
829- # - CDP healthy + process up → reapply only
830- # - process up, CDP missing → restart with CDP flags, wait, reapply
831- # - process down → start with CDP flags, wait, reapply
832- # DSH: start dsh web if needed, open the page if no browser client, then reapply.
752+ # Re-publish the active (default) background into live pages. Used by tray
753+ # "应用或重新应用". beautiCode never starts/stops a host:
754+ # - DSH: bridge up → open page if no client → reapply; else ask user to run dsh web
755+ # - Codex: loopback CDP up → reapply; else ask user to open Codex with CDP flags
833756function Invoke-BcEnsureHostAndReapply {
834757 if ($script :targetHost -eq " dsh" ) {
835758 Ensure- BcDshReady
@@ -869,22 +792,9 @@ function Invoke-BcEnsureHostAndReapply {
869792 }
870793
871794 if (-not $cdpOk ) {
872- $running = Test-ChatGptRunning
873- if ($running ) {
874- Show-Tip - Title $L.AppName - Text $L.RestartingChat - Icon Info
875- if (-not (Stop-ChatGptDesktop )) { return $false }
876- } else {
877- Show-Tip - Title $L.AppName - Text $L.StartingChat - Icon Info
878- }
879- $launchPort = Get-BcLoopbackCdpPort - Preferred $preferred
880- [void ](Start-ChatGptDesktop - CdpPort $launchPort )
881- # Codex cold start is the real wall clock; poll aggressively so we attach
882- # as soon as :9335 answers instead of sleeping 700ms between probes.
883- $readyPort = Wait-BcCdpReady - PreferredPort $launchPort - TimeoutSec 40
884- if ($readyPort -le 0 ) {
885- throw $L.NoCdp
886- }
887- $script :cdpPort = $readyPort
795+ # beautiCode never launches/restarts Codex. Ask the user to open Codex
796+ # Desktop with loopback CDP instead.
797+ throw " 未发现健康的 Codex CDP。请先打开带本机 CDP 调试端口的 Codex Desktop(如 --remote-debugging-port=9335 --remote-debugging-address=127.0.0.1),再点「应用或重新应用」。"
888798 }
889799
890800 # Import / re-publish the stored default (active) background into live pages.
@@ -988,15 +898,9 @@ $L = @{
988898 RolledBack = (U " 5DF2 56DE 6EDA 3002" ) # 已回滚。
989899 ApplyFail = (U " 5E94 7528 5931 8D25" ) # 应用失败
990900 BusyTip = (U " 6B63 5728 5E94 7528 6216 6821 9A8C FF0C 8BF7 7B49 5F85 5F53 524D 64CD 4F5C 5B8C 6210 3002" ) # 正在应用或校验,请等待当前操作完成。
991- NoCdp = (U " 672A 627E 5230 5065 5EB7 7684 672C 673A 0020 0043 006F 0064 0065 0078 0020 0043 0044 0050 3002 8BF7 7A0D 5019 518D 8BD5 3002" ) # 未找到健康的本机 Codex CDP。请稍后再试。
992- StartingChat = (U " 6B63 5728 6253 5F00 0020 0043 0068 0061 0074 0047 0050 0054 002F 0043 006F 0064 0065 0078 2026" ) # 正在打开 ChatGPT/Codex…
993901 OpeningDsh = (U " 6B63 5728 6253 5F00 0020 0044 0065 0065 0070 0053 0065 0065 006B 0020 0048 0061 0072 006E 0065 0073 0073 0020 7F51 9875 2026" ) # 正在打开 DeepSeek Harness 网页…
994902 DshPageWaitFail = (U " 5DF2 6253 5F00 0020 0044 0065 0065 0070 0053 0065 0065 006B 0020 0048 0061 0072 006E 0065 0073 0073 0020 7F51 9875 FF0C 4F46 9875 9762 5C1A 672A 8FDE 4E0A 3002 8BF7 5237 65B0 540E 518D 8BD5 3002" ) # 已打开 DeepSeek Harness 网页,但页面尚未连上。请刷新后再试。
995903 ReapplyNoBgDsh = (U " 5DF2 6253 5F00 0020 0044 0065 0065 0070 0053 0065 0065 006B 0020 0048 0061 0072 006E 0065 0073 0073 3002 5F53 524D 65E0 9ED8 8BA4 80CC 666F 53EF 5BFC 5165 3002" ) # 已打开 DeepSeek Harness。当前无默认背景可导入。
996- RestartingChat = (U " 6B63 5728 91CD 542F 0020 0043 0068 0061 0074 0047 0050 0054 002F 0043 006F 0064 0065 0078 2026" ) # 正在重启 ChatGPT/Codex…
997- RestartConfirm = (U " 0043 0068 0061 0074 0047 0050 0054 002F 0043 006F 0064 0065 0078 0020 6B63 5728 8FD0 884C 3002 91CD 542F 53EF 80FD 4E22 5931 672A 4FDD 5B58 5185 5BB9 3002 662F 5426 7EE7 7EED FF1F" )
998- ForceCloseConfirm = (U " 5E94 7528 672A 5728 0020 0035 0020 79D2 5185 9000 51FA 3002 662F 5426 5F3A 5236 7ED3 675F 5269 4F59 8FDB 7A0B FF1F" )
999- RestartCancelled = (U " 5DF2 53D6 6D88 91CD 542F 3002" )
1000904 RunningTip = (U " 6258 76D8 5DF2 542F 52A8 3002 0043 0074 0072 006C 002B 0053 0068 0069 0066 0074 002B 0053 0070 0061 0063 0065 0020 6478 9C7C 3002" ) # 托盘已启动。Ctrl+Shift+Space 摸鱼。
1001905 RunningTipDsh = (U " 6258 76D8 5DF2 542F 52A8 3002 8BF7 5148 6253 5F00 0020 0044 0065 0065 0070 0053 0065 0065 006B 0020 0048 0061 0072 006E 0065 0073 0073 0020 7F51 9875 3002" ) # 托盘已启动。请先打开 DeepSeek Harness 网页。
1002906 HostCodex = " Codex Desktop"
0 commit comments