跳到主要内容

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

提交记录
修改.github/workflows/windows-build.yml+13 −0看文件
@@ -88,6 +88,19 @@ jobs:
8888 if-no-files-found: error
8989 overwrite: true
9090 retention-days: 14
91新增: - name: Preserve failed unsigned candidates for installation debugging
92新增: if: ${{ always() && job.status != 'success' }}
93新增: uses: actions/upload-artifact@v4
94新增: with:
95新增: name: ${{ inputs.artifact_name }}-${{ matrix.os }}-failed-candidate
96新增: path: |
97新增: _output/windows-amd64/app/**
98新增: _output/releases/*/windows/Cage-*-windows-amd64-setup-unsigned.exe
99新增: _output/releases/*/windows/SHA256SUMS
100新增: if-no-files-found: ignore
101新增: compression-level: 0
102新增: overwrite: true
103新增: retention-days: 14
91104 - name: Preserve public test reports
92105 if: always()
93106 uses: actions/upload-artifact@v4
修改packaging/windows/Cage.nsi+82 −7看文件
@@ -83,6 +83,49 @@ Var DesktopShortcutControl
8383Var StartMenuShortcutsControl
8484Var InstallationMutex
8585Var TransactionRecord
86新增:Var DiagnosticFile
87新增:Var InstallPhase
88新增:Var InstallOutcome
89新增:Var HelperExit
90新增:Var DiagnosticArguments
91新增:
92新增:Function WriteInstallDiagnostic
93新增: ${If} $DiagnosticFile != ""
94新增: Push $2
95新增: Push $3
96新增: StrCpy $3 0
97新增: IfErrors 0 +2
98新增: StrCpy $3 1
99新增: ClearErrors
100新增: FileOpen $2 "$DiagnosticFile" w
101新增: ${IfNot} ${Errors}
102新增: FileWrite $2 '{"phase":"$InstallPhase","status":"$InstallOutcome","helperExit":"$HelperExit"}$\r$\n'
103新增: FileClose $2
104新增: ${EndIf}
105新增: ${If} $3 == 1
106新增: SetErrors
107新增: ${Else}
108新增: ClearErrors
109新增: ${EndIf}
110新增: Pop $3
111新增: Pop $2
112新增: ${EndIf}
113新增:FunctionEnd
114新增:
115新增:!macro InstallPhase NAME
116新增: StrCpy $InstallPhase "${NAME}"
117新增: Call WriteInstallDiagnostic
118新增:!macroend
119新增:
120新增:Function .onInstFailed
121新增: StrCpy $InstallOutcome "failed"
122新增: Call WriteInstallDiagnostic
123新增:FunctionEnd
124新增:
125新增:Function .onInstSuccess
126新增: StrCpy $InstallOutcome "success"
127新增: Call WriteInstallDiagnostic
128新增:FunctionEnd
86129
87130!macro AcquireInstallationMutex
88131 ; NSIS and UpdateInstaller both reject an existing named object and keep
@@ -215,6 +258,15 @@ FunctionEnd
215258!macroend
216259
217260Function .onInit
261新增: StrCpy $InstallOutcome "running"
262新增: StrCpy $HelperExit ""
263新增: ${GetParameters} $0
264新增: ${GetOptions} $0 "/DIAGNOSTICS=" $DiagnosticFile
265新增: StrCpy $DiagnosticArguments ""
266新增: ${If} $DiagnosticFile != ""
267新增: StrCpy $DiagnosticArguments '-Diagnostics "$DiagnosticFile.helper.json"'
268新增: ${EndIf}
269新增: !insertmacro InstallPhase "initializing"
218270 SetShellVarContext current
219271 SetRegView 64
220272 ${IfNot} ${IsNativeAMD64}
@@ -275,7 +327,7 @@ Function CheckDestination
275327FunctionEnd
276328
277329Function RestorePreservedFiles
278删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation restore -Target "$BackupDir" -Source "$StageDir" -Receipt "$TransactionRecord"'
330新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation restore -Target "$BackupDir" -Source "$StageDir" -Receipt "$TransactionRecord" $DiagnosticArguments'
279331 Pop $0
280332 Pop $1
281333 ${If} $0 != 0
@@ -289,7 +341,7 @@ Function RestorePreservedFiles
289341 SetErrorLevel 2
290342 Abort "原安装目录未能恢复。文件保留在 $BackupDir,新程序保留在 $StageDir。"
291343 ${EndIf}
292删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"'
344新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments'
293345 Pop $0
294346 Pop $1
295347 ${If} $0 != 0
@@ -299,18 +351,21 @@ Function RestorePreservedFiles
299351FunctionEnd
300352
301353Section "Cage" Main
354新增: !insertmacro InstallPhase "acquiring_installation_lock"
302355 !insertmacro AcquireInstallationMutex
303356 StrCpy $TransactionRecord "$INSTDIR.cage-installation.json"
304357 ${If} ${FileExists} "$TransactionRecord"
305358 SetErrorLevel 2
306359 Abort "存在未处理的安装事务记录:$TransactionRecord。请先按记录恢复保留的目录,再重试。"
307360 ${EndIf}
361新增: !insertmacro InstallPhase "checking_destination"
308362 Call CheckDestination
309363 ${GetParent} "$INSTDIR" $0
310364 CreateDirectory "$0"
311365 GetTempFileName $StageDir "$0"
312366 Delete "$StageDir"
313367 CreateDirectory "$StageDir"
368新增: !insertmacro InstallPhase "unpacking_application"
314369 SetOutPath "$StageDir"
315370 ClearErrors
316371!ifdef NSIS_WIN32_MAKENSIS
@@ -327,6 +382,7 @@ Section "Cage" Main
327382 ${EndIf}
328383
329384 ; Install the bundled offline runtime only when WebView2 is absent.
385新增: !insertmacro InstallPhase "detecting_webview_runtime"
330386 SetRegView 32
331387 ReadRegStr $0 HKLM "SOFTWARE\Microsoft\EdgeUpdate\Clients\${WEBVIEW2_APP_ID}" "pv"
332388 ReadRegStr $1 HKCU "Software\Microsoft\EdgeUpdate\Clients\${WEBVIEW2_APP_ID}" "pv"
@@ -336,7 +392,10 @@ Section "Cage" Main
336392 ${If} $1 == ""
337393 ${OrIf} $1 == "0.0.0.0"
338394 DetailPrint "Installing the bundled Microsoft WebView2 runtime..."
395新增: !insertmacro InstallPhase "installing_webview_runtime"
339396 ExecWait '"$StageDir\resources\runtime\MicrosoftEdgeWebView2RuntimeInstallerX64.exe" /silent /install' $0
397新增: StrCpy $HelperExit $0
398新增: Call WriteInstallDiagnostic
340399 ${If} $0 != 0
341400 SetOutPath "$TEMP"
342401 RMDir /r "$StageDir"
@@ -358,9 +417,12 @@ Section "Cage" Main
358417 File /oname=installation-files.ps1 "installation-files.ps1"
359418 File /oname=verified-file-deletion.cs "verified-file-deletion.cs"
360419 DetailPrint "正在检查并保留已有项目和修改文件…"
361删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation prepare -Target "$StageDir" -Source "$INSTDIR" -Backup "$BackupDir" -Receipt "$TransactionRecord"'
420新增: !insertmacro InstallPhase "preparing_file_transaction"
421新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation prepare -Target "$StageDir" -Source "$INSTDIR" -Backup "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments'
362422 Pop $0
363423 Pop $1
424新增: StrCpy $HelperExit $0
425新增: Call WriteInstallDiagnostic
364426 DetailPrint "$1"
365427 ${If} $0 != 0
366428 SetOutPath "$TEMP"
@@ -370,10 +432,11 @@ Section "Cage" Main
370432 ${EndIf}
371433 SetOutPath "$TEMP"
372434 ${If} $ExistingInstall == "1"
435新增: !insertmacro InstallPhase "moving_previous_application"
373436 ClearErrors
374437 Rename "$INSTDIR" "$BackupDir"
375438 ${If} ${Errors}
376删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"'
439新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments'
377440 Pop $0
378441 Pop $1
379442 RMDir /r "$StageDir"
@@ -381,9 +444,12 @@ Section "Cage" Main
381444 Abort "Could not move the installed application. Quit Cage and retry."
382445 ${EndIf}
383446 DetailPrint "正在迁入个人文件并保留原有链接…"
384删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation move -Target "$StageDir" -Source "$BackupDir" -Receipt "$TransactionRecord"'
447新增: !insertmacro InstallPhase "moving_personal_files"
448新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation move -Target "$StageDir" -Source "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments'
385449 Pop $0
386450 Pop $1
451新增: StrCpy $HelperExit $0
452新增: Call WriteInstallDiagnostic
387453 DetailPrint "$1"
388454 ${If} $0 != 0
389455 Call RestorePreservedFiles
@@ -394,6 +460,7 @@ Section "Cage" Main
394460 ${Else}
395461 RMDir "$INSTDIR"
396462 ${EndIf}
463新增: !insertmacro InstallPhase "publishing_application"
397464 ClearErrors
398465 Rename "$StageDir" "$INSTDIR"
399466 ${If} ${Errors}
@@ -405,10 +472,13 @@ Section "Cage" Main
405472 Abort "Could not install Cage. The previous installation has been restored."
406473 ${EndIf}
407474 ${If} $BackupDir != ""
475新增: !insertmacro InstallPhase "cleaning_previous_application"
408476 DetailPrint "正在清理已核对的旧程序文件…"
409删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation cleanup -Target "$INSTDIR" -Source "$BackupDir" -Receipt "$TransactionRecord"'
477新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation cleanup -Target "$INSTDIR" -Source "$BackupDir" -Receipt "$TransactionRecord" $DiagnosticArguments'
410478 Pop $0
411479 Pop $1
480新增: StrCpy $HelperExit $0
481新增: Call WriteInstallDiagnostic
412482 DetailPrint "$1"
413483 ${If} $0 != 0
414484 DetailPrint "旧目录中仍有需要保留的文件:$BackupDir"
@@ -416,14 +486,18 @@ Section "Cage" Main
416486 Abort "安装仍有待恢复的文件。请保留 $TransactionRecord 及其中记录的目录,再处理恢复。"
417487 ${EndIf}
418488 ${Else}
419删除: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord"'
489新增: !insertmacro InstallPhase "completing_file_transaction"
490新增: nsExec::ExecToStack '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$PLUGINSDIR\installation-files.ps1" -Operation complete -Target "$INSTDIR" -Receipt "$TransactionRecord" $DiagnosticArguments'
420491 Pop $0
421492 Pop $1
493新增: StrCpy $HelperExit $0
494新增: Call WriteInstallDiagnostic
422495 ${If} $0 != 0
423496 SetErrorLevel 2
424497 Abort "安装回执未能完成,记录保留在 $TransactionRecord。"
425498 ${EndIf}
426499 ${EndIf}
500新增: !insertmacro InstallPhase "registering_installation"
427501 WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "Cage"
428502 WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}"
429503 WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "Cage contributors"
@@ -450,6 +524,7 @@ Section "Cage" Main
450524 ${EndIf}
451525 WriteRegDWORD HKCU "${UNINSTALL_KEY}" "DesktopShortcut" $DesktopShortcut
452526 WriteRegDWORD HKCU "${UNINSTALL_KEY}" "StartMenuShortcuts" $StartMenuShortcuts
527新增: !insertmacro InstallPhase "completed"
453528 SetErrorLevel 0
454529SectionEnd
455530
修改packaging/windows/installation-files.ps1+28 −0看文件
@@ -7,9 +7,29 @@ param(
77 [string]$Receipt,
88 [string]$Manifest,
99 [string]$Backup,
10新增: [string]$Diagnostics,
1011 [switch]$LegacyTarget
1112)
1213$ErrorActionPreference = 'Stop'
14新增:$diagnosticStep = 'initializing'
15新增:trap {
16新增: $failure = $_
17新增: if ($Diagnostics) {
18新增: try {
19新增: if (!(Test-Path -LiteralPath $Diagnostics)) {
20新增: $chain = @()
21新增: $exception = $failure.Exception
22新增: for ($index = 0; $exception -and $index -lt 4; $index++) {
23新增: $chain += @{type = $exception.GetType().FullName; hresult = $exception.HResult}
24新增: $exception = $exception.InnerException
25新增: }
26新增: @{operation = $Operation; phase = $diagnosticStep; pointerSize = [IntPtr]::Size; errors = $chain} | ConvertTo-Json -Depth 4 |
27新增: Set-Content -LiteralPath $Diagnostics -Encoding UTF8
28新增: }
29新增: } catch { }
30新增: }
31新增: throw $failure
32新增:}
1333$manifestName = 'Cage.install-files.json'
1434$identityName = 'Cage.install-id'
1535
@@ -144,6 +164,7 @@ foreach ($rootPath in @($Target, $Source)) {
144164 }
145165}
146166if ($Operation -eq 'prepare') {
167新增: $diagnosticStep = 'reading_new_manifest'
147168 if (Test-Path -LiteralPath $Receipt) { throw ('仍有未完成的安装事务,请保留并检查回执:' + $Receipt) }
148169 $current = Read-FileManifest (Join-Path $Target $manifestName)
149170 $legacySnapshot = !$current.Count -and $LegacyTarget
@@ -152,6 +173,7 @@ if ($Operation -eq 'prepare') {
152173 try { $current[$identityName] = Stream-Hash $identity } finally { $identity.Dispose() }
153174 }
154175 if (!$current.Count) { throw '新程序缺少有效文件清单,安装已停止。' }
176新增: $diagnosticStep = 'reading_new_uninstaller'
155177 $uninstaller = Open-ReadLocked (Join-Path $Target 'Uninstall.exe')
156178 try { $current['Uninstall.exe'] = Stream-Hash $uninstaller } finally { $uninstaller.Dispose() }
157179 $transfers = [Collections.Generic.List[object]]::new()
@@ -160,6 +182,7 @@ if ($Operation -eq 'prepare') {
160182 $recovery = 'Cage-preserved-files/' + [guid]::NewGuid().ToString('N')
161183 $programDirectories = Directory-Paths @($current.Keys)
162184 if ($Source -and (Test-Path -LiteralPath $Source -PathType Container)) {
185新增: $diagnosticStep = 'scanning_previous_installation'
163186 $Source = [IO.Path]::GetFullPath($Source).TrimEnd([IO.Path]::DirectorySeparatorChar)
164187 $previous = Read-FileManifest (Join-Path $Source $manifestName)
165188 $previousDirectories = Directory-Paths @($previous.Keys)
@@ -220,8 +243,10 @@ if ($Operation -eq 'prepare') {
220243 }
221244 }
222245 }
246新增: $diagnosticStep = 'writing_new_manifest'
223247 $files = @($current.Keys | Sort-Object | ForEach-Object { @{ path = $_; sha256 = $current[$_] } })
224248 @{ version = 1; files = $files } | ConvertTo-Json -Depth 4 | Set-Content -LiteralPath (Join-Path $Target $manifestName) -Encoding UTF8
249新增: $diagnosticStep = 'writing_transaction_receipt'
225250 $record = @{kind = 'cage-installation'; version = 1; installPath = $Source; stagePath = $Target; backupPath = $Backup; files = @($transfers); directories = $directories; moves = @($moves)}
226251 $encoding = [Text.UTF8Encoding]::new($true)
227252 [byte[]]$bytes = $encoding.GetPreamble() + $encoding.GetBytes(($record | ConvertTo-Json -Depth 6))
@@ -232,6 +257,7 @@ if ($Operation -eq 'prepare') {
232257 [IO.File]::Move($temporary, $Receipt)
233258 } finally { if (Test-Path -LiteralPath $temporary) { [IO.File]::Delete($temporary) } }
234259} elseif ($Operation -in @('move','restore')) {
260新增: $diagnosticStep = 'moving_preserved_files'
235261 $transfer = Get-Content -LiteralPath $Receipt -Raw -Encoding UTF8 | ConvertFrom-Json
236262 $moves = @($transfer.moves)
237263 if ($Operation -eq 'restore') { [Array]::Reverse($moves) }
@@ -263,6 +289,7 @@ if ($Operation -eq 'prepare') {
263289 Write-Output ('同名修改或旧程序文件已保留在 ' + (Join-Path $Target 'Cage-preserved-files'))
264290 }
265291} elseif ($Operation -eq 'cleanup') {
292新增: $diagnosticStep = 'verifying_previous_file_ownership'
266293 $transfer = Get-Content -LiteralPath $Receipt -Raw -Encoding UTF8 | ConvertFrom-Json
267294 $actual = @(Read-Tree $Source @($transfer.files.path) | Where-Object { !($_.Attributes -band [IO.FileAttributes]::ReparsePoint) } | ForEach-Object { Relative-Path $Source $_.FullName })
268295 foreach ($entry in $transfer.files) {
@@ -284,6 +311,7 @@ if ($Operation -eq 'prepare') {
284311 } else { [IO.Directory]::Delete($Source) }
285312 Complete-Transfer
286313} elseif ($Operation -eq 'complete') {
314新增: $diagnosticStep = 'completing_transaction_receipt'
287315 Complete-Transfer
288316} else {
289317 # The payload list comes from this uninstaller's embedded build manifest.
修改scripts/test-windows-install.ps1+15 −2看文件
@@ -16,13 +16,26 @@ function Assert-PersonalData {
1616}
1717function Run-Installer {
1818 param([switch]$Update, [int]$ExpectedExitCode = 0, [string[]]$ShortcutOptions = @())
19删除: $arguments = @('/S')
19新增: $installationReport = Join-Path (Get-WindowsWorkbenchTestBase) ('cage-smoke-installation-' + [guid]::NewGuid().ToString('N') + '.json')
20新增: $arguments = @('/S', "/DIAGNOSTICS=$installationReport")
2021 if ($Update) { $arguments += '/UPDATE' }
2122 $arguments += $ShortcutOptions
2223 $arguments += "/D=$target"
2324 $process = Start-Process -FilePath $Installer -ArgumentList $arguments -PassThru
2425 if (-not $process.WaitForExit(300000)) { throw 'Installer exceeded five minutes.' }
25删除: if ($process.ExitCode -ne $ExpectedExitCode) { throw "Installer returned $($process.ExitCode), expected $ExpectedExitCode" }
26新增: if ($process.ExitCode -ne $ExpectedExitCode) {
27新增: foreach ($path in @($installationReport, "$installationReport.helper.json")) {
28新增: try {
29新增: if ((Test-Path -LiteralPath $path -PathType Leaf) -and (Get-Item -LiteralPath $path).Length -le 8192) {
30新增: $value = Get-Content -LiteralPath $path -Raw | ConvertFrom-Json -AsHashtable
31新增: $safe = @{phase = $value['phase']; status = $value['status']; helperExit = $value['helperExit']; operation = $value['operation']; pointerSize = $value['pointerSize']}
32新增: if ($value['errors']) { $safe.errors = @($value['errors'] | Select-Object -First 4 | ForEach-Object { @{type = $_['type']; hresult = $_['hresult']} }) }
33新增: Write-Host ('Cage installer diagnostic: ' + ($safe | ConvertTo-Json -Depth 4 -Compress))
34新增: }
35新增: } catch { Write-Warning 'The bounded installer diagnostic could not be read.' }
36新增: }
37新增: throw "Installer returned $($process.ExitCode), expected $ExpectedExitCode"
38新增: }
2639}
2740$desktopShortcut = Join-Path ([Environment]::GetFolderPath('DesktopDirectory')) 'Cage.lnk'
2841$startMenuDirectory = Join-Path ([Environment]::GetFolderPath('Programs')) 'Cage'
修改scripts/test-windows-installation-files.ps1+20 −0看文件
@@ -63,6 +63,26 @@ function Commit([string]$Old, [string]$Stage, [string]$Receipt) {
6363 return $backup
6464}
6565try {
66新增: # A new install has no backup path or existing ownership manifest.
67新增: $scenario = Join-Path $root 'first-install'
68新增: $old = Join-Path $scenario 'empty-destination'; $stage = Join-Path $scenario 'staged'; $receipt = Join-Path $scenario 'receipt.json'
69新增: [IO.Directory]::CreateDirectory($old) | Out-Null
70新增: App $stage 'fresh'
71新增: Invoke-Helper @('-Operation','prepare','-Source',$old,'-Target',$stage,'-Receipt',$receipt)
72新增: $transfer = Get-Content -LiteralPath $receipt -Raw | ConvertFrom-Json
73新增: Check (!$transfer.backupPath -and @($transfer.moves).Count -eq 0) 'First install invented a backup or personal file transfer.'
74新增: [IO.Directory]::Delete($old); [IO.Directory]::Move($stage, $old)
75新增: Invoke-Helper @('-Operation','complete','-Target',$old,'-Receipt',$receipt)
76新增: Check (!(Test-Path -LiteralPath $receipt)) 'First install did not finish its transaction.'
77新增:
78新增: $diagnostic = Join-Path $scenario 'diagnostic.json'
79新增: Write-File (Join-Path $old 'Cage.install-files.json') 'invalid-private-manifest'
80新增: Invoke-Helper @('-Operation','prepare','-Target',$old,'-Receipt',$receipt,'-Diagnostics',$diagnostic) 1
81新增: $text = Get-Content -LiteralPath $diagnostic -Raw
82新增: $failure = $text | ConvertFrom-Json
83新增: Check ($failure.operation -eq 'prepare' -and $failure.phase -eq 'reading_new_manifest' -and @($failure.errors).Count -gt 0) 'Helper omitted its safe failure classification.'
84新增: Check (!$text.Contains($root) -and !$text.Contains('invalid-private-manifest') -and !$text.Contains('message')) 'Helper diagnostic contains file paths or private error text.'
85新增:
6686 foreach ($manifestState in @('current','missing','invalid')) {
6787 $scenario = Join-Path $root $manifestState
6888 $old = Join-Path $scenario 'installed'; $stage = Join-Path $scenario 'staged'; $receipt = Join-Path $scenario 'receipt.json'