mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* Add --all flag to plugin update and enable agy Add -a/--all to skillshare plugin update so users can update all tracked plugins in a single command without tying slow target CLI runs to skillshare update --all or sync --all. - Reject --all outside plugin update or when combined with a plugin name or --source-ref - Share source repository discoveries and discovery errors across the Preview and Apply lifecycle via Service.WithDiscoveryCache so multi- plugin marketplaces are cloned at most once per command - Isolate source, manifest, and target failures per binding when --all is active so healthy plugins update while partial failures exit non-zero and leave failed bindings unchanged in config.yaml - Skip unfiltered OMP bindings during --all updates so sibling targets on the same package still update without failing the batch - Enable plugin update for antigravity-cli while skipping disabled plugins when agy extensions list reports an entry as disabled Closes #653 * Add plugin update --all to docs and completions Advertise -a/--all for skillshare plugin across all five shell completion scripts and document the bulk update workflow and antigravity-cli update support in the user and built-in skill docs. - Add --all and -a to plugin completions in bash, zsh, fish, PowerShell, and Nushell with TestPluginCompletionsIncludeAllFlag - Document update [NAME | --all], -a/--all, and antigravity-cli source updates in website/docs/reference/commands/plugin.md (and its zh-Hans, zh-Hant, ja, and ko translations), sharing-plugins.md, and quick-reference.md - Document plugin update --all and antigravity-cli enablement checks in skills/skillshare/references/plugins.md * Require known enabled state for native updates Require a matching EnabledKnown && Enabled inventory entry before updating copilot or antigravity-cli bindings, and align the localized plugin workflow pages with the English docs. - Skip copilot and antigravity-cli updates in Service.Preview and refuse reinstallation in applyNativeTarget when the binding is absent from native inventory or not known to be enabled - Cover absent native inventory in TestAntigravityCLIUpdateRespectsEnablement - Synchronize plugin update [name | --all] and Antigravity CLI update guidance across the ja, ko, zh-Hans, and zh-Hant copies of quick-reference.md and sharing-plugins.md
195 lines
6.7 KiB
Go
195 lines
6.7 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func (s *Service) Apply(ctx context.Context, r Request, revision string) (*Result, error) {
|
|
if revision == "" {
|
|
return nil, fmt.Errorf("preview the plugin changes before applying")
|
|
}
|
|
unlock, err := s.Lock()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer unlock()
|
|
p, err := s.Preview(ctx, r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if p.Revision != revision {
|
|
return nil, fmt.Errorf("plugin state changed since preview; preview again")
|
|
}
|
|
return s.applyPlan(ctx, r, p)
|
|
}
|
|
|
|
// Lock serializes CLI and UI mutations across processes, not just HTTP requests.
|
|
func (s *Service) Lock() (unlock func(), err error) {
|
|
if err := os.MkdirAll(filepath.Dir(s.ConfigPath), 0755); err != nil {
|
|
return nil, err
|
|
}
|
|
lock, err := os.OpenFile(s.ConfigPath+".plugins.lock", os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("another plugin operation is running (lock: %s.plugins.lock)", s.ConfigPath)
|
|
}
|
|
_ = lock.Close()
|
|
return func() { _ = os.Remove(s.ConfigPath + ".plugins.lock") }, nil
|
|
}
|
|
|
|
// applyPlan carries out a plan previewed under the lock the caller holds.
|
|
func (s *Service) applyPlan(ctx context.Context, r Request, p *Plan) (*Result, error) {
|
|
if p.Blocked {
|
|
return nil, fmt.Errorf("resolve blocked plugin targets before applying")
|
|
}
|
|
if r.Action == "check" {
|
|
return nil, fmt.Errorf("check is read-only")
|
|
}
|
|
d, err := s.load()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// Preserve private entries before writing references to them into config.
|
|
for _, c := range p.Changes {
|
|
if c.Action != "skip" && c.Action != "noop" {
|
|
if err := s.savePiRegistration(c); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
}
|
|
result := &Result{Results: []Outcome{}}
|
|
var failures []error
|
|
changed := false
|
|
for _, c := range p.Changes {
|
|
if c.Action == "skip" {
|
|
// Unlike noop, a skipped update stays pending for a later sync.
|
|
status := "skipped"
|
|
if c.batchError {
|
|
status = "failed"
|
|
failures = append(failures, errors.New(c.Message))
|
|
}
|
|
result.Results = append(result.Results, Outcome{Name: c.Name, Target: c.Target, Status: status, Message: c.Message, MessageKey: c.MessageKey, MessageArgs: c.MessageArgs})
|
|
continue
|
|
}
|
|
if c.Action == "noop" {
|
|
result.Results = append(result.Results, Outcome{Name: c.Name, Target: c.Target, Status: "unchanged"})
|
|
if r.Action == "sync" && d.packages[c.Name].Bindings[c.Target].Pending != "" {
|
|
changed = true
|
|
pack := d.packages[c.Name]
|
|
b := pack.Bindings[c.Target]
|
|
b.Pending = ""
|
|
pack.Bindings[c.Target] = b
|
|
d.packages[c.Name] = pack
|
|
}
|
|
continue
|
|
}
|
|
changed = true
|
|
pack := d.packages[c.Name]
|
|
if pack.Bindings == nil {
|
|
pack.Bindings = map[string]Binding{}
|
|
}
|
|
if c.Target == "" {
|
|
if c.Action == "forget" {
|
|
delete(d.packages, c.Name)
|
|
} else {
|
|
pack.Source, pack.SourceRef, pack.Plugin, pack.Entry, pack.Version = c.Binding.Source, c.Binding.SourceRef, c.Binding.Plugin, c.Binding.Entry, c.Binding.Version
|
|
d.packages[c.Name] = pack
|
|
}
|
|
continue
|
|
}
|
|
if r.Action == "add" && pack.Source == "" && c.Binding.Source != "" {
|
|
pack.Source, pack.SourceRef, pack.Plugin, pack.Entry = c.Binding.Source, c.Binding.SourceRef, c.Binding.Plugin, r.Entry
|
|
}
|
|
b := c.Binding
|
|
b.Pending = c.Action
|
|
if c.Action == "import" || c.Action == "selection" {
|
|
b.Pending = ""
|
|
}
|
|
pack.Bindings[c.Target] = b
|
|
d.packages[c.Name] = pack
|
|
}
|
|
if !changed {
|
|
return result, errors.Join(failures...)
|
|
}
|
|
if err := s.save(d); err != nil {
|
|
return result, err
|
|
}
|
|
// Receipts are private to this Apply, and record only bytes our restore wrote.
|
|
piRestores := map[string]piRestoreReceipt{}
|
|
for _, c := range p.Changes {
|
|
if c.Action == "noop" || c.Action == "skip" {
|
|
continue
|
|
}
|
|
if c.Target == "" {
|
|
outcome := Outcome{Name: c.Name, Status: "saved", Message: "Added to Skillshare. Choose Agents when you want to install it."}
|
|
if c.Action == "forget" {
|
|
outcome.Status, outcome.Message = "removed", "Removed from Skillshare."
|
|
}
|
|
result.Results = append(result.Results, outcome)
|
|
continue
|
|
}
|
|
b := d.packages[c.Name].Bindings[c.Target]
|
|
c.piRestores = piRestores
|
|
applyErr := s.applyChange(ctx, c, &b)
|
|
outcome := Outcome{Name: c.Name, Target: c.Target, Status: "installed", Message: "Native installation recorded. Reload the Agent and complete any required login or hook trust."}
|
|
if applyErr != nil {
|
|
outcome.Status = "failed"
|
|
outcome.Message = applyErr.Error()
|
|
outcome.MessageKey, outcome.MessageArgs = ErrorKey(applyErr)
|
|
failures = append(failures, applyErr)
|
|
} else {
|
|
pack := d.packages[c.Name]
|
|
if c.Action == "remove" || c.Action == "forget" {
|
|
delete(pack.Bindings, c.Target)
|
|
outcome.Status = "removed"
|
|
outcome.Message = "Native plugin removed; shared marketplaces are retained."
|
|
if s.agentOf(c.Target) == "omp" {
|
|
outcome.Message, outcome.MessageKey = "Removed from this scope; shared cache, marketplaces and plugin settings were retained.", "plugins.outcome.ompRemoved"
|
|
}
|
|
if c.Action == "forget" && s.agentOf(c.Target) == "omp" {
|
|
outcome.Message = "Removed from Skillshare; the native plugin was already absent. Shared marketplaces are retained."
|
|
}
|
|
} else {
|
|
b.Pending = ""
|
|
if c.piRecordAfter {
|
|
if err := s.recordPiEntry(ctx, c.Target, &b); err != nil {
|
|
outcome.Message = "Installed, but its extension settings could not be recorded to restore on a later reinstall: " + err.Error()
|
|
}
|
|
}
|
|
pack.Bindings[c.Target] = b
|
|
if c.Action == "selection" {
|
|
outcome.Status = "saved"
|
|
outcome.Message = "Sync selection saved. Run sync to apply installation changes."
|
|
}
|
|
if c.Action == "uninstall" {
|
|
outcome.Status = "excluded"
|
|
outcome.Message = "Removed from this target; plugin definition retained."
|
|
if s.agentOf(c.Target) == "omp" {
|
|
outcome.Message, outcome.MessageKey = "Removed from this scope; shared cache, marketplaces and plugin settings were retained.", "plugins.outcome.ompRemoved"
|
|
}
|
|
}
|
|
if c.Action == "import" {
|
|
outcome.Status = "imported"
|
|
outcome.Message = "Existing installation adopted without changing its enabled state."
|
|
}
|
|
}
|
|
// A package with a recorded source stays managed without Agents until it is removed whole.
|
|
if len(pack.Bindings) == 0 && (pack.Source == "" || (r.Action == "remove" && len(r.Targets) == 0)) {
|
|
delete(d.packages, c.Name)
|
|
} else {
|
|
d.packages[c.Name] = pack
|
|
}
|
|
if err := s.save(d); err != nil {
|
|
outcome.Status = "failed"
|
|
outcome.Message = "Native operation completed, but recording its result failed; inspect status before retrying."
|
|
failures = append(failures, err)
|
|
}
|
|
}
|
|
result.Results = append(result.Results, outcome)
|
|
}
|
|
return result, errors.Join(failures...)
|
|
}
|