mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +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.
101 lines
3.2 KiB
Go
101 lines
3.2 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// Native install recursively removes its runtime destination before linking the
|
|
// cache. Require an absent destination, including undeclared/transitive packages.
|
|
func ompEmptyRuntime(path string) error {
|
|
if err := ompSafePath(path); err != nil {
|
|
return err
|
|
}
|
|
if _, err := os.Lstat(path); !os.IsNotExist(err) {
|
|
return fmt.Errorf("OMP runtime destination is not verified empty: %s", path)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) prepareOMPInstall(ctx context.Context, h Host, c *Change) {
|
|
check := func() error {
|
|
ref := c.Binding.Commit
|
|
if ref == "" {
|
|
ref = c.Binding.SourceRef
|
|
}
|
|
root, source, cleanup, err := acquireRef(ctx, c.Binding.Source, ref)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer cleanup()
|
|
d, err := discoverRoot(root, source, c.Binding.Entry)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.Digest != c.Binding.Digest {
|
|
return fmt.Errorf("OMP source changed; preview again")
|
|
}
|
|
for _, candidate := range d.Candidates {
|
|
if candidate.Name != c.Binding.Plugin {
|
|
continue
|
|
}
|
|
module, _, err := ompRemovalPackage(filepath.Join(root, candidate.pathFor("omp")), candidate.Name)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
runtimeRoot := filepath.Dir(filepath.Dir(h.ompCacheRoot))
|
|
if s.ProjectRoot != "" {
|
|
runtimeRoot = filepath.Join(s.ProjectRoot, ".omp", "plugins")
|
|
}
|
|
c.ompRuntimePath = filepath.Join(runtimeRoot, "node_modules", filepath.FromSlash(module))
|
|
return ompEmptyRuntime(c.ompRuntimePath)
|
|
}
|
|
return fmt.Errorf("OMP source no longer provides the reviewed plugin")
|
|
}
|
|
if err := check(); err != nil {
|
|
c.Action, c.Message, c.MessageKey = "blocked", err.Error(), "plugins.error.ompRuntimeSafety"
|
|
}
|
|
}
|
|
|
|
// Reinstalls use a new marketplace/cache identity instead of replacing the
|
|
// retained cache an invisible project can still use. Preview chooses the same
|
|
// first free identity until native state changes and invalidates its revision.
|
|
func ompFreshCache(h Host, c *Change) error {
|
|
if err := ompSafePath(h.ompCacheRoot); err != nil {
|
|
return err
|
|
}
|
|
if v := c.Binding.Version; v != "" && (filepath.Base(v) != v || strings.ContainsAny(v, "\\/\r\n\x00")) {
|
|
return fmt.Errorf("unsafe OMP cache version")
|
|
}
|
|
original := c.ID
|
|
name, _, ok := strings.Cut(original, "@")
|
|
if !ok || !validOMPName(name) {
|
|
return fmt.Errorf("invalid OMP plugin identity")
|
|
}
|
|
for attempt := 0; attempt < 100; attempt++ {
|
|
candidate := original
|
|
if attempt > 0 {
|
|
candidate = name + "@skillshare-" + hash([]byte(fmt.Sprintf("%s\x00reinstall\x00%d", original, attempt)))[:16]
|
|
}
|
|
info, err := os.Lstat(ompCachePath(h.ompCacheRoot, candidate, c.Binding.Version))
|
|
if os.IsNotExist(err) {
|
|
if attempt > 0 {
|
|
_, market, _ := strings.Cut(candidate, "@")
|
|
if _, registered := h.Marketplaces[market]; registered {
|
|
continue
|
|
}
|
|
c.ID, c.Binding.ID = candidate, candidate
|
|
c.Message, c.MessageKey = "Installs into a new cache identity; retained cache used by other projects is not changed.", "plugins.note.ompFreshCache"
|
|
}
|
|
return nil
|
|
}
|
|
if err != nil || !info.IsDir() || info.Mode()&os.ModeSymlink != 0 {
|
|
return fmt.Errorf("unreadable or linked OMP cache destination")
|
|
}
|
|
}
|
|
return fmt.Errorf("no free OMP cache identity")
|
|
}
|