events

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Copyright 2026 The GOT Authors. MIT License.

Package events provides a minimal in-memory event bus for in-process pub/sub communication. It is designed for the v0.4 Knowledge Engine and is intentionally simple — no persistence, no delivery guarantees beyond best-effort synchronous dispatch to subscribers, no wildcard patterns. Copyright 2026 The GOT Authors. MIT License.

Index

Constants

View Source
const (
	// Decision lifecycle
	EventDecisionCreated    = "DecisionCreated"
	EventDecisionUpdated    = "DecisionUpdated"
	EventDecisionSuperseded = "DecisionSuperseded"
	EventDecisionLinked     = "DecisionLinked"

	// Notes
	EventNoteAdded   = "NoteAdded"
	EventNoteDeleted = "NoteDeleted"

	// Decision lifecycle (continued)
	EventDecisionDeleted = "DecisionDeleted"

	// Git adapter
	EventRepositoryOpened = "RepositoryOpened"
	EventBranchCreated    = "BranchCreated"
	EventBranchDeleted    = "BranchDeleted"
	EventBranchCheckedOut = "BranchCheckedOut"
	EventCommitCreated    = "CommitCreated"
	EventRemoteAdded      = "RemoteAdded"
	EventRemoteRemoved    = "RemoteRemoved"
	EventPushCompleted    = "PushCompleted"
	EventPullCompleted    = "PullCompleted"

	// Workspaces
	EventWorkspaceCreated     = "WorkspaceCreated"
	EventWorkspaceUpdated     = "WorkspaceUpdated"
	EventWorkspaceDeleted     = "WorkspaceDeleted"
	EventWorkspaceItemAdded   = "WorkspaceItemAdded"
	EventWorkspaceItemRemoved = "WorkspaceItemRemoved"

	// Onboarding
	EventOnboardingStarted     = "OnboardingStarted"
	EventOnboardingItemCovered = "OnboardingItemCovered"
	EventOnboardingCompleted   = "OnboardingCompleted"

	// GitHub integration
	EventPullRequestCreated  = "PullRequestCreated"
	EventIssueCreated        = "IssueCreated"
	EventPullRequestReviewed = "PullRequestReviewed"
	EventPullRequestMerged   = "PullRequestMerged"
)

Event type constants published by the Knowledge Engine. Plugins and in-process consumers subscribe to these strings.

Variables

View Source
var ErrBusClosed = errors.New("events: bus is closed")

Sentinel errors returned by Bus methods.

Functions

This section is empty.

Types

type BranchCheckedOutPayload

type BranchCheckedOutPayload struct {
	PreviousBranch string `json:"previous_branch,omitempty"`
	NewBranch      string `json:"new_branch"`
	CheckedOutAt   int64  `json:"checked_out_at"`
}

BranchCheckedOutPayload is published when a branch is checked out.

type BranchCreatedPayload

type BranchCreatedPayload struct {
	Name      string `json:"name"`
	Ref       string `json:"ref,omitempty"`
	CreatedAt int64  `json:"created_at"`
}

BranchCreatedPayload is published when a branch is created.

type BranchDeletedPayload

type BranchDeletedPayload struct {
	Name      string `json:"name"`
	DeletedAt int64  `json:"deleted_at"`
}

BranchDeletedPayload is published when a branch is deleted.

type Bus

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

Bus is a minimal in-memory event bus for in-process pub/sub. It is thread-safe and intentionally simple:

  • Dispatch is synchronous — Publish blocks while handlers execute.
  • Handlers are called in registration order.
  • A closed bus refuses new Subscribe and Publish calls.

For the v0.4 Knowledge Engine this is sufficient. A future version may add async dispatch, timeouts, handler worker pools, or delivery guarantees.

func New

func New() *Bus

New creates and returns an initialised, ready-to-use Bus.

func (*Bus) Close

func (b *Bus) Close() error

Close prevents any further Subscribe or Publish calls and clears all registered handlers. It waits for any in-flight Publish calls to complete (via the write lock) and then returns.

Calling Close more than once returns ErrBusClosed.

func (*Bus) Publish

func (b *Bus) Publish(ctx context.Context, eventType string, payload any) error

Publish dispatches an event to all handlers registered for eventType. Handlers are called synchronously in registration order. If any handler returns an error, Publish continues dispatching to remaining handlers and returns all errors aggregated via errors.Join.

Publish sets Event.Timestamp to the current time before dispatch.

Publish returns ErrBusClosed if the bus has been closed.

func (*Bus) Subscribe

