* feat: add bd prime and setup commands for AI agent integration This commit consolidates context optimization features for AI agents: ## New Commands **bd prime** - AI-optimized workflow context injection - Outputs ~1-2k tokens of workflow context - Context-aware: adapts to MCP vs CLI mode - MCP mode: minimal reminders (~500 tokens) - CLI mode: full command reference (~1-2k tokens) - Warns against TodoWrite tool and markdown TODOs - Designed for SessionStart/PreCompact hooks **bd setup claude** - Claude Code integration installer - Installs hooks via JSON configuration (not file scripts) - Supports --project for project-only installation - Supports --check to verify installation - Supports --remove to uninstall hooks - Idempotent (safe to run multiple times) - Merges with existing settings **bd setup cursor** - Cursor IDE integration installer - Creates .cursor/rules/beads.mdc with workflow rules - Simplified implementation (just overwrites file) ## bd doctor Enhancements - New: CheckClaude() verifies Claude Code integration - Detects plugin, MCP server, and hooks installation - Provides actionable fix suggestions - Extracted legacy pattern detection to doctor/legacy.go - Detects JSONL-only mode and warns about legacy issues.jsonl ## Core Improvements - FindBeadsDir() utility for cross-platform .beads/ discovery - Works in JSONL-only mode (no database required) - Sorted noDbCommands alphabetically (one per line for easy diffs) ## Testing - Unit tests for setup command hook manipulation - Tests for idempotency, adding/removing hooks - All tests passing ## Documentation - cmd/bd/doctor/claude.md - Documents why beads doesn't use Claude Skills - commands/prime.md - Slash command for bd prime - Fixed G304 gosec warnings with nosec comments ## Token Efficiency The bd prime approach reduces AI context usage dramatically: - MCP mode: ~500 tokens (vs ~10.5k for full MCP tool scan) - CLI mode: ~1-2k tokens - 80-99% reduction in standing context overhead * fix: resolve linting errors in setup utils and remove obsolete test - Add error check for tmpFile.Close() in setup/utils.go to fix golangci-lint G104 - Remove TestCheckMultipleJSONLFiles test that referenced deleted checkMultipleJSONLFiles function Fixes golangci-lint errcheck violations introduced in the bd prime/setup feature.
102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
package setup
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
const cursorRulesTemplate = `# 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 sync`" + ` 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> --status=in_progress # Claim work
|
|
bd close <id> # Mark complete
|
|
bd dep <from> <to> # Add dependency (from blocks to)
|
|
bd sync # Sync with git remote
|
|
` + "```" + `
|
|
|
|
## Workflow
|
|
1. Check for ready work: ` + "`bd ready`" + `
|
|
2. Claim an issue: ` + "`bd update <id> --status=in_progress`" + `
|
|
3. Do the work
|
|
4. Mark complete: ` + "`bd close <id>`" + `
|
|
5. Sync: ` + "`bd sync`" + ` (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 {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Write beads rules file (overwrite if exists)
|
|
if err := atomicWriteFile(rulesPath, []byte(cursorRulesTemplate), 0644); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: write rules: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
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 _, err := os.Stat(rulesPath); os.IsNotExist(err) {
|
|
fmt.Println("✗ Cursor integration not installed")
|
|
fmt.Println(" Run: bd setup cursor")
|
|
os.Exit(1)
|
|
}
|
|
|
|
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
|
|
}
|
|
fmt.Fprintf(os.Stderr, "Error: failed to remove file: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Println("✓ Removed Cursor integration")
|
|
}
|