Skip to content

mission control for agent skills

Add global install flag to skill installation commands

Alvin Unreal1dca70f2fe0c
diff --git a/internal/actions/actions.go b/internal/actions/actions.go
index b009d97..f8929d1 100644
--- a/internal/actions/actions.go
+++ b/internal/actions/actions.go
@@ -138,10 +138,10 @@ func bulkBatch(skills []*model.Skill, resolve SkillsResolver, actionID string) (
}
func ForAvailableSkill(source, name string) []CommandPreview {
- return ForAvailableSkillWithResolver(source, name, ResolveSkillsCommand)
+ return ForAvailableSkillWithResolver(source, name, false, ResolveSkillsCommand)
}
-func ForAvailableSkillWithResolver(source, name string, resolve SkillsResolver) []CommandPreview {
+func ForAvailableSkillWithResolver(source, name string, global bool, resolve SkillsResolver) []CommandPreview {
if !safeExecValue(source) || strings.HasPrefix(source, "-") {
return []CommandPreview{unavailablePreview("Install selected skill", "source is empty, option-like, or contains unsafe characters")}
}
@@ -157,8 +157,15 @@ func ForAvailableSkillWithResolver(source, name string, resolve SkillsResolver)
args := append([]string{}, baseArgs...)
args = append(args, "add", source, "--skill", name, "--yes")
+ if global {
+ args = append(args, "--global")
+ }
- preview := newPreview("install_skill", "Install selected skill", program, args, "Install this skill to project.", true, true, false, "yes")
+ description := "Install this skill to project."
+ if global {
+ description = "Install this skill globally."
+ }
+ preview := newPreview("install_skill", "Install selected skill", program, args, description, true, true, false, "yes")
gateAvailability(&preview, available, reason)
return []CommandPreview{preview}
}
diff --git a/internal/actions/actions_test.go b/internal/actions/actions_test.go
index 2547269..c7b7a0c 100644
--- a/internal/actions/actions_test.go
+++ b/internal/actions/actions_test.go
@@ -394,6 +394,17 @@ func TestForAvailableSkill(t *testing.T) {
if !containsArg(inst.Exec.Args, "owner/repo") || !containsArg(inst.Exec.Args, "test-skill") {
t.Errorf("expected source and skill name in args, got %+v", inst.Exec.Args)
}
+ if containsArg(inst.Exec.Args, "--global") {
+ t.Errorf("expected project install by default, got %+v", inst.Exec.Args)
+ }
+
+ globalPreviews := ForAvailableSkillWithResolver("owner/repo", "test-skill", true, ResolveSkillsCommand)
+ if len(globalPreviews) != 1 {
+ t.Fatalf("expected 1 global install preview, got %d", len(globalPreviews))
+ }
+ if !containsArg(globalPreviews[0].Exec.Args, "--global") {
+ t.Errorf("expected global install args to include --global, got %+v", globalPreviews[0].Exec.Args)
+ }
}
func TestForAvailableSkillUnsafeRejection(t *testing.T) {
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go
index 206bf40..9137e40 100644
--- a/internal/tui/tui_test.go
+++ b/internal/tui/tui_test.go
@@ -1507,6 +1507,26 @@ func actionIndex(t *testing.T, m appModel, title string) int {
return 0
}
+func actionByID(t *testing.T, previews []actions.CommandPreview, id string) actions.CommandPreview {
+ t.Helper()
+ for _, action := range previews {
+ if action.ID == id {
+ return action
+ }
+ }
+ t.Fatalf("action %q not found in %#v", id, previews)
+ return actions.CommandPreview{}
+}
+
+func argsContain(args []string, want string) bool {
+ for _, arg := range args {
+ if arg == want {
+ return true
+ }
+ }
+ return false
+}
+
func TestActionSelectionDoesNotResetDetailScroll(t *testing.T) {
m := actionTestModel(t.TempDir())
for i := 0; i < 40; i++ {
@@ -2921,6 +2941,65 @@ func TestInteractiveSourceDetailModal(t *testing.T) {
}
}
+func TestSourceModalAvailableSkillInstallUsesGlobalScopeForGlobalSource(t *testing.T) {
+ m := appModel{
+ modalSource: "owner/repo",
+ modalSelected: 1,
+ result: model.ScanResult{
+ Skills: []*model.Skill{
+ {
+ Name: "InstalledSkill",
+ Scope: model.ScopeGlobal,
+ GlobalLock: &model.GlobalLockEntry{Source: "owner/repo", Ref: "main"},
+ },
+ },
+ },
+ discovery: map[string]SourceDiscovery{
+ "owner/repo": {
+ Status: DiscoveryReady,
+ Skills: []DiscoveredSkill{{Name: "AvailableSkill", Source: "owner/repo"}},
+ },
+ },
+ }
+
+ install := actionByID(t, m.currentActions(), "install_skill")
+ if !argsContain(install.Exec.Args, "--global") {
+ t.Fatalf("expected global source install to include --global, got %+v", install.Exec.Args)
+ }
+}
+
+func TestSourceModalAvailableSkillInstallKeepsProjectScopeForMixedSource(t *testing.T) {
+ m := appModel{
+ modalSource: "owner/repo",
+ modalSelected: 2,
+ result: model.ScanResult{
+ Skills: []*model.Skill{
+ {
+ Name: "GlobalSkill",
+ Scope: model.ScopeGlobal,
+ GlobalLock: &model.GlobalLockEntry{Source: "owner/repo", Ref: "main"},
+ },
+ {
+ Name: "ProjectSkill",
+ Scope: model.ScopeProject,
+ LocalLock: &model.LocalLockEntry{Source: "owner/repo", Ref: "main"},
+ },
+ },
+ },
+ discovery: map[string]SourceDiscovery{
+ "owner/repo": {
+ Status: DiscoveryReady,
+ Skills: []DiscoveredSkill{{Name: "AvailableSkill", Source: "owner/repo"}},
+ },
+ },
+ }
+
+ install := actionByID(t, m.currentActions(), "install_skill")
+ if argsContain(install.Exec.Args, "--global") {
+ t.Fatalf("expected mixed source install to stay project-scoped, got %+v", install.Exec.Args)
+ }
+}
+
func TestModalEnterInstallsAvailableSkill(t *testing.T) {
m := appModel{width: 120, height: 32, detailModal: true, modalSource: "owner/repo", modalSelected: 1,
result: model.ScanResult{Skills: []*model.Skill{
@@ -3477,6 +3556,48 @@ func TestTUIPreviewRenderInFlightSuppression(t *testing.T) {
}
}
+func TestTUIPreviewRenderUsesSkillModalWidth(t *testing.T) {
+ m := appModel{
+ width: 120,
+ height: 32,
+ selected: 1,
+ detailModal: true,
+ modalSource: "",
+ previewCache: make(map[previewCacheKey][]string),
+ result: model.ScanResult{
+ Skills: []*model.Skill{
+ {
+ Name: "TestSkill",
+ Scope: model.ScopeProject,
+ Preview: "some preview text",
+ LocalLock: &model.LocalLockEntry{Source: "owner/repo"},
+ },
+ },
+ },
+ }
+
+ cmd := m.dispatchPreviewRender()
+ if cmd == nil {
+ t.Fatal("expected skill detail modal to dispatch preview render on cache miss")
+ }
+
+ msg, ok := cmd().(previewRenderedMsg)
+ if !ok {
+ t.Fatalf("expected previewRenderedMsg, got %T", msg)
+ }
+
+ modalWidth, _ := detailModalDimensions(newAppLayout(m.width, m.height))
+ wantWidth := max(1, modalWidth-4)
+ if msg.width != wantWidth {
+ t.Fatalf("expected modal preview width %d, got %d", wantWidth, msg.width)
+ }
+
+ _, rightWidth, _, _ := m.getThreePaneLayout()
+ if msg.width == max(1, rightWidth-4) {
+ t.Fatalf("expected modal width, got three-pane preview width %d", msg.width)
+ }
+}
+
func TestTUIWindowResizeDispatchesPreviewRender(t *testing.T) {
m := appModel{
width: 100,
diff --git a/internal/tui/update.go b/internal/tui/update.go
index 9c537b0..c9e760e 100644
--- a/internal/tui/update.go
+++ b/internal/tui/update.go
@@ -248,7 +248,7 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if m.modalSource != "" {
if child, ok := m.currentModalSelectedChild(); ok {
if child.isAvailable {
- for _, a := range actions.ForAvailableSkill(m.modalSource, child.discoveredSkill.Name) {
+ for _, a := range actions.ForAvailableSkillWithResolver(m.modalSource, child.discoveredSkill.Name, m.sourceGroupInstallsGlobally(m.modalSource), actions.ResolveSkillsCommand) {
if a.ID != "install_skill" || !a.Available {
continue
}
@@ -789,6 +789,15 @@ func (m *appModel) markPreviewRendering() {
m.previewRenderingGeneration = m.previewGeneration
}
+func (m appModel) activePreviewWidth() int {
+ if m.detailModal && m.modalSource == "" {
+ modalWidth, _ := detailModalDimensions(newAppLayout(m.width, m.height))
+ return max(1, modalWidth-4)
+ }
+ _, rightWidth, _, _ := m.getThreePaneLayout()
+ return max(1, rightWidth-4)
+}
+
// dispatchPreviewRender checks whether the currently selected skill needs an
// async glamour markdown render. Returns nil when the preview is already cached
// or the skill has no preview content.
@@ -811,8 +820,7 @@ func (m appModel) dispatchPreviewRender() tea.Cmd {
if m.previewCache == nil {
return nil // cache not initialized (bootstrapping)
}
- _, rightWidth, _, _ := m.getThreePaneLayout()
- previewWidth := max(1, rightWidth-4)
+ previewWidth := m.activePreviewWidth()
key := previewCacheKey{markdown: view.Preview, width: previewWidth}
if _, ok := m.previewCache[key]; ok {
return nil // already cached
@@ -854,7 +862,7 @@ func (m appModel) currentActionsForRows(rows []skillsRow) []actions.CommandPrevi
child, ok := m.currentModalSelectedChild()
if ok {
if child.isAvailable {
- return actions.ForAvailableSkill(m.modalSource, child.discoveredSkill.Name)
+ return actions.ForAvailableSkillWithResolver(m.modalSource, child.discoveredSkill.Name, m.sourceGroupInstallsGlobally(m.modalSource), actions.ResolveSkillsCommand)
}
return m.appendEnableDisableActions(actions.ForSkill(child.skill), child.skill)
}
@@ -1000,6 +1008,19 @@ func (m appModel) currentModalSelectedChild() (modalChildRow, bool) {
return childRows[m.modalSelected], true
}
+func (m appModel) sourceGroupInstallsGlobally(groupName string) bool {
+ var hasGlobal, hasProject bool
+ for _, sk := range m.sourceGroupSkills(groupName) {
+ switch sk.Scope {
+ case model.ScopeGlobal:
+ hasGlobal = true
+ case model.ScopeProject:
+ hasProject = true
+ }
+ }
+ return hasGlobal && !hasProject
+}
+
func preferredUpdateActionID(selectedCount int) string {
if selectedCount > 0 {
return "bulk_reinstall_update"