跳到主要内容

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

浏览文件

qa-large-file.ps1

25 行 · 3.2 KB历史下载
1#requires -Version 5.1
2param([Parameter(Mandatory)][string]$ProfilePath,[Parameter(Mandatory)][string]$EvidenceDirectory)
3$ErrorActionPreference='Stop';$ProgressPreference='SilentlyContinue'
4$profile=Get-Content -LiteralPath $ProfilePath -Raw|ConvertFrom-Json;$utf8=[Text.UTF8Encoding]::new($false)
5$owned=[Collections.Generic.List[Diagnostics.Process]]::new()
6function Start-Transfer([string]$Operation,[bool]$Helper=$false){
7 $s=[Diagnostics.ProcessStartInfo]::new();$s.FileName=if($Helper){Join-Path ([IO.Path]::GetDirectoryName($profile.relay_executable)) 'cage-guest-files.exe'}else{$profile.relay_executable}
8 $s.Arguments=if($Helper){$Operation}else{'--relay-profile "'+$ProfilePath+'" '+$Operation};if($Operation -eq 'export'){$s.Arguments+=' --paths-stdin'}
9 $s.UseShellExecute=$false;$s.CreateNoWindow=$true;$s.RedirectStandardInput=$true;$s.RedirectStandardOutput=$true;$s.RedirectStandardError=$true;$s.StandardOutputEncoding=$utf8
10 $p=[Diagnostics.Process]::Start($s);$owned.Add($p);$null=$p.StandardError.ReadToEndAsync();$p
11}
12function Paths($P,$Selection){$bytes=$utf8.GetBytes((ConvertTo-Json -InputObject @($Selection) -Compress)+"`n");$P.StandardInput.BaseStream.Write($bytes,0,$bytes.Length);$P.StandardInput.Close()}
13function Result($P){$read=$P.StandardOutput.ReadLineAsync();if(!$read.Wait(120000) -or !$read.Result -or !$P.WaitForExit(120000) -or $P.ExitCode -ne 0){throw 'The bounded archive stream did not complete.'};$read.Result|ConvertFrom-Json}
14function Hash([string]$File){(Get-FileHash -LiteralPath $File -Algorithm SHA256).Hash}
15try {
16 $directory=Join-Path $EvidenceDirectory ([guid]::NewGuid().ToString('N'));$null=[IO.Directory]::CreateDirectory($directory)
17 $source=Join-Path $directory 'stream-64MiB.bin';$file=[IO.File]::Open($source,'CreateNew','Write','None');$buffer=New-Object byte[] (64KB);for($i=0;$i -lt $buffer.Length;$i++){$buffer[$i]=[byte]($i%251)}
18 try{for($i=0;$i -lt 1024;$i++){$file.Write($buffer,0,$buffer.Length)}}finally{$file.Dispose()}
19 $write=Start-Transfer 'export' $true;Paths $write @($source);$import=Start-Transfer 'import';$write.StandardOutput.BaseStream.CopyTo($import.StandardInput.BaseStream);$import.StandardInput.Close();$guest=Result $import
20 if(!$write.WaitForExit(120000) -or $write.ExitCode -ne 0 -or @($guest.paths).Count -ne 1){throw 'The host archive source failed.'}
21 $export=Start-Transfer 'export';Paths $export @($guest.paths);$read=Start-Transfer 'import' $true;$export.StandardOutput.BaseStream.CopyTo($read.StandardInput.BaseStream);$read.StandardInput.Close();$returnedHost=Result $read
22 if(!$export.WaitForExit(120000) -or $export.ExitCode -ne 0 -or @($returnedHost.paths).Count -ne 1 -or (Get-Item -LiteralPath $returnedHost.paths[0]).Length -ne 64MB -or (Hash $source) -ne (Hash $returnedHost.paths[0])){throw 'The 64 MiB stream hash or completion status differs.'}
23 $result=[ordered]@{bytes=64MB;host_to_guest_complete=$true;guest_to_host_complete=$true;sha256_equal=$true;clipboard_unchanged=$true}
24 [IO.File]::WriteAllText((Join-Path $EvidenceDirectory 'large-file-result.json'),($result|ConvertTo-Json),$utf8);$result|ConvertTo-Json -Compress
25}finally{foreach($p in $owned){try{$p.StandardInput.Close();if(!$p.WaitForExit(1000)){$p.Kill()};$p.Dispose()}catch{}}}