Files
beads/cmd/bd/setup.go
Abhinav Gupta 4a7d7b0b41 feat(setup claude): add --stealth flag
Add a `--stealth` flag to `bd setup claude` that installs
Claude Code hooks using `bd prime --stealth` instead of
`bd prime`. This extends the stealth workflow introduced for
`bd prime` to the setup command, enabling workflows where git
operations should be deferred or handled separately from bd
database flushing.

When `--stealth` is specified, the installed hooks call
`bd prime --stealth`, which outputs only `bd sync --flush-only`
in the close protocol, omitting all git operations.

Update `RemoveClaude()` to remove both command variants
(`bd prime` and `bd prime --stealth`) for backwards
compatibility with existing installations. Update
`hasBeadsHooks()` to detect either variant as a valid
installation.

Add comprehensive test coverage for stealth mode: hook
installation with stealth command, removal of both variants,
detection of both variants, and idempotency with stealth mode.

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 18:10:35 -08:00

111 lines
3.0 KiB
Go

package main
import (
"github.com/spf13/cobra"
"github.com/steveyegge/beads/cmd/bd/setup"
)
var (
setupProject bool
setupCheck bool
setupRemove bool
setupStealth bool
)
var setupCmd = &cobra.Command{
Use: "setup",
Short: "Setup integration with AI editors",
Long: `Setup integration files for AI editors like Claude Code, Cursor, and Aider.`,
}
var setupCursorCmd = &cobra.Command{
Use: "cursor",
Short: "Setup Cursor IDE integration",
Long: `Install Beads workflow rules for Cursor IDE.
Creates .cursor/rules/beads.mdc with bd workflow context.
Uses BEGIN/END markers for safe idempotent updates.`,
Run: func(cmd *cobra.Command, args []string) {
if setupCheck {
setup.CheckCursor()
return
}
if setupRemove {
setup.RemoveCursor()
return
}
setup.InstallCursor()
},
}
var setupAiderCmd = &cobra.Command{
Use: "aider",
Short: "Setup Aider integration",
Long: `Install Beads workflow configuration for Aider.
Creates .aider.conf.yml with bd workflow instructions.
The AI will suggest bd commands for you to run via /run.
Note: Aider requires explicit command execution - the AI cannot
run commands autonomously. It will suggest bd commands which you
must confirm using Aider's /run command.`,
Run: func(cmd *cobra.Command, args []string) {
if setupCheck {
setup.CheckAider()
return
}
if setupRemove {
setup.RemoveAider()
return
}
setup.InstallAider()
},
}
var setupClaudeCmd = &cobra.Command{
Use: "claude",
Short: "Setup Claude Code integration",
Long: `Install Claude Code hooks that auto-inject bd workflow context.
By default, installs hooks globally (~/.claude/settings.json).
Use --project flag to install only for this project.
Hooks call 'bd prime' on SessionStart and PreCompact events to prevent
agents from forgetting bd workflow after context compaction.`,
Run: func(cmd *cobra.Command, args []string) {
if setupCheck {
setup.CheckClaude()
return
}
if setupRemove {
setup.RemoveClaude(setupProject)
return
}
setup.InstallClaude(setupProject, setupStealth)
},
}
func init() {
setupClaudeCmd.Flags().BoolVar(&setupProject, "project", false, "Install for this project only (not globally)")
setupClaudeCmd.Flags().BoolVar(&setupCheck, "check", false, "Check if Claude integration is installed")
setupClaudeCmd.Flags().BoolVar(&setupRemove, "remove", false, "Remove bd hooks from Claude settings")
setupClaudeCmd.Flags().BoolVar(&setupStealth, "stealth", false, "Use 'bd prime --stealth' (flush only, no git operations)")
setupCursorCmd.Flags().BoolVar(&setupCheck, "check", false, "Check if Cursor integration is installed")
setupCursorCmd.Flags().BoolVar(&setupRemove, "remove", false, "Remove bd rules from Cursor")
setupAiderCmd.Flags().BoolVar(&setupCheck, "check", false, "Check if Aider integration is installed")
setupAiderCmd.Flags().BoolVar(&setupRemove, "remove", false, "Remove bd config from Aider")
setupCmd.AddCommand(setupClaudeCmd)
setupCmd.AddCommand(setupCursorCmd)
setupCmd.AddCommand(setupAiderCmd)
rootCmd.AddCommand(setupCmd)
}