-
-
Notifications
You must be signed in to change notification settings - Fork 111
v0.19.3 #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
v0.19.3 #137
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a268417
feat(ui): add web-based skill editor with metadata, live preview, and…
runkids 974b6bb
refactor(ui): simplify skill editor — dedupe parser, defer preview, d…
runkids 8cf3a82
refactor(ui): consolidate skill editor controls and throttle scroll sync
runkids e193b29
test(ui): update useCursorField test for bare list value handling
runkids 4822130
style(ui): restore paper-themed segmented control in skill editor
runkids 9ef9c07
feat(i18n): extract DashboardPage strings to en.json
runkids 2743068
feat: add i18n
runkids 50ac649
chore: release v0.19.3
runkids b11ad25
fix(ui): remove unused prefix variable in InstallForm
runkids f44cf3a
fix(server): restrict editor whitelist and harden withinDir path check
runkids File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ openspec/ | |
|
|
||
| # Worktrees | ||
| .worktrees/ | ||
| showcase/ | ||
|
|
||
| video/node_modules/ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| // openInEditorRequest controls which editor to launch. | ||
| // editor="auto" (or empty) walks a platform-aware fallback chain. | ||
| type openInEditorRequest struct { | ||
| Editor string `json:"editor,omitempty"` | ||
| } | ||
|
|
||
| type openInEditorResponse struct { | ||
| Editor string `json:"editor"` | ||
| Path string `json:"path"` | ||
| PID int `json:"pid"` | ||
| } | ||
|
|
||
| // editorCandidate represents an external editor we can try to launch. | ||
| type editorCandidate struct { | ||
| // name is the alias the API accepts (e.g. "code", "cursor"). | ||
| name string | ||
| // bin is the executable to spawn. | ||
| bin string | ||
| // args are appended before the file path. | ||
| args []string | ||
| } | ||
|
|
||
| // knownEditors returns explicit editor aliases the API accepts. | ||
| func knownEditors() map[string]editorCandidate { | ||
| return map[string]editorCandidate{ | ||
| "code": {name: "code", bin: "code", args: []string{"--goto"}}, | ||
| "cursor": {name: "cursor", bin: "cursor", args: nil}, | ||
| "windsurf": {name: "windsurf", bin: "windsurf", args: nil}, | ||
| "subl": {name: "subl", bin: "subl", args: nil}, | ||
| "sublime": {name: "subl", bin: "subl", args: nil}, | ||
| "vim": {name: "vim", bin: "vim", args: nil}, | ||
| "nvim": {name: "nvim", bin: "nvim", args: nil}, | ||
| "nano": {name: "nano", bin: "nano", args: nil}, | ||
| "emacs": {name: "emacs", bin: "emacs", args: nil}, | ||
| "idea": {name: "idea", bin: "idea", args: nil}, | ||
| "webstorm": {name: "webstorm", bin: "webstorm", args: nil}, | ||
| "goland": {name: "goland", bin: "goland", args: nil}, | ||
| "textmate": {name: "textmate", bin: "mate", args: nil}, | ||
| "mate": {name: "mate", bin: "mate", args: nil}, | ||
| "zed": {name: "zed", bin: "zed", args: nil}, | ||
| } | ||
| } | ||
|
|
||
| // handleOpenSkillInEditor launches the configured (or auto-detected) local | ||
| // editor against the skill's canonical markdown file. | ||
| // | ||
| // POST /api/resources/{name}/open-in-editor | ||
| // Body: {"editor": "auto" | "code" | "cursor" | "vim" | ...} | ||
| func (s *Server) handleOpenSkillInEditor(w http.ResponseWriter, r *http.Request) { | ||
| start := time.Now() | ||
|
|
||
| s.mu.RLock() | ||
| source := s.skillsSource() | ||
| agentsSource := s.agentsSource() | ||
| s.mu.RUnlock() | ||
|
|
||
| name := r.PathValue("name") | ||
| kind := r.URL.Query().Get("kind") | ||
| if kind != "" && kind != "skill" && kind != "agent" { | ||
| writeError(w, http.StatusBadRequest, "invalid kind: "+kind) | ||
| return | ||
| } | ||
|
|
||
| var req openInEditorRequest | ||
| // Body is optional; silently ignore decode errors when empty. | ||
| if r.Body != nil { | ||
| _ = json.NewDecoder(r.Body).Decode(&req) | ||
| } | ||
|
|
||
| targetPath, resolvedKind, err := s.resolveEditableSkillPath(source, agentsSource, name, kind) | ||
| if err != nil { | ||
| writeError(w, http.StatusNotFound, err.Error()) | ||
| return | ||
| } | ||
|
|
||
| // Skills are directories (SKILL.md + supporting files); open the folder | ||
| // so editors like VS Code / Cursor load the whole workspace. Agents are | ||
| // single .md files and stay as-is. | ||
| if resolvedKind == "skill" { | ||
| targetPath = filepath.Dir(targetPath) | ||
| } | ||
|
|
||
| if os.Getenv("SKILLSHARE_HEADLESS") == "1" { | ||
| writeError(w, http.StatusConflict, "refusing to launch editor: SKILLSHARE_HEADLESS=1") | ||
| return | ||
| } | ||
|
|
||
| editor, picked, err := pickEditor(strings.TrimSpace(req.Editor)) | ||
| if err != nil { | ||
| writeError(w, http.StatusConflict, "no editor available: "+err.Error()) | ||
| return | ||
| } | ||
|
|
||
| cmd := exec.Command(editor.bin, append(editor.args, targetPath)...) //nolint:gosec // editor choice is explicit | ||
| // Detach from the current process so the server doesn't wait on the editor. | ||
| cmd.Stdin = nil | ||
| cmd.Stdout = nil | ||
| cmd.Stderr = nil | ||
|
|
||
| if err := cmd.Start(); err != nil { | ||
| writeError(w, http.StatusInternalServerError, fmt.Sprintf("failed to launch %s: %s", editor.bin, err)) | ||
| return | ||
| } | ||
| // Reap in the background so we don't accumulate zombies on *nix. | ||
| go func() { _ = cmd.Wait() }() | ||
|
|
||
| s.writeOpsLog("skill.openInEditor", "ok", start, map[string]any{ | ||
| "name": name, | ||
| "kind": resolvedKind, | ||
| "editor": picked, | ||
| "path": targetPath, | ||
| }, "") | ||
|
|
||
| writeJSON(w, openInEditorResponse{ | ||
| Editor: picked, | ||
| Path: targetPath, | ||
| PID: cmd.Process.Pid, | ||
| }) | ||
| } | ||
|
|
||
| // pickEditor returns the editor to launch, honouring an explicit request | ||
| // (e.g. "code") when it resolves, otherwise walking the fallback chain. | ||
| func pickEditor(requested string) (editorCandidate, string, error) { | ||
| if requested != "" && requested != "auto" { | ||
| if cand, ok := knownEditors()[strings.ToLower(requested)]; ok { | ||
| if _, err := exec.LookPath(cand.bin); err == nil { | ||
| return cand, cand.name, nil | ||
| } | ||
| return editorCandidate{}, "", fmt.Errorf("%s not found on PATH", cand.bin) | ||
| } | ||
| // Unknown alias — treat as raw binary. | ||
| if _, err := exec.LookPath(requested); err == nil { | ||
| return editorCandidate{name: requested, bin: requested}, requested, nil | ||
| } | ||
| return editorCandidate{}, "", fmt.Errorf("%s not found on PATH", requested) | ||
| } | ||
|
|
||
| // Auto: respect $VISUAL / $EDITOR first. | ||
| for _, env := range []string{"VISUAL", "EDITOR"} { | ||
| if v := strings.TrimSpace(os.Getenv(env)); v != "" { | ||
| // $EDITOR may include flags, e.g. "code --wait". | ||
| head, rest := splitCommand(v) | ||
| if _, err := exec.LookPath(head); err == nil { | ||
| return editorCandidate{name: head, bin: head, args: rest}, head, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // GUI IDE preferences. | ||
| for _, alias := range []string{"code", "cursor", "zed", "subl", "windsurf", "idea"} { | ||
| if cand, ok := knownEditors()[alias]; ok { | ||
| if _, err := exec.LookPath(cand.bin); err == nil { | ||
| return cand, cand.name, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // OS native fallback — opens with the user's default handler. | ||
| switch runtime.GOOS { | ||
| case "darwin": | ||
| if _, err := exec.LookPath("open"); err == nil { | ||
| return editorCandidate{name: "open", bin: "open"}, "open", nil | ||
| } | ||
| case "linux": | ||
| if _, err := exec.LookPath("xdg-open"); err == nil { | ||
| return editorCandidate{name: "xdg-open", bin: "xdg-open"}, "xdg-open", nil | ||
| } | ||
| case "windows": | ||
| if _, err := exec.LookPath("rundll32"); err == nil { | ||
| return editorCandidate{name: "rundll32", bin: "rundll32", args: []string{"url.dll,FileProtocolHandler"}}, "rundll32", nil | ||
| } | ||
| } | ||
|
|
||
| // Terminal fallbacks — nano is friendlier than vim for newcomers. | ||
| for _, alias := range []string{"nano", "vim", "nvim", "emacs"} { | ||
| if cand, ok := knownEditors()[alias]; ok { | ||
| if _, err := exec.LookPath(cand.bin); err == nil { | ||
| return cand, cand.name, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return editorCandidate{}, "", fmt.Errorf("no usable editor found; set $EDITOR or pass editor=<name>") | ||
| } | ||
|
|
||
| // splitCommand naively splits an $EDITOR value into (bin, args...). | ||
| // Quoted arguments are not supported because $EDITOR rarely needs them. | ||
| func splitCommand(v string) (string, []string) { | ||
| fields := strings.Fields(v) | ||
| if len(fields) == 0 { | ||
| return "", nil | ||
| } | ||
| return fields[0], fields[1:] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package server | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestHandleOpenInEditor_UsesEchoAsEditor(t *testing.T) { | ||
| s, src := newTestServer(t) | ||
| addSkill(t, src, "my-skill") | ||
|
|
||
| // `true` is a universally-available no-op binary on POSIX. | ||
| body := openInEditorRequest{Editor: "true"} | ||
| raw, _ := json.Marshal(body) | ||
| req := httptest.NewRequest(http.MethodPost, "/api/resources/my-skill/open-in-editor", bytes.NewReader(raw)) | ||
| rr := httptest.NewRecorder() | ||
| s.handler.ServeHTTP(rr, req) | ||
|
|
||
| if rr.Code != http.StatusOK { | ||
| t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String()) | ||
| } | ||
| var resp openInEditorResponse | ||
| if err := json.Unmarshal(rr.Body.Bytes(), &resp); err != nil { | ||
| t.Fatalf("decode: %v", err) | ||
| } | ||
| if resp.PID == 0 { | ||
| t.Errorf("expected pid > 0, got %d", resp.PID) | ||
| } | ||
| if resp.Path != filepath.Join(src, "my-skill") { | ||
| t.Errorf("unexpected path: %s", resp.Path) | ||
| } | ||
| } | ||
|
|
||
| func TestHandleOpenInEditor_NotFound(t *testing.T) { | ||
| s, _ := newTestServer(t) | ||
| raw, _ := json.Marshal(openInEditorRequest{Editor: "true"}) | ||
| req := httptest.NewRequest(http.MethodPost, "/api/resources/no-skill/open-in-editor", bytes.NewReader(raw)) | ||
| rr := httptest.NewRecorder() | ||
| s.handler.ServeHTTP(rr, req) | ||
|
|
||
| if rr.Code != http.StatusNotFound { | ||
| t.Fatalf("expected 404, got %d: %s", rr.Code, rr.Body.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestHandleOpenInEditor_HeadlessRefuses(t *testing.T) { | ||
| t.Setenv("SKILLSHARE_HEADLESS", "1") | ||
| s, src := newTestServer(t) | ||
| addSkill(t, src, "my-skill") | ||
|
|
||
| raw, _ := json.Marshal(openInEditorRequest{Editor: "true"}) | ||
| req := httptest.NewRequest(http.MethodPost, "/api/resources/my-skill/open-in-editor", bytes.NewReader(raw)) | ||
| rr := httptest.NewRecorder() | ||
| s.handler.ServeHTTP(rr, req) | ||
|
|
||
| if rr.Code != http.StatusConflict { | ||
| t.Fatalf("expected 409, got %d", rr.Code) | ||
| } | ||
| } | ||
|
|
||
| func TestHandleOpenInEditor_UnknownBinary(t *testing.T) { | ||
| s, src := newTestServer(t) | ||
| addSkill(t, src, "my-skill") | ||
|
|
||
| raw, _ := json.Marshal(openInEditorRequest{Editor: "this-is-not-a-real-editor-xyz"}) | ||
| req := httptest.NewRequest(http.MethodPost, "/api/resources/my-skill/open-in-editor", bytes.NewReader(raw)) | ||
| rr := httptest.NewRecorder() | ||
| s.handler.ServeHTTP(rr, req) | ||
|
|
||
| if rr.Code != http.StatusConflict { | ||
| t.Fatalf("expected 409, got %d", rr.Code) | ||
| } | ||
| } | ||
|
|
||
| func TestPickEditor_AutoPrefersEditorEnv(t *testing.T) { | ||
| t.Setenv("VISUAL", "") | ||
| t.Setenv("EDITOR", "true") | ||
|
|
||
| cand, name, err := pickEditor("auto") | ||
| if err != nil { | ||
| t.Fatalf("pickEditor: %v", err) | ||
| } | ||
| if cand.bin != "true" || name != "true" { | ||
| t.Errorf("expected bin=true, got bin=%s name=%s", cand.bin, name) | ||
| } | ||
| } | ||
|
|
||
| func TestSplitCommand(t *testing.T) { | ||
| head, rest := splitCommand("code --wait --new-window") | ||
| if head != "code" { | ||
| t.Errorf("expected head=code, got %s", head) | ||
| } | ||
| if len(rest) != 2 || rest[0] != "--wait" || rest[1] != "--new-window" { | ||
| t.Errorf("unexpected rest: %v", rest) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
pickEditorfunction allows executing any binary found on the system'sPATHif the requested editor is not a known alias. This is a security risk as it could allow arbitrary command execution if the API endpoint is exposed or triggered via a cross-site request (e.g., if the server lacks CSRF protection). It is safer to restrict the allowed editors to theknownEditorswhitelist.