feat(install): add Branch field to InstallOptions, SkillMeta, SkillEntry, SkillEntryDTO

This commit is contained in:
Willie
2026-04-01 00:32:49 +08:00
parent ccdafd3293
commit 8def337c05
6 changed files with 54 additions and 0 deletions
+1
View File
@@ -189,6 +189,7 @@ type SkillEntry struct {
Source string `yaml:"source"`
Tracked bool `yaml:"tracked,omitempty"`
Group string `yaml:"group,omitempty"`
Branch string `yaml:"branch,omitempty"`
}
// EffectiveKind returns the resource kind for this entry.
+1
View File
@@ -10,6 +10,7 @@ type SkillEntryDTO struct {
Source string
Tracked bool
Group string
Branch string
}
// FullName returns the full relative path for the skill entry.
+1
View File
@@ -25,6 +25,7 @@ type InstallOptions struct {
AuditThreshold string // Block threshold: CRITICAL/HIGH/MEDIUM/LOW/INFO
AuditProjectRoot string // Project root for project-mode audit rule resolution
Quiet bool // Suppress per-skill output in InstallFromConfig
Branch string // Git branch to clone from (empty = remote default)
}
// ShouldInstallAll returns true if all discovered skills should be installed without prompting.
+1
View File
@@ -24,6 +24,7 @@ type SkillMeta struct {
Version string `json:"version,omitempty"` // Git commit hash or version
TreeHash string `json:"tree_hash,omitempty"` // Git tree SHA of Subdir
FileHashes map[string]string `json:"file_hashes,omitempty"` // sha256:<hex> per file
Branch string `json:"branch,omitempty"` // Git branch (when non-default)
}
// WriteMeta saves metadata to the skill directory
+45
View File
@@ -0,0 +1,45 @@
package install
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestMetaBranchRoundTrip(t *testing.T) {
dir := t.TempDir()
meta := &SkillMeta{
Source: "github.com/owner/repo",
Type: "github",
Branch: "develop",
}
if err := WriteMeta(dir, meta); err != nil {
t.Fatalf("WriteMeta: %v", err)
}
loaded, err := ReadMeta(dir)
if err != nil {
t.Fatalf("ReadMeta: %v", err)
}
if loaded.Branch != "develop" {
t.Errorf("Branch = %q, want %q", loaded.Branch, "develop")
}
}
func TestMetaBranchOmittedWhenEmpty(t *testing.T) {
dir := t.TempDir()
meta := &SkillMeta{
Source: "github.com/owner/repo",
Type: "github",
}
if err := WriteMeta(dir, meta); err != nil {
t.Fatalf("WriteMeta: %v", err)
}
data, err := os.ReadFile(filepath.Join(dir, MetaFileName))
if err != nil {
t.Fatalf("ReadFile: %v", err)
}
if strings.Contains(string(data), "branch") {
t.Errorf("empty branch should be omitted from JSON, got: %s", data)
}
}
+5
View File
@@ -46,6 +46,11 @@
"type": "string",
"description": "Subdirectory group the resource belongs to (set by --into).",
"examples": ["frontend", "backend"]
},
"branch": {
"type": "string",
"description": "Git branch to clone from. Omit for remote default branch.",
"examples": ["develop", "frontend"]
}
}
}