Add daemon RPC support for gate commands (bd-likt)
- Add gate operation constants (OpGateCreate, OpGateList, OpGateShow, OpGateClose, OpGateWait) to protocol.go - Add Gate*Args and Gate*Result types to protocol.go - Add gate handler methods (handleGateCreate, handleGateList, handleGateShow, handleGateClose, handleGateWait) to server_issues_epics.go - Register gate handlers in handleRequest switch - Add gate client methods (GateCreate, GateList, GateShow, GateClose, GateWait) to client.go - Update cmd/bd/gate.go to use daemon client when available, falling back to direct store access Gate commands now work with the daemon, eliminating the need for --no-daemon flag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -395,6 +395,33 @@ func (c *Client) EpicStatus(args *EpicStatusArgs) (*Response, error) {
|
||||
return c.Execute(OpEpicStatus, args)
|
||||
}
|
||||
|
||||
// Gate operations (bd-likt)
|
||||
|
||||
// GateCreate creates a gate via the daemon
|
||||
func (c *Client) GateCreate(args *GateCreateArgs) (*Response, error) {
|
||||
return c.Execute(OpGateCreate, args)
|
||||
}
|
||||
|
||||
// GateList lists gates via the daemon
|
||||
func (c *Client) GateList(args *GateListArgs) (*Response, error) {
|
||||
return c.Execute(OpGateList, args)
|
||||
}
|
||||
|
||||
// GateShow shows a gate via the daemon
|
||||
func (c *Client) GateShow(args *GateShowArgs) (*Response, error) {
|
||||
return c.Execute(OpGateShow, args)
|
||||
}
|
||||
|
||||
// GateClose closes a gate via the daemon
|
||||
func (c *Client) GateClose(args *GateCloseArgs) (*Response, error) {
|
||||
return c.Execute(OpGateClose, args)
|
||||
}
|
||||
|
||||
// GateWait adds waiters to a gate via the daemon
|
||||
func (c *Client) GateWait(args *GateWaitArgs) (*Response, error) {
|
||||
return c.Execute(OpGateWait, args)
|
||||
}
|
||||
|
||||
// cleanupStaleDaemonArtifacts removes stale daemon.pid file when socket is missing and lock is free.
|
||||
// This prevents stale artifacts from accumulating after daemon crashes.
|
||||
// Only removes pid file - lock file is managed by OS (released on process exit).
|
||||
|
||||
@@ -2,6 +2,7 @@ package rpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Operation constants for all bd commands
|
||||
@@ -37,6 +38,13 @@ const (
|
||||
OpGetMutations = "get_mutations"
|
||||
OpShutdown = "shutdown"
|
||||
OpDelete = "delete"
|
||||
|
||||
// Gate operations (bd-likt)
|
||||
OpGateCreate = "gate_create"
|
||||
OpGateList = "gate_list"
|
||||
OpGateShow = "gate_show"
|
||||
OpGateClose = "gate_close"
|
||||
OpGateWait = "gate_wait"
|
||||
)
|
||||
|
||||
// Request represents an RPC request from client to daemon
|
||||
@@ -413,3 +421,46 @@ type ImportArgs struct {
|
||||
type GetMutationsArgs struct {
|
||||
Since int64 `json:"since"` // Unix timestamp in milliseconds (0 for all recent)
|
||||
}
|
||||
|
||||
// Gate operations (bd-likt)
|
||||
|
||||
// GateCreateArgs represents arguments for creating a gate
|
||||
type GateCreateArgs struct {
|
||||
Title string `json:"title"`
|
||||
AwaitType string `json:"await_type"` // gh:run, gh:pr, timer, human, mail
|
||||
AwaitID string `json:"await_id"` // ID/value for the await type
|
||||
Timeout time.Duration `json:"timeout"` // Timeout duration
|
||||
Waiters []string `json:"waiters"` // Mail addresses to notify when gate clears
|
||||
}
|
||||
|
||||
// GateCreateResult represents the result of creating a gate
|
||||
type GateCreateResult struct {
|
||||
ID string `json:"id"` // Created gate ID
|
||||
}
|
||||
|
||||
// GateListArgs represents arguments for listing gates
|
||||
type GateListArgs struct {
|
||||
All bool `json:"all"` // Include closed gates
|
||||
}
|
||||
|
||||
// GateShowArgs represents arguments for showing a gate
|
||||
type GateShowArgs struct {
|
||||
ID string `json:"id"` // Gate ID (partial or full)
|
||||
}
|
||||
|
||||
// GateCloseArgs represents arguments for closing a gate
|
||||
type GateCloseArgs struct {
|
||||
ID string `json:"id"` // Gate ID (partial or full)
|
||||
Reason string `json:"reason,omitempty"` // Close reason
|
||||
}
|
||||
|
||||
// GateWaitArgs represents arguments for adding waiters to a gate
|
||||
type GateWaitArgs struct {
|
||||
ID string `json:"id"` // Gate ID (partial or full)
|
||||
Waiters []string `json:"waiters"` // Additional waiters to add
|
||||
}
|
||||
|
||||
// GateWaitResult represents the result of adding waiters
|
||||
type GateWaitResult struct {
|
||||
AddedCount int `json:"added_count"` // Number of new waiters added
|
||||
}
|
||||
|
||||
@@ -1373,3 +1373,341 @@ func (s *Server) handleEpicStatus(req *Request) Response {
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
// Gate handlers (bd-likt)
|
||||
|
||||
func (s *Server) handleGateCreate(req *Request) Response {
|
||||
var args GateCreateArgs
|
||||
if err := json.Unmarshal(req.Args, &args); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("invalid gate create args: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
store := s.storage
|
||||
if store == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "storage not available",
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
now := time.Now()
|
||||
|
||||
// Create gate issue
|
||||
gate := &types.Issue{
|
||||
Title: args.Title,
|
||||
IssueType: types.TypeGate,
|
||||
Status: types.StatusOpen,
|
||||
Priority: 1, // Gates are typically high priority
|
||||
Assignee: "deacon/",
|
||||
Wisp: true, // Gates are wisps (ephemeral)
|
||||
AwaitType: args.AwaitType,
|
||||
AwaitID: args.AwaitID,
|
||||
Timeout: args.Timeout,
|
||||
Waiters: args.Waiters,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
gate.ContentHash = gate.ComputeContentHash()
|
||||
|
||||
if err := store.CreateIssue(ctx, gate, s.reqActor(req)); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to create gate: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
// Emit mutation event
|
||||
s.emitMutation(MutationCreate, gate.ID)
|
||||
|
||||
data, _ := json.Marshal(GateCreateResult{ID: gate.ID})
|
||||
return Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleGateList(req *Request) Response {
|
||||
var args GateListArgs
|
||||
if err := json.Unmarshal(req.Args, &args); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("invalid gate list args: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
store := s.storage
|
||||
if store == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "storage not available",
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
|
||||
// Build filter for gates
|
||||
gateType := types.TypeGate
|
||||
filter := types.IssueFilter{
|
||||
IssueType: &gateType,
|
||||
}
|
||||
if !args.All {
|
||||
openStatus := types.StatusOpen
|
||||
filter.Status = &openStatus
|
||||
}
|
||||
|
||||
gates, err := store.SearchIssues(ctx, "", filter)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to list gates: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(gates)
|
||||
return Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleGateShow(req *Request) Response {
|
||||
var args GateShowArgs
|
||||
if err := json.Unmarshal(req.Args, &args); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("invalid gate show args: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
store := s.storage
|
||||
if store == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "storage not available",
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
|
||||
// Resolve partial ID
|
||||
gateID, err := utils.ResolvePartialID(ctx, store, args.ID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to resolve gate ID: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
gate, err := store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to get gate: %v", err),
|
||||
}
|
||||
}
|
||||
if gate == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("gate %s not found", gateID),
|
||||
}
|
||||
}
|
||||
if gate.IssueType != types.TypeGate {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("%s is not a gate (type: %s)", gateID, gate.IssueType),
|
||||
}
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(gate)
|
||||
return Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleGateClose(req *Request) Response {
|
||||
var args GateCloseArgs
|
||||
if err := json.Unmarshal(req.Args, &args); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("invalid gate close args: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
store := s.storage
|
||||
if store == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "storage not available",
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
|
||||
// Resolve partial ID
|
||||
gateID, err := utils.ResolvePartialID(ctx, store, args.ID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to resolve gate ID: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
// Verify it's a gate
|
||||
gate, err := store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to get gate: %v", err),
|
||||
}
|
||||
}
|
||||
if gate == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("gate %s not found", gateID),
|
||||
}
|
||||
}
|
||||
if gate.IssueType != types.TypeGate {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("%s is not a gate (type: %s)", gateID, gate.IssueType),
|
||||
}
|
||||
}
|
||||
|
||||
reason := args.Reason
|
||||
if reason == "" {
|
||||
reason = "Gate closed"
|
||||
}
|
||||
|
||||
oldStatus := string(gate.Status)
|
||||
|
||||
if err := store.CloseIssue(ctx, gateID, reason, s.reqActor(req)); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to close gate: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
// Emit rich status change event
|
||||
s.emitRichMutation(MutationEvent{
|
||||
Type: MutationStatus,
|
||||
IssueID: gateID,
|
||||
OldStatus: oldStatus,
|
||||
NewStatus: "closed",
|
||||
})
|
||||
|
||||
closedGate, _ := store.GetIssue(ctx, gateID)
|
||||
data, _ := json.Marshal(closedGate)
|
||||
return Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) handleGateWait(req *Request) Response {
|
||||
var args GateWaitArgs
|
||||
if err := json.Unmarshal(req.Args, &args); err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("invalid gate wait args: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
store := s.storage
|
||||
if store == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "storage not available",
|
||||
}
|
||||
}
|
||||
|
||||
ctx := s.reqCtx(req)
|
||||
|
||||
// Resolve partial ID
|
||||
gateID, err := utils.ResolvePartialID(ctx, store, args.ID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to resolve gate ID: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
// Get existing gate
|
||||
gate, err := store.GetIssue(ctx, gateID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to get gate: %v", err),
|
||||
}
|
||||
}
|
||||
if gate == nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("gate %s not found", gateID),
|
||||
}
|
||||
}
|
||||
if gate.IssueType != types.TypeGate {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("%s is not a gate (type: %s)", gateID, gate.IssueType),
|
||||
}
|
||||
}
|
||||
if gate.Status == types.StatusClosed {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("gate %s is already closed", gateID),
|
||||
}
|
||||
}
|
||||
|
||||
// Add new waiters (avoiding duplicates)
|
||||
waiterSet := make(map[string]bool)
|
||||
for _, w := range gate.Waiters {
|
||||
waiterSet[w] = true
|
||||
}
|
||||
newWaiters := []string{}
|
||||
for _, addr := range args.Waiters {
|
||||
if !waiterSet[addr] {
|
||||
newWaiters = append(newWaiters, addr)
|
||||
waiterSet[addr] = true
|
||||
}
|
||||
}
|
||||
|
||||
addedCount := len(newWaiters)
|
||||
|
||||
if addedCount > 0 {
|
||||
// Update waiters using SQLite directly
|
||||
sqliteStore, ok := store.(*sqlite.SQLiteStorage)
|
||||
if !ok {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: "gate wait requires SQLite storage",
|
||||
}
|
||||
}
|
||||
|
||||
allWaiters := append(gate.Waiters, newWaiters...)
|
||||
waitersJSON, _ := json.Marshal(allWaiters)
|
||||
|
||||
// Use raw SQL to update the waiters field
|
||||
_, err = sqliteStore.UnderlyingDB().ExecContext(ctx, `UPDATE issues SET waiters = ?, updated_at = ? WHERE id = ?`,
|
||||
string(waitersJSON), time.Now(), gateID)
|
||||
if err != nil {
|
||||
return Response{
|
||||
Success: false,
|
||||
Error: fmt.Sprintf("failed to add waiters: %v", err),
|
||||
}
|
||||
}
|
||||
|
||||
// Emit mutation event
|
||||
s.emitMutation(MutationUpdate, gateID)
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(GateWaitResult{AddedCount: addedCount})
|
||||
return Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,17 @@ func (s *Server) handleRequest(req *Request) Response {
|
||||
resp = s.handleGetMutations(req)
|
||||
case OpShutdown:
|
||||
resp = s.handleShutdown(req)
|
||||
// Gate operations (bd-likt)
|
||||
case OpGateCreate:
|
||||
resp = s.handleGateCreate(req)
|
||||
case OpGateList:
|
||||
resp = s.handleGateList(req)
|
||||
case OpGateShow:
|
||||
resp = s.handleGateShow(req)
|
||||
case OpGateClose:
|
||||
resp = s.handleGateClose(req)
|
||||
case OpGateWait:
|
||||
resp = s.handleGateWait(req)
|
||||
default:
|
||||
s.metrics.RecordError(req.Operation)
|
||||
return Response{
|
||||
|
||||
Reference in New Issue
Block a user