跳到主要内容

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

浏览文件

version.go

97 行 · 2.4 KB历史下载
1// Package version provides the application version and version comparisons.
2package version
3
4import (
5 agentvm "github.com/sylvinus/agent-vm"
6 "strings"
7)
8
9// Version is set at build time (-ldflags -X); integrators gate on it with
10// `agent-vm version --min`.
11var Version string
12
13func init() {
14 if Version == "" {
15 Version = strings.TrimSpace(agentvm.CageVersion)
16 }
17}
18
19// AtLeast reports whether version have is want or later. The numbers before
20// any "-" compare first, anything but digits in a component dropped, a
21// missing component being 0 (1.2 is 1.2.0). With equal numbers, a version
22// with a suffix after "-" is a prerelease and is older than the same
23// without: 0.3.0-dev, as 0.3.0-dev.<commit> from a development build, does
24// not satisfy 0.3.0. Two prereleases compare identifier by identifier, as
25// semver does.
26func AtLeast(have, want string) bool {
27 a, apre, _ := strings.Cut(have, "-")
28 b, bpre, _ := strings.Cut(want, "-")
29 for a != "" || b != "" {
30 var x, y string
31 x, a, _ = strings.Cut(a, ".")
32 y, b, _ = strings.Cut(b, ".")
33 x, y = number(x), number(y)
34 if len(x) != len(y) {
35 return len(x) > len(y)
36 }
37 if x != y {
38 return x > y
39 }
40 }
41 switch {
42 case bpre == "":
43 return apre == ""
44 case apre == "":
45 return true
46 }
47 return comparePre(apre, bpre) >= 0
48}
49
50// comparePre orders two prerelease strings: dot-separated identifiers, the
51// numeric ones as numbers and lower than the others, which compare as text;
52// a longer list is higher when the shorter is its start.
53func comparePre(a, b string) int {
54 for a != "" || b != "" {
55 if a == "" {
56 return -1
57 }
58 if b == "" {
59 return 1
60 }
61 var x, y string
62 x, a, _ = strings.Cut(a, ".")
63 y, b, _ = strings.Cut(b, ".")
64 xn, yn := isNumeric(x), isNumeric(y)
65 switch {
66 case xn && yn:
67 x, y = strings.TrimLeft(x, "0"), strings.TrimLeft(y, "0")
68 if len(x) != len(y) {
69 return len(x) - len(y)
70 }
71 case xn:
72 return -1
73 case yn:
74 return 1
75 }
76 if c := strings.Compare(x, y); c != 0 {
77 return c
78 }
79 }
80 return 0
81}
82
83func isNumeric(s string) bool {
84 return s != "" && strings.Trim(s, "0123456789") == ""
85}
86
87// number is the digits of s, without leading zeros: compared by length,
88// then as text, it compares as a number of any size.
89func number(s string) string {
90 var b strings.Builder
91 for _, r := range s {
92 if r >= '0' && r <= '9' {
93 b.WriteRune(r)
94 }
95 }
96 return strings.TrimLeft(b.String(), "0")
97}