跳到主要内容

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

浏览文件

native-component-manifest.pl

41 行 · 2.3 KB历史下载
1#!/usr/bin/perl
2use strict;
3use warnings;
4use JSON::PP;
5use Digest::SHA;
6use Fcntl qw(:DEFAULT);
7
8my ($mode, $manifest_path, $kit) = @ARGV;
9die "Invalid component operation\n" unless defined($mode) && $mode =~ /^(source|targets|verify|publish)$/;
10open(my $input, '<', $manifest_path) or die "Component manifest unavailable\n";
11local $/;
12my $encoded = <$input>;
13close($input);
14die "Component manifest too large\n" if length($encoded) > 4 * 1024 * 1024;
15my $manifest = decode_json($encoded);
16die "Invalid component manifest\n" unless $manifest->{protocol} == 1 && $manifest->{system} eq 'macos' && ref($manifest->{files}) eq 'ARRAY' && $manifest->{revision} =~ /^[a-f0-9]{64}$/;
17for my $entry (@{$manifest->{files}}) {
18 my ($source, $target) = ($entry->{source}, $entry->{target} // '');
19 die "Invalid component source\n" unless defined($source) && $source !~ m{(?:^/|(?:^|/)\.\.?(?:/|$)|[\x00\r\n])};
20 die "Invalid component target\n" if $target ne '' && ($target !~ m{^/(?:Applications/Cage[^/]*\.app/|usr/local/libexec/cage-)} || $target =~ m{(?:^|/)\.\.?(?:/|$)|[\x00\r\n]});
21 die "Invalid component digest\n" unless $entry->{sha256} =~ /^[a-f0-9]{64}$/ && $entry->{installed_sha256} =~ /^[a-f0-9]{64}$/;
22 if ($mode eq 'targets') { print "$source\0$target\0" if $target ne ''; next; }
23 next if $mode ne 'source' && $target eq '';
24 my $path = $mode eq 'source' ? "$kit/$source" : $target;
25 open(my $file, '<', $path) or die "Missing component $path\n";
26 binmode($file);
27 my $actual = Digest::SHA->new(256)->addfile($file)->hexdigest;
28 close($file);
29 my $expected = $mode eq 'source' ? $entry->{sha256} : $entry->{installed_sha256};
30 die "Component digest mismatch $path\n" unless $actual eq $expected;
31}
32if ($mode eq 'publish') {
33 die "Component publication requires administrator\n" unless $> == 0;
34 my $target = '/var/db/cage-components.json';
35 die "Invalid existing component receipt\n" if -l $target || (-e $target && !-f $target);
36 my $temporary = "$target.$$";
37 sysopen(my $output, $temporary, O_WRONLY | O_CREAT | O_EXCL, 0644) or die "Cannot stage component receipt\n";
38 print $output $encoded or die "Cannot write component receipt\n";
39 close($output) or die "Cannot close component receipt\n";
40 rename($temporary, $target) or die "Cannot publish component receipt\n";
41}