beads/cmd/bd/setup/cursor.go
Steven Syrek 39ee50d64c
fix(setup): add alwaysApply frontmatter to Cursor rules template (GH#3191) (#3193)
Without YAML frontmatter, Cursor defaults .mdc files to Manual mode,
requiring users to @-reference the rule explicitly. Add alwaysApply: true
so beads context loads automatically every session, consistent with the
Claude and Gemini integrations.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-20 17:40:28 -07:00

100 lines
2.9 KiB
Go

package setup
import (
"fmt"
"os"
"path/filepath"
)
const cursorRulesTemplate = `---
alwaysApply: true
---
# Beads Issue Tracking
# Auto-generated by 'bd setup cursor' - do not remove these markers
# BEGIN BEADS INTEGRATION
This project uses [Beads (bd)](https://github.com/steveyegge/beads) for issue tracking.
## Core Rules
- Track ALL work in bd (never use markdown TODOs or comment-based task lists)
- Use ` + "`bd ready`" + ` to find available work
- Use ` + "`bd create`" + ` to track new issues/tasks/bugs
- Use ` + "`bd dolt push`" + ` at end of session to sync with git remote
- Git hooks auto-sync on commit/merge
## Quick Reference
` + "```bash" + `
bd prime # Load complete workflow context
bd ready # Show issues ready to work (no blockers)
bd list --status=open # List all open issues
bd create --title="..." --type=task # Create new issue
bd update <id> --claim # Claim work atomically
bd close <id> # Mark complete
bd dep add <issue> <depends-on> # Add dependency (issue depends on depends-on)
bd dolt push # Sync with git remote
` + "```" + `
## Workflow
1. Check for ready work: ` + "`bd ready`" + `
2. Claim an issue atomically: ` + "`bd update <id> --claim`" + `
3. Do the work
4. Mark complete: ` + "`bd close <id>`" + `
5. Sync: ` + "`bd dolt push`" + ` (or let git hooks handle it)
## Context Loading
Run ` + "`bd prime`" + ` to get complete workflow documentation in AI-optimized format (~1-2k tokens).
For detailed docs: see AGENTS.md, QUICKSTART.md, or run ` + "`bd --help`" + `
# END BEADS INTEGRATION
`
// InstallCursor installs Cursor IDE integration
func InstallCursor() {
rulesPath := ".cursor/rules/beads.mdc"
fmt.Println("Installing Cursor integration...")
// Ensure parent directory exists
if err := EnsureDir(filepath.Dir(rulesPath), 0755); err != nil {
FatalError("%v", err)
}
// Write beads rules file (overwrite if exists)
if err := atomicWriteFile(rulesPath, []byte(cursorRulesTemplate)); err != nil {
FatalError("write rules: %v", err)
}
fmt.Printf("\n✓ Cursor integration installed\n")
fmt.Printf(" Rules: %s\n", rulesPath)
fmt.Println("\nRestart Cursor for changes to take effect.")
}
// CheckCursor checks if Cursor integration is installed
func CheckCursor() {
rulesPath := ".cursor/rules/beads.mdc"
if !FileExists(rulesPath) {
FatalErrorWithHint("Cursor integration not installed", "Run: bd setup cursor")
}
fmt.Println("✓ Cursor integration installed:", rulesPath)
}
// RemoveCursor removes Cursor integration
func RemoveCursor() {
rulesPath := ".cursor/rules/beads.mdc"
fmt.Println("Removing Cursor integration...")
if err := os.Remove(rulesPath); err != nil {
if os.IsNotExist(err) {
fmt.Println("No rules file found")
return
}
FatalError("failed to remove file: %v", err)
}
fmt.Println("✓ Removed Cursor integration")
}