mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* feat(mcp): let mcp serve clients edit listed skills A remote assistant that reaches skills only through `mcp serve` could read them but had to hand every change back to a person (#540). Skills listed in `mcp.serve.edit.skills` can now be changed one existing file at a time: `preview_skill_edit` writes nothing and returns the full diff, the audit result and a preview id, and `apply_skill_edit` saves exactly that preview, once. Every save is tied to the revision the client read, so a file changed in the meantime fails with a conflict instead of being overwritten. Skills that `update` would overwrite stay read-only: tracked repos, upstream installs, and skills nested inside an install. The skill is validated and audited in a temporary copy before anything is written; as with install, a finding at or above `audit.block_threshold` refuses the edit unless it was accepted with `--force`, and findings are marked new or existing so the client can see what its change adds. The write is atomic, keeps the file mode, goes through sourcefs link checks, and is recorded in the operation log. Native Skills extension clients still see the edit tools, since the extension cannot write. * fix(mcp): close gaps in mcp serve skill editing Codex review of #577 found five ways the edit tools could do more, or record less, than they promise: - A blank pattern in mcp.serve.edit.skills was dropped by the filter, and no patterns match every skill, so `skills: [' ']` made every skill editable. Blank patterns are now a config error. - preview_ttl was only checked when skills were listed, so the dashboard could save an invalid value that later stopped mcp serve. It is now checked whenever edit is present. - Apply compared only the edited file's digest, so two previews of different files, or an edit made elsewhere in between, could save a skill state that was never validated or audited. Apply now checks and audits the skill again as it will be saved. - Edit audits were not written to audit.log, so blocked attempts left no trace in `skillshare log --audit`. Each preview and apply audit is now logged like install's audit gate. - The writability check migrated legacy metadata, so a "writes nothing" preview (and --check) could rewrite .metadata.json and delete registry.yaml. It now reads the store without migrating; a legacy registry.yaml keeps every skill read-only, and a legacy sidecar marks its skill as installed.
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
// Package textdiff renders a line diff of two texts.
|
|
package textdiff
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/sergi/go-diff/diffmatchpatch"
|
|
)
|
|
|
|
// Lines returns every line of the two texts: added lines prefixed "+ ",
|
|
// removed lines "- ", and unchanged lines " ".
|
|
func Lines(old, new string) string {
|
|
dmp := diffmatchpatch.New()
|
|
a, b, lineArray := dmp.DiffLinesToChars(old, new)
|
|
diffs := dmp.DiffMain(a, b, false)
|
|
diffs = dmp.DiffCharsToLines(diffs, lineArray)
|
|
diffs = dmp.DiffCleanupSemantic(diffs)
|
|
return format(diffs)
|
|
}
|
|
|
|
// format writes diffmatchpatch.Diff slices as whole lines.
|
|
// Insert lines are prefixed with "+ ", Delete lines with "- ", Equal lines with " ".
|
|
func format(diffs []diffmatchpatch.Diff) string {
|
|
var b strings.Builder
|
|
|
|
for _, d := range diffs {
|
|
lines := strings.Split(d.Text, "\n")
|
|
// If the text ends with \n, Split produces a trailing empty string.
|
|
// Don't emit a line for that trailing empty element.
|
|
if len(lines) > 0 && lines[len(lines)-1] == "" {
|
|
lines = lines[:len(lines)-1]
|
|
}
|
|
|
|
var prefix string
|
|
switch d.Type {
|
|
case diffmatchpatch.DiffInsert:
|
|
prefix = "+ "
|
|
case diffmatchpatch.DiffDelete:
|
|
prefix = "- "
|
|
case diffmatchpatch.DiffEqual:
|
|
prefix = " "
|
|
}
|
|
|
|
for _, line := range lines {
|
|
b.WriteString(prefix)
|
|
b.WriteString(line)
|
|
b.WriteString("\n")
|
|
}
|
|
}
|
|
|
|
return b.String()
|
|
}
|