webhook

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package webhook provides an event-driven HTTP notification client for cloop. It fires JSON payloads to a configured URL on task/session lifecycle events, with automatic Slack incoming-webhook format detection and optional HMAC-SHA256 request signing (X-Hub-Signature-256 header, compatible with GitHub-style webhooks).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TruncateError

func TruncateError(s string) string

TruncateError caps an error message at maxPayloadErrorBytes so a verbose underlying error (e.g. a multi-KB stream-truncated upstream response) doesn't bloat the webhook payload or break Slack's character limit. Exported so orchestrator call sites can use it inline when assembling Payload literals that already need to set Session/Progress fields.

Types

type Client

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

Client sends webhook notifications.

func New

func New(url string, events []string, headers map[string]string, secret string) *Client

New creates a Client. If events is empty all events are sent. headers are added verbatim to every request. secret, if non-empty, causes every request to include an X-Hub-Signature-256 header computed as HMAC-SHA256(secret, body) — compatible with GitHub webhooks.

func (*Client) Send

func (c *Client) Send(event EventType, payload Payload)

Send fires an asynchronous HTTP POST for the given event. It is non-blocking and never returns an error to the caller — failures are silently discarded so that a broken webhook never interrupts the main loop.

func (*Client) ShouldSend

func (c *Client) ShouldSend(event EventType) bool

ShouldSend returns true when the client is configured and the event is enabled.

func (*Client) Wait added in v0.0.5

func (c *Client) Wait(timeout time.Duration) bool

Wait blocks until every send in flight has finished, or timeout has passed, and reports whether they all finished. Safe on a nil client.

type EventType

type EventType string

EventType classifies a lifecycle notification.

const (
	EventSessionStarted   EventType = "session_started"
	EventSessionComplete  EventType = "session_complete"
	EventSessionFailed    EventType = "session_failed"
	EventTaskStarted      EventType = "task_started"
	EventTaskDone         EventType = "task_done"
	EventTaskFailed       EventType = "task_failed"
	EventTaskSkipped      EventType = "task_skipped"
	EventPlanComplete     EventType = "plan_complete"
	EventEvolveDiscovered EventType = "evolve_discovered"
)

type Payload

type Payload struct {
	Event     EventType    `json:"event"`
	Timestamp time.Time    `json:"timestamp"`
	Goal      string       `json:"goal,omitempty"`
	Task      *TaskInfo    `json:"task,omitempty"`
	Progress  *Progress    `json:"progress,omitempty"`
	Session   *SessionInfo `json:"session,omitempty"`
	// Error is a short human-readable failure reason, populated for
	// EventSessionFailed and EventTaskFailed so downstream consumers (Slack
	// alerts, dashboards) can triage without grepping logs. Truncated by the
	// orchestrator to keep payloads small.
	Error string `json:"error,omitempty"`
}

Payload is the JSON body sent to the webhook URL.

type Progress

type Progress struct {
	Done   int `json:"done"`
	Total  int `json:"total"`
	Failed int `json:"failed,omitempty"`
}

Progress carries plan completion progress inside a Payload.

type SessionInfo

type SessionInfo struct {
	TotalTasks    int    `json:"total_tasks,omitempty"`
	DoneTasks     int    `json:"done_tasks,omitempty"`
	FailedTasks   int    `json:"failed_tasks,omitempty"`
	InputTokens   int    `json:"input_tokens,omitempty"`
	OutputTokens  int    `json:"output_tokens,omitempty"`
	Duration      string `json:"duration,omitempty"`
	EstCostUSD    string `json:"est_cost_usd,omitempty"`
	NewTasksFound int    `json:"new_tasks_found,omitempty"`
	EvolveStep    int    `json:"evolve_step,omitempty"`
}

SessionInfo carries aggregate session stats inside a Payload.

type TaskInfo

type TaskInfo struct {
	ID          int    `json:"id"`
	Title       string `json:"title"`
	Description string `json:"description,omitempty"`
	Status      string `json:"status"`
	Duration    string `json:"duration,omitempty"`
}

TaskInfo carries task metadata inside a Payload.

Jump to

Keyboard shortcuts

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