daemon

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Overview

Package daemon implements the long-running ttal manager-plane process.

The daemon starts all agent sessions (tmux for Claude Code), bridges messages between Telegram and agent runtimes via a Unix socket, watches JSONL output files to forward agent responses to Telegram, and manages the worker lifecycle through fsnotify-based cleanup and PR watchers. It is managed by launchd and handles all inter-agent and human-agent messaging for every configured team from a single process.

Plane: manager

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Breathe added in v1.4.0

func Breathe(req BreatheRequest) error

Breathe sends a breathe request to the daemon, asking it to restart an agent's CC session with a fresh context window and the provided handoff prompt.

func Install

func Install() error

Install installs the launchd plist and creates a config template if needed.

func IsRunning

func IsRunning() (bool, int, error)

IsRunning checks whether the daemon is running by inspecting the pid file. Uses fixed path at ~/.ttal/daemon.pid.

func Restart

func Restart() error

Restart performs an atomic daemon restart using launchctl kickstart -k. This kills the running process and lets launchd relaunch it immediately, avoiding the race condition in a Stop+Start (bootout+bootstrap) sequence.

func Run

func Run() error

Run starts the daemon in the foreground. This is what launchd calls. Config-driven: loads all teams from config.toml, no database required.

func Send

func Send(req SendRequest) error

Send connects to the daemon socket and sends a message via HTTP. Returns an error if the daemon is not running or if delivery fails. Auto-populates Team from TTAL_TEAM env if not set.

func SocketPath

func SocketPath() (string, error)

SocketPath returns the path to the daemon unix socket. TTAL_SOCKET_PATH overrides the default. Delegates to config.SocketPath() to keep a single source of truth.

func Start

func Start() error

Start boots the daemon launchd service.

func Stop

func Stop() error

Stop stops the daemon launchd service.

func Uninstall

func Uninstall() error

Uninstall removes the launchd plist and cleans up daemon files.

Types

type AskHumanRequest added in v1.3.0

type AskHumanRequest struct {
	Question  string   `json:"question"`
	Options   []string `json:"options,omitempty"`
	AgentName string   `json:"agent_name,omitempty"` // from TTAL_AGENT_NAME
	Session   string   `json:"session,omitempty"`    // from tmux session name
}

AskHumanRequest is the CLI → daemon POST body for POST /ask/human.

type AskHumanResponse added in v1.3.0

type AskHumanResponse struct {
	OK      bool   `json:"ok"`
	Answer  string `json:"answer,omitempty"`
	Skipped bool   `json:"skipped,omitempty"`
	Error   string `json:"error,omitempty"`
}

AskHumanResponse is the daemon → CLI JSON response for /ask/human.

func AskHuman added in v1.3.0

func AskHuman(req AskHumanRequest) (AskHumanResponse, error)

AskHuman sends a question to a human via Telegram and blocks until answered. Returns the response with the human's answer, or Skipped=true on timeout/skip.

type BotCommand

type BotCommand struct {
	Command      string `json:"command"`
	Description  string `json:"description"`
	OriginalName string `json:"-"` // original name before sanitization (for dispatch to agent)
}

BotCommand represents a bot command for the menu.

func AllCommands

func AllCommands(discovered []BotCommand) []BotCommand

AllCommands returns the full command list: static commands + discovered dynamic commands.

func DiscoverCommands

func DiscoverCommands(commandsPaths []string) []BotCommand

DiscoverCommands reads canonical command .md files from configured paths and returns BotCommand entries for registration.

type BreatheRequest added in v1.4.0

type BreatheRequest struct {
	Team    string `json:"team,omitempty"` // defaults to "default"
	Agent   string `json:"agent"`          // agent name
	Handoff string `json:"handoff"`        // handoff prompt content
}

BreatheRequest asks the daemon to restart an agent with a fresh context window.

type PRCIFailureDetail added in v1.6.0

type PRCIFailureDetail struct {
	JobName      string `json:"job_name"`
	WorkflowName string `json:"workflow_name"`
	HTMLURL      string `json:"html_url"`
	LogTail      string `json:"log_tail"`
}

PRCIFailureDetail is a single CI failure entry.

type PRCIFailureDetailsResponse added in v1.6.0

type PRCIFailureDetailsResponse struct {
	OK      bool                `json:"ok"`
	Error   string              `json:"error,omitempty"`
	Details []PRCIFailureDetail `json:"details,omitempty"`
}

