跳到主要内容

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

浏览文件

Makefile

161 行 · 6.7 KB历史下载
1# agent-vm 0.3, the Go binary, with Lima built in from third_party/.
2#
3# make _output/bin/agent-vm, with the guest agent and templates
4# make install build it, then link it onto the PATH (AGENT_VM_BIN_DIR
5# to choose where; ~/.local/bin by default)
6# make limactl Lima's own limactl from third_party/, for debugging
7# make test the Go tests
8# make check-windows the Windows build and tests compile and vet, from any OS
9# make test-third-party the tests of the modules in third_party/, patched
10
11GO ?= go
12GOOS ?= $(shell $(GO) env GOOS)
13GOARCH ?= $(shell $(GO) env GOARCH)
14# Cage's VERSION file owns the default. Upstream release tooling can still
15# supply VERSION explicitly when building a historical agent-vm tag.
16VERSION ?= $(shell tr -d '\r\n' < VERSION)
17LIMA_VERSION := $(shell cat internal/limaembed/lima-version)
18
19ifeq ($(GOARCH),amd64)
20GUEST_ARCH := x86_64
21else ifeq ($(GOARCH),arm64)
22GUEST_ARCH := aarch64
23else
24GUEST_ARCH := $(GOARCH)
25endif
26ifeq ($(GOOS),windows)
27EXE := .exe
28endif
29
30ASSETS := internal/limaembed/assets
31LDFLAGS := -s -w \
32 -X github.com/sylvinus/agent-vm/internal/version.Version=$(VERSION) \
33 -X github.com/lima-vm/lima/v2/pkg/version.Version=$(LIMA_VERSION)
34# yq only edits Lima's YAML here: without its other formats (Lua, HCL, TOML,
35# XML...), 10% smaller. Tests run with the same tags.
36TAGS := yq_noxml,yq_nolua,yq_noini,yq_nohcl,yq_notoml,yq_noprops,yq_nocsv,yq_nouri,yq_nobase64,yq_nosh,yq_noshell
37# cgo on macOS only, where vz and Lima's file watcher need it. On Linux the
38# hostagent's DNS server uses Go's resolver (Lima builds it with the
39# system's), and the binary cross-compiles with no C compiler.
40ifeq ($(GOOS),darwin)
41CGO_ENABLED ?= 1
42else
43CGO_ENABLED ?= 0
44endif
45GO_BUILD := CGO_ENABLED=$(CGO_ENABLED) $(GO) build -trimpath -tags $(TAGS) -ldflags "$(LDFLAGS)"
46
47.PHONY: all agent-vm install limactl assets test test-go check-windows test-third-party fuzz clean
48
49all: agent-vm
50
51# Claude Cage ships a separate entry point with a mandatory proxy profile.
52cage: cage-ui assets tailnet-assets
53 $(GO_BUILD) -o _output/bin/cage$(EXE) ./cmd/cage
54ifeq ($(GOOS),darwin)
55 codesign -f --entitlements third_party/lima/vz.entitlements -s - _output/bin/cage
56endif
57
58cage-ui:
59 npm --prefix ui ci --no-audit --no-fund
60 npm run --prefix ui build
61
62.PHONY: cage cage-ui cage-windows package-windows cage-linux package-linux check-linux
63cage-linux:
64 bash scripts/build-linux.sh
65
66package-linux:
67 bash scripts/package-linux.sh
68
69check-linux:
70 GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO) vet -tags $(TAGS) . ./cmd/... ./internal/...
71
72cage-windows:
73 pwsh -NoProfile -File scripts/build-windows.ps1
74
75package-windows:
76 pwsh -NoProfile -File scripts/package-windows.ps1
77
78agent-vm: assets
79 $(GO_BUILD) -o _output/bin/agent-vm$(EXE) ./cmd/agent-vm
80ifeq ($(GOOS),darwin)
81 codesign -f -v --entitlements third_party/lima/vz.entitlements -s - _output/bin/agent-vm
82endif
83
84# For developers: the binary install puts on the PATH, with its own
85# wording, replacement of earlier installs and next steps.
86install: agent-vm
87 ./_output/bin/agent-vm$(EXE) install
88
89limactl:
90 $(GO_BUILD) -o _output/bin/limactl$(EXE) github.com/lima-vm/lima/v2/cmd/limactl
91 mkdir -p _output/share/lima
92 CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GO) build -trimpath -ldflags "-s -w" \
93 -o _output/share/lima/lima-guestagent.Linux-$(GUEST_ARCH) github.com/lima-vm/lima/v2/cmd/lima-guestagent
94 rm -rf _output/share/lima/templates && cp -R third_party/lima/templates _output/share/lima/templates
95ifeq ($(GOOS),darwin)
96 codesign -f -v --entitlements third_party/lima/vz.entitlements -s - _output/bin/limactl
97endif
98
99# Build each guest helper for the OS in which it will run.
100assets:
101 CGO_ENABLED=0 GOOS=linux GOARCH=$(GOARCH) $(GO) build -trimpath \
102 -ldflags "-s -w -X github.com/lima-vm/lima/v2/pkg/version.Version=$(LIMA_VERSION)" \
103 -o $(ASSETS)/lima-guestagent.Linux-$(GUEST_ARCH) github.com/lima-vm/lima/v2/cmd/lima-guestagent
104 gzip -9 -n -f $(ASSETS)/lima-guestagent.Linux-$(GUEST_ARCH)
105ifeq ($(GOOS)/$(GOARCH),darwin/arm64)
106 mkdir -p $(ASSETS)/Darwin
107 CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 $(GO) build -trimpath -tags $(TAGS) \
108 -ldflags "-s -w -X github.com/lima-vm/lima/v2/pkg/version.Version=$(LIMA_VERSION)" \
109 -o $(ASSETS)/Darwin/lima-guestagent.Darwin-aarch64 github.com/lima-vm/lima/v2/cmd/lima-guestagent
110 gzip -9 -n -f $(ASSETS)/Darwin/lima-guestagent.Darwin-aarch64
111endif
112 rm -rf $(ASSETS)/templates && cp -R third_party/lima/templates $(ASSETS)/templates
113
114test: test-go
115
116test-go:
117 $(GO) test -tags $(TAGS) . ./cmd/... ./internal/...
118 cd tools/tailnet && GOFLAGS= $(GO) test ./...
119
120# The Windows build and its tests compile and vet, from any OS. The Windows
121# paths' logic is tested everywhere (paths.Windows); the tests themselves
122# run on Windows in CI (windows-latest).
123check-windows:
124 GOOS=windows GOARCH=amd64 $(GO) vet -tags $(TAGS) . ./cmd/... ./internal/...
125 GOOS=windows GOARCH=arm64 $(GO) vet -tags $(TAGS) . ./cmd/... ./internal/...
126
127# From this module, so that each library is built with the others patched.
128# Lima's MCP packages and sshocker's command are not part of agent-vm (-e:
129# listing them needs sums nothing built here uses; grep keeps them out of
130# the tests).
131test-third-party:
132 $(GO) test -vet=off -race github.com/pkg/sftp/...
133 $(GO) test -race github.com/lima-vm/sshocker/pkg/...
134 $(GO) test $$($(GO) list -e github.com/lima-vm/lima/v2/pkg/... | grep -v /mcp)
135 $(GO) test github.com/containers/gvisor-tap-vsock/pkg/...
136
137# Each fuzzer for FUZZTIME (their seeds run with the tests). The vendored
138# sshocker's through tests/fuzz/go.work, which makes it fuzzable.
139FUZZTIME ?= 1m
140FUZZ = github.com/lima-vm/sshocker/pkg/reversesshfs github.com/pkg/sftp ./internal/env ./internal/gitguard \
141 ./internal/mounts ./internal/paths ./internal/runscript ./internal/ui ./internal/vmname
142fuzz:
143 @set -e; for pkg in $(FUZZ); do \
144 case $$pkg in ./*) work=off ;; *) work=$(CURDIR)/tests/fuzz/go.work ;; esac; \
145 fs=$$(GOWORK=$$work $(GO) test -vet=off -list '^Fuzz' $$pkg) || { echo "$$fs"; exit 1; }; \
146 for f in $$(echo "$$fs" | grep '^Fuzz'); do \
147 echo "== $$pkg $$f"; \
148 GOWORK=$$work $(GO) test -vet=off -run '^$$' -fuzz "^$$f$$" -fuzztime $(FUZZTIME) $$pkg; \
149 done; \
150 done
151
152clean:
153 rm -rf _output
154 find $(ASSETS) -mindepth 1 ! -name README -exec rm -rf {} +
155
156.PHONY: tailnet-assets
157tailnet-assets:
158 bash scripts/build-tailnet.sh linux amd64 "$(CURDIR)/_output/tailnet/cage-tailnet-linux-amd64"
159 bash scripts/build-tailnet.sh linux arm64 "$(CURDIR)/_output/tailnet/cage-tailnet-linux-arm64"
160 gzip -n -c _output/tailnet/cage-tailnet-linux-amd64 > internal/tailnetassets/assets/cage-tailnet-linux-amd64.gz
161 gzip -n -c _output/tailnet/cage-tailnet-linux-arm64 > internal/tailnetassets/assets/cage-tailnet-linux-arm64.gz