func (b *Bus) Subscribe(eventType string, handler Handler) (func(), error)

Subscribe registers handler for the given eventType. It returns an unsubscribe function that removes the handler. Calling unsubscribe more than once is a no-op.

Subscribe returns ErrBusClosed if the bus has been closed.

type CommitCreatedPayload

type CommitCreatedPayload struct {
	SHA       string `json:"sha"`
	Message   string `json:"message"`
	Author    string `json:"author"`
	Branch    string `json:"branch,omitempty"`
	CreatedAt int64  `json:"created_at"`
}

CommitCreatedPayload is published when a commit is created.

type DecisionCreatedPayload

type DecisionCreatedPayload struct {
	ID           string `json:"id"`
	Title        string `json:"title"`
	Status       string `json:"status"`
	WorkspaceID  string `json:"workspace_id,omitempty"`
	SupersedesID string `json:"supersedes_id,omitempty"`
	CreatedAt    int64  `json:"created_at"`
}

DecisionCreatedPayload is published after a decision is created.

type DecisionDeletedPayload

type DecisionDeletedPayload struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	Status      string `json:"status"`
	WorkspaceID string `json:"workspace_id,omitempty"`
	DeletedAt   int64  `json:"deleted_at"`
}

DecisionDeletedPayload is published after a decision is hard-deleted.

type DecisionLinkedPayload

type DecisionLinkedPayload struct {
	DecisionID string `json:"decision_id"`
	LinkType   string `json:"link_type"` // "commit", "file", "workspace"
	Target     string `json:"target"`
	CreatedAt  int64  `json:"created_at"`
}

DecisionLinkedPayload is published when a link (commit, file, workspace) is attached to a decision.

type DecisionSupersededPayload

type DecisionSupersededPayload struct {
	ID           string `json:"id"`
	NewID        string `json:"new_id"`
	OldStatus    string `json:"old_status"`
	SupersededAt int64  `json:"superseded_at"`
}

DecisionSupersededPayload is published when one decision supersedes another.

type DecisionUpdatedPayload

type DecisionUpdatedPayload struct {
	ID             string `json:"id"`
	Title          string `json:"title"`
	Status         string `json:"status"`
	PreviousStatus string `json:"previous_status"`
	WorkspaceID    string `json:"workspace_id,omitempty"`
	UpdatedAt      int64  `json:"updated_at"`
}

DecisionUpdatedPayload is published after a decision's status or fields change.

type Event

type Event struct {
	// Type identifies the kind of event (e.g. "DecisionCreated").
	Type string

	// Payload holds the typed event data. See the payload structs in this
	// package for the concrete types published by the Knowledge Engine.
	Payload any

	// Timestamp is the time at which the event was published. It is set
	// automatically by Bus.Publish.
	Timestamp time.Time
}

Event is the canonical event envelope published through the Bus.

type Handler

type Handler func(ctx context.Context, e Event) error

Handler receives events published to the bus. Returning an error signals that the handler failed to process the event. The Publish caller receives all handler errors aggregated.

type IssueCreatedPayload

type IssueCreatedPayload struct {
	Number    int      `json:"number"`
	Title     string   `json:"title"`
	Labels    []string `json:"labels,omitempty"`
	URL       string   `json:"url,omitempty"`
	CreatedAt int64    `json:"created_at"`
}

IssueCreatedPayload is published when an issue is created via GOT.

type NoteAddedPayload

type NoteAddedPayload struct {
	ID          string `json:"id"`
	WorkspaceID string `json:"workspace_id,omitempty"`
	Branch      string `json:"branch,omitempty"`
	CommitHash  string `json:"commit_hash,omitempty"`
	CreatedAt   int64  `json:"created_at"`
}

NoteAddedPayload is published after a note is created.

type NoteDeletedPayload

type NoteDeletedPayload struct {
	ID          string `json:"id"`
	Message     string `json:"message"`
	WorkspaceID string `json:"workspace_id,omitempty"`
	Branch      string `json:"branch,omitempty"`
	DeletedAt   int64  `json:"deleted_at"`
}

NoteDeletedPayload is published after a note is hard-deleted.

type OnboardingCompletedPayload

type OnboardingCompletedPayload struct {
	SessionID   string `json:"session_id"`
	Participant string `json:"participant"`
	TotalItems  int    `json:"total_items"`
	CompletedAt int64  `json:"completed_at"`
}

OnboardingCompletedPayload is published when an onboarding session completes.

type OnboardingItemCoveredPayload

