-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproject_windsurf.go
More file actions
160 lines (140 loc) · 4.79 KB
/
project_windsurf.go
File metadata and controls
160 lines (140 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"strings"
)
// WindsurfProjector generates Windsurf (Cascade) platform files.
type WindsurfProjector struct{}
func (p *WindsurfProjector) Name() string { return "windsurf" }
func (p *WindsurfProjector) OutputPaths(rules, skills, agents []string, hasMCP bool) []string {
paths := []string{"AGENTS.md", ".windsurfrules", ".windsurf/hooks.json"}
for _, n := range rules {
paths = append(paths, ".windsurf/rules/"+n+".md")
}
for _, n := range skills {
paths = append(paths, ".windsurf/skills/"+n+"/", ".windsurf/skills/"+n+"/SKILL.md")
paths = append(paths, ".windsurf/workflows/"+n+".md")
}
return paths
}
func (p *WindsurfProjector) Project(root string, ms *MergedSet) error {
windsurfDir := filepath.Join(root, ".windsurf")
// Rules → .windsurf/rules/<name>.md
for _, name := range sortedKeys(ms.Rules) {
rule := ms.Rules[name]
if err := p.writeRule(windsurfDir, name, rule); err != nil {
return err
}
}
// Skills → .windsurf/skills/<name>/SKILL.md
if err := projectSkills(windsurfDir, ms); err != nil {
return err
}
// .windsurfrules — legacy mandate file (kept for compatibility)
if err := p.writeWindsurfRules(root, ms); err != nil {
return err
}
// Agents → AGENTS.md (flat markdown, Windsurf has no structured agents dir)
if err := writeAGENTSMD(root, ms); err != nil {
return err
}
// User-invocable skills → .windsurf/workflows/<name>.md (Windsurf slash commands)
// Windsurf uses [arguments] placeholder syntax; translate from $ARGUMENTS.
for _, skill := range userInvocableSkills(ms) {
var sb strings.Builder
sb.WriteString("---\n")
if skill.Description != "" {
sb.WriteString(fmt.Sprintf("description: %s\n", skill.Description))
}
sb.WriteString("---\n\n")
body := strings.ReplaceAll(skill.Body, "$ARGUMENTS", "[arguments]")
sb.WriteString(body)
sb.WriteString("\n")
path := filepath.Join(root, ".windsurf", "workflows", skill.Name+".md")
if err := writeFile(path, []byte(sb.String())); err != nil {
return fmt.Errorf("write windsurf workflow %s: %w", skill.Name, err)
}
}
// .windsurf/hooks.json
if err := p.writeHooks(root); err != nil {
return err
}
// MCP → ~/.codeium/windsurf/mcp_config.json (global, merge not overwrite)
if len(ms.MCP) > 0 {
home, err := os.UserHomeDir()
if err != nil {
return fmt.Errorf("windsurf MCP: get home dir: %w", err)
}
mcpPath := filepath.Join(home, ".codeium", "windsurf", "mcp_config.json")
if err := writeMCPConfigMerge(mcpPath, ms.MCP); err != nil {
return fmt.Errorf("windsurf MCP: %w", err)
}
}
return nil
}
func (p *WindsurfProjector) writeRule(windsurfDir, name string, rule *AgenticFile) error {
var sb strings.Builder
sb.WriteString("---\n")
if rule.Description != "" {
sb.WriteString(fmt.Sprintf("description: %s\n", rule.Description))
}
if len(rule.Globs) > 0 {
sb.WriteString("globs:\n")
for _, p := range rule.Globs {
sb.WriteString(fmt.Sprintf(" - %s\n", p))
}
} else {
sb.WriteString("alwaysApply: true\n")
}
sb.WriteString("---\n\n")
sb.WriteString(rule.Body)
sb.WriteString("\n")
path := filepath.Join(windsurfDir, "rules", name+".md")
return writeFile(path, []byte(sb.String()))
}
func (p *WindsurfProjector) writeWindsurfRules(root string, ms *MergedSet) error {
var sb strings.Builder
if ms.LoreMD != "" {
sb.WriteString(ms.LoreMD)
sb.WriteString("\n\n")
}
for _, name := range sortedKeys(ms.Rules) {
rule := ms.Rules[name]
sb.WriteString(fmt.Sprintf("## %s\n\n", rule.Name))
sb.WriteString(rule.Body)
sb.WriteString("\n\n")
}
return writeFile(filepath.Join(root, ".windsurfrules"), []byte(sb.String()))
}
// windsurfHooksConfig matches .windsurf/hooks.json format.
type windsurfHooksConfig struct {
Hooks map[string][]windsurfHook `json:"hooks"`
}
type windsurfHook struct {
Command string `json:"command"`
}
func (p *WindsurfProjector) writeHooks(root string) error {
h := func(cmd string) []windsurfHook { return []windsurfHook{{Command: cmd}} }
cfg := windsurfHooksConfig{
Hooks: map[string][]windsurfHook{
"pre_read_code": h("lore hook pre-tool-use"),
"pre_write_code": h("lore hook pre-tool-use"),
"pre_run_command": h("lore hook pre-tool-use"),
"pre_mcp_tool_use": h("lore hook pre-tool-use"),
"post_read_code": h("lore hook post-tool-use"),
"post_write_code": h("lore hook post-tool-use"),
"post_run_command": h("lore hook post-tool-use"),
"post_mcp_tool_use": h("lore hook post-tool-use"),
"pre_user_prompt": h("lore hook prompt-submit"),
"post_cascade_response": h("lore hook stop"),
},
}
data, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return fmt.Errorf("marshal windsurf hooks: %w", err)
}
return writeFile(filepath.Join(root, ".windsurf", "hooks.json"), append(data, '\n'))
}