PRCIFailureDetailsResponse is the daemon's response for GetCIFailureDetails.

func PRGetCIFailureDetails added in v1.6.0

PRGetCIFailureDetails asks the daemon to fetch CI failure details.

type PRCIStatus added in v1.6.0

type PRCIStatus struct {
	Context     string `json:"context"`
	State       string `json:"state"`
	Description string `json:"description"`
	TargetURL   string `json:"target_url"`
}

PRCIStatus is a single CI check status.

type PRCIStatusResponse added in v1.6.0

type PRCIStatusResponse struct {
	OK       bool         `json:"ok"`
	Error    string       `json:"error,omitempty"`
	State    string       `json:"state,omitempty"`
	Statuses []PRCIStatus `json:"statuses,omitempty"`
}

PRCIStatusResponse is the daemon's response for GetCombinedStatus.

func PRGetCombinedStatus added in v1.6.0

func PRGetCombinedStatus(req PRGetCombinedStatusRequest) (PRCIStatusResponse, error)

PRGetCombinedStatus asks the daemon to fetch CI status for a commit.

type PRCheckMergeableRequest added in v1.6.0

type PRCheckMergeableRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
}

PRCheckMergeableRequest asks the daemon to check if a PR is mergeable.

type PRCommentCreateRequest added in v1.6.0

type PRCommentCreateRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
	Body         string `json:"body"`
}

PRCommentCreateRequest asks the daemon to post a comment on a PR.

type PRCommentItem added in v1.6.0

type PRCommentItem struct {
	User      string `json:"user"`
	Body      string `json:"body"`
	CreatedAt string `json:"created_at"`
	HTMLURL   string `json:"html_url"`
}

PRCommentItem is a single comment in a PRResponse.

type PRCommentListRequest added in v1.6.0

type PRCommentListRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
}

PRCommentListRequest asks the daemon to list comments on a PR.

type PRCreateRequest added in v1.6.0

type PRCreateRequest struct {
	ProviderType string `json:"provider_type"` // "forgejo" or "github"
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Head         string `json:"head"` // source branch
	Base         string `json:"base"` // target branch
	Title        string `json:"title"`
	Body         string `json:"body"`
}

PRCreateRequest asks the daemon to create a PR via the authenticated provider.

type PRGetCIFailureDetailsRequest added in v1.6.0

type PRGetCIFailureDetailsRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	SHA          string `json:"sha"`
}

PRGetCIFailureDetailsRequest asks the daemon to fetch CI failure details.

type PRGetCombinedStatusRequest added in v1.6.0

type PRGetCombinedStatusRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	SHA          string `json:"sha"`
}

PRGetCombinedStatusRequest asks the daemon to fetch CI status for a commit.

type PRGetPRRequest added in v1.6.0

type PRGetPRRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
}

PRGetPRRequest asks the daemon to fetch a PR (for HeadSHA resolution in CI commands).

type PRGetPRResponse added in v1.6.0

type PRGetPRResponse struct {
	OK        bool   `json:"ok"`
	Error     string `json:"error,omitempty"`
	HeadSHA   string `json:"head_sha,omitempty"`
	Merged    bool   `json:"merged,omitempty"`
	Mergeable bool   `json:"mergeable,omitempty"`
}

PRGetPRResponse is the daemon's response for GetPR.

func PRGetPR added in v1.6.0

func PRGetPR(req PRGetPRRequest) (PRGetPRResponse, error)

PRGetPR asks the daemon to fetch a PR.

type PRMergeRequest added in v1.6.0

type PRMergeRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
	DeleteBranch bool   `json:"delete_branch"`
}

PRMergeRequest asks the daemon to squash-merge a PR.

type PRModifyRequest added in v1.6.0

type PRModifyRequest struct {
	ProviderType string `json:"provider_type"`
	Owner        string `json:"owner"`
	Repo         string `json:"repo"`
	Index        int64  `json:"index"`
	Title        string `json:"title,omitempty"`
	Body         string `json:"body,omitempty"`
}

PRModifyRequest asks the daemon to edit a PR title/body.

type PRResponse added in v1.6.0

type PRResponse struct {
	OK       bool            `json:"ok"`
	Error    string          `json:"error,omitempty"`
	PRURL    string          `json:"pr_url,omitempty"`
	PRIndex  int64           `json:"pr_index,omitempty"`
	HeadSHA  string          `json:"head_sha,omitempty"`
	Comments []PRCommentItem `json:"comments,omitempty"`
}

