WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。
[CmdletBinding()]
param(
[string]$OutputDirectory = '',
[string]$IsccPath = '',
[ValidateSet('workbuddy-cn', 'workbuddy-ai', 'codebuddy-cn', 'codebuddy-intl')][string]$Profile = 'workbuddy-cn',
[string]$Version = ''
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 2.0
$scriptsRoot = $PSScriptRoot
$repoRoot = Split-Path -Parent $scriptsRoot
$versionSource = Get-Content -LiteralPath (Join-Path $scriptsRoot 'daemon.js') -Raw -Encoding UTF8
$versionMatch = [regex]::Match($versionSource, "const DAEMON_VERSION = '([^']+)'")
if (-not $versionMatch.Success) { throw 'daemon.js does not contain DAEMON_VERSION.' }
$version = if ([string]::IsNullOrWhiteSpace($Version)) { $versionMatch.Groups[1].Value } else { $Version.Trim() }
if ($version -notmatch '^\d+\.\d+\.\d+$') { throw "Invalid daemon version: $version" }
$productName = (@{'workbuddy-cn'='WorkDaddy'; 'workbuddy-ai'='WorkDaddy AI'; 'codebuddy-cn'='CodeDaddy CN'; 'codebuddy-intl'='CodeDaddy'})[$Profile]
$packageName = (@{'workbuddy-cn'='WorkDaddy'; 'workbuddy-ai'='WorkDaddy-AI'; 'codebuddy-cn'='CodeDaddy-CN'; 'codebuddy-intl'='CodeDaddy'})[$Profile]
$startDescription = ('立即打开 ' + $productName)
$appGuid = if ($Profile -eq 'codebuddy-cn') {
'{{563ABF72-E1F4-4C60-8C6A-B485CC4C5561}'
} elseif ($Profile -eq 'codebuddy-intl') {
'{{399D058D-D944-4333-9935-0CD38C12B44C}'
} elseif ($Profile -eq 'workbuddy-ai') {
'{{D1A8A90C-1F55-4E56-8BB2-7F12A39B9D12}'
} else {
'{{4B857D52-8C5A-4A9A-A17D-0EE8A34A12C7}'
}
if (-not $OutputDirectory) { $OutputDirectory = Join-Path $repoRoot 'release\windows' }
$OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory)
New-Item -ItemType Directory -Force -Path $OutputDirectory | Out-Null
$zipPath = Join-Path $OutputDirectory ("$packageName-$version-win64.zip")
if (-not (Test-Path -LiteralPath $zipPath -PathType Leaf)) {
throw "Windows ZIP is missing: $zipPath. Run scripts/build-win-zip.sh first."
}
if (-not $IsccPath) {
$candidates = @(
(Join-Path ${env:ProgramFiles(x86)} 'Inno Setup 6\ISCC.exe'),
(Join-Path $env:ProgramFiles 'Inno Setup 6\ISCC.exe')
)
$command = Get-Command ISCC.exe -ErrorAction SilentlyContinue
if ($command) { $candidates += $command.Source }
$IsccPath = $candidates | Where-Object { $_ -and (Test-Path -LiteralPath $_ -PathType Leaf) } | Select-Object -First 1
}
if (-not $IsccPath -or -not (Test-Path -LiteralPath $IsccPath -PathType Leaf)) {
throw 'Inno Setup 6 ISCC.exe was not found.'
}
$stageRoot = Join-Path ([IO.Path]::GetTempPath()) ('workdaddy-installer-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Force -Path $stageRoot | Out-Null
try {
Expand-Archive -LiteralPath $zipPath -DestinationPath $stageRoot -Force
$scriptsPayload = Join-Path $stageRoot 'scripts'
if (-not (Test-Path -LiteralPath (Join-Path $stageRoot 'WorkDaddy.portable') -PathType Leaf) -or
-not (Test-Path -LiteralPath (Join-Path $stageRoot 'Start-WorkDaddy.cmd') -PathType Leaf) -or
-not (Test-Path -LiteralPath (Join-Path $stageRoot 'Stop-WorkDaddy.cmd') -PathType Leaf) -or
-not (Test-Path -LiteralPath (Join-Path $stageRoot 'WorkDaddyLauncher.exe') -PathType Leaf)) {
throw 'Portable ZIP is missing its marker or native launcher.'
}
$stagedProfile = (Get-Content -LiteralPath (Join-Path $scriptsPayload 'profile-id.txt') -Raw -Encoding UTF8).Trim()
if ($stagedProfile -ne $Profile) { throw "Portable ZIP profile mismatch: $stagedProfile != $Profile" }
if (-not (Test-Path -LiteralPath (Join-Path $scriptsPayload 'runtime\node\node.exe') -PathType Leaf)) {
throw 'The ZIP payload does not contain the bundled Node runtime.'
}
$builtinPayload = Join-Path $scriptsPayload 'builtin'
$wallpaperPayload = Join-Path $builtinPayload 'wallpapers'
$themePayload = Join-Path $builtinPayload 'nebula\theme.json'
if (-not (Test-Path -LiteralPath $wallpaperPayload -PathType Container) -or
-not (Test-Path -LiteralPath $themePayload -PathType Leaf)) {
throw 'ZIP 内部缺少内置官方壁纸或 nebula/theme.json。'
}
$wallpaperCount = @(Get-ChildItem -LiteralPath $wallpaperPayload -Filter '*.webp' -File -ErrorAction SilentlyContinue).Count
if ($wallpaperCount -le 0) {
throw 'ZIP 内置官方壁纸为空,拒绝生成安装包。'
}
$stagedDaemon = Get-Content -LiteralPath (Join-Path $scriptsPayload 'daemon.js') -Raw -Encoding UTF8
$stagedVersionMatch = [regex]::Match($stagedDaemon, "const DAEMON_VERSION = '([^']+)'")
if (-not $stagedVersionMatch.Success -or $stagedVersionMatch.Groups[1].Value -ne $version) {
throw "ZIP 内部 daemon 版本与安装器版本不一致: $($stagedVersionMatch.Groups[1].Value) != $version"
}
$iss = Join-Path $scriptsRoot 'win\workdaddy.iss'
$args = @(
"/DAppVersion=$version",
"/DProfileId=$Profile",
"/DProductName=$productName",
"/DPackageName=$packageName",
"/DStartDescription=$startDescription",
"/DAppGuid=$appGuid",
"/DStageRoot=$stageRoot",
"/DOutputDir=$OutputDirectory",
$iss
)
& $IsccPath @args
if ($LASTEXITCODE -ne 0) { throw "Inno Setup failed with exit code $LASTEXITCODE." }
$setup = Join-Path $OutputDirectory ("$packageName-Setup-$version.exe")
if (-not (Test-Path -LiteralPath $setup -PathType Leaf) -or (Get-Item -LiteralPath $setup).Length -le 0) {
throw "Setup artifact is missing or empty: $setup"
}
Write-Host "Created $setup"
# Setup.exe 只安装 scripts/ 与原生启动器;便携标记和启动/停止脚本留在 ZIP 中。
$portable = Join-Path $OutputDirectory ("$packageName-Portable-$version.zip")
Move-Item -LiteralPath $zipPath -Destination $portable -Force
if (-not (Test-Path -LiteralPath $portable -PathType Leaf) -or (Get-Item -LiteralPath $portable).Length -le 0) {
throw "Portable artifact is missing or empty: $portable"
}
Write-Host "Created $portable"
} finally {
if (Test-Path -LiteralPath $stageRoot) {
Remove-Item -LiteralPath $stageRoot -Recurse -Force -ErrorAction SilentlyContinue
}
# 构建失败时暂存 ZIP 不再具有发布意义,清理掉;成功路径中它已被改名为便携版。
if (Test-Path -LiteralPath $zipPath -PathType Leaf) {
Remove-Item -LiteralPath $zipPath -Force -ErrorAction SilentlyContinue
}
}