Files
beads/internal/rpc/protocol.go
Steve Yegge b40de9bc41 Implement daemon RPC with per-request context routing (bd-115)
- Added per-request storage routing in daemon server
  - Server now supports Cwd field in requests for database discovery
  - Tree-walking to find .beads/*.db from any working directory
  - Storage caching for performance across requests

- Created Python daemon client (bd_daemon_client.py)
  - RPC over Unix socket communication
  - Implements full BdClientBase interface
  - Auto-discovery of daemon socket from working directory

- Refactored bd_client.py with abstract interface
  - BdClientBase abstract class for common interface
  - BdCliClient for CLI-based operations (renamed from BdClient)
  - create_bd_client() factory with daemon/CLI fallback
  - Backwards-compatible BdClient alias

Next: Update MCP server to use daemon client when available
2025-10-17 16:28:29 -07:00

154 lines
4.6 KiB
Go

package rpc
import "encoding/json"
// Operation constants for all bd commands
const (
OpPing = "ping"
OpCreate = "create"
OpUpdate = "update"
OpClose = "close"
OpList = "list"
OpShow = "show"
OpReady = "ready"
OpStats = "stats"
OpDepAdd = "dep_add"
OpDepRemove = "dep_remove"
OpDepTree = "dep_tree"
OpLabelAdd = "label_add"
OpLabelRemove = "label_remove"
OpBatch = "batch"
)
// Request represents an RPC request from client to daemon
type Request struct {
Operation string `json:"operation"`
Args json.RawMessage `json:"args"`
Actor string `json:"actor,omitempty"`
RequestID string `json:"request_id,omitempty"`
Cwd string `json:"cwd,omitempty"` // Working directory for database discovery
}
// Response represents an RPC response from daemon to client
type Response struct {
Success bool `json:"success"`
Data json.RawMessage `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
// CreateArgs represents arguments for the create operation
type CreateArgs struct {
ID string `json:"id,omitempty"`
Title string `json:"title"`
Description string `json:"description,omitempty"`
IssueType string `json:"issue_type"`
Priority int `json:"priority"`
Design string `json:"design,omitempty"`
AcceptanceCriteria string `json:"acceptance_criteria,omitempty"`
Assignee string `json:"assignee,omitempty"`
Labels []string `json:"labels,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
}
// UpdateArgs represents arguments for the update operation
type UpdateArgs struct {
ID string `json:"id"`
Title *string `json:"title,omitempty"`
Status *string `json:"status,omitempty"`
Priority *int `json:"priority,omitempty"`
Design *string `json:"design,omitempty"`
AcceptanceCriteria *string `json:"acceptance_criteria,omitempty"`
Notes *string `json:"notes,omitempty"`
Assignee *string `json:"assignee,omitempty"`
}
// CloseArgs represents arguments for the close operation
type CloseArgs struct {
ID string `json:"id"`
Reason string `json:"reason,omitempty"`
}
// ListArgs represents arguments for the list operation
type ListArgs struct {
Query string `json:"query,omitempty"`
Status string `json:"status,omitempty"`
Priority *int `json:"priority,omitempty"`
IssueType string `json:"issue_type,omitempty"`
Assignee string `json:"assignee,omitempty"`
Label string `json:"label,omitempty"`
Limit int `json:"limit,omitempty"`
}
// ShowArgs represents arguments for the show operation
type ShowArgs struct {
ID string `json:"id"`
}
// ReadyArgs represents arguments for the ready operation
type ReadyArgs struct {
Assignee string `json:"assignee,omitempty"`
Priority *int `json:"priority,omitempty"`
Limit int `json:"limit,omitempty"`
}
// DepAddArgs represents arguments for adding a dependency
type DepAddArgs struct {
FromID string `json:"from_id"`
ToID string `json:"to_id"`
DepType string `json:"dep_type"`
}
// DepRemoveArgs represents arguments for removing a dependency
type DepRemoveArgs struct {
FromID string `json:"from_id"`
ToID string `json:"to_id"`
DepType string `json:"dep_type,omitempty"`
}
// DepTreeArgs represents arguments for the dep tree operation
type DepTreeArgs struct {
ID string `json:"id"`
MaxDepth int `json:"max_depth,omitempty"`
}
// LabelAddArgs represents arguments for adding a label
type LabelAddArgs struct {
ID string `json:"id"`
Label string `json:"label"`
}
// LabelRemoveArgs represents arguments for removing a label
type LabelRemoveArgs struct {
ID string `json:"id"`
Label string `json:"label"`
}
// PingResponse is the response for a ping operation
type PingResponse struct {
Message string `json:"message"`
Version string `json:"version"`
}
// BatchArgs represents arguments for batch operations
type BatchArgs struct {
Operations []BatchOperation `json:"operations"`
}
// BatchOperation represents a single operation in a batch
type BatchOperation struct {
Operation string `json:"operation"`
Args json.RawMessage `json:"args"`
}
// BatchResponse contains the results of a batch operation
type BatchResponse struct {
Results []BatchResult `json:"results"`
}
// BatchResult represents the result of a single operation in a batch
type BatchResult struct {
Success bool `json:"success"`
Data json.RawMessage `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}