Skip to content

Commit 6d4df6a

Browse files
committed
refactor: keep Codex as host adapter, remove its launcher
Multi-host by contract, not by launcher. adapter-codex stays as a first-class HostSession adapter (loopback CDP); beautiCode no longer launches, stops, or restarts any host — same rule Phase 2 applied to DSH. - delete scripts/start-beauticode-engine.ps1, codex-launch.ps1, start-beauticode.ps1 (host picker) - tray: strip Codex launch/stop/restart + confirm dialogs; no-CDP now asks the user to open Codex with loopback CDP instead of launching it - installer/shortcuts: point at apps/tray/start-tray.ps1 -TargetHost dsh - docs/host-adapter.md: formalize HostSession as the multi-host extension point; new hosts are new adapters sharing only packages/core
1 parent bbb10af commit 6d4df6a

9 files changed

Lines changed: 48 additions & 1280 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ dsh plugin --profile web add @beauticode/dsh-plugin
179179
dsh web
180180
```
181181

182-
安装完成后启动 beautiCode,选择 **DeepSeek Harness** 目标。Windows 右下角会出现托盘图标。
182+
安装完成后从开始菜单或桌面启动 beautiCode,Windows 右下角会出现托盘图标。
183183

184184
之后在托盘里:
185185

apps/tray/start-tray.ps1

Lines changed: 7 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
267259
if ($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-
698628
function 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-
730655
function 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
833756
function 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"

docs/host-adapter.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
# Host adapter contract
22

3+
## Multi-host model
4+
5+
beautiCode is host-agnostic. Every supported tool (DeepSeek Harness, Codex
6+
Desktop, future hosts) is one **host adapter** that implements the shared
7+
`HostSession` interface from `packages/core` and nothing else is host-aware:
8+
9+
```
10+
control plane (tray / session-host / CLI)
11+
│ talks to HostSession only
12+
13+
host adapter (adapter-dsh | adapter-codex | adapter-<future>)
14+
│ owns one host mechanism
15+
16+
host page (DSH web / Codex Desktop / …)
17+
```
18+
19+
- The control plane never knows a host's internals; it drives apply, reapply,
20+
modes, themes, progress through `HostSession`.
21+
- `ApplyTransaction` (packages/core) is reused by every adapter: snapshot →
22+
commit → stage → host apply → verify → finalize/rollback.
23+
- **beautiCode never starts or stops a host.** Each adapter attaches to a host
24+
the user already launched (DSH: Cordis plugin; Codex: loopback CDP). A
25+
missing host is a clear error, not an auto-launch.
26+
- The browser half is shared too: DSH loads it via the `@beauticode/dsh-plugin`
27+
Cordis plugin (`client.js` + `/__beauticode/*`). A new adapter either serves
28+
the same bridge protocol or injects its own page runtime — the control plane
29+
does not care which.
30+
331
## Principles
432

533
1. **Background-first and scoped.** The injected stage owns media. The adapter
@@ -148,6 +176,8 @@ Runtime API: `getPlaybackPosition()` / `seekTo(seconds)` (no media rebuild).
148176

149177
- Full theme CSS packs
150178
- DOM screenshot pipelines
151-
- Non-Codex hosts (terminal adapters come later and share only `packages/core`)
152179
- Renaming the host window title / taskbar icon for disguise
153180
- Persisting fish mode across tray restarts
181+
182+
New hosts are added by writing a new `HostSession` adapter (see
183+
[Multi-host model](#multi-host-model)); they share only `packages/core`.

installer/windows/beauticode.iss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ Name: "autostart"; Description: "登录 Windows 后自动启动"; GroupDescripti
5353
Source: "{#StageDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
5454

5555
[Icons]
56-
Name: "{autoprograms}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\scripts\start-beauticode.ps1"""; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"
57-
Name: "{autodesktop}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\scripts\start-beauticode.ps1"""; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"; Tasks: desktopicon
58-
Name: "{userstartup}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\scripts\start-beauticode-engine.ps1"" -NoLaunchCodex"; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"; Tasks: autostart
56+
Name: "{autoprograms}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\apps\tray\start-tray.ps1"" -TargetHost dsh"; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"
57+
Name: "{autodesktop}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\apps\tray\start-tray.ps1"" -TargetHost dsh"; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"; Tasks: desktopicon
58+
Name: "{userstartup}\beautiCode"; Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\apps\tray\start-tray.ps1"" -TargetHost dsh"; WorkingDir: "{app}"; IconFilename: "{app}\beauticode.ico"; Tasks: autostart
5959

6060
[Run]
61-
Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\scripts\start-beauticode.ps1"""; WorkingDir: "{app}"; Description: "启动 beautiCode"; Flags: postinstall nowait skipifsilent
61+
Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File ""{app}\apps\tray\start-tray.ps1"" -TargetHost dsh"; WorkingDir: "{app}"; Description: "启动 beautiCode"; Flags: postinstall nowait skipifsilent

scripts/build-windows-installer.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ foreach ($relativeFile in @(
223223
"apps\tray\session-host.mjs",
224224
"apps\tray\start-tray.ps1",
225225
"assets\beauticode-icon-borderless.png",
226-
"scripts\codex-launch.ps1",
227-
"scripts\start-beauticode.ps1",
228-
"scripts\start-beauticode-engine.ps1",
229226
"packages\core\package.json",
230227
"packages\adapter-codex\package.json",
231228
"packages\adapter-dsh\package.json",

0 commit comments

Comments
 (0)