PRResponse is the daemon's response for PR operations.

func PRCheckMergeable added in v1.6.0

func PRCheckMergeable(req PRCheckMergeableRequest) (PRResponse, error)

PRCheckMergeable asks the daemon to check if a PR is mergeable.

func PRCommentCreate added in v1.6.0

func PRCommentCreate(req PRCommentCreateRequest) (PRResponse, error)

PRCommentCreate asks the daemon to post a comment on a PR.

func PRCommentList added in v1.6.0

func PRCommentList(req PRCommentListRequest) (PRResponse, error)

PRCommentList asks the daemon to list comments on a PR.

func PRCreate added in v1.6.0

func PRCreate(req PRCreateRequest) (PRResponse, error)

PRCreate asks the daemon to create a PR via the authenticated provider.

func PRMerge added in v1.6.0

func PRMerge(req PRMergeRequest) (PRResponse, error)

PRMerge asks the daemon to squash-merge a PR.

func PRModify added in v1.6.0

func PRModify(req PRModifyRequest) (PRResponse, error)

PRModify asks the daemon to edit a PR title/body.

type SendRequest

type SendRequest struct {
	From    string `json:"from,omitempty"`
	To      string `json:"to,omitempty"`
	Team    string `json:"team,omitempty"`
	Message string `json:"message"`
}

SendRequest is the JSON message sent to the daemon. Direction is determined by which fields are set:

From only:       agent → human via Telegram
To only:         system/hook → agent via tmux
From + To:       agent → agent via tmux with attribution

Team disambiguates when agent names collide across teams. Auto-populated from TTAL_TEAM env if unset.

type SendResponse

type SendResponse struct {
	OK    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

SendResponse is the JSON reply from the daemon.

type StatusResponse

type StatusResponse struct {
	OK     bool                 `json:"ok"`
	Agents []status.AgentStatus `json:"agents,omitempty"`
	Error  string               `json:"error,omitempty"`
}

StatusResponse returns agent status data.

func QueryStatus

func QueryStatus(team, agent string) (*StatusResponse, error)

QueryStatus connects to the daemon and queries agent status via HTTP.

type StatusUpdateRequest

type StatusUpdateRequest struct {
	Type                string  `json:"type"`                  // "statusUpdate"
	Team                string  `json:"team,omitempty"`        // team name (defaults to "default")
	Agent               string  `json:"agent"`                 // agent name
	ContextUsedPct      float64 `json:"context_used_pct"`      // percentage of context used
	ContextRemainingPct float64 `json:"context_remaining_pct"` // percentage remaining
	ModelID             string  `json:"model_id"`              // model identifier
	SessionID           string  `json:"session_id"`            // session identifier
}

StatusUpdateRequest writes agent context status to the daemon. Wire format: {"type":"statusUpdate","agent":"kestrel","context_used_pct":45.2,...}

type TaskCompleteRequest added in v1.0.0

type TaskCompleteRequest struct {
	Type     string `json:"type"` // "taskComplete"
	TaskUUID string `json:"task_uuid"`
	Team     string `json:"team,omitempty"`     // defaults to "default"
	Spawner  string `json:"spawner,omitempty"`  // "team:agent", optional
	Desc     string `json:"desc,omitempty"`     // task description for the notification message
	PRID     string `json:"pr_id,omitempty"`    // PR number for the notification message
	PRTitle  string `json:"pr_title,omitempty"` // PR title (preferred over Desc for notifications)
}

TaskCompleteRequest notifies the daemon that a task has been marked done. Wire format: {"type":"taskComplete","task_uuid":"...","team":"default",...}

type UsageData added in v1.0.0

type UsageData struct {
	SessionUsage   *float64  `json:"sessionUsage,omitempty"`
	SessionResetAt string    `json:"sessionResetAt,omitempty"`
	WeeklyUsage    *float64  `json:"weeklyUsage,omitempty"`
	WeeklyResetAt  string    `json:"weeklyResetAt,omitempty"`
	FetchedAt      time.Time `json:"fetchedAt"`
	Error          string    `json:"error,omitempty"`
}

UsageData holds the parsed Claude.ai usage response.

Jump to

Keyboard shortcuts

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