gunk-dev/the-valley

event.go

source6a7605f70901main's published tip history
10.8 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 naming that command ("klaus ready", or "valley flow ready" under
66 // the bridge naming generation), when it marks a draft ready.
67 AgentChangeReady = "agent:change-ready"
68 // AgentChangeRecorded signals that finalize recorded, for a run without
69 // a PR, the change or branch the run pushed in place of the ones launch
70 // recorded, as when an agent made a new change instead of continuing
71 // the one it was launched on; or that the run pushed heads of more than
72 // one change, and finalize recorded the one its final head belongs to.
73 // It comes before agent:completed and carries change_id, branch and
74 // head as recorded, launch_change_id and launch_branch, and, when the
75 // run pushed more than one change, pushed: each head's change_id,
76 // branch and head.
77 AgentChangeRecorded = "agent:change-recorded"
78 // AgentChangeDraft signals that finalize recorded a pushed branch's head
79 // as a version of the run's change on its valley but left the change a
80 // draft awaiting review (ready_at_finalize off): `klaus ready` marks it
81 // ready, emitting agent:change-ready. It follows agent:branch-pushed and
82 // carries what agent:change-ready does.
83 AgentChangeDraft = "agent:change-draft"
84 // ChangeRestackDispatched signals that klaus launched a run to resolve
85 // a restack conflict the valley reported on a change klaus owns (klaus
86 // restack-conflicts, which the dashboard runs). It goes out under the
87 // new run's ID and carries repo, change_id, handle, version, head,
88 // target_tip, report (the report commit), attempt and max_attempts.
89 ChangeRestackDispatched = "change:restack-dispatched"
90 // ChangeRestackStalled signals that klaus stopped short of resolving a
91 // change's restack conflict: its attempts are spent, it couldn't
92 // return the change to draft, or the launch failed. It goes out under
93 // the change ID, once per conflict, and carries what
94 // change:restack-dispatched does, with reason in place of the attempt.
95 ChangeRestackStalled = "change:restack-stalled"
96 // The change:* types below report a valley change's life as the
97 // valley lists it, as pr:approved and pr:merged report a PR's: the
98 // dashboard's integration check reads the listing and emits each once,
99 // through the change ledger (pipeline.ChangeLedger), for the changes
100 // of the session's runs and tracked changes. A change the ledger hasn't
101 // seen before is recorded as it stands, with no event. Each goes out
102 // under the change's handle and carries repo, handle, change_id,
103 // version, head and title: those of the version it concerns.
104 //
105 // ChangeApproved signals that a ready version of a change has an
106 // integration request: the operator approved it.
107 ChangeApproved = "change:approved"
108 // ChangeIntegrated signals that a change landed. It carries
109 // landed_commit too.
110 ChangeIntegrated = "change:integrated"
111 // ChangeStale, ChangeRejected and ChangeFailed signal the integrator's
112 // decision on the request for a change's active version. Each goes out
113 // again only for a new version or a new decision.
114 ChangeStale = "change:stale"
115 ChangeRejected = "change:rejected"
116 ChangeFailed = "change:failed"
117 // ChangeWithdrawn signals that a change was withdrawn.
118 ChangeWithdrawn = "change:withdrawn"
119 // ChangeNewVersion signals a version of a change that neither this
120 // session's finalize nor its klaus ready recorded: the valley's
121 // restacker's, or a human's. It carries uploader too.
122 ChangeNewVersion = "change:new-version"
123 // ChangeChecksFailed and ChangeChecksPassed signal that the host's
124 // check worker failed, or passed, the required checks of a ready
125 // change's active version, as agent:ci-failed and agent:ci-passed do
126 // a PR's CI. Each goes out once per version, and again only when the
127 // checks of that version change their verdict. They carry failed:
128 // the names of the failed checks.
129 ChangeChecksFailed = "change:checks-failed"
130 ChangeChecksPassed = "change:checks-passed"
131 // ChangeChecksStalled signals that klaus stopped short of fixing the
132 // failed checks of a ready change it owns (klaus failed-checks, which
133 // the dashboard runs): its fix runs are spent, or it couldn't launch
134 // one. It goes out under the change ID, once per failed head, and
135 // carries repo, change_id, handle, version, head, failed, attempts and
136 // reason.
137 ChangeChecksStalled = "change:checks-stalled"
138 // PhaseStarted and PhaseCompleted bracket a phase of a run (Phase*
139 // below). phase:completed carries the phase's started_at, ended_at and
140 // duration_ms, so a reader needn't pair it with its start.
141 PhaseStarted = "phase:started"
142 PhaseCompleted = "phase:completed"
143 // CheckStarted and CheckCompleted bracket a check an agent ran where
144 // klaus can see it: `klaus _pre-review`, or a build, test or lint
145 // command in the agent's stream (Check* kinds below). check:completed
146 // carries duration_ms and, when known, success. A stream check whose
147 // command line also ran _pre-review carries includes_pre_review; a
148 // sandbox run's _pre-review check, which reached the run through the
149 // agent's stream, carries via: stream.
150 CheckStarted = "check:started"
151 CheckCompleted = "check:completed"
152)
153
154// The phases of a run. Setup is launch's work before the agent starts (fetch,
155// worktree, hooks, pane); it has no phase:started, since a launch that fails
156// records no run. Agent is the agent's own work, from its pane starting to
157// finalize starting. Finalize is _finalize's work, up to killing the pane.
158const (
159 PhaseSetup = "setup"
160 PhaseAgent = "agent"
161 PhaseFinalize = "finalize"
162)
163
164// The kinds of check:started and check:completed.
165const (
166 CheckPreReview = "pre-review"
167 CheckBuild = "build"
168 CheckTest = "test"
169 CheckLint = "lint"
170)
171
172// Dispatch reasons: why a run was launched, recorded on the run
173// (dispatch_reason) and on its events. `klaus launch --reason` names any
174// other, such as a timer's "docs-timer".
175const (
176 DispatchLaunch = "launch" // an operator or coordinator launch of new work
177 DispatchPRFollowUp = "pr-follow-up" // klaus launch --pr
178 DispatchChangeFollowUp = "change-follow-up" // klaus launch --change
179 DispatchResume = "resume" // klaus launch --resume-from, without --pr or --change
180 DispatchBudgetResume = "budget-resume" // --pr on a budget-paused PR
181 DispatchCIFix = "ci-fix" // the pipeline, for failing CI
182 DispatchReviewFix = "review-fix" // the pipeline, for changes requested
183 DispatchReviewCommentFix = "review-comment-fix" // the pipeline, for a trusted reviewer's comments
184 DispatchConflictFix = "conflict-fix" // the pipeline, for merge conflicts
185 DispatchRestackConflict = "restack-conflict" // klaus restack-conflicts, for a valley change's restack conflict
186 DispatchChecksFailed = "checks-failed" // klaus failed-checks, for a ready valley change's failed checks
187)
188
189// BudgetPausedLabel is the GitHub label applied to PRs whose agents have
190// paused due to budget exhaustion. Flow uses the label as the persistence
191// signal for the paused state; the draft PR + label is the canonical record.
192const (
193 BudgetPausedLabel = "klaus:budget-paused"
194 FlowBudgetPausedLabel = "flow:budget-paused"
195)
196
197// IsBudgetPausedLabel reports whether label is either accepted spelling of the
198// budget-paused label.
199func IsBudgetPausedLabel(label string) bool {
200 return label == BudgetPausedLabel || label == FlowBudgetPausedLabel
201}
202
203// New creates an Event with the current timestamp.
204func New(runID, eventType string, data map[string]interface{}) Event {
205 return Event{
206 Timestamp: time.Now().UTC().Format(time.RFC3339),
207 RunID: runID,
208 Type: eventType,
209 Data: data,
210 }
211}