跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录
修改packaging/windows/Cage.nsi+61 −1看文件
@@ -117,6 +117,44 @@ FunctionEnd
117117 Call WriteInstallDiagnostic
118118!macroend
119119
120新增:Function un.WriteInstallDiagnostic
121新增: ${If} $DiagnosticFile != ""
122新增: Push $2
123新增: Push $3
124新增: StrCpy $3 0
125新增: IfErrors 0 +2
126新增: StrCpy $3 1
127新增: ClearErrors
128新增: FileOpen $2 "$DiagnosticFile" w
129新增: ${IfNot} ${Errors}
130新增: FileWrite $2 '{"phase":"$InstallPhase","status":"$InstallOutcome","helperExit":"$HelperExit"}$\r$\n'
131新增: FileClose $2
132新增: ${EndIf}
133新增: ${If} $3 == 1
134新增: SetErrors
135新增: ${Else}
136新增: ClearErrors
137新增: ${EndIf}
138新增: Pop $3
139新增: Pop $2
140新增: ${EndIf}
141新增:FunctionEnd
142新增:
143新增:!macro UninstallPhase NAME
144新增: StrCpy $InstallPhase "${NAME}"
145新增: Call un.WriteInstallDiagnostic
146新增:!macroend
147新增:
148新增:Function un.onUninstFailed
149新增: StrCpy $InstallOutcome "failed"
150新增: Call un.WriteInstallDiagnostic
151新增:FunctionEnd
152新增:
153新增:Function un.onUninstSuccess
154新增: StrCpy $InstallOutcome "success"
155新增: !insertmacro UninstallPhase "completed"
156新增:FunctionEnd
157新增:
120158Function .onInstFailed
121159 StrCpy $InstallOutcome "failed"
122160 Call WriteInstallDiagnostic
@@ -250,6 +288,7 @@ FunctionEnd
250288 ; Exclusive write access also detects images whose VM/controller has no window.
251289 System::Call 'kernel32::CreateFileW(w "$INSTDIR\${FILE}", i 0x40000000, i 0, p 0, i 3, i 0, p 0) p .r0'
252290 ${If} $0 == -1
291新增: StrCpy $HelperExit "application_file_in_use"
253292 SetErrorLevel 2
254293 Abort "Quit Cage and stop its environment before installing or uninstalling."
255294 ${EndIf}
@@ -529,15 +568,27 @@ Section "Cage" Main
529568SectionEnd
530569
531570Function un.onInit
571新增: StrCpy $InstallOutcome "running"
572新增: StrCpy $HelperExit ""
573新增: StrCpy $DiagnosticArguments ""
574新增: ${GetParameters} $0
575新增: ${GetOptions} $0 "/DIAGNOSTICS=" $DiagnosticFile
576新增: ${If} $DiagnosticFile != ""
577新增: StrCpy $DiagnosticArguments '-Diagnostics "$DiagnosticFile.helper.json"'
578新增: ${EndIf}
579新增: !insertmacro UninstallPhase "checking_installation_identity"
532580 SetShellVarContext current
533581 SetRegView 64
534582 FileOpen $0 "$INSTDIR\Cage.install-id" r
535583 FileRead $0 $1
536584 FileClose $0
537585 ${If} $1 != "${APP_ID}"
586新增: StrCpy $HelperExit "identity_mismatch"
587新增: Call un.WriteInstallDiagnostic
538588 SetErrorLevel 2
539589 Abort "This is not a Cage installation folder."
540590 ${EndIf}
591新增: !insertmacro UninstallPhase "checking_stopped_processes"
541592 !insertmacro CheckStopped "Cage.exe"
542593 !insertmacro CheckStopped "resources\cage.exe"
543594 !insertmacro CheckStopped "resources\mihomo.exe"
@@ -545,8 +596,12 @@ Function un.onInit
545596FunctionEnd
546597
547598Section "Uninstall"
599新增: !insertmacro UninstallPhase "acquiring_installation_lock"
548600 !insertmacro AcquireInstallationMutex
601新增: !insertmacro UninstallPhase "checking_pending_transaction"
549602 ${If} ${FileExists} "$INSTDIR.cage-installation.json"
603新增: StrCpy $HelperExit "pending_install_transaction"
604新增: Call un.WriteInstallDiagnostic
550605 SetErrorLevel 2
551606 Abort "存在待恢复的安装事务,请先处理 $INSTDIR.cage-installation.json 中记录的目录。"
552607 ${EndIf}
@@ -555,18 +610,23 @@ Section "Uninstall"
555610 File /oname=installation-files.ps1 "installation-files.ps1"
556611 File /oname=verified-file-deletion.cs "verified-file-deletion.cs"
557612 File /oname=install-files.json "${FILE_MANIFEST}"
558删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation uninstall -Target "$INSTDIR" -Manifest "$PLUGINSDIR\install-files.json"'
613新增: !insertmacro UninstallPhase "removing_owned_files"
614新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation uninstall -Target "$INSTDIR" -Manifest "$PLUGINSDIR\install-files.json" $DiagnosticArguments'
559615 Pop $0
560616 Pop $1
617新增: StrCpy $HelperExit $0
618新增: Call un.WriteInstallDiagnostic
561619 DetailPrint "$1"
562620 ${If} $0 != 0
563621 SetErrorLevel 2
564622 Abort "部分程序文件正在使用或无法读取,卸载未完成。个人文件已保留,请关闭占用程序后重试。"
565623 ${EndIf}
624新增: !insertmacro UninstallPhase "removing_shortcuts_and_registration"
566625 Delete "$DESKTOP\Cage.lnk"
567626 Delete "$SMPROGRAMS\Cage\Cage.lnk"
568627 Delete "$SMPROGRAMS\Cage\Uninstall Cage.lnk"
569628 RMDir "$SMPROGRAMS\Cage"
570629 DeleteRegKey HKCU "${UNINSTALL_KEY}"
630新增: !insertmacro UninstallPhase "removing_install_directory"
571631 RMDir "$INSTDIR"
572632SectionEnd
修改packaging/windows/installation-files.ps1+3 −0看文件
@@ -316,11 +316,13 @@ if ($Operation -eq 'prepare') {
316316 Complete-Transfer
317317} else {
318318 # The payload list comes from this uninstaller's embedded build manifest.
319新增: $diagnosticStep = 'reading_uninstall_manifest'
319320 $owned = Read-FileManifest $Manifest
320321 if (!$owned.Count) { throw '卸载文件清单无效,原文件已保留。' }
321322 $installed = Read-FileManifest (Join-Path $Target $manifestName)
322323 if ($installed.ContainsKey('Uninstall.exe')) { $owned['Uninstall.exe'] = $installed['Uninstall.exe'] }
323324 $actual = @(Read-Tree $Target @($owned.Keys) | Where-Object { !($_.Attributes -band [IO.FileAttributes]::ReparsePoint) } | ForEach-Object { Relative-Path $Target $_.FullName })
325新增: $diagnosticStep = 'deleting_verified_program_files'
324326 foreach ($relative in $owned.Keys) {
325327 if ($relative -ne $identityName -and $relative -in $actual) { Remove-MatchingFile $Target $relative $owned[$relative] }
326328 }
@@ -334,6 +336,7 @@ if ($Operation -eq 'prepare') {
334336 $directory = Split-Path $relative -Parent
335337 while ($directory) { $directories += $directory.Replace('\', '/'); $directory = Split-Path $directory -Parent }
336338 }
339新增: $diagnosticStep = 'removing_program_directories'
337340 Remove-EmptyDirectories $Target $directories
338341 # A retained identity lets a later installation reuse this data-bearing folder.
339342 $remaining = @(Get-ChildItem -LiteralPath $Target -Force | Where-Object Name -ne $identityName)
修改scripts/test-windows-installation-files.ps1+7 −2看文件
@@ -101,7 +101,7 @@ function Test-InstallerTransaction {
101101 try {
102102 if (!$process.WaitForExit(30000)) { $process.Kill($true); $process.WaitForExit(); throw 'The owned NSIS fixture exceeded 30 seconds.' }
103103 if ($process.ExitCode -ne 0) {
104删除: foreach ($path in @($report, "$report.helper.json")) {
104新增: foreach ($path in @($report, "$report.helper.json", "$report.uninstall.json", "$report.uninstall.json.helper.json")) {
105105 if ((Test-Path -LiteralPath $path) -and (Get-Item -LiteralPath $path).Length -le 8192) { Write-Output ('Quick NSIS diagnostic: ' + (Get-Content -LiteralPath $path -Raw)) }
106106 }
107107 throw "The NSIS fixture returned $($process.ExitCode)."
@@ -117,7 +117,7 @@ function Test-InstallerTransaction {
117117 } finally {
118118 if (Test-Path $key) {
119119 if ((Get-ItemProperty $key).InstallLocation -ne $target) { throw 'NSIS fixture registration changed owner; retained for inspection.' }
120删除: Run-Fixture (Join-Path $target 'Uninstall.exe') @('/S')
120新增: Run-Fixture (Join-Path $target 'Uninstall.exe') @('/S',('/DIAGNOSTICS="' + $report + '.uninstall.json"'))
121121 # NSIS can return from its bootstrapper while the TEMP worker is
122122 # still running. Its helper removes the target before NSIS clears
123123 # registration and shortcuts, so target disappearance is not done.
@@ -126,6 +126,11 @@ function Test-InstallerTransaction {
126126 }
127127 }
128128 $remaining = @{target = (Test-Path -LiteralPath $target); registration = (Test-Path $key); desktopShortcut = (Test-Path -LiteralPath $desktop); startMenu = (Test-Path -LiteralPath $menu)}
129新增: if ($remaining.Values -contains $true) {
130新增: foreach ($path in @("$report.uninstall.json", "$report.uninstall.json.helper.json")) {
131新增: if ((Test-Path -LiteralPath $path) -and (Get-Item -LiteralPath $path).Length -le 8192) { Write-Output ('Quick NSIS uninstall diagnostic: ' + (Get-Content -LiteralPath $path -Raw)) }
132新增: }
133新增: }
129134 Check (!($remaining.Values -contains $true)) ('NSIS fixture did not finish uninstalling owned artifacts: ' + ($remaining | ConvertTo-Json -Compress))
130135 Write-Output 'PASS: production NSIS silently installed/uninstalled its text-only fixture through PowerShell 5.1 transactions; no application or VM was started.'
131136}