commands

package
v0.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 42 Imported by: 0

Documentation

Overview

Package commands implements the bdh CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute() error

Execute runs the root command. Routing rules:

  • :* commands → bdh handles (cobra subcommands)
  • -h, --help → bdh help, then bd --help
  • -V, --version → bdh version, then bd --version
  • everything else → passthrough to bd

func FormatCoordinationHeader

func FormatCoordinationHeader() string

FormatCoordinationHeader returns the header on first call, empty string thereafter. Safe to call multiple times - only the first call produces output.

func FormatGoneWorkspaces

func FormatGoneWorkspaces(gone []GoneWorkspace) string

FormatGoneWorkspaces formats the gone workspaces message.

func FormatNotifications

func FormatNotifications(ctx *NotificationContext, excludeAlias string) string

FormatNotifications formats the notifications section for the agent. Uses second-person language to make it explicit these are for the agent to act on.

func GetBeadsPrimeContent

func GetBeadsPrimeContent() (string, error)

GetBeadsPrimeContent runs `bd prime --export` and returns the content with bd replaced by bdh.

func PrintAgentDocsResult

func PrintAgentDocsResult(result *AgentDocsResult)

PrintAgentDocsResult prints the result of agent docs injection.

func PrintClaudeHooksResult

func PrintClaudeHooksResult(result *ClaudeHooksResult)

PrintClaudeHooksResult prints the result of setting up Claude Code hooks.

func PrintNotifications

func PrintNotifications(w io.Writer)

PrintNotifications fetches and prints notifications. This is the single entry point called by main.go at the end of every command.

func PrintPrimeOverrideResult

func PrintPrimeOverrideResult(result *PrimeOverrideResult)

PrintPrimeOverrideResult prints the result of PRIME.md injection.

func ResetCoordinationHeader

func ResetCoordinationHeader()

ResetCoordinationHeader clears state for next command.

func SetCoordinationHeaderAlias

func SetCoordinationHeaderAlias(alias string)

SetCoordinationHeaderAlias enables the coordination header for this command. Call this early in command execution, before any coordination output.

func SetExcludeChatAlias

func SetExcludeChatAlias(alias string)

SetExcludeChatAlias sets an alias to exclude from chat notifications. Used by :chat command to avoid showing "you have a chat with X" when already chatting with X.

func SetVersionInfo

func SetVersionInfo(version, commit, date string)

SetVersionInfo sets version information from main (populated by goreleaser).

Types

type AgentDocsResult

type AgentDocsResult struct {
	Created  []string // Files that were created from scratch
	Injected []string // Files that were modified (bdh section added)
	Skipped  []string // Files skipped (already has bdh instructions)
	Upgraded []string // Files that had bd instructions replaced with bdh
	Errors   []string // Files that had errors
}

AgentDocsResult contains the result of injecting agent docs.

func InjectAgentDocs

func InjectAgentDocs(repoRoot string) (*AgentDocsResult, error)

InjectAgentDocs injects bdh instructions into CLAUDE.md and AGENTS.md files. It handles symlinks by resolving them and avoiding duplicate writes.

type AliasMatch

type AliasMatch struct {
	WorkspaceID string
	Alias       string
	HumanName   string
	MatchType   MatchType
}

AliasMatch represents a matched workspace.

type AliasResolution

type AliasResolution struct {
	WorkspaceID string
	Alias       string
	MatchType   MatchType
}

AliasResolution is the result of resolving an alias.

type AutoReserveResult

type AutoReserveResult struct {
	Acquired  []string
	Renewed   []string
	Released  []string
	Conflicts []ReservationConflict
	Warning   string
}

type ClaimInfo

type ClaimInfo struct {
	BeadID    string `json:"bead_id"`
	Title     string `json:"title,omitempty"`
	ClaimedAt string `json:"claimed_at"`
}

ClaimInfo represents a bead claim for display.

type ClaudeHooksResult

