mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* fix(opencode): preserve v2 directory packages
Stage the reviewed issue 913 source for isolated fork validation. Preserve
package directories and manifests without executing managed packages or
installing their dependencies, and include receipt and localized UI fixes.
Reviewed local source: 15ac88e2f266571b8a6dc8d777302db0f4dcae44
Exact source tree: 45ebabfe2b
Static checks and independent inspection completed. Go, integration,
dashboard, rendering, and hosted runtime validation remain pending.
This fork staging commit is not an upstream publication or merge.
* test(opencode): align schema and snapshot assertions
Check the version-aware binding schema and verify native unregister retains the unchanged managed snapshot.
* fix(opencode): resolve Windows npm native launchers
Probe recognized native Opencode executables without invoking a batch shell; exercise the default version probe on hosted Windows.
* test(opencode): normalize Windows fixture line endings
Avoid doubling carriage returns when Git checks out the npm fixture with CRLF.
* fix(opencode): keep an undetected OpenCode version from blocking other agents
Review of the v2 directory package change found that one failed
`opencode --version` probe failed the whole hooks plan, so a machine
without the binary (a second machine sharing the config, CI, a
devcontainer) could no longer sync hooks to any agent, and doctor and
the dashboard preview failed with it.
Hooks:
- A probe that fails or reports an unknown major now skips only the
OpenCode bindings with one warning per target. Outputs already owned
there are parked, so they are neither rewritten nor removed while the
layout is unknown. The probe runs once per plan, list and import.
- A `package` binding on OpenCode v1 is skipped with a warning instead
of failing the plan.
- The v2 dependency warning is reported once, and only when a package
file is written, so a synced hook no longer keeps doctor yellow.
- `hooks import` reports an unreadable file such as a symlink as that
package's problem; other packages and flat files stay importable.
The package validation problem is reported once instead of twice.
- Directories under `plugins/` are listed as unmanaged only on v2.
Plugins:
- The inventory leaves `plugins/skillshare-NAME` registrations to
hooks, so a synced v2 hook is not offered as an importable plugin.
Dashboard: the new warnings are translated in every locale, a
`hook NAME:` prefix no longer defeats translation, the native preview
translates its per-file error, and the YAML editor documents `package`.
Docs: the English pages and the built-in skill describe the behavior
above; the ja, ko, zh-Hans and zh-Hant pages now carry the same
content as the English ones. The runbook drives the CLI with mdproof
assertions instead of prose expectations.
Refs #913.
---------
Co-authored-by: Willie <egg358358@gmail.com>
125 lines
4.1 KiB
Go
125 lines
4.1 KiB
Go
package hooks
|
|
|
|
import (
|
|
"fmt"
|
|
"maps"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// RenderedFile is one native output of a single hook: its contribution to a shared
|
|
// hooks file in that file's native wrapper, or a whole file it owns.
|
|
type RenderedFile struct {
|
|
Target string `json:"target"`
|
|
Path string `json:"path,omitempty"`
|
|
Content string `json:"content"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// RenderNative shows what one hook writes, per Agent, without the rest of any existing
|
|
// file. It reads no ownership state or native file contents and writes nothing.
|
|
// OpenCode runs only a read-only version probe. A disabled entry renders its stored
|
|
// bindings, which sync would not write.
|
|
// A binding whose path cannot be resolved or safely written reports its own error.
|
|
func (s *Service) RenderNative(m Mutation) ([]RenderedFile, error) {
|
|
if m.Remove || m.Replace {
|
|
return nil, fmt.Errorf("render takes a hook definition, not a remove or replace")
|
|
}
|
|
if m.Name == "" || m.Entry == nil {
|
|
return nil, fmt.Errorf("hook name and entry are required")
|
|
}
|
|
root := ""
|
|
scope := s
|
|
if m.Project != "" {
|
|
if s.ProjectRoot != "" {
|
|
return nil, fmt.Errorf("hooks.projects belongs in the global config")
|
|
}
|
|
var err error
|
|
if root, err = projectRoot(m.Project); err != nil {
|
|
return nil, err
|
|
}
|
|
scope = s.scoped(root)
|
|
}
|
|
entry := *m.Entry
|
|
if err := entry.normalize(); err != nil {
|
|
return nil, err
|
|
}
|
|
// The dashboard may send contents cached before a referenced file changed; show
|
|
// what sync would write by reading every reference again.
|
|
for target, b := range entry.Bindings {
|
|
if b.CodeFile != "" {
|
|
b.Code = ""
|
|
}
|
|
if len(b.FilesFrom) > 0 {
|
|
b.Files = maps.Clone(b.Files)
|
|
for name := range b.FilesFrom {
|
|
if _, kept := b.Files[name]; kept {
|
|
b.Files[name] = fileRefMark
|
|
}
|
|
}
|
|
}
|
|
entry.Bindings[target] = b
|
|
}
|
|
if err := entry.resolveRefs(filepath.Dir(s.ConfigPath)); err != nil {
|
|
return nil, fmt.Errorf("hook %s: %w", m.Name, err)
|
|
}
|
|
if err := s.validateEntry(m.Name, entry, root); err != nil {
|
|
return nil, err
|
|
}
|
|
entry.Enabled = nil
|
|
scope = scope.memoProbe()
|
|
out := []RenderedFile{}
|
|
for _, target := range sortedKeys(entry.Bindings) {
|
|
one := Entry{Bindings: map[string]Binding{target: entry.Bindings[target]}}
|
|
d := &desired{elements: map[string][]wantElement{}, targets: map[string]string{}, roots: map[string]string{}, files: map[string]wantFile{}}
|
|
if err := scope.renderScope(d, root, map[string]Entry{m.Name: one}); err != nil {
|
|
out = append(out, RenderedFile{Target: target, Error: err.Error()})
|
|
continue
|
|
}
|
|
// A skipped account home writes nothing; say why instead of rendering no file.
|
|
if len(d.warnings) > 0 && len(d.files)+len(d.elements)+len(d.git) == 0 {
|
|
out = append(out, RenderedFile{Target: target, Error: strings.Join(d.warnings, "; ")})
|
|
continue
|
|
}
|
|
base, err := scope.base(target, root)
|
|
if err != nil {
|
|
out = append(out, RenderedFile{Target: target, Error: err.Error()})
|
|
continue
|
|
}
|
|
var files []RenderedFile
|
|
for _, w := range d.git {
|
|
files = append(files, RenderedFile{Target: target, Path: w.destination.hooksFile, Content: string(w.content)})
|
|
}
|
|
if len(d.notes) > 0 {
|
|
out = append(out, RenderedFile{Target: target, Error: d.notes[0].Message})
|
|
continue
|
|
}
|
|
for path, want := range d.elements {
|
|
f := RenderedFile{Target: target, Path: path}
|
|
ops := make([]elementOp, len(want))
|
|
for i, w := range want {
|
|
ops[i] = elementOp{Event: w.event, Index: -1, Value: w.value}
|
|
}
|
|
doc, _ := parseNative(scope.agentOf(target), nil)
|
|
if data, _, err := doc.edit(ops, nil, false); err != nil {
|
|
f.Error = err.Error()
|
|
} else {
|
|
f.Content = string(data)
|
|
}
|
|
files = append(files, f)
|
|
}
|
|
for path, want := range d.files {
|
|
files = append(files, RenderedFile{Target: target, Path: path, Content: string(want.content)})
|
|
}
|
|
for i := range files {
|
|
if err := checkPath(base, files[i].Path); err != nil && files[i].Error == "" {
|
|
files[i].Error = err.Error()
|
|
}
|
|
}
|
|
slices.SortFunc(files, func(a, b RenderedFile) int { return strings.Compare(a.Path, b.Path) })
|
|
out = append(out, files...)
|
|
}
|
|
return out, nil
|
|
}
|