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
- Variables
- type BranchCheckedOutPayload
- type BranchCreatedPayload
- type BranchDeletedPayload
- type Bus
- type CommitCreatedPayload
- type DecisionCreatedPayload
- type DecisionDeletedPayload
- type DecisionLinkedPayload
- type DecisionSupersededPayload
- type DecisionUpdatedPayload
- type Event
- type Handler
- type IssueCreatedPayload
- type NoteAddedPayload
- type NoteDeletedPayload
- type OnboardingCompletedPayload
- type OnboardingItemCoveredPayload
- type OnboardingStartedPayload
- type PullCompletedPayload
- type PullRequestCreatedPayload
- type PullRequestMergedPayload
- type PullRequestReviewedPayload
- type PushCompletedPayload
- type RemoteAddedPayload
- type RemoteRemovedPayload
- type RepositoryOpenedPayload
- type WorkspaceCreatedPayload
- type WorkspaceDeletedPayload
- type WorkspaceItemAddedPayload
- type WorkspaceItemRemovedPayload
- type WorkspaceUpdatedPayload
Constants ¶
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 ¶
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 ¶
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 (*Bus) Close ¶
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 ¶
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.
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 ¶
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 ¶
RemoteRemovedPayload is published when a remote is removed.
type RepositoryOpenedPayload ¶
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.