跳到主要内容

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

浏览文件

bundle-cloud-kit.mjs

54 行 · 3.2 KB历史下载
1// Prepare the Linux server and installation recipe for SSH deployment.
2// An explicitly selected offline kit can also be supplied for private builds.
3import fs from "node:fs";
4import os from "node:os";
5import path from "node:path";
6import { createHash } from "node:crypto";
7import { execFileSync } from "node:child_process";
8import { createGzip } from "node:zlib";
9import { pipeline } from "node:stream/promises";
10
11const target = path.resolve(process.argv[2], "cloud-linux-amd64.tar");
12const digest = async file => {
13 const hash = createHash("sha256");
14 for await (const chunk of fs.createReadStream(file)) hash.update(chunk);
15 return hash.digest("hex");
16};
17const offline = process.env.CAGE_CLOUD_KIT;
18if (offline) {
19 if (await digest(offline) !== fs.readFileSync(offline + ".sha256", "utf8").trim())
20 throw Error("Cloud deployment kit checksum mismatch");
21 fs.copyFileSync(offline, target);
22} else {
23 const stage = fs.mkdtempSync(path.join(os.tmpdir(), "cage-bootstrap-"));
24 try {
25 const version = fs.readFileSync("VERSION", "utf8").trim();
26 const binary = path.join(stage, "cage");
27 for (const arch of ["amd64", "arm64"]) {
28 if (!fs.existsSync(path.resolve("internal/tailnetassets/assets/cage-tailnet-linux-" + arch + ".gz"))) throw Error("Build Tailscale guest assets before packaging the cloud kit");
29 }
30 execFileSync("go", ["build", "-trimpath", "-ldflags", "-s -w -X github.com/sylvinus/agent-vm/internal/version.Version=" + version, "-o", binary, "./cmd/cage"], {
31 env: {...process.env, CGO_ENABLED:"0", GOOS:"linux", GOARCH:"amd64"}, stdio:"inherit"
32 });
33 await pipeline(fs.createReadStream(binary), createGzip(), fs.createWriteStream(binary + ".gz"));
34 fs.unlinkSync(binary);
35 const {mihomo} = JSON.parse(fs.readFileSync("packaging/linux/dependencies.json"));
36 const cache = path.resolve("_output/linux-deps", mihomo.file);
37 const core = path.join(stage, "mihomo.gz");
38 if (fs.existsSync(cache)) fs.copyFileSync(cache, core);
39 else execFileSync("curl", ["--fail","--location","--retry","3","--max-time","300","--output",core,mihomo.url],{stdio:"inherit"});
40 if (await digest(core) !== mihomo.sha256) throw Error("Linux Mihomo checksum mismatch");
41 const recipe = path.join(stage, "deploy/cloud");
42 fs.mkdirSync(recipe, {recursive:true});
43 for (const name of ["Dockerfile.guest","restore-apt-sources.sh","build-guest.sh"])
44 fs.copyFileSync(path.join("deploy/cloud",name),path.join(recipe,name));
45 fs.mkdirSync(path.join(stage,"internal/cage"),{recursive:true});
46 fs.copyFileSync("internal/cage/apt-bootstrap.sh",path.join(stage,"internal/cage/apt-bootstrap.sh"));
47 for (const name of ["cage-server.service","cage-container-engine.service"])
48 fs.copyFileSync(path.join("deploy/cloud",name),path.join(stage,name));
49 const runtime = JSON.parse(fs.readFileSync("deploy/cloud/runtime-artifacts.json"));
50 fs.writeFileSync(path.join(stage,"engine-downloads"),runtime.artifacts.map(a=>[a.sha256,a.file,a.url].join(" ")).join("\n")+"\n");
51 execFileSync("tar", ["-cf",target,"-C",stage,"."],{env:{...process.env,COPYFILE_DISABLE:"1"},stdio:"inherit"});
52 } finally { fs.rmSync(stage,{recursive:true,force:true}); }
53}
54fs.writeFileSync(target+".sha256",await digest(target)+"\n");