mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* chore(design): export dashboard tokens for design tools
Mockup tools read a design system's tokens.json rather than our CSS, so
designs drifted from the dashboard's Clean theme. The script derives the
tokens from components.css, and CI runs its test so a new color
variable without a usage note fails instead of silently going missing.
* feat(plugin): add npm packages from pi.dev through Pi
Pi packages on pi.dev are npm packages, which Plugins could not add:
it only took local or Git sources, so users had to install them with Pi
and import them. `plugin add npm:<package>` now hands them to
`pi install` for Pi targets and records the binding like an import.
Skillshare can't fetch or review an npm package, and Pi runs its install
scripts, so the preview says so, discover refuses npm sources, and only
targets that run pi itself take them. Pi keeps one entry per package
name, so another version replaces it in place and keeps its extension
filters; Skillshare records the new entry so a reinstall restores them,
and refuses a package another Skillshare package already manages, since
removing one would remove both. Pinned versions are skipped on update
because pi update keeps them.
The dashboard accepts npm sources, a pasted `pi install` command or a
pi.dev address, lists only Pi targets, and the Pi Extensions tab links
to adding a package with that target selected. Pi packages show Pi's
mark in the plugin list.
A blocked change now keeps its own reason when the Agent's CLI is also
missing, and the message key always matches the message the CLI prints.
* fix(plugin): keep npm package names and accept pi by path
The default name of an npm package went through the file-path rule, which
cut its last dot segment as an extension: npm:foo.bar was recorded as foo,
and adding npm:foo.bar@1.2.3 later derived foo.bar and was refused as
another package managing the same Pi entry. npm names are now taken from
the package spec.
A Pi account whose CLI is an absolute path to pi was treated as running
another executable, so it could not take npm packages. It now uses the
same path- and platform-aware check as the Pi Extensions tab.
* docs(wiki): add a pull-requests topic for Codex review rounds
Handling Codex's review was only known from practice: confirm each
finding, fix it with a failing test first, reply in its thread, ask for
another review, and follow up until it answers. Writing it down keeps
agents from resolving threads, amending pushed commits, or stopping at
the 👀 that only means the review is still running.
* feat(ui): give the Extras AGENTS.md and Memory tabs one layout
The two tabs shared a page but looked like different products: the header
shifted between them, notes sat in a joined box with an icon toolbar, and
agents showed as an icon strip in a side card. Switching tabs felt jarring.
Memory now follows the AGENTS.md layout: a sticky list column with search,
the note's name with Edit and a More actions menu, the same preview box,
and Use with agents as one row per tool under the note. Long notes open
collapsed like shared files do. The AGENTS.md list gains a search box and
the same sticky column. The Memory tab label stays English in every locale,
like AGENTS.md. Docs and screenshots follow the new layout.
* chore(docs): add a script that serves the Memory screenshot homes
The Memory how-to screenshots came from demo homes that were never
recorded, so reshooting them meant rebuilding the data by hand. The script
rebuilds the fresh and the populated home inside the devcontainer, serves
each behind the Vite dev server, and hands the port back to air afterwards.
* fix(plugin): refuse npm sources Pi can't resolve
validNpmSource accepted specs such as npm:foo/bar, npm:foo@ and names
containing "..", which Pi's own parser rejects. They passed preview, and
Apply recorded a pending binding before pi install failed, leaving an
entry every later sync retried. Validate with the same grammar the Pi
settings reader uses, which also covers a scope without a package name.
* fix(ui): show the default name when adding an npm package to Pi
The name field for an npm source was blank, so it looked like a name was
missing. Leaving it empty records the package name without its version or
scope, as the git flow already shows; the field now shows that name as its
placeholder.
168 lines
5.6 KiB
Go
168 lines
5.6 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")
|
|
}
|
|
// Serialize CLI and UI mutations across processes, not just HTTP requests.
|
|
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()
|
|
defer os.Remove(s.ConfigPath + ".plugins.lock")
|
|
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")
|
|
}
|
|
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{}}
|
|
changed := false
|
|
for _, c := range p.Changes {
|
|
if c.Action == "skip" {
|
|
// Unlike noop, a skipped update stays pending for a later sync.
|
|
result.Results = append(result.Results, Outcome{Name: c.Name, Target: c.Target, Status: "skipped", 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, nil
|
|
}
|
|
if err := s.save(d); err != nil {
|
|
return result, err
|
|
}
|
|
var failures []error
|
|
// 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."
|
|
} 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 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...)
|
|
}
|