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 ¶
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 ¶
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 ¶
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 ¶
ShouldSend returns true when the client is configured and the event is enabled.
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.