mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* feat(omp): add native Oh My Pi support Support OMP skills, instructions, MCP, code hooks and guarded extension selection using its verified native contracts rather than Pi aliases. Add reviewed marketplace plugin installation, cache-preserving scoped removal and fresh-cache reinstall. Align Pi/OMP extension cards and localize inventory guidance while keeping native ownership and read-only constraints. Include regression coverage, isolated E2E runbooks, documentation and verification policies. Native plugin updates and unverified runtime platforms remain guarded. Refs #409 * fix(omp): guard runtime ownership and localize inventory guidance Native install recursively replaces its runtime destination, and a missing cache manifest could leave the real runtime link installed after removal. Bind and recheck an absent reviewed destination, and recover removal names only from verified scope-local links. Localize fixed backend reasons and warnings across dashboard locales while preserving paths and external diagnostics. Restore the reviewed source in the existing reinstall fixture and record real native verification. * fix(omp): allow forgetting natively removed plugins A different plugin can retain node_modules after native uninstall deletes this installation. When its cache, registration and known runtime state are absent, forget only the stale Skillshare binding instead of demanding runtime-name proof for unrelated files. Extend the existing removal recovery test with a failing-before-fix case that verifies the binding is dropped and unrelated native lock bytes and plugin files are preserved. make check passes.
109 lines
3.0 KiB
Go
109 lines
3.0 KiB
Go
package plugin
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func ompPlanRevision(revision string, changes []OMPExtensionChange) string {
|
|
sorted := slices.Clone(changes)
|
|
slices.SortFunc(sorted, func(a, b OMPExtensionChange) int { return strings.Compare(a.Key, b.Key) })
|
|
raw, _ := json.Marshal([]any{revision, sorted})
|
|
return hash(raw)
|
|
}
|
|
|
|
// Replace just the disabledExtensions entry. Unknown values and unrelated
|
|
// comments keep their original bytes rather than round-tripping the whole file.
|
|
func ompRenderDisabled(raw []byte, root, disabled *yaml.Node) ([]byte, error) {
|
|
index := -1
|
|
for i := 0; i < len(root.Content); i += 2 {
|
|
if root.Content[i].Value == "disabledExtensions" {
|
|
index = i
|
|
break
|
|
}
|
|
}
|
|
if index < 0 {
|
|
return nil, fmt.Errorf("missing disabledExtensions node")
|
|
}
|
|
key := *root.Content[index]
|
|
key.HeadComment = ""
|
|
key.FootComment = ""
|
|
pair := &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map", Content: []*yaml.Node{&key, disabled}}
|
|
var out bytes.Buffer
|
|
enc := yaml.NewEncoder(&out)
|
|
enc.SetIndent(2)
|
|
if err := enc.Encode(pair); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := enc.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
lines := strings.SplitAfter(string(raw), "\n")
|
|
if key.Line == 0 {
|
|
prefix := string(raw)
|
|
if prefix != "" && !strings.HasSuffix(prefix, "\n") {
|
|
prefix += "\n"
|
|
}
|
|
return []byte(prefix + out.String()), nil
|
|
}
|
|
start := key.Line - 1
|
|
end := len(lines)
|
|
if index+2 < len(root.Content) {
|
|
end = root.Content[index+2].Line - 1
|
|
}
|
|
// Blank lines/comments immediately before the next key belong to untouched
|
|
// content, not to the disabled list. Preserve their spelling and position.
|
|
for end > start+1 {
|
|
text := strings.TrimSpace(lines[end-1])
|
|
if text != "" && !strings.HasPrefix(text, "#") {
|
|
break
|
|
}
|
|
end--
|
|
}
|
|
return []byte(strings.Join(lines[:start], "") + out.String() + strings.Join(lines[end:], "")), nil
|
|
}
|
|
|
|
func (s *Service) ompBackup(path string, before, after []byte, id string) (string, error) {
|
|
selection := func(raw []byte) (map[string]any, error) {
|
|
var doc map[string]any
|
|
if len(bytes.TrimSpace(raw)) > 0 {
|
|
if err := yaml.Unmarshal(raw, &doc); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
value, exists := doc["disabledExtensions"]
|
|
return map[string]any{"present": exists, "disabledExtensions": value}, nil
|
|
}
|
|
old, err := selection(before)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
next, err := selection(after)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
dir := filepath.Join(s.StateDir, "omp-extensions", "backups")
|
|
if err := ompSafePath(dir); err != nil {
|
|
return "", err
|
|
}
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
return "", err
|
|
}
|
|
raw, err := json.MarshalIndent(map[string]any{"path": path, "beforeHash": hash(before), "afterHash": hash(after), "before": old, "after": next}, "", " ")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
record := filepath.Join(dir, id+".json")
|
|
if err := atomicNativeWrite(s.StateDir, record, append(raw, '\n'), 0600); err != nil {
|
|
return "", err
|
|
}
|
|
return id, nil
|
|
}
|