type OnboardingItemCoveredPayload struct {
	SessionID  string `json:"session_id"`
	ItemType   string `json:"item_type"` // "decision", "note", "file"
	ItemTarget string `json:"item_target"`
	CoveredAt  int64  `json:"covered_at"`
}

OnboardingItemCoveredPayload is published when an onboarding item is marked covered.

type OnboardingStartedPayload

type OnboardingStartedPayload struct {
	SessionID   string `json:"session_id"`
	Participant string `json:"participant"`
	ItemCount   int    `json:"item_count"`
	CreatedAt   int64  `json:"created_at"`
}

OnboardingStartedPayload is published when an onboarding session begins.

type PullCompletedPayload

type PullCompletedPayload struct {
	Remote      string `json:"remote"`
	Branch      string `json:"branch"`
	FastForward bool   `json:"fast_forward"`
	CompletedAt int64  `json:"completed_at"`
}

PullCompletedPayload is published after a pull completes.

type PullRequestCreatedPayload

type PullRequestCreatedPayload struct {
	Number    int    `json:"number"`
	Title     string `json:"title"`
	Branch    string `json:"branch"`
	Base      string `json:"base"`
	URL       string `json:"url,omitempty"`
	CreatedAt int64  `json:"created_at"`
}

PullRequestCreatedPayload is published when a PR is created via GOT.

type PullRequestMergedPayload

type PullRequestMergedPayload struct {
	PRNumber       int    `json:"pr_number"`
	MergeCommitSHA string `json:"merge_commit_sha,omitempty"`
	MergedAt       int64  `json:"merged_at"`
}

PullRequestMergedPayload is published when a PR is merged.

type PullRequestReviewedPayload

type PullRequestReviewedPayload struct {
	PRNumber    int    `json:"pr_number"`
	Reviewer    string `json:"reviewer"`
	State       string `json:"state"` // APPROVED, CHANGES_REQUESTED, COMMENTED
	Body        string `json:"body,omitempty"`
	SubmittedAt int64  `json:"submitted_at"`
}

PullRequestReviewedPayload is published when a review is submitted.

type PushCompletedPayload

type PushCompletedPayload struct {
	Remote      string `json:"remote"`
	Branch      string `json:"branch"`
	Force       bool   `json:"force"`
	CompletedAt int64  `json:"completed_at"`
}

PushCompletedPayload is published after a push completes.

type RemoteAddedPayload

type RemoteAddedPayload struct {
	Name    string `json:"name"`
	URL     string `json:"url"`
	AddedAt int64  `json:"added_at"`
}

RemoteAddedPayload is published when a remote is added.

type RemoteRemovedPayload

type RemoteRemovedPayload struct {
	Name      string `json:"name"`
	RemovedAt int64  `json:"removed_at"`
}

RemoteRemovedPayload is published when a remote is removed.

type RepositoryOpenedPayload

type RepositoryOpenedPayload struct {
	Path     string `json:"path"`
	OpenedAt int64  `json:"opened_at"`
}

RepositoryOpenedPayload is published when a repository is opened.

type WorkspaceCreatedPayload

type WorkspaceCreatedPayload struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	CreatedAt   int64    `json:"created_at"`
}

WorkspaceCreatedPayload is published when a workspace is created.

type WorkspaceDeletedPayload

type WorkspaceDeletedPayload struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	ItemCount int    `json:"item_count"`
	DeletedAt int64  `json:"deleted_at"`
}

WorkspaceDeletedPayload is published when a workspace is deleted.

type WorkspaceItemAddedPayload

type WorkspaceItemAddedPayload struct {
	WorkspaceID string `json:"workspace_id"`
	ItemType    string `json:"item_type"`   // "file", "branch", "decision", "note"
	ItemTarget  string `json:"item_target"` // path, branch name, decision ID, note ID
	CreatedAt   int64  `json:"created_at"`
}

WorkspaceItemAddedPayload is published when an item (file, branch, decision, note) is added to a workspace.

type WorkspaceItemRemovedPayload

type WorkspaceItemRemovedPayload struct {
	WorkspaceID string `json:"workspace_id"`
	ItemType    string `json:"item_type"`
	ItemTarget  string `json:"item_target"`
	RemovedAt   int64  `json:"removed_at"`
}

WorkspaceItemRemovedPayload is published when an item is removed from a workspace.

type WorkspaceUpdatedPayload

type WorkspaceUpdatedPayload struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	UpdatedAt   int64    `json:"updated_at"`
}

WorkspaceUpdatedPayload is published when a workspace is updated.

Jump to

Keyboard shortcuts

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