Skip to content

版本属性

源文件

对应的 Skill 定义位于 skills/version-properties/SKILL.md

前置: 一次性安装见 /installation,完成 SDK / CLI / MCP 配置。
三层入口: SDK (Go) → CLI (shell) → MCP (AI 工具),按需选用。

When to Use

  • Extracting numeric segments from a version string ([1, 2, 3])
  • Getting the sub-version number embedded in a prerelease suffix (beta2 -> 2)
  • Determining the semantic weight of a suffix for ordering (rc = 400)
  • Getting the clean prefix without trailing delimiters ("curl-" -> "curl")
  • Getting the group ID used by Group() for version grouping

Decision Tree

Need all components at once?
  → Use version_info (MCP) or version info (CLI)
Need numeric segments only?
  → Use Segments() / Segments64()
Need suffix semantic weight?
  → Use SuffixWeight() or GetSuffixWeight()
Need the group key for Group()?
  → Use BuildGroupID()
Need a clean prefix string?
  → Use Prefix.PurePrefix()

Task Patterns

Get all numeric segments

Goal: Extract the version number components as a slice.

LayerApproach
SDKv.Segments(), v.Major(), v.Minor(), v.Patch()
CLIversions segments v1.2.3-rc2
MCP{"tool": "version_info", "arguments": {"version_string": "v1.2.3-rc2"}} → major, minor, patch, version_numbers

Determine suffix type and weight

Goal: Classify the prerelease suffix and get its ordering weight.

LayerApproach
SDKv.SuffixWeight() → SuffixWeight(400); versions.GetSuffixWeight("-beta3") → beta (200)
CLIversions suffix-weight 1.2.3-rc1
MCP{"tool": "version_info", "arguments": {"version_string": "1.2.3-rc1"}} → suffix_weight field

Extract sub-version number from suffix

Goal: Get the numeric part of a prerelease suffix (e.g., beta2 -> 2).

LayerApproach
SDKv.SubVersion() → 2 (returns 0 if suffix has no number)
CLIversions sub-version 1.2.3-beta2
MCP{"tool": "version_info", "arguments": {"version_string": "1.2.3-beta2"}}

Get the group ID for grouping

Goal: Obtain the key used by Group() to cluster versions.

LayerApproach
SDKv.BuildGroupID()"1.2.3" from "v1.2.3-beta1"
CLIversions group-id v1.2.3-beta1
MCP{"tool": "version_info", "arguments": {"version_string": "v1.2.3-beta1"}} → group_id field

Clean a prefix string

Goal: Strip trailing delimiter characters from a prefix.

LayerApproach
SDKv.Prefix.PurePrefix()"curl" from "curl-"
CLIversions pure-prefix curl-7.85.0
MCP{"tool": "version_info", "arguments": {"version_string": "curl-7.85.0"}}

Deep-copy a version

Goal: Create an independent copy safe for mutation.

LayerApproach
SDKcloned := v.Clone() — deep copy, modifying cloned does not affect v
CLIversions clone v1.2.3
MCPUse version_parse and reconstruct with version_build

API Reference

SDK — Segment Accessors

go
v.Major() int           // VersionNumbers[0] or 0
v.Minor() int           // VersionNumbers[1] or 0
v.Patch() int           // VersionNumbers[2] or 0
v.Segments() []int      // all VersionNumbers
v.Segments64() []int64  // as int64

SDK — Suffix Properties

go
v.SubVersion() int                    // numeric from suffix (e.g. "beta2" → 2, "-beta" → 0)
v.SuffixWeight() SuffixWeight         // semantic ordering weight on the Version
versions.GetSuffixWeight(s string) SuffixWeight  // package-level: weight of any suffix string

Suffix weight ordering:

WeightSuffix TypeValue
0unknown (no suffix / unclassified)0
50dev50
60snapshot60
70nightly70
100alpha100
200beta200
300milestone300
400rc400
500final / release / ga500
600sp600
700patch700
800post800

SDK — Prefix, Group, Clone, Serialization

go
v.Prefix.PurePrefix() string   // prefix without trailing delimiters, e.g. "curl-" → "curl"
v.BuildGroupID() string        // group key, e.g. "v1.2.3-beta1" → "1.2.3"
v.Clone() *Version             // deep copy, independent of original
v.RawString() string           // original parsed string (human-readable, unlike String())

CLI Commands

bash
versions segments <v>            # {"segments": [1, 2, 3]}
versions sub-version <v>         # {"sub_version": 2}
versions suffix-weight <v>       # {"suffix_weight": "rc", "weight_value": 400}
versions pure-prefix <v>         # {"prefix": "curl-", "pure_prefix": "curl"}
versions group-id <v>            # {"group_id": "1.2.3"}
versions clone <v>               # full version object as JSON

MCP Tools

ToolArgumentsReturns
version_infoversion_stringraw, valid, major, minor, patch, version_numbers, prefix, suffix, suffix_weight, group_id, all Is* flags

Cross-References

  • [[version-check]] — boolean checks on version type (IsBeta, IsStable, etc.)
  • [[version-grouping]] — Group() uses BuildGroupID() for clustering
  • [[version-comparison]] — CompareTo uses SuffixWeight for ordering
  • [[version-mutation]] — modify version components after inspecting them

Important Notes

  • Suffix weight order: dev(50) < snapshot(60) < nightly(70) < alpha(100) < beta(200) < milestone(300) < rc(400) < final/release/ga(500) < sp(600) < patch(700) < post(800)
  • SubVersion() returns 0 if the suffix has no numeric part ("-beta" -> 0, "-beta2" -> 2).
  • PurePrefix() strips trailing -, ., _ — use it to extract a clean package name.
  • BuildGroupID() is the key for Group() — versions differing only by suffix share the same group.
  • Clone() creates a fully independent deep copy — safe for concurrent modification.
  • RawString() returns the original parsed string; String() returns a different (JSON) format.

基于 MIT 协议发布