type ClaudeHooksResult struct {
	Created       bool   // .claude/settings.json was created
	Updated       bool   // Hook was added to existing settings
	AlreadyExists bool   // Hook was already configured
	Skipped       bool   // User declined or error occurred
	Error         error  // Any error that occurred
	FilePath      string // Path to the settings file
}

ClaudeHooksResult contains the result of setting up Claude Code hooks.

func SetupClaudeHooks

func SetupClaudeHooks(repoRoot string, askConfirmation bool) *ClaudeHooksResult

SetupClaudeHooks configures the PostToolUse hook in .claude/settings.json. If askConfirmation is true (TTY mode), prompts before modifying.

type Dependency

type Dependency struct {
	IssueID     string `json:"issue_id"`
	DependsOnID string `json:"depends_on_id"`
	Type        string `json:"type"` // "blocks", "parent-child", "discovered-from"
}

Dependency represents a dependency relationship between issues.

type EscalateResult

type EscalateResult struct {
	EscalationID string
	Status       string
	CreatedAt    string
	ExpiresAt    string
}

EscalateResult contains the result of creating an escalation.

type GoneWorkspace

type GoneWorkspace struct {
	WorkspaceID   string `json:"workspace_id"`
	Alias         string `json:"alias"`
	WorkspacePath string `json:"workspace_path"`
}

GoneWorkspace represents a workspace that was cleaned up because its worktree path no longer exists.

type Issue

type Issue struct {
	ID           string       `json:"id"`
	Title        string       `json:"title"`
	Status       string       `json:"status"`
	Dependencies []Dependency `json:"dependencies,omitempty"`
	Labels       []string     `json:"labels,omitempty"`
}

Issue represents a bead issue from issues.jsonl.

type LockSummary

type LockSummary struct {
	Path                string  `json:"path"`
	TTLRemainingSeconds int     `json:"ttl_remaining_seconds"`
	BeadID              *string `json:"bead_id,omitempty"`
	Reason              *string `json:"reason,omitempty"`
}

LockSummary represents a file reservation held by a workspace.

type MatchType

type MatchType int

MatchType describes how an alias was matched.

const (
	MatchExact MatchType = iota
	MatchPrefix
	MatchSubstring
)

func (MatchType) String

func (m MatchType) String() string

type NotificationContext

type NotificationContext struct {
	PendingConversations []PendingConversation
	MessagesWaiting      int
	GoneWorkspaces       []GoneWorkspace
	CurrentAlias         string
	Warning              string
}

NotificationContext contains all notification data fetched from BeadHub.

func FetchNotifications

func FetchNotifications(cfg *config.Config) *NotificationContext

FetchNotifications retrieves all notification data from BeadHub.

type PassthroughResult

type PassthroughResult struct {
	// From bd execution
	Stdout   string
	Stderr   string
	ExitCode int
	JSONMode bool

	// From coordination
	Warning         string // Warning message (e.g., server unreachable)
	Rejected        bool   // True if server rejected the command
	RejectionReason string // Why the command was rejected
	BeadsInProgress []client.BeadInProgress

	// From sync
	SyncWarning             string // Warning message from sync attempt
	SyncStats               *client.SyncStats
	SyncMode                string // "full" or "incremental"
	SyncConflicts           []string
	SyncClaimRejected       bool
	SyncClaimRejectedReason string

	// From auto-reserve
	AutoReserveWarning   string
	AutoReserved         []string
	AutoRenewed          []string
	AutoReleased         []string
	AutoReserveConflicts []ReservationConflict

	// Ready command context (shown after bd ready output)
	IsReadyCommand   bool
	MyAlias          string         // Current agent's alias for filtering
	MyClaims         []client.Claim // My own active bead claims
	MyFocusApexID    string
	MyFocusApexTitle string
	MyFocusApexType  string
	TeamStatus       []client.Workspace // Other workspaces with their current beads
	TeamStatusLimit  int
	TeamStatusMore   bool
	ReadyLocks       []aweb.ReservationView

	// Close command context: related work in progress
	RelatedWork []RelatedWorkItem
}

PassthroughResult contains the result of running a bd command through bdh.

type PendingConversation

