跳到主要内容

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

浏览文件

windows_resources.ps1

26 行 · 2.5 KB历史下载
1param([Parameter(Mandatory)][string]$Query)
2$ErrorActionPreference='Stop'
3$targetId=[guid]'9e97dd9a-eb36-489a-bb1d-8d28a0d78682'
4$module=New-Module -Name Hyper-V -ScriptBlock {
5 $script:id=[guid]'9e97dd9a-eb36-489a-bb1d-8d28a0d78682';$script:state='Off';$script:cpus=2;$script:start=5GB;$script:min=512MB;$script:max=1TB;$script:dynamic=$false;$script:mutations=0;$script:failMemory=$false
6 function Get-VM {param([Guid]$Id) if($Id -ne $script:id){throw 'Unscoped VM'};[pscustomobject]@{Id=$Id;State=$script:state;MemoryAssigned=0}}
7 function Get-VMProcessor {param($VM) if($VM.Id -ne $script:id){throw 'Wrong VM'};[pscustomobject]@{Count=$script:cpus}}
8 function Get-VMMemory {param($VM) if($VM.Id -ne $script:id){throw 'Wrong VM'};[pscustomobject]@{Startup=$script:start;Minimum=$script:min;Maximum=$script:max;DynamicMemoryEnabled=$script:dynamic}}
9 function Set-VMProcessor {param($VM,[int]$Count) if($VM.Id -ne $script:id -or $script:state -ne 'Off'){throw 'Unsafe apply'};$script:cpus=$Count;$script:mutations++}
10 function Set-VMMemory {param($VM,[bool]$DynamicMemoryEnabled,[long]$MinimumBytes,[long]$StartupBytes,[long]$MaximumBytes) if($VM.Id -ne $script:id -or $script:state -ne 'Off'){throw 'Unsafe memory apply'};if($script:failMemory -and $MaximumBytes -eq 16GB){throw 'Synthetic memory failure'};$script:min=$MinimumBytes;$script:start=$StartupBytes;$script:max=$MaximumBytes;$script:dynamic=$DynamicMemoryEnabled;$script:mutations++}
11 Export-ModuleMember -Function *
12};$module|Import-Module -Force
13$memoryGiB=0;$cpus=0;$read=(& $Query)|ConvertFrom-Json
14if($read.cpus -ne 2 -or $read.memory_startup_bytes -ne 5GB -or (& $module {$script:mutations}) -ne 0){throw 'Read mutated resource settings'}
15$memoryGiB=8;$cpus=4;$applied=(& $Query)|ConvertFrom-Json
16if($applied.cpus -ne 4 -or $applied.memory_maximum_bytes -ne 8GB -or !$applied.dynamic_memory){throw 'Apply mismatch'}
17& $module {$script:state='Running'}
18$blocked=$false;try{& $Query|Out-Null}catch{$blocked=$true}
19if(!$blocked -or (& $module {$script:mutations}) -ne 2){throw 'Running VM changed'}
20& $module {$script:state='Off'};$memoryGiB=2
21$blocked=$false;try{& $Query|Out-Null}catch{$blocked=$true}
22if(!$blocked -or (& $module {$script:mutations}) -ne 2){throw 'Invalid memory changed VM'}
23& $module {$script:failMemory=$true};$memoryGiB=16;$cpus=6
24$blocked=$false;try{& $Query|Out-Null}catch{$blocked=$true}
25if(!$blocked -or (& $module {$script:cpus}) -ne 4 -or (& $module {$script:max}) -ne 8GB){throw 'Failed apply did not restore prior resource settings'}
26'Windows resource exact VM, readback, stopped apply and rollback passed.'