/ cmd / ghostty.go
ghostty.go
 1  package cmd
 2  
 3  import (
 4  	"fmt"
 5  	"os"
 6  	"path/filepath"
 7  
 8  	"github.com/Kocoro-lab/ShanClaw/internal/agents"
 9  	"github.com/Kocoro-lab/ShanClaw/internal/config"
10  	"github.com/Kocoro-lab/ShanClaw/internal/tools"
11  	"github.com/spf13/cobra"
12  )
13  
14  var ghosttyCmd = &cobra.Command{
15  	Use:   "ghostty",
16  	Short: "Ghostty terminal integration",
17  }
18  
19  var workspaceCmd = &cobra.Command{
20  	Use:   "workspace [agent1] [agent2] ...",
21  	Short: "Open a Ghostty window with one tab per agent (defaults to all agents)",
22  	RunE: func(cmd *cobra.Command, args []string) error {
23  		if !tools.GhosttyAvailable() {
24  			return fmt.Errorf("Ghostty >= 1.3.0 is required. Install/update from https://ghostty.org")
25  		}
26  		agentNames := args
27  		if len(agentNames) == 0 {
28  			agentsDir := filepath.Join(config.ShannonDir(), "agents")
29  			entries, err := agents.ListAgents(agentsDir)
30  			if err != nil {
31  				return fmt.Errorf("failed to list agents: %w", err)
32  			}
33  			if len(entries) == 0 {
34  				return fmt.Errorf("no agents found in %s", agentsDir)
35  			}
36  			for _, entry := range entries {
37  				agentNames = append(agentNames, entry.Name)
38  			}
39  		}
40  		shanBin, _ := os.Executable()
41  		if shanBin == "" {
42  			shanBin = "shan"
43  		}
44  		script := tools.GhosttyWorkspaceScript(shanBin, agentNames)
45  		if script == "" {
46  			return fmt.Errorf("ghostty workspace requires macOS")
47  		}
48  		return tools.ExecGhosttyScript(script)
49  	},
50  }
51  
52  func init() {
53  	ghosttyCmd.AddCommand(workspaceCmd)
54  	rootCmd.AddCommand(ghosttyCmd)
55  }