type PendingConversation struct {
	SessionID     string   `json:"session_id"`
	Participants  []string `json:"participants"`
	LastMessage   string   `json:"last_message"`
	LastFrom      string   `json:"last_from"`
	UnreadCount   int      `json:"unread_count"`
	LastActivity  string   `json:"last_activity"`
	SenderWaiting bool     `json:"sender_waiting"`
}

PendingConversation is a minimal view of a chat session with unread messages.

type PolicyCacheInfo

type PolicyCacheInfo struct {
	Used     bool   `json:"used"`
	Mode     string `json:"mode,omitempty"` // fresh, validated, offline
	Stale    bool   `json:"stale,omitempty"`
	CachedAt string `json:"cached_at,omitempty"`
}

type PolicyResult

type PolicyResult struct {
	Role         string                       `json:"role"`
	OnlySelected bool                         `json:"only_selected"`
	Policy       *client.ActivePolicyResponse `json:"policy"`
	Cache        *PolicyCacheInfo             `json:"cache,omitempty"`
}

type PrimeOverrideResult

type PrimeOverrideResult struct {
	Injected bool   // True if PRIME.md was created/updated
	Skipped  bool   // True if already has bdh content
	Error    string // Error message if failed
}

PrimeOverrideResult contains the result of injecting the PRIME.md override.

func InjectPrimeOverride

func InjectPrimeOverride(repoRoot string) *PrimeOverrideResult

InjectPrimeOverride creates .beads/PRIME.md with bdh-aware content. It runs `bd prime --export` to get the default content, then replaces bd references with bdh and adds bdh-specific sections.

type RelatedWorkItem

type RelatedWorkItem struct {
	BeadID      string // e.g., "bd-43"
	Title       string // Bead title
	Alias       string // Agent alias working on it
	HumanName   string // Human name of the agent
	WorkspaceID string // Workspace ID for sending messages
	Relation    string // How it's related (e.g., "blocked by bd-42", "same parent epic")
}

RelatedWorkItem represents a bead being worked on that is related to the one just closed.

type ReservationConflict

type ReservationConflict struct {
	ResourceKey       string `json:"resource_key"`
	HeldBy            string `json:"held_by"`
	RetryAfterSeconds int    `json:"retry_after_seconds"`
	ExpiresAt         string `json:"expires_at,omitempty"`
}

type ReservationsResult

type ReservationsResult struct {
	Reservations []client.LockInfo
	Count        int
	MyAlias      string
	Warning      string
}

ReservationsResult contains the result of listing reservations.

type StatusResult

type StatusResult struct {
	Alias              string
	Role               string
	Hostname           string
	Path               string
	RepoName           string
	Branch             string
	YourClaims         []ClaimInfo
	YourLocks          []LockSummary
	Team               []TeamMemberInfo
	EscalationsPending int
}

StatusResult contains the result of the status command.

type SyncResult

type SyncResult struct {
	Synced      bool
	UpToDate    bool
	Warning     string
	IssuesCount int
	// Sync mode and stats
	SyncMode            string // "full" or "incremental"
	Stats               *client.SyncStats
	Conflicts           []string
	ClaimRejected       bool
	ClaimRejectedReason string
}

SyncResult contains the result of syncing to BeadHub.

type TeamMemberInfo

type TeamMemberInfo struct {
	Alias     string        `json:"alias"`
	Role      string        `json:"role,omitempty"`
	Status    string        `json:"status"`
	LastSeen  string        `json:"last_seen"`
	Hostname  string        `json:"hostname,omitempty"`
	Path      string        `json:"workspace_path,omitempty"`
	RepoName  string        `json:"repo_name,omitempty"`
	Branch    string        `json:"branch,omitempty"`
	ApexID    string        `json:"apex_id,omitempty"`
	ApexTitle string        `json:"apex_title,omitempty"`
	ApexType  string        `json:"apex_type,omitempty"`
	Claims    []ClaimInfo   `json:"claims,omitempty"`
	Locks     []LockSummary `json:"locks,omitempty"`
}

TeamMemberInfo contains information about a team member.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL