From 8def337c05ca9fbd76dfc417f89db55bac71bf11 Mon Sep 17 00:00:00 2001 From: Willie Date: Tue, 31 Mar 2026 17:40:02 +0800 Subject: [PATCH] feat(install): add Branch field to InstallOptions, SkillMeta, SkillEntry, SkillEntryDTO --- internal/config/project.go | 1 + internal/install/context.go | 1 + internal/install/install.go | 1 + internal/install/meta.go | 1 + internal/install/meta_branch_test.go | 45 ++++++++++++++++++++++++++++ schemas/registry.schema.json | 5 ++++ 6 files changed, 54 insertions(+) create mode 100644 internal/install/meta_branch_test.go diff --git a/internal/config/project.go b/internal/config/project.go index 2bcfedc0b..8753643cc 100644 --- a/internal/config/project.go +++ b/internal/config/project.go @@ -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. diff --git a/internal/install/context.go b/internal/install/context.go index e8d1e561c..2cf418f93 100644 --- a/internal/install/context.go +++ b/internal/install/context.go @@ -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. diff --git a/internal/install/install.go b/internal/install/install.go index 1c84b8d40..b368297dd 100644 --- a/internal/install/install.go +++ b/internal/install/install.go @@ -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. diff --git a/internal/install/meta.go b/internal/install/meta.go index 51afda439..f42d02b22 100644 --- a/internal/install/meta.go +++ b/internal/install/meta.go @@ -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: per file + Branch string `json:"branch,omitempty"` // Git branch (when non-default) } // WriteMeta saves metadata to the skill directory diff --git a/internal/install/meta_branch_test.go b/internal/install/meta_branch_test.go new file mode 100644 index 000000000..3a7441ba2 --- /dev/null +++ b/internal/install/meta_branch_test.go @@ -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) + } +} diff --git a/schemas/registry.schema.json b/schemas/registry.schema.json index 0454608e6..9d79d96fd 100644 --- a/schemas/registry.schema.json +++ b/schemas/registry.schema.json @@ -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"] } } }