ipc

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ipc provides inter-process communication between the Forge daemon and CLI/TUI clients via platform-native mechanisms (named pipe on Windows, Unix domain socket on Linux/macOS).

Protocol: newline-delimited JSON messages.

Server side (daemon):

svr := ipc.NewServer()
svr.OnCommand(func(cmd Command) Response { ... })
svr.Start(ctx)

Client side (CLI/TUI):

client := ipc.NewClient()
resp, err := client.Send(Command{Type: "status"})
events := client.Subscribe(ctx) // stream events

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForgeDir

func ForgeDir() string

ForgeDir returns the Forge data directory.

func SocketExists

func SocketExists() bool

SocketExists checks whether the daemon's IPC socket file exists.

Types

type AppendNotesPayload added in v0.4.0

type AppendNotesPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
	Notes  string `json:"notes"`
}

AppendNotesPayload is the payload for an "append_notes" command. Adds human notes to a bead's history via bd update.

type ClarificationPayload

type ClarificationPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`  // Required: which anvil the bead belongs to
	Reason string `json:"reason"` // Why clarification is needed (used when setting)
}

ClarificationPayload is the payload for "set_clarification" / "clear_clarification" commands.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client connects to the daemon's IPC socket.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new IPC client connected to the daemon.

func (*Client) Close

func (c *Client) Close() error

Close closes the client connection.

func (*Client) Send

func (c *Client) Send(cmd Command) (*Response, error)

Send sends a command and waits for a response.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context) <-chan Event

Subscribe returns a channel that receives events from the daemon. The channel is closed when ctx is cancelled or the connection drops.

type CloseBeadPayload

type CloseBeadPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
}

CloseBeadPayload is the payload for a "close_bead" command that closes a bead via bd close.

type Command

type Command struct {
	Type    string          `json:"type"`    // "status", "kill_worker", "refresh", "queue", "run_bead", "set_clarification", "clear_clarification"
	Payload json.RawMessage `json:"payload"` // Type-specific data
}

Command is a message sent from a client to the daemon.

type CommandHandler

type CommandHandler func(cmd Command) Response

CommandHandler is called by the server for each incoming command.

type CrucibleActionPayload added in v0.6.0

type CrucibleActionPayload struct {
	ParentID string `json:"parent_id"` // Parent bead ID of the Crucible
	Anvil    string `json:"anvil"`
	Action   string `json:"action"` // "resume" | "stop"
}

CrucibleActionPayload is the payload for a "crucible_action" command. Triggers a resume or stop action on a paused Crucible.

type CrucibleStatusItem

type CrucibleStatusItem struct {
	ParentID          string `json:"parent_id"`
	ParentTitle       string `json:"parent_title"`
	Anvil             string `json:"anvil"`
	Branch            string `json:"branch"`
	Phase             string `json:"phase"` // "started", "dispatching", "waiting", "final_pr", "complete", "paused"
	TotalChildren     int    `json:"total_children"`
	CompletedChildren int    `json:"completed_children"`
	CurrentChild      string `json:"current_child"`
	StartedAt         string `json:"started_at"`
}

CrucibleStatusItem represents an active Crucible's current state.

type CruciblesResponse

type CruciblesResponse struct {
	Crucibles []CrucibleStatusItem `json:"crucibles"`
}

CruciblesResponse is the response payload for a "crucibles" command.

type DismissBeadPayload

type DismissBeadPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
	PRID   int    `json:"pr_id,omitempty"`
}

DismissBeadPayload is the payload for a "dismiss_bead" command. Removes the bead from the Needs Attention list. When PRID > 0, the dismiss targets an exhausted PR (setting status to closed) rather than the retries table.

type Event

type Event struct {
	Type      string          `json:"type"`
	Timestamp time.Time       `json:"timestamp"`
	Data      json.RawMessage `json:"data"`
}

Event is a push notification from daemon to subscribed clients.

type KillWorkerPayload

type KillWorkerPayload struct {
	WorkerID string `json:"worker_id"`
	PID      int    `json:"pid"`
}

KillWorkerPayload is the payload for a "kill_worker" command.

type MergePRPayload

type MergePRPayload struct {
	PRID     int    `json:"pr_id"`
	PRNumber int    `json:"pr_number"`
	Anvil    string `json:"anvil"`
}

MergePRPayload is the payload for a "merge_pr" command. Triggers a squash merge (or configured strategy) of a ready-to-merge PR.

type PRActionPayload added in v0.5.0

type PRActionPayload struct {
	PRID     int    `json:"pr_id"`
	PRNumber int    `json:"pr_number"`
	Anvil    string `json:"anvil"`
	BeadID   string `json:"bead_id"`
	Branch   string `json:"branch"`
	Action   string `json:"action"` // "open_browser" | "merge" | "quench" | "burnish" | "rebase" | "close"
}

PRActionPayload is the payload for a "pr_action" command. Triggers an action on an open PR.

type ResolveOrphanPayload added in v0.4.0

type ResolveOrphanPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
	Action string `json:"action"` // "recover" | "close" | "discard"
}

ResolveOrphanPayload is the payload for a "resolve_orphan" command. Sent by Hearth to the daemon when the user picks an action for an orphaned bead. Action is one of "recover", "close", or "discard".

type Response

type Response struct {
	Type    string          `json:"type"`    // "ok", "error", "status", "event"
	Payload json.RawMessage `json:"payload"` // Type-specific data
}

Response is a message sent from the daemon to a client.

type RetryBeadPayload

type RetryBeadPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
	PRID   int    `json:"pr_id,omitempty"`
}

RetryBeadPayload is the payload for a "retry_bead" command. Clears needs_human flag and resets retry count so the bead re-enters the queue. When PRID > 0, the retry targets an exhausted PR (resetting fix counters and status back to open) rather than the retries table.

type RunBeadPayload

type RunBeadPayload struct {
	BeadID   string `json:"bead_id"`
	Anvil    string `json:"anvil"`     // Optional: narrows search if multiple anvils have same bead ID
	ForceRun bool   `json:"force_run"` // When true, fetch via bd show (bypass bd ready), skip crucible/parent checks
}

RunBeadPayload is the payload for a "run_bead" command.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server listens for IPC connections from CLI/TUI clients.

func NewServer

func NewServer() *Server

NewServer creates a new IPC server.

func (*Server) Broadcast

func (s *Server) Broadcast(evt Event)

Broadcast sends an event to all connected clients.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the server and all client connections.

func (*Server) HasClients added in v0.4.0

func (s *Server) HasClients() bool

HasClients reports whether any IPC clients are currently connected.

func (*Server) OnCommand

func (s *Server) OnCommand(h CommandHandler)

OnCommand sets the handler for incoming commands.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start begins listening for IPC connections. Blocks until ctx is cancelled.

type StatusPayload

type StatusPayload struct {
	Running        bool                      `json:"running"`
	PID            int                       `json:"pid"`
	Uptime         string                    `json:"uptime"`
	Workers        int                       `json:"workers"`
	QueueSize      int                       `json:"queue_size"`
	OpenPRs        int                       `json:"open_prs"`
	LastPoll       string                    `json:"last_poll"`
	Quotas         map[string]provider.Quota `json:"quotas,omitempty"`
	DailyCost      float64                   `json:"daily_cost"`
	DailyCostLimit float64                   `json:"daily_cost_limit,omitempty"`
	// CostLimitPaused reports that cost-based auto-dispatch via the Poller is
	// currently paused due to hitting the daily cost limit. Manual run_bead
	// dispatch remains allowed while this flag is true.
	CostLimitPaused bool `json:"cost_limit_paused,omitempty"`
	// CopilotPremiumRequests is the weighted count of Copilot premium requests used today.
	CopilotPremiumRequests float64 `json:"copilot_premium_requests,omitempty"`
	// CopilotRequestLimit is the configured daily limit (0 = no limit).
	CopilotRequestLimit int `json:"copilot_request_limit,omitempty"`
	// CopilotLimitReached is true when the copilot daily request limit has been reached.
	CopilotLimitReached bool `json:"copilot_limit_reached,omitempty"`
}

StatusPayload is the response for a "status" command.

type StopBeadPayload added in v0.5.0

type StopBeadPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
	Reason string `json:"reason"` // Optional; defaults to "manually stopped"
}

StopBeadPayload is the payload for a "stop_bead" command. Stops all processing of a bead: kills any running worker, marks the bead as needing clarification (so the poller skips it), and releases it back to open. The bead will not be dispatched again until unclarified.

type TagBeadPayload

type TagBeadPayload struct {
	BeadID string `json:"bead_id"`
	Anvil  string `json:"anvil"`
}

TagBeadPayload is the payload for a "tag_bead" command that adds the anvil's configured auto-dispatch label to a bead via bd update. The daemon derives the tag from its own config; the client only needs to supply the bead identity.

type ViewLogsPayload

type ViewLogsPayload struct {
	BeadID string `json:"bead_id"`
}

ViewLogsPayload is the payload for a "view_logs" command.

type ViewLogsResponse

type ViewLogsResponse struct {
	LogPath   string   `json:"log_path"`
	LastLines []string `json:"last_lines"`
}

ViewLogsResponse is the response payload for a "view_logs" command.

Jump to

Keyboard shortcuts

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