gunk-dev/the-valley

event.go

sourcecaaa5bee5e11main's published tip history
10.5 KiB
1package event
2
3import "time"
4
5// Event represents a single event in the klaus event log.
6type Event struct {
7 Timestamp string `json:"timestamp"` // RFC3339
8 RunID string `json:"run_id"` // Run that produced the event
9 Type string `json:"type"` // e.g. "agent:completed"
10 Data map[string]interface{} `json:"data,omitempty"` // Type-specific payload
11}
12
13// Supported event types.
14const (
15 ConsultStarted = "consult:started"
16 ConsultCompleted = "consult:completed"
17 ReviewStarted = "review:started"
18 ReviewCompleted = "review:completed"
19 AgentStarted = "agent:started"
20 AgentCompleted = "agent:completed"
21 AgentPRCreated = "agent:pr-created"
22 AgentPaused = "agent:paused"
23 AgentResumed = "agent:resumed"
24 AgentCIPassed = "agent:ci-passed"
25 AgentCIFailed = "agent:ci-failed"
26 AgentNeedsAttention = "agent:needs-attention"
27 PRAwaitingApproval = "pr:awaiting-approval"
28 PRApproved = "pr:approved"
29 PRMerged = "pr:merged"
30 // PRApprovalChanged signals that an external decision about a PR's
31 // merge-readiness has changed (e.g. `klaus approve` flipped an internal
32 // approval flag). It is an invalidation signal — the dashboard reacts by
33 // re-fetching GitHub status and re-evaluating the pipeline FSM, just as
34 // it does for a real webhook. The name is deliberately backend-agnostic
35 // so the same signal can be reused once klaus supports non-GitHub
36 // merge-readiness sources.
37 PRApprovalChanged = "pr:approval-changed"
38 // PipelineStalled signals that the pipeline gave up on a PR after
39 // exhausting its retry budget (fix, rebase, review-fix or auto-merge
40 // attempts). It is emitted once per entry into the stalled stage, so a
41 // coordinator watching the channel gets one loud notification instead of
42 // a per-poll stream, and knows the PR now needs a human.
43 PipelineStalled = "pipeline:stalled"
44 // AgentBranchPushed signals that a run finished without a PR but with its
45 // branch on origin — the normal finish in a direct-push repo, where the
46 // operator integrates the branch by hand. It carries repo, branch and sha.
47 AgentBranchPushed = "agent:branch-pushed"
48 // AgentSharedGitChanged signals that finalize found a file its run's
49 // clone shares across worktrees (its git config, info/attributes or a
50 // hook) changed since launch. It carries dir, the clone's common git
51 // dir, and files, the changed paths relative to it.
52 AgentSharedGitChanged = "agent:shared-git-changed"
53 // AgentDataRefPush records that finalize published the run's data ref to
54 // origin, or did not try (push_data_ref off). It carries ref, commit and
55 // status (published or not_attempted).
56 AgentDataRefPush = "agent:data-ref-push"
57 // AgentDataRefPushFailed warns that finalize's push of the run's data ref
58 // to origin failed. The run's outcome and the local data ref are
59 // unaffected. It carries ref, commit, status (failed), class and message.
60 AgentDataRefPushFailed = "agent:data-ref-push-failed"
61 // AgentChangeReady signals that finalize marked a pushed branch's head
62 // ready on the valley its repo delivers to, as a version of the run's
63 // change. It follows agent:branch-pushed and carries repo, change_id,
64 // handle, version, title and head. `klaus ready` emits it too, with
65 // via "klaus ready", when it marks a draft ready.
66 AgentChangeReady = "agent:change-ready"
67 // AgentChangeRecorded signals that finalize recorded, for a run without
68 // a PR, the change or branch the run pushed in place of the ones launch
69 // recorded, as when an agent made a new change instead of continuing
70 // the one it was launched on; or that the run pushed heads of more than
71 // one change, and finalize recorded the one its final head belongs to.
72 // It comes before agent:completed and carries change_id, branch and
73 // head as recorded, launch_change_id and launch_branch, and, when the
74 // run pushed more than one change, pushed: each head's change_id,
75 // branch and head.
76 AgentChangeRecorded = "agent:change-recorded"
77 // AgentChangeDraft signals that finalize recorded a pushed branch's head
78 // as a version of the run's change on its valley but left the change a
79 // draft awaiting review (ready_at_finalize off): `klaus ready` marks it
80 // ready, emitting agent:change-ready. It follows agent:branch-pushed and
81 // carries what agent:change-ready does.
82 AgentChangeDraft = "agent:change-draft"
83 // ChangeRestackDispatched signals that klaus launched a run to resolve
84 // a restack conflict the valley reported on a change klaus owns (klaus
85 // restack-conflicts, which the dashboard runs). It goes out under the
86 // new run's ID and carries repo, change_id, handle, version, head,
87 // target_tip, report (the report commit), attempt and max_attempts.
88 ChangeRestackDispatched = "change:restack-dispatched"
89 // ChangeRestackStalled signals that klaus stopped short of resolving a
90 // change's restack conflict: its attempts are spent, it couldn't
91 // return the change to draft, or the launch failed. It goes out under
92 // the change ID, once per conflict, and carries what
93 // change:restack-dispatched does, with reason in place of the attempt.
94 ChangeRestackStalled = "change:restack-stalled"
95 // The change:* types below report a valley change's life as the
96 // valley lists it, as pr:approved and pr:merged report a PR's: the
97 // dashboard's integration check reads the listing and emits each once,
98 // through the change ledger (pipeline.ChangeLedger), for the changes
99 // of the session's runs and tracked changes. A change the ledger hasn't
100 // seen before is recorded as it stands, with no event. Each goes out
101 // under the change's handle and carries repo, handle, change_id,
102 // version, head and title: those of the version it concerns.
103 //
104 // ChangeApproved signals that a ready version of a change has an
105 // integration request: the operator approved it.
106 ChangeApproved = "change:approved"
107 // ChangeIntegrated signals that a change landed. It carries
108 // landed_commit too.
109 ChangeIntegrated = "change:integrated"
110 // ChangeStale, ChangeRejected and ChangeFailed signal the integrator's
111 // decision on the request for a change's active version. Each goes out
112 // again only for a new version or a new decision.
113 ChangeStale = "change:stale"
114 ChangeRejected = "change:rejected"
115 ChangeFailed = "change:failed"
116 // ChangeWithdrawn signals that a change was withdrawn.
117 ChangeWithdrawn = "change:withdrawn"
118 // ChangeNewVersion signals a version of a change that neither this
119 // session's finalize nor its klaus ready recorded: the valley's
120 // restacker's, or a human's. It carries uploader too.
121 ChangeNewVersion = "change:new-version"
122 // ChangeChecksFailed and ChangeChecksPassed signal that the host's
123 // check worker failed, or passed, the required checks of a ready
124 // change's active version, as agent:ci-failed and agent:ci-passed do
125 // a PR's CI. Each goes out once per version, and again only when the
126 // checks of that version change their verdict. They carry failed:
127 // the names of the failed checks.
128 ChangeChecksFailed = "change:checks-failed"
129 ChangeChecksPassed = "change:checks-passed"
130 // ChangeChecksStalled signals that klaus stopped short of fixing the
131 // failed checks of a ready change it owns (klaus failed-checks, which
132 // the dashboard runs): its fix runs are spent, or it couldn't launch
133 // one. It goes out under the change ID, once per failed head, and
134 // carries repo, change_id, handle, version, head, failed, attempts and
135 // reason.
136 ChangeChecksStalled = "change:checks-stalled"
137 // PhaseStarted and PhaseCompleted bracket a phase of a run (Phase*
138 // below). phase:completed carries the phase's started_at, ended_at and
139 // duration_ms, so a reader needn't pair it with its start.
140 PhaseStarted = "phase:started"
141 PhaseCompleted = "phase:completed"
142 // CheckStarted and CheckCompleted bracket a check an agent ran where
143 // klaus can see it: `klaus _pre-review`, or a build, test or lint
144 // command in the agent's stream (Check* kinds below). check:completed
145 // carries duration_ms and, when known, success. A stream check whose
146 // command line also ran _pre-review carries includes_pre_review; a
147 // sandbox run's _pre-review check, which reached the run through the
148 // agent's stream, carries via: stream.
149 CheckStarted = "check:started"
150 CheckCompleted = "check:completed"
151)
152
153// The phases of a run. Setup is launch's work before the agent starts (fetch,
154// worktree, hooks, pane); it has no phase:started, since a launch that fails
155// records no run. Agent is the agent's own work, from its pane starting to
156// finalize starting. Finalize is _finalize's work, up to killing the pane.
157const (
158 PhaseSetup = "setup"
159 PhaseAgent = "agent"
160 PhaseFinalize = "finalize"
161)
162
163// The kinds of check:started and check:completed.
164const (
165 CheckPreReview = "pre-review"
166 CheckBuild = "build"
167 CheckTest = "test"
168 CheckLint = "lint"
169)
170
171// Dispatch reasons: why a run was launched, recorded on the run
172// (dispatch_reason) and on its events. `klaus launch --reason` names any
173// other, such as a timer's "docs-timer".
174const (
175 DispatchLaunch = "launch" // an operator or coordinator launch of new work
176 DispatchPRFollowUp = "pr-follow-up" // klaus launch --pr
177 DispatchChangeFollowUp = "change-follow-up" // klaus launch --change
178 DispatchResume = "resume" // klaus launch --resume-from, without --pr or --change
179 DispatchBudgetResume = "budget-resume" // --pr on a budget-paused PR
180 DispatchCIFix = "ci-fix" // the pipeline, for failing CI
181 DispatchReviewFix = "review-fix" // the pipeline, for changes requested
182 DispatchReviewCommentFix = "review-comment-fix" // the pipeline, for a trusted reviewer's comments
183 DispatchConflictFix = "conflict-fix" // the pipeline, for merge conflicts
184 DispatchRestackConflict = "restack-conflict" // klaus restack-conflicts, for a valley change's restack conflict
185 DispatchChecksFailed = "checks-failed" // klaus failed-checks, for a ready valley change's failed checks
186)
187
188// BudgetPausedLabel is the GitHub label applied to PRs whose agents have
189// paused due to budget exhaustion. Klaus uses the label as the persistence
190// signal for the paused state; the draft PR + label is the canonical record.
191const BudgetPausedLabel = "klaus:budget-paused"
192
193// New creates an Event with the current timestamp.
194func New(runID, eventType string, data map[string]interface{}) Event {
195 return Event{
196 Timestamp: time.Now().UTC().Format(time.RFC3339),
197 RunID: runID,
198 Type: eventType,
199 Data: data,
200 }
201}