Quick Start
This guide walks you through creating, building, and installing your first Sky plugin.
Prerequisites
Section titled “Prerequisites”- Go 1.21 or later
- Sky CLI installed (
go install github.com/albertocavalcante/sky/cmd/sky@latest)
Create Your Plugin
Section titled “Create Your Plugin”-
Initialize the plugin project
Terminal window sky plugin init hellocd helloThis creates a directory with boilerplate code:
main.go- Plugin source codego.mod- Go module fileREADME.md- Documentation template
-
Build the plugin
Terminal window go build -o plugin -
Install the plugin
Terminal window sky plugin install --path ./plugin hello -
Run your plugin
Terminal window sky helloYou should see:
Hello from helloWorkspace: /path/to/your/directory
Understanding the Code
Section titled “Understanding the Code”Open main.go to see the plugin structure:
package main
import ( "encoding/json" "flag" "fmt" "os")
const ( pluginName = "hello" pluginVersion = "0.1.0" pluginSummary = "A Sky plugin")
func main() { // 1. Verify we're running as a Sky plugin if os.Getenv("SKY_PLUGIN") != "1" { fmt.Fprintf(os.Stderr, "Run via: sky %s\n", pluginName) os.Exit(1) }
// 2. Handle metadata mode if os.Getenv("SKY_PLUGIN_MODE") == "metadata" { json.NewEncoder(os.Stdout).Encode(map[string]any{ "api_version": 1, "name": pluginName, "version": pluginVersion, "summary": pluginSummary, "commands": []map[string]string{ {"name": pluginName, "summary": pluginSummary}, }, }) return }
// 3. Run the plugin os.Exit(run(os.Args[1:]))}Key Concepts
Section titled “Key Concepts”- Plugin Detection: Check
SKY_PLUGIN=1to verify the plugin is run by Sky - Metadata Mode: When
SKY_PLUGIN_MODE=metadata, output JSON describing your plugin - Execution Mode: Otherwise, run your plugin’s main logic
Add Custom Logic
Section titled “Add Custom Logic”Let’s modify the plugin to do something useful. Edit main.go:
func run(args []string) int { fs := flag.NewFlagSet(pluginName, flag.ContinueOnError) name := fs.String("name", "World", "name to greet") count := fs.Int("count", 1, "number of times to greet")
if err := fs.Parse(args); err != nil { return 2 }
for i := 0; i < *count; i++ { fmt.Printf("Hello, %s!\n", *name) }
return 0}Rebuild and test:
go build -o pluginsky plugin install --path ./plugin hellosky hello --name "Sky User" --count 3Output:
Hello, Sky User!Hello, Sky User!Hello, Sky User!Using the SDK
Section titled “Using the SDK”For larger plugins, use the SDK to reduce boilerplate:
package main
import ( "context" "fmt"
"github.com/albertocavalcante/sky/pkg/skyplugin")
func main() { skyplugin.Serve(skyplugin.Plugin{ Metadata: skyplugin.Metadata{ APIVersion: 1, Name: "hello", Version: "1.0.0", Summary: "A greeting plugin", }, Run: func(ctx context.Context, args []string) error { fmt.Println("Hello from Sky!")
// Access workspace root fmt.Println("Workspace:", skyplugin.WorkspaceRoot())
return nil }, })}Update your go.mod:
go get github.com/albertocavalcante/sky/pkg/skypluginNext Steps
Section titled “Next Steps”- Plugin Protocol - Learn the full protocol specification
- Native Plugins - Build feature-rich native plugins
- WASM Plugins - Build portable WASM plugins
- SDK Reference - Explore the SDK API