| 1 | package wire |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/copydesk" |
| 5 | "regexp" |
| 6 | "strings" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | // Task stages. A task is recorded the moment the person reports |
| 11 | // something (noted), gains the coordinator's findings (investigated), |
| 12 | // runs its Engineering step (in_progress), goes to checks and review |
| 13 | // (in_review), is ready to merge once both pass on one SHA, and Equipo |
| 14 | // merges it (merging) into the default branch. done and cancelled are |
| 15 | // final. |
| 16 | const ( |
| 17 | StageNoted = "noted" |
| 18 | StageInvestigated = "investigated" |
| 19 | StageInProgress = "in_progress" |
| 20 | StageInReview = "in_review" |
| 21 | StageReadyToMerge = "ready_to_merge" |
| 22 | StageMerging = "merging" |
| 23 | StageDone = "done" |
| 24 | StageCancelled = "cancelled" |
| 25 | ) |
| 26 | |
| 27 | // Stages lists every stage in order. |
| 28 | var Stages = []string{StageNoted, StageInvestigated, StageInProgress, StageInReview, StageReadyToMerge, StageMerging, StageDone, StageCancelled} |
| 29 | |
| 30 | // FinalStage reports whether a task can no longer change. |
| 31 | func FinalStage(stage string) bool { return stage == StageDone || stage == StageCancelled } |
| 32 | |
| 33 | // Step states. A step ends failed or cancelled only with the runner's |
| 34 | // termination proof for that attempt; Retry waits for it. |
| 35 | const ( |
| 36 | StepQueued = "queued" |
| 37 | StepRunning = "running" |
| 38 | StepDone = "done" |
| 39 | StepFailed = "failed" |
| 40 | StepCancelled = "cancelled" |
| 41 | ) |
| 42 | |
| 43 | // StepTerminal reports whether a step attempt has ended. |
| 44 | func StepTerminal(state string) bool { |
| 45 | return state == StepDone || state == StepFailed || state == StepCancelled |
| 46 | } |
| 47 | |
| 48 | // Specialists. Engineering changes the code and pushes a candidate; |
| 49 | // Checks runs the repository's own gate on a candidate; Review reads a |
| 50 | // candidate and gives a verdict. Checks and Review judge CandidateSHA, |
| 51 | // the commit named when they were dispatched. |
| 52 | const ( |
| 53 | SpecialistCopy = "copy" |
| 54 | SpecialistEngineering = "engineering" |
| 55 | SpecialistChecks = "checks" |
| 56 | SpecialistReview = "review" |
| 57 | // SpecialistMerge is the merge itself: the person's runner merges the |
| 58 | // judged SHA into the default branch through the hub (forge holds the |
| 59 | // credential). Nothing runs in a namespace. |
| 60 | SpecialistMerge = "merge" |
| 61 | // SpecialistPreview publishes an approved candidate's static output |
| 62 | // to a temporary Carloku site (release preview slice); protocol 9. |
| 63 | SpecialistPreview = "preview" |
| 64 | ) |
| 65 | |
| 66 | // Merge strategies, as the hub names them. Equipo uses the hub's own |
| 67 | // default, a merge commit (the hub records a landing by ancestry). |
| 68 | const ( |
| 69 | MergeCommit = "merge" |
| 70 | MergeSquash = "squash" |
| 71 | ) |
| 72 | |
| 73 | // Checks outcomes. none is "No checks found", which is not a failure; |
| 74 | // cannot_run is honest about a gate this runner cannot run (Reason says |
| 75 | // why, for example needs_macos), never a pass. |
| 76 | const ( |
| 77 | ChecksPassed = "passed" |
| 78 | ChecksFailed = "failed" |
| 79 | ChecksNone = "none" |
| 80 | ChecksCannotRun = "cannot_run" |
| 81 | ) |
| 82 | |
| 83 | // Review verdicts. |
| 84 | const ( |
| 85 | VerdictApprove = "approve" |
| 86 | VerdictChanges = "changes_requested" |
| 87 | ) |
| 88 | |
| 89 | // Review labels: how independent the reviewer was of Engineering. |
| 90 | // other_family is another provider family; same_family another account |
| 91 | // of the same family with fresh context; same_account a fresh session on |
| 92 | // the account Engineering used. |
| 93 | const ( |
| 94 | ReviewOtherFamily = "other_family" |
| 95 | ReviewSameFamily = "same_family" |
| 96 | ReviewSameAccount = "same_account" |
| 97 | ) |
| 98 | |
| 99 | // What a task needs from its person (Task.NeedsYou). merge: ready to |
| 100 | // merge on Amadan, the person's decision; fix_rounds: review or checks |
| 101 | // still object after the automatic fix rounds; review_blocked: the |
| 102 | // review ended without a verdict; retry: a step stopped and can be |
| 103 | // retried. |
| 104 | const ( |
| 105 | NeedsMerge = "merge" |
| 106 | NeedsFixRounds = "fix_rounds" |
| 107 | NeedsReviewBlocked = "review_blocked" |
| 108 | NeedsRetry = "retry" |
| 109 | // NeedsBranchMoved: the task branch's head on Amadan is no longer the |
| 110 | // SHA that was checked and reviewed, so nothing judged applies. |
| 111 | NeedsBranchMoved = "branch_moved" |
| 112 | // NeedsMergeConflict: the branch still conflicts with the default |
| 113 | // branch after Engineering's one rebase round. |
| 114 | NeedsMergeConflict = "merge_conflict" |
| 115 | // NeedsMachineRemoved: a step was running on a machine removed at |
| 116 | // once; the task's creator makes sure it is off, then recovers it. |
| 117 | NeedsMachineRemoved = "machine_removed" |
| 118 | // NeedsRunnerOffline: the only runner that can do the next step has |
| 119 | // been offline for 30 minutes. |
| 120 | NeedsRunnerOffline = "runner_offline" |
| 121 | // NeedsMacSandbox: checks wait for the Mac's sandbox; they run by |
| 122 | // themselves once it is proven, or the creator may choose to run them |
| 123 | // outside it. |
| 124 | NeedsMacSandbox = "mac_sandbox" |
| 125 | // NeedsMacRunner: Mac work waits for a Mac runner to be added; it |
| 126 | // starts by itself once one is. |
| 127 | NeedsMacRunner = "mac_runner" |
| 128 | // NeedsMacEngineering: Engineering for Mac work waits because a Mac |
| 129 | // runner does not take Engineering yet, and it never runs on Linux. |
| 130 | NeedsMacEngineering = "mac_engineering" |
| 131 | ) |
| 132 | |
| 133 | // MaxRebaseRounds is how many times Engineering is sent to put the change |
| 134 | // on top of a default branch it conflicts with, per task. |
| 135 | const MaxRebaseRounds = 1 |
| 136 | |
| 137 | // MaxFixRounds is how many Engineering fix rounds the coordinator sends |
| 138 | // on its own after changes are requested or checks fail. |
| 139 | const MaxFixRounds = 2 |
| 140 | |
| 141 | // Event types for tasks. |
| 142 | const ( |
| 143 | EventTask = "task" |
| 144 | EventStep = "step" |
| 145 | ) |
| 146 | |
| 147 | // CardTask is a task receipt in the conversation; TaskID names the task. |
| 148 | // CardResolved is an access card whose namespace became reachable. |
| 149 | const ( |
| 150 | CardTask = "task" |
| 151 | CardResolved = "resolved" |
| 152 | // CardMerge asks the task's creator, once per judged SHA, whether to |
| 153 | // merge a task whose checks could not run here (Name is the task's |
| 154 | // title, TaskID the task). ChoiceMerge merges that SHA, labelled |
| 155 | // without checks; ChoiceWait leaves it at Ready to merge. |
| 156 | CardMerge = "merge" |
| 157 | ChoiceMerge = "merge" |
| 158 | ChoiceWait = "wait" |
| 159 | // ChoiceNotNow declines adopting a candidate that was Ready before |
| 160 | // Equipo merged on its own ("Merge <title>?"). |
| 161 | ChoiceNotNow = "not_now" |
| 162 | // ChoiceCheck is the answer on an access card: the person granted |
| 163 | // access, so the runner checks its reach now. |
| 164 | ChoiceCheck = "check" |
| 165 | // ChoiceNotNeeded marks an access card Equipo resolved itself because |
| 166 | // no access was needed: its target was never a repository or |
| 167 | // namespace, the agent already reached it, or the turn's task found a |
| 168 | // repository the agent reaches. It is never a person's answer. |
| 169 | ChoiceNotNeeded = "not_needed" |
| 170 | ) |
| 171 | |
| 172 | // Bounds for tasks. |
| 173 | const ( |
| 174 | MaxTaskTitle = 120 |
| 175 | MaxTaskBrief = 4000 |
| 176 | MaxFindingText = 1000 |
| 177 | MaxFindings = 20 |
| 178 | MaxThreadText = 4000 |
| 179 | MaxThread = 50 |
| 180 | MaxLogTail = 4 << 10 |
| 181 | MaxStepSummary = 2000 |
| 182 | MaxTaskList = 100 |
| 183 | MaxBranchLength = 100 |
| 184 | // MaxChecksLines and MaxChecksOutput bound the checks output kept |
| 185 | // beside the SHA: its last 200 lines. |
| 186 | MaxChecksLines = 200 |
| 187 | MaxChecksOutput = 32 << 10 |
| 188 | MaxDiffBytes = 48 << 10 |
| 189 | MaxStepFindings = 20 |
| 190 | ) |
| 191 | |
| 192 | // Attachment is something a project is made of: an Amadan repository now |
| 193 | // (Kind "repo", Ref the forge key), later CARLOS apps and links. |
| 194 | type Attachment struct { |
| 195 | Kind string `json:"kind"` |
| 196 | Ref string `json:"ref"` |
| 197 | Name string `json:"name"` |
| 198 | // For a repository, from the runner's index: its default branch and |
| 199 | // that branch's newest commit (SHA, subject, time); empty until the |
| 200 | // index has read it. |
| 201 | DefaultBranch string `json:"default_branch"` |
| 202 | HeadSHA string `json:"head_sha"` |
| 203 | HeadSubject string `json:"head_subject"` |
| 204 | HeadAt *time.Time `json:"head_at"` |
| 205 | } |
| 206 | |
| 207 | // AttachmentRepo is a repository attachment. |
| 208 | const AttachmentRepo = "repo" |
| 209 | |
| 210 | // Finding is what the coordinator found while investigating, attached to |
| 211 | // the task: a diagnosis with the file and line it points at, if any. |
| 212 | type Finding struct { |
| 213 | ID string `json:"id"` |
| 214 | // Headline is one plain sentence a person reads first (no paths, at |
| 215 | // most MaxHeadline bytes); Text is the full diagnosis. |
| 216 | Headline string `json:"headline"` |
| 217 | Text string `json:"text"` |
| 218 | Repo string `json:"repo"` |
| 219 | Path string `json:"path"` |
| 220 | Line int `json:"line"` |
| 221 | At time.Time `json:"at"` |
| 222 | } |
| 223 | |
| 224 | // ThreadEntry is one line of a task's own thread: a person's note or an |
| 225 | // update the instance wrote (Author "equipo"). |
| 226 | type ThreadEntry struct { |
| 227 | ID string `json:"id"` |
| 228 | Author string `json:"author"` |
| 229 | Text string `json:"text"` |
| 230 | At time.Time `json:"at"` |
| 231 | } |
| 232 | |
| 233 | // StepHosted is the device-visible hosted CI evidence. Runner reports retain |
| 234 | // the full result; devices need only the failed job names for log sections. |
| 235 | type StepHosted struct { |
| 236 | Failed []string `json:"failed"` |
| 237 | } |
| 238 | |
| 239 | // Step is one specialist's run on the task branch. CandidateSHA is the |
| 240 | // commit the runner made from the step's changes; Pushed is true once |
| 241 | // forge confirmed the branch points at it. Terminated is the runner's |
| 242 | // proof that the attempt's namespace has exited. |
| 243 | type Step struct { |
| 244 | // ChangeFiles is included only by the device GET /tasks/{id} detail projection. |
| 245 | ChangeFiles *ChangeFiles `json:"change_files,omitempty"` |
| 246 | BaseChecks string `json:"base_checks,omitempty"` |
| 247 | ID string `json:"id"` |
| 248 | Revision int64 `json:"revision"` |
| 249 | TaskID string `json:"task_id"` |
| 250 | Index int `json:"index"` |
| 251 | Specialist string `json:"specialist"` |
| 252 | State string `json:"state"` |
| 253 | Reason string `json:"reason"` |
| 254 | Attempt int64 `json:"attempt"` |
| 255 | BaseSHA string `json:"base_sha"` |
| 256 | CandidateSHA string `json:"candidate_sha"` |
| 257 | Pushed bool `json:"pushed"` |
| 258 | Terminated bool `json:"terminated"` |
| 259 | Summary string `json:"summary"` |
| 260 | // Headline is the step's outcome in one plain sentence (Engineering's |
| 261 | // change, Review's verdict), written by the specialist; Summary has the |
| 262 | // rest. Empty when the specialist gave none. |
| 263 | Headline string `json:"headline"` |
| 264 | LogTail string `json:"log_tail"` |
| 265 | StartedAt *time.Time `json:"started_at"` |
| 266 | FinishedAt *time.Time `json:"finished_at"` |
| 267 | // Round is the fix round the step belongs to: 0 for the first |
| 268 | // Engineering step, then 1 and 2 for the automatic fix rounds. |
| 269 | Round int `json:"round"` |
| 270 | // Family and Account say what ran the step (a provider family and |
| 271 | // the runner's account binding); empty for checks. |
| 272 | Family string `json:"family"` |
| 273 | Account string `json:"account"` |
| 274 | // Model is the model the step's newest attempt ran on (connectors |
| 275 | // spec rev 3.3 §16.7), as its usage reported it. |
| 276 | Model string `json:"model,omitempty"` |
| 277 | // Review: the verdict on CandidateSHA, its independence label and its |
| 278 | // findings (file and line). |
| 279 | Verdict string `json:"verdict"` |
| 280 | ReviewLabel string `json:"review_label"` |
| 281 | Findings []Finding `json:"findings"` |
| 282 | // Checks: the outcome on CandidateSHA, the gate that ran (".amadan/ |
| 283 | // ci.d", ".amadan/ci", "make ci" or ""), its exit code (null when it |
| 284 | // did not run); the last 200 lines are GET /steps/{id}/log. |
| 285 | Checks string `json:"checks"` |
| 286 | Gate string `json:"gate"` |
| 287 | ExitCode *int `json:"exit_code"` |
| 288 | Hosted *StepHosted `json:"hosted,omitempty"` |
| 289 | // Askable is true while the runner keeps the step's own session, so |
| 290 | // the task's creator can ask it a question (Engineering and Review). |
| 291 | Askable bool `json:"askable"` |
| 292 | // Rebase marks the Engineering round that puts the change on top of a |
| 293 | // default branch it conflicted with. |
| 294 | Rebase bool `json:"rebase"` |
| 295 | // Merge: the commit the hub made (MergeSHA) on the default branch |
| 296 | // (Into) with Strategy; WithoutChecks when the person chose to merge a |
| 297 | // SHA whose checks could not run. |
| 298 | MergeSHA string `json:"merge_sha"` |
| 299 | Into string `json:"into"` |
| 300 | Strategy string `json:"strategy"` |
| 301 | WithoutChecks bool `json:"without_checks"` |
| 302 | // Switched: the step moved to another connection after the first was |
| 303 | // limited ("Engineering on Codex (Claude was limited)"). |
| 304 | Switched *Switched `json:"switched"` |
| 305 | // Activity is what the specialist did most recently in this attempt, |
| 306 | // oldest first, at most MaxStepActivity lines; empty until the runner |
| 307 | // reports any. It stays after the step ends (its last lines). |
| 308 | Activity []ActivityLine `json:"activity"` |
| 309 | // Runners: where the attempt runs (RunnerLabel for people; the house |
| 310 | // rule mentions it only when it is not the primary; while Placement is |
| 311 | // waiting_sandbox, the Mac it waits for), what it needs, |
| 312 | // whether it waits for a runner, how its end was proven, and the |
| 313 | // publication of a worker's Engineering candidate. |
| 314 | RunnerID string `json:"runner_id"` |
| 315 | RunnerLabel string `json:"runner_label"` |
| 316 | Needs []string `json:"needs"` |
| 317 | Placement string `json:"placement"` |
| 318 | Publication string `json:"publication"` |
| 319 | TerminationKind string `json:"termination_kind"` |
| 320 | // EngineeringStatus is, while Placement is waiting_mac_connection, the |
| 321 | // Engineering status the Mac it waits for (RunnerLabel) says now. |
| 322 | EngineeringStatus *EngineeringStatus `json:"engineering_status,omitempty"` |
| 323 | // SandboxChoice is, while Placement is waiting_sandbox, whether the |
| 324 | // task's creator may run the checks outside the Mac's sandbox |
| 325 | // (SandboxChoiceOffered) or not, because the instance holds that Mac |
| 326 | // as having a model credential (SandboxChoiceHeld); absent when |
| 327 | // neither is known. |
| 328 | SandboxChoice string `json:"sandbox_choice,omitempty"` |
| 329 | // WaitingFor is the id of the runner a step placed nowhere waits for |
| 330 | // (a Mac's sandbox, its Claude connection or update, its base): |
| 331 | // RunnerLabel names it. Absent once the step is placed. |
| 332 | WaitingFor string `json:"waiting_for,omitempty"` |
| 333 | // MadeOn names the worker an Engineering attempt ran on, when it is |
| 334 | // not the person's main runner; XcodeAccess is what that attempt got |
| 335 | // of Xcode's services (sandboxed, or "" for none: the Mac's checks |
| 336 | // build and test the change). |
| 337 | MadeOn string `json:"made_on,omitempty"` |
| 338 | XcodeAccess string `json:"xcode_access,omitempty"` |
| 339 | // ChecksSandbox: seatbelt or none (ran outside the sandbox) for a |
| 340 | // worker's checks; absent for the primary's. |
| 341 | ChecksSandbox string `json:"checks_sandbox,omitempty"` |
| 342 | // Preview: a preview step's export and, once done, its outcome. |
| 343 | Preview *PreviewResult `json:"preview,omitempty"` |
| 344 | // Research: a done Research step's findings, fetch log and kept |
| 345 | // images, on the task's read shape only. |
| 346 | Research *StepResearch `json:"research,omitempty"` |
| 347 | // Design: a done Design attempt's kept captures by option, on the |
| 348 | // task's read shape only. |
| 349 | Design *StepDesign `json:"design,omitempty"` |
| 350 | // Maker is the data-defined specialist that makes this step's work |
| 351 | // (Design is a maker on Engineering's step kind): the one its binding |
| 352 | // names, or, before its dispatch, its task's maker. Absent for a step |
| 353 | // its own kind's specialist makes. A step is named by its maker. |
| 354 | Maker *Maker `json:"maker,omitempty"` |
| 355 | // Hold is why the scheduler holds the step now (absent when it does |
| 356 | // not). |
| 357 | Hold *StepHold `json:"hold,omitempty"` |
| 358 | // Paused is what the instance adds to a step that waits and will |
| 359 | // carry on by itself or by a tap (paused work, 2026-11-24): absent |
| 360 | // when it does not wait. |
| 361 | Paused *StepPaused `json:"paused,omitempty"` |
| 362 | // Publish: a publish step's export and, once done, its outcome. |
| 363 | Publish *PublishResult `json:"publish,omitempty"` |
| 364 | // RetriedBy is "coordinator" when the coordinator's retry_step |
| 365 | // started the current attempt (protocol 30), else empty. |
| 366 | RetriedBy string `json:"retried_by,omitempty"` |
| 367 | } |
| 368 | |
| 369 | // Task is one piece of work under a project. Branch is the task's own |
| 370 | // branch, equipo/<task-id>-<slug>; URL opens it on Amadan once pushed. |
| 371 | type Task struct { |
| 372 | Stopping bool `json:"stopping,omitempty"` |
| 373 | MoveHoldReason string `json:"move_hold_reason,omitempty"` |
| 374 | PreparingProject bool `json:"preparing_project,omitempty"` |
| 375 | Moving bool `json:"moving,omitempty"` |
| 376 | EarlierSteps []Step `json:"earlier_steps,omitempty"` |
| 377 | CopyCanSkip bool `json:"copy_can_skip,omitempty"` |
| 378 | CopyHold bool `json:"copy_hold,omitempty"` |
| 379 | CopyRepeat *CopyRepeat `json:"copy_repeat,omitempty"` |
| 380 | CopyFlags []CopyFlag `json:"copy_flags,omitempty"` |
| 381 | ID string `json:"id"` |
| 382 | Revision int64 `json:"revision"` |
| 383 | ProjectID string `json:"project_id"` |
| 384 | Project string `json:"project"` |
| 385 | Repo string `json:"repo"` |
| 386 | Title string `json:"title"` |
| 387 | Brief string `json:"brief"` |
| 388 | Stage string `json:"stage"` |
| 389 | Branch string `json:"branch"` |
| 390 | BaseSHA string `json:"base_sha"` |
| 391 | URL string `json:"url"` |
| 392 | Creator string `json:"creator"` |
| 393 | TurnID string `json:"turn_id"` |
| 394 | Findings []Finding `json:"findings"` |
| 395 | Steps []Step `json:"steps"` |
| 396 | Thread []ThreadEntry `json:"thread"` |
| 397 | CreatedAt time.Time `json:"created_at"` |
| 398 | UpdatedAt time.Time `json:"updated_at"` |
| 399 | // DoneAt is the most recent transition to done, stable across later notes. |
| 400 | DoneAt *time.Time `json:"done_at,omitempty"` |
| 401 | // CandidateSHA is the newest pushed Engineering candidate. Checks, |
| 402 | // ChecksReason, Verdict and ReviewLabel are the judgements stored |
| 403 | // beside that SHA ("" until they exist); a new candidate clears them. |
| 404 | // NeedsYou is what the person must decide (Needs* constants), or "". |
| 405 | CandidateSHA string `json:"candidate_sha"` |
| 406 | Checks string `json:"checks"` |
| 407 | ChecksReason string `json:"checks_reason"` |
| 408 | // ChecksSandbox is the newest checks' confinement when a worker ran |
| 409 | // them: none means they ran outside the sandbox (Paul's ruling 2). |
| 410 | ChecksSandbox string `json:"checks_sandbox,omitempty"` |
| 411 | Verdict string `json:"verdict"` |
| 412 | ReviewLabel string `json:"review_label"` |
| 413 | NeedsYou string `json:"needs_you"` |
| 414 | FixRounds int `json:"fix_rounds"` |
| 415 | // BranchHead is the task branch's head on Amadan when it moved away |
| 416 | // from CandidateSHA ("" while it is there, or once the branch is gone |
| 417 | // with NeedsYou branch_moved). |
| 418 | BranchHead string `json:"branch_head"` |
| 419 | // Questions are the creator's questions to the specialists and their |
| 420 | // answers, oldest first (the task thread beside Thread's notes). |
| 421 | Questions []Question `json:"questions"` |
| 422 | // Merged is set once Equipo merged the task: the commit on the |
| 423 | // default branch, and how. A merge by a person leaves it nil. |
| 424 | Merged *Merged `json:"merged"` |
| 425 | // Reports counts the person's reports attached to this task after it |
| 426 | // was recorded (the same problem reported again). |
| 427 | Reports int `json:"reports"` |
| 428 | // AskOpen is whether the task's creator may ask its specialists now: |
| 429 | // until it ends, and for KeepMergedSessions after it is done. |
| 430 | AskOpen bool `json:"ask_open"` |
| 431 | // MergeOffered is whether the creator can have Equipo merge it now |
| 432 | // (POST /api/v1/tasks/{id}/merge): Ready to merge, the branch at the |
| 433 | // judged SHA, no merge yet and no merge card open (after Not now, or |
| 434 | // Wait for checks). |
| 435 | MergeOffered bool `json:"merge_offered"` |
| 436 | // Merge authority: the newest decision on its merge, the coordinator's |
| 437 | // hold, and the task it reverts (all absent when none). |
| 438 | MergeDecision *MergeDecision `json:"merge_decision,omitempty"` |
| 439 | MergeHold string `json:"merge_hold,omitempty"` |
| 440 | RevertOf string `json:"revert_of,omitempty"` |
| 441 | // UndoOffered: Equipo merged it on its own, the hub named the merge |
| 442 | // commit, and the creator may still Undo it. |
| 443 | UndoOffered bool `json:"undo_offered,omitempty"` |
| 444 | // CreatorName is the creator's display name (from the address until |
| 445 | // people have profiles). |
| 446 | CreatorName string `json:"creator_name"` |
| 447 | // SourceMessageID is the person's message the task was noted from |
| 448 | // (in the creator's conversation) and SourceAt its time; empty and |
| 449 | // null when no message is known. |
| 450 | SourceMessageID string `json:"source_message_id"` |
| 451 | SourceAt *time.Time `json:"source_at"` |
| 452 | // DuplicateOf is an open task in the same project that reads like this |
| 453 | // one, when the coordinator recorded it anyway; null otherwise. A task |
| 454 | // folded into another (POST /tasks/{id}/duplicate) is cancelled with |
| 455 | // DuplicateOf naming where it went. |
| 456 | DuplicateOf *TaskRef `json:"duplicate_of"` |
| 457 | // Coordinator is what the coordinator is doing on the task right now |
| 458 | // (looking into it, merging it); null when nothing. |
| 459 | Coordinator *TaskActivity `json:"coordinator"` |
| 460 | // Folded is set while Equipo has combined this task into another one |
| 461 | // (its stage is then cancelled); Combined are the tasks folded into |
| 462 | // this one, newest first. |
| 463 | Folded *TaskFold `json:"folded"` |
| 464 | Combined []TaskRef `json:"combined"` |
| 465 | // EngineeringRunner is the runner Engineering is pinned to. |
| 466 | EngineeringRunner string `json:"engineering_runner"` |
| 467 | // Triage is what Equipo is doing about the task instead of asking its |
| 468 | // person, or, when the task needs them, Equipo's recommendation; |
| 469 | // absent when neither. |
| 470 | Triage *TaskTriage `json:"triage,omitempty"` |
| 471 | // Kind is KindExplore for an exploration, which ends at the person's |
| 472 | // choice of direction, never a merge; absent for a change. |
| 473 | Kind string `json:"kind,omitempty"` |
| 474 | // ExploredFrom is the exploration this change was built from; BuiltAs |
| 475 | // the change an exploration became. |
| 476 | ExploredFrom *TaskRef `json:"explored_from,omitempty"` |
| 477 | // Maker is the data-defined specialist that makes the task's work |
| 478 | // now (absent when Engineering does). |
| 479 | Maker *Maker `json:"maker,omitempty"` |
| 480 | BuiltAs *TaskRef `json:"built_as,omitempty"` |
| 481 | // Direction is what the direction card shows while an exploration |
| 482 | // waits for its person's choice. |
| 483 | Direction *TaskDirection `json:"direction,omitempty"` |
| 484 | // Priority is the task's priority and deadline (the scheduler); absent |
| 485 | // on shapes that predate it. |
| 486 | Priority *TaskPriority `json:"priority,omitempty"` |
| 487 | // PreviewURL is the newest candidate's preview link while it is up |
| 488 | // (an unexpired temporary site, or a devbox link until the task |
| 489 | // ends); absent when there is none. |
| 490 | PreviewURL string `json:"preview_url,omitempty"` |
| 491 | // Site is a merged website's publishing: asked, publishing, published |
| 492 | // with its public URL, or how it ended; absent when there is none. |
| 493 | Site *TaskSite `json:"site,omitempty"` |
| 494 | } |
| 495 | |
| 496 | // TaskRef names another task. |
| 497 | type TaskRef struct { |
| 498 | ID string `json:"id"` |
| 499 | Title string `json:"title"` |
| 500 | Stage string `json:"stage"` |
| 501 | Creator string `json:"creator"` |
| 502 | } |
| 503 | |
| 504 | // TaskFold is how Equipo combined a duplicate into another task: Into |
| 505 | // keeps the work; this task is cancelled until someone undoes it |
| 506 | // (POST /api/v1/tasks/{id}/uncombine restores it exactly as it was). |
| 507 | type TaskFold struct { |
| 508 | Into TaskRef `json:"into"` |
| 509 | At time.Time `json:"at"` |
| 510 | } |
| 511 | |
| 512 | // CardCombined is the quiet receipt in the creator's conversation when |
| 513 | // Equipo combined two of their tasks (TaskID the folded task, Name the |
| 514 | // line); ChoiceUndo restores the folded task. |
| 515 | const CardCombined = "combined" |
| 516 | |
| 517 | // TaskActivity is the coordinator at work on a task: Kind is |
| 518 | // CoordinatorLooking (its turn that noted the task is still running) or |
| 519 | // CoordinatorMerging (the merge step), since Since. |
| 520 | type TaskActivity struct { |
| 521 | Kind string `json:"kind"` |
| 522 | Since time.Time `json:"since"` |
| 523 | } |
| 524 | |
| 525 | // Coordinator activities on a task. |
| 526 | const ( |
| 527 | CoordinatorLooking = "looking" |
| 528 | CoordinatorMerging = "merging" |
| 529 | ) |
| 530 | |
| 531 | // ActivityLine is one thing a specialist started during a step: Kind is |
| 532 | // an Activity* constant and Subject the file (repository-relative) or the |
| 533 | // command's first line, clipped; At is when the runner saw it. |
| 534 | type ActivityLine struct { |
| 535 | Kind string `json:"kind"` |
| 536 | Subject string `json:"subject"` |
| 537 | At time.Time `json:"at"` |
| 538 | } |
| 539 | |
| 540 | // Step activity kinds. |
| 541 | const ( |
| 542 | ActivityRead = "read" |
| 543 | ActivitySearch = "search" |
| 544 | ActivityEdit = "edit" |
| 545 | ActivityRun = "run" |
| 546 | ActivityOther = "other" |
| 547 | ) |
| 548 | |
| 549 | // MaxHeadline bounds a headline: one sentence, about 80 characters. |
| 550 | const MaxHeadline = 120 |
| 551 | |
| 552 | // MaxStepActivity is how many activity lines a step keeps; |
| 553 | // MaxActivitySubject bounds a line's subject. |
| 554 | const ( |
| 555 | MaxStepActivity = 5 |
| 556 | MaxActivitySubject = 160 |
| 557 | ) |
| 558 | |
| 559 | // FrameStepActivity reports what a running step's specialist started |
| 560 | // (runner to instance, not durable: a lost line is only a lost line). |
| 561 | const FrameStepActivity = "step_activity" |
| 562 | |
| 563 | // StepActivityReport is one activity line of a running step attempt. |
| 564 | type StepActivityReport struct { |
| 565 | TaskID string `json:"task_id"` |
| 566 | StepID string `json:"step_id"` |
| 567 | Attempt int64 `json:"attempt"` |
| 568 | Kind string `json:"kind"` |
| 569 | Subject string `json:"subject"` |
| 570 | } |
| 571 | |
| 572 | // StepActivity is the activity event's data for resource "step": the |
| 573 | // step's newest lines, oldest first. |
| 574 | type StepActivity struct { |
| 575 | TaskID string `json:"task_id"` |
| 576 | StepID string `json:"step_id"` |
| 577 | Attempt int64 `json:"attempt"` |
| 578 | Activity []ActivityLine `json:"activity"` |
| 579 | } |
| 580 | |
| 581 | // ResourceStep is the activity event's resource for a step. |
| 582 | const ResourceStep = "step" |
| 583 | |
| 584 | // MarkDuplicate is the body of POST /api/v1/tasks/{id}/duplicate: the |
| 585 | // task's creator folds it into Of, an open task in the same project. The |
| 586 | // task is cancelled (its running step stopped first) and its brief goes |
| 587 | // on Of's thread as a report. |
| 588 | type MarkDuplicate struct { |
| 589 | Of string `json:"of"` |
| 590 | } |
| 591 | |
| 592 | // PersonRef is a team member as screens show them: the address, a |
| 593 | // display name and initials for an avatar. |
| 594 | type PersonRef struct { |
| 595 | Address string `json:"address"` |
| 596 | Name string `json:"name"` |
| 597 | Initials string `json:"initials"` |
| 598 | } |
| 599 | |
| 600 | // ProjectChecks says whether the project's checks can run on the team's |
| 601 | // runner: Here with the Gate that runs, or not with Reason (a checks |
| 602 | // reason such as needs_macos, or none when no gate was found). |
| 603 | type ProjectChecks struct { |
| 604 | Here bool `json:"here"` |
| 605 | Gate string `json:"gate"` |
| 606 | Reason string `json:"reason"` |
| 607 | } |
| 608 | |
| 609 | // Merged is how Equipo merged a task: SHA on Into, with Strategy; |
| 610 | // WithoutChecks when the person chose to merge without checks. |
| 611 | type Merged struct { |
| 612 | SHA string `json:"sha"` |
| 613 | Into string `json:"into"` |
| 614 | Strategy string `json:"strategy"` |
| 615 | WithoutChecks bool `json:"without_checks"` |
| 616 | At time.Time `json:"at"` |
| 617 | } |
| 618 | |
| 619 | // TaskList is GET /api/v1/tasks: the team's tasks, newest first. |
| 620 | type TaskList struct { |
| 621 | Items []Task `json:"items"` |
| 622 | } |
| 623 | |
| 624 | // TaskAccepted is the 202 body of POST /tasks/{id}/cancel and |
| 625 | // /tasks/{id}/retry: the attempt the request applies to. |
| 626 | type TaskAccepted struct { |
| 627 | Attempt int64 `json:"attempt"` |
| 628 | } |
| 629 | |
| 630 | // StepLog is GET /api/v1/steps/{id}/log: the bounded tail. |
| 631 | type StepLog struct { |
| 632 | StepID string `json:"step_id"` |
| 633 | Attempt int64 `json:"attempt"` |
| 634 | Tail string `json:"tail"` |
| 635 | } |
| 636 | |
| 637 | // PostThread is the body of POST /api/v1/tasks/{id}/thread. |
| 638 | type PostThread struct { |
| 639 | Text string `json:"text"` |
| 640 | IdempotencyKey string `json:"idempotency_key"` |
| 641 | } |
| 642 | |
| 643 | // TaskBranch is the task's own branch: equipo/<task-id>-<slug>, the slug |
| 644 | // from the title, so two tasks never share one. |
| 645 | func TaskBranch(id, title string) string { |
| 646 | var b strings.Builder |
| 647 | dash := false |
| 648 | for _, r := range strings.ToLower(title) { |
| 649 | switch { |
| 650 | case r >= 'a' && r <= 'z' || r >= '0' && r <= '9': |
| 651 | b.WriteRune(r) |
| 652 | dash = false |
| 653 | case !dash && b.Len() > 0: |
| 654 | b.WriteByte('-') |
| 655 | dash = true |
| 656 | } |
| 657 | } |
| 658 | slug := strings.Trim(b.String(), "-") |
| 659 | // At most 40 characters, cut at a word boundary when there is one. |
| 660 | if len(slug) > 40 { |
| 661 | cut := slug[:41] |
| 662 | if i := strings.LastIndexByte(cut, '-'); i > 0 { |
| 663 | slug = cut[:i] |
| 664 | } else { |
| 665 | slug = slug[:40] |
| 666 | } |
| 667 | slug = strings.Trim(slug, "-") |
| 668 | } |
| 669 | if slug == "" { |
| 670 | return "equipo/" + id |
| 671 | } |
| 672 | return "equipo/" + id + "-" + slug |
| 673 | } |
| 674 | |
| 675 | var taskBranch = regexp.MustCompile(`^equipo/[a-z0-9]+(?:-[a-z0-9]+)*$`) |
| 676 | |
| 677 | var branchName = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._/-]{0,99}$`) |
| 678 | |
| 679 | // ValidBranchName reports whether b is a plain branch name (a default |
| 680 | // branch a task merged into). |
| 681 | func ValidBranchName(b string) bool { |
| 682 | return branchName.MatchString(b) && !strings.Contains(b, "..") && !strings.HasSuffix(b, ".lock") && !strings.HasSuffix(b, "/") |
| 683 | } |
| 684 | |
| 685 | // ValidTaskBranch reports whether b is a task branch name. |
| 686 | func ValidTaskBranch(b string) bool { |
| 687 | return len(b) <= MaxBranchLength && taskBranch.MatchString(b) |
| 688 | } |
| 689 | |
| 690 | // Frames for steps. dispatch and cancel_step go to the runner; step comes |
| 691 | // back. recheck asks the runner to look at what its agent reaches now. |
| 692 | const ( |
| 693 | FrameDispatch = "dispatch" |
| 694 | FrameCancelStep = "cancel_step" |
| 695 | FrameStep = "step" |
| 696 | FrameRecheck = "recheck" |
| 697 | // FrameWatchMerge asks the runner to watch a task's branch until its |
| 698 | // candidate lands on the default branch (an empty candidate stops |
| 699 | // watching); FrameMerged reports that it landed. |
| 700 | FrameWatchMerge = "watch_merge" |
| 701 | FrameMerged = "merged" |
| 702 | // FrameBranch reports the task branch's head when it differs from the |
| 703 | // watched candidate (or is back at it). |
| 704 | FrameBranch = "branch" |
| 705 | ) |
| 706 | |
| 707 | // DispatchCommand starts one attempt of a step on the person's runner. |
| 708 | // BaseSHA is empty for the first attempt: the runner takes the default |
| 709 | // branch's tip and reports it. |
| 710 | type DispatchCommand struct { |
| 711 | PreviewUnsafeDigest string `json:"preview_unsafe_digest,omitempty"` |
| 712 | AvoidFamilies []string `json:"avoid_families,omitempty"` |
| 713 | Copy *CopyDispatch `json:"copy,omitempty"` |
| 714 | Person string `json:"person"` |
| 715 | TaskID string `json:"task_id"` |
| 716 | StepID string `json:"step_id"` |
| 717 | Attempt int64 `json:"attempt"` |
| 718 | Specialist string `json:"specialist"` |
| 719 | Repo string `json:"repo"` |
| 720 | Branch string `json:"branch"` |
| 721 | BaseSHA string `json:"base_sha"` |
| 722 | Title string `json:"title"` |
| 723 | Brief string `json:"brief"` |
| 724 | PersonWords []string `json:"person_words,omitempty"` |
| 725 | Findings []Finding `json:"findings"` |
| 726 | // CandidateSHA is the commit a checks or review step judges (BaseSHA |
| 727 | // is then the task's base, for the diff), or the recorded commit a |
| 728 | // republish attempt pushes again (Republish, from FromAttempt's |
| 729 | // private repository) without running the specialist. |
| 730 | CandidateSHA string `json:"candidate_sha"` |
| 731 | Republish bool `json:"republish"` |
| 732 | FromAttempt int64 `json:"from_attempt"` |
| 733 | // AvoidAccount is the account binding Engineering used; Review runs |
| 734 | // elsewhere when it can. |
| 735 | AvoidAccount string `json:"avoid_account"` |
| 736 | // AvoidFamily (ProtocolModels) is the family Engineering's attempt |
| 737 | // recorded: Review reads it from that record, never from the |
| 738 | // connection, which may allow several models (§16.5). |
| 739 | AvoidFamily string `json:"avoid_family,omitempty"` |
| 740 | Round int `json:"round"` |
| 741 | // Feedback (an Engineering fix round): what checks and review said |
| 742 | // about the commit this round starts from, the fix-round part of |
| 743 | // Brief. A runner holding the session that made that commit sends it |
| 744 | // as that session's next message instead of starting afresh. |
| 745 | // Protocol 3: an older runner never gets it, and runs the round fresh. |
| 746 | Feedback string `json:"feedback,omitempty"` |
| 747 | // Rebase (Engineering): put the change of CandidateSHA, made on |
| 748 | // FromBase, on top of the default branch's tip (BaseSHA is empty: the |
| 749 | // runner takes the tip), resolving any conflicts. |
| 750 | Rebase bool `json:"rebase"` |
| 751 | FromBase string `json:"from_base"` |
| 752 | // Protocol 2: the tags the step needs and the runner it is placed on; |
| 753 | // a runner lacking a need refuses it (placement_refused). |
| 754 | Needs []string `json:"needs,omitempty"` |
| 755 | RunnerID string `json:"runner_id,omitempty"` |
| 756 | // Protocol 3: RevertSHA is the merge commit a revert task undoes; the |
| 757 | // review measures whether the candidate reverts exactly that. |
| 758 | RevertSHA string `json:"revert_sha,omitempty"` |
| 759 | // Protocol 5: HostedChecks offers a checks step on the primary the |
| 760 | // hub's own CI verdict on the candidate, when the repository's hosted |
| 761 | // CI is on (release slice 1). An older runner never gets it. |
| 762 | HostedChecks bool `json:"hosted_checks,omitempty"` |
| 763 | // Protocol 7: Unsandboxed is the task creator's recorded choice to |
| 764 | // run this attempt's checks on this Mac outside the sandbox. Without |
| 765 | // it a Mac whose sandbox is not proven refuses the checks |
| 766 | // (ReasonSandboxUnproven) and runs nothing. |
| 767 | Unsandboxed bool `json:"unsandboxed,omitempty"` |
| 768 | // Protocol 13: Research is a Research step's inputs (Specialist |
| 769 | // research, with no Repo, Branch, BaseSHA or CandidateSHA). Encode |
| 770 | // refuses a Research dispatch below 13 and drops the field from any |
| 771 | // other. |
| 772 | Research *ResearchDispatch `json:"research,omitempty"` |
| 773 | // ResearchNote (protocol 13) is an Engineering or Review step's view of |
| 774 | // the task's latest Research findings: quoted data, never instructions. |
| 775 | ResearchNote *ResearchHandoff `json:"research_note,omitempty"` |
| 776 | // Protocol 14 (the scheduler): the task's priority and deadline, and |
| 777 | // a Run now not yet consumed for this step revision (its id). Encode |
| 778 | // drops all three for an older runner, which never spends. |
| 779 | Priority string `json:"priority,omitempty"` |
| 780 | By *time.Time `json:"by,omitempty"` |
| 781 | Release string `json:"release,omitempty"` |
| 782 | // ReleaseConnection pins Release (protocol 29): the runner admits the |
| 783 | // step on that connection only (ReleaseCommand.Connection). |
| 784 | ReleaseConnection string `json:"release_connection,omitempty"` |
| 785 | // PriorityRevision orders the task's priority and deadline: the |
| 786 | // runner keeps a priority frame's value only while no dispatch carries |
| 787 | // a newer one. Housekeeping marks an attempt housekeeping dispatched: |
| 788 | // it counts as low and never spends, whatever its task's priority or |
| 789 | // a release (§7, Housekeeping). |
| 790 | PriorityRevision int64 `json:"priority_revision,omitempty"` |
| 791 | Housekeeping bool `json:"housekeeping,omitempty"` |
| 792 | // Protocol 16: Publish is a publish step's target (Specialist |
| 793 | // publish; CandidateSHA the merged commit). Encode refuses a publish |
| 794 | // dispatch below 16. |
| 795 | Publish *PublishDispatch `json:"publish,omitempty"` |
| 796 | // Protocol 37: XcodeAccess (XcodeAccessSandboxed or "") gives a Mac |
| 797 | // worker's Engineering the Mach services Xcode needs. |
| 798 | XcodeAccess string `json:"xcode_access,omitempty"` |
| 799 | // ProtocolDesign: the specialist binding of a maker step made by a |
| 800 | // data-defined specialist (Design is a maker on Engineering's step |
| 801 | // kind): its id, the revision and project ("" the team) of its grant, |
| 802 | // and its profile and capabilities, recorded when dispatched. All |
| 803 | // empty for Engineering itself (ValidSpecialistBinding). Encode |
| 804 | // refuses a dispatch carrying any of them below ProtocolDesign. |
| 805 | SpecialistID string `json:"specialist_id,omitempty"` |
| 806 | SpecialistRevision int64 `json:"specialist_revision,omitempty"` |
| 807 | SpecialistProject string `json:"specialist_project,omitempty"` |
| 808 | Profile string `json:"profile,omitempty"` |
| 809 | Capabilities []string `json:"capabilities,omitempty"` |
| 810 | // Explore and SpecialistBrief go with a binding only (part of it for |
| 811 | // ValidSpecialistBinding and Encode): the task is an exploration, and |
| 812 | // the specialist's brief as its owner added it (at most |
| 813 | // MaxSpecialistBrief bytes), for the maker's prompt. |
| 814 | Explore bool `json:"explore,omitempty"` |
| 815 | SpecialistBrief string `json:"specialist_brief,omitempty"` |
| 816 | } |
| 817 | |
| 818 | // WatchMergeCommand watches a task's branch for its candidate landing on |
| 819 | // the default branch. CandidateSHA "" stops watching the task. |
| 820 | type WatchMergeCommand struct { |
| 821 | Person string `json:"person"` |
| 822 | TaskID string `json:"task_id"` |
| 823 | Repo string `json:"repo"` |
| 824 | Branch string `json:"branch"` |
| 825 | CandidateSHA string `json:"candidate_sha"` |
| 826 | } |
| 827 | |
| 828 | // MergedReport says a task's candidate is on the repository's default |
| 829 | // branch now. |
| 830 | type MergedReport struct { |
| 831 | TaskID string `json:"task_id"` |
| 832 | CandidateSHA string `json:"candidate_sha"` |
| 833 | } |
| 834 | |
| 835 | // BranchReport is the task branch's head on Amadan as the runner saw it, |
| 836 | // sent when it changes: Head "" means the branch is gone. |
| 837 | type BranchReport struct { |
| 838 | TaskID string `json:"task_id"` |
| 839 | CandidateSHA string `json:"candidate_sha"` |
| 840 | Head string `json:"head"` |
| 841 | } |
| 842 | |
| 843 | // CancelStepCommand interrupts one attempt of a step. |
| 844 | type CancelStepCommand struct { |
| 845 | Person string `json:"person"` |
| 846 | TaskID string `json:"task_id"` |
| 847 | StepID string `json:"step_id"` |
| 848 | Attempt int64 `json:"attempt"` |
| 849 | } |
| 850 | |
| 851 | // StepReport moves a step attempt forward: running (started, then with |
| 852 | // its candidate), done (pushed), failed or cancelled. Termination is true |
| 853 | // once the attempt's namespace exit was observed. Reason is a fixed code. |
| 854 | type StepReport struct { |
| 855 | // Protocol 31: Engineering file-list facts, presentation only. |
| 856 | ChangeDiffs string `json:"change_diffs,omitempty"` |
| 857 | ChangeFiles *ChangeFiles `json:"change_files,omitempty"` |
| 858 | BaseChecks string `json:"base_checks,omitempty"` |
| 859 | BaseChecksSHA string `json:"base_checks_sha,omitempty"` |
| 860 | Failure *copydesk.Signature `json:"failure,omitempty"` |
| 861 | Copy *CopyResult `json:"copy,omitempty"` |
| 862 | TaskID string `json:"task_id"` |
| 863 | StepID string `json:"step_id"` |
| 864 | Attempt int64 `json:"attempt"` |
| 865 | State string `json:"state"` |
| 866 | Reason string `json:"reason"` |
| 867 | BaseSHA string `json:"base_sha"` |
| 868 | CandidateSHA string `json:"candidate_sha"` |
| 869 | Pushed bool `json:"pushed"` |
| 870 | Termination bool `json:"termination"` |
| 871 | Summary string `json:"summary"` |
| 872 | Headline string `json:"headline"` |
| 873 | LogTail string `json:"log_tail"` |
| 874 | // What ran (family, account binding) and, for checks and review, |
| 875 | // their result on CandidateSHA. Output is the checks' last 200 lines. |
| 876 | Family string `json:"family"` |
| 877 | Account string `json:"account"` |
| 878 | Verdict string `json:"verdict"` |
| 879 | ReviewLabel string `json:"review_label"` |
| 880 | Findings []Finding `json:"findings"` |
| 881 | Checks string `json:"checks"` |
| 882 | Gate string `json:"gate"` |
| 883 | ExitCode *int `json:"exit_code"` |
| 884 | Output string `json:"output"` |
| 885 | // Askable: the runner kept the step's session for questions. |
| 886 | Askable bool `json:"askable"` |
| 887 | // Merge: the commit the hub made on Into with Strategy, once the hub |
| 888 | // confirmed it (done), or what refused it (failed with Reason). |
| 889 | MergeSHA string `json:"merge_sha"` |
| 890 | Into string `json:"into"` |
| 891 | Strategy string `json:"strategy"` |
| 892 | // Usage is the attempt's token use (null for checks and merges); |
| 893 | // Switched is set when the attempt moved to another connection after |
| 894 | // the first was limited (its partial work was discarded). |
| 895 | Usage []Usage `json:"usage"` |
| 896 | Switched *Switched `json:"switched"` |
| 897 | // Protocol 2: how termination was proven (namespace or |
| 898 | // process_group), the commits a worker holds for thin packs, and the |
| 899 | // phase (committed: a worker's candidate, not pushed). |
| 900 | TerminationKind string `json:"termination_kind,omitempty"` |
| 901 | Have []string `json:"have,omitempty"` |
| 902 | Phase string `json:"phase,omitempty"` |
| 903 | // Apple: Engineering's change touched Swift, Objective-C or Xcode |
| 904 | // files, so its checks need macOS. |
| 905 | Apple bool `json:"apple,omitempty"` |
| 906 | // ChecksSandbox is how a worker's checks were confined: seatbelt |
| 907 | // (srt, P2 denied every hostile attempt) or none (they ran outside |
| 908 | // the sandbox, Paul's ruling 2). |
| 909 | ChecksSandbox string `json:"checks_sandbox,omitempty"` |
| 910 | // Protocol 3. Change is what the reviewed change is, measured by the |
| 911 | // runner on exactly the reviewed pair (review steps). MergeSource says |
| 912 | // where a merge's SHA came from (MergeSourceHub: this request's answer) |
| 913 | // and MergeParents are that commit's parents, read after the merge. |
| 914 | Change *ChangeFacts `json:"change,omitempty"` |
| 915 | MergeSource string `json:"merge_source,omitempty"` |
| 916 | MergeParents []string `json:"merge_parents,omitempty"` |
| 917 | // Protocol 5. Hosted binds a checks verdict taken from the hub's |
| 918 | // hosted CI (Gate GateHosted) to what it judged. |
| 919 | Hosted *HostedResult `json:"hosted,omitempty"` |
| 920 | // Protocol 9. HasPreview: Review found release/preview.json on the |
| 921 | // candidate (scheduling evidence only). Preview is a preview step's |
| 922 | // result: built (the exported digest) or done. |
| 923 | HasPreview bool `json:"has_preview,omitempty"` |
| 924 | Preview *PreviewResult `json:"preview,omitempty"` |
| 925 | // Protocol 13. Research is a Research step's result: its findings, |
| 926 | // its fetch log and the images it kept (their bytes travel first, in |
| 927 | // research_file frames). |
| 928 | Research *ResearchResult `json:"research,omitempty"` |
| 929 | // Protocol 14. Hold: the scheduler holds the step (state running; |
| 930 | // the instance keeps it queued until it starts). A report without it |
| 931 | // ends the hold. Encode refuses a held report below 14. |
| 932 | Hold *StepHold `json:"hold,omitempty"` |
| 933 | // Protocol 16. Publish is a publish step's export and, once done, its |
| 934 | // outcome. |
| 935 | Publish *PublishResult `json:"publish,omitempty"` |
| 936 | // Protocol 37. XcodeAccess echoes what Engineering ran with; |
| 937 | // SessionID names the kept Engineering session (from any runner); |
| 938 | // OutcomePhase is what the commit is (OutcomeCommitted, |
| 939 | // OutcomeUnfinished, OutcomeNoShell), apart from Phase. |
| 940 | XcodeAccess string `json:"xcode_access,omitempty"` |
| 941 | SessionID string `json:"session_id,omitempty"` |
| 942 | OutcomePhase string `json:"outcome_phase,omitempty"` |
| 943 | // ProtocolDesign. Options are a Design step's mockup options and the |
| 944 | // captures it names for each (ValidOptions); their bytes travel |
| 945 | // first, in render_file frames. Encode drops them below it. |
| 946 | Options []DesignOption `json:"options,omitempty"` |
| 947 | // ProtocolDesign. Renders are a Design step's render_page calls |
| 948 | // (ValidRenderAudits), on its final report. Encode drops them below |
| 949 | // it. |
| 950 | Renders []RenderAudit `json:"renders,omitempty"` |
| 951 | } |
| 952 | |
| 953 | // ReasonRunnerOutdated settles a preview step whose primary connected |
| 954 | // below protocol 9. |
| 955 | const ReasonRunnerOutdated = "runner_outdated" |
| 956 | |
| 957 | // PreviewResult is a preview step's word: Phase built with the export's |
| 958 | // digest, files and bytes; then, done, the app, URL, version, the |
| 959 | // platform's expiry and the Outcome (deployed once the marker answered, |
| 960 | // unconfirmed when it never did). |
| 961 | type PreviewResult struct { |
| 962 | Unsafe bool `json:"unsafe,omitempty"` |
| 963 | Phase string `json:"phase"` |
| 964 | App string `json:"app,omitempty"` |
| 965 | URL string `json:"url,omitempty"` |
| 966 | Version string `json:"version,omitempty"` |
| 967 | Digest string `json:"digest"` |
| 968 | Files int `json:"files"` |
| 969 | Bytes int64 `json:"bytes"` |
| 970 | ExpiresAt *time.Time `json:"expires_at,omitempty"` |
| 971 | Outcome string `json:"outcome,omitempty"` |
| 972 | } |
| 973 | |
| 974 | // Preview phases and outcomes. |
| 975 | const ( |
| 976 | PreviewBuilt = "built" |
| 977 | PreviewDone = "done" |
| 978 | PreviewDeployed = "deployed" |
| 979 | PreviewUnconfirmed = "unconfirmed" |
| 980 | ) |
| 981 | |
| 982 | // GateHosted is the gate a checks report names when its verdict is the |
| 983 | // hub's hosted CI on the candidate, not a gate the runner ran. |
| 984 | const GateHosted = "hosted CI" |
| 985 | |
| 986 | // Hosted CI states the hub reports that end a run with a verdict. |
| 987 | const ( |
| 988 | HostedSuccess = "success" |
| 989 | HostedFailure = "failure" |
| 990 | ) |
| 991 | |
| 992 | // HostedResult is a hosted CI verdict as the hub reported it: the |
| 993 | // repository and branch asked about, the tip it judged (the candidate), |
| 994 | // its state, when the hub recorded the run (ReportedAt, Unix seconds; the |
| 995 | // hub exposes no run id) and the units that failed. |
| 996 | type HostedResult struct { |
| 997 | Repo string `json:"repo"` |
| 998 | Branch string `json:"branch"` |
| 999 | SHA string `json:"sha"` |
| 1000 | State string `json:"state"` |
| 1001 | ReportedAt int64 `json:"reported_at"` |
| 1002 | Failed []string `json:"failed"` |
| 1003 | } |
| 1004 | |
| 1005 | // MaxHostedFailed bounds the failing units a hosted result names, and |
| 1006 | // MaxHostedName each name. |
| 1007 | const ( |
| 1008 | MaxHostedFailed = 20 |
| 1009 | MaxHostedName = 120 |
| 1010 | ) |
| 1011 | |
| 1012 | // Merge sources: the hub's answer to this request, the default branch |
| 1013 | // read after an uncertain answer, or the runner's earlier record. |
| 1014 | const ( |
| 1015 | MergeSourceHub = "hub" |
| 1016 | MergeSourceReconciled = "reconciled" |
| 1017 | MergeSourceCached = "cached" |
| 1018 | ) |
| 1019 | |
| 1020 | // ChangeFacts is a reviewed change as the runner measured it, with no |
| 1021 | // model: git diff --raw and --numstat of Base..SHA, both paths of every |
| 1022 | // entry, and the signing lines of Xcode project files. Complete is false |
| 1023 | // when the listings disagree, an error occurred or there were more than |
| 1024 | // MaxChangeEntries entries. |
| 1025 | type ChangeFacts struct { |
| 1026 | GateFilesChanged bool `json:"gate_files_changed,omitempty"` |
| 1027 | ReviewTruncated bool `json:"review_truncated,omitempty"` |
| 1028 | ReviewStep string `json:"review_step"` |
| 1029 | Attempt int64 `json:"attempt"` |
| 1030 | Repo string `json:"repo"` |
| 1031 | Base string `json:"base"` |
| 1032 | SHA string `json:"sha"` |
| 1033 | Files int `json:"files"` |
| 1034 | Lines int `json:"lines"` |
| 1035 | Binary int `json:"binary"` |
| 1036 | Special bool `json:"special"` |
| 1037 | Signing bool `json:"signing"` |
| 1038 | Entries []ChangeEntry `json:"entries"` |
| 1039 | Complete bool `json:"complete"` |
| 1040 | Revert *RevertCheck `json:"revert,omitempty"` |
| 1041 | } |
| 1042 | |
| 1043 | // ChangeEntry is one changed path: its status letter, both paths (Old |
| 1044 | // is "" unless renamed or copied) and both modes. |
| 1045 | type ChangeEntry struct { |
| 1046 | Status string `json:"status"` |
| 1047 | Old string `json:"old"` |
| 1048 | New string `json:"new"` |
| 1049 | OldMode string `json:"old_mode"` |
| 1050 | NewMode string `json:"new_mode"` |
| 1051 | } |
| 1052 | |
| 1053 | // RevertCheck says whether a revert task's candidate exactly reverts SHA: |
| 1054 | // OnTop when its parent is SHA itself, Exact when its tree is SHA's first |
| 1055 | // parent's tree. |
| 1056 | type RevertCheck struct { |
| 1057 | SHA string `json:"sha"` |
| 1058 | OnTop bool `json:"on_top"` |
| 1059 | Exact bool `json:"exact"` |
| 1060 | } |
| 1061 | |
| 1062 | // MaxChangeEntries bounds a ChangeFacts listing. |
| 1063 | const MaxChangeEntries = 200 |
| 1064 | |
| 1065 | // RecheckCommand asks the runner to check now what its agent reaches. |
| 1066 | type RecheckCommand struct { |
| 1067 | Person string `json:"person"` |
| 1068 | } |
| 1069 | |
| 1070 | // StepRun is a step attempt the runner holds, in sync. |
| 1071 | type StepRun struct { |
| 1072 | TaskID string `json:"task_id"` |
| 1073 | StepID string `json:"step_id"` |
| 1074 | Attempt int64 `json:"attempt"` |
| 1075 | State string `json:"state"` |
| 1076 | CandidateSHA string `json:"candidate_sha"` |
| 1077 | } |
| 1078 | |
| 1079 | // ReasonShellUnavailable is a pushed Engineering fix round whose engineer |
| 1080 | // ran shell commands and none worked, so it could not check its work |
| 1081 | // (stopped-jobs audit, 2026-11-25, fix 4): the round does not count |
| 1082 | // against the task's rounds, up to MaxFixRounds such rounds. |
| 1083 | const ReasonShellUnavailable = "shell_unavailable" |
| 1084 | |
| 1085 | // DoneOnlyReasons are reasons a runner reports only on a done step, where |
| 1086 | // no reason is shown as a stop: on any other state the instance records |
| 1087 | // them as unknown, so they need no words of their own. |
| 1088 | var DoneOnlyReasons = map[string]bool{ReasonShellUnavailable: true} |
| 1089 | |
| 1090 | // StepReasons are the failure codes a runner may report for a step. |
| 1091 | var StepReasons = map[string]bool{ |
| 1092 | "copy_budget": true, |
| 1093 | "copy_budget_unknown": true, |
| 1094 | "copy_update_required": true, |
| 1095 | "copy_question": true, |
| 1096 | "": true, |
| 1097 | "cancelled": true, |
| 1098 | "runner_restarted": true, |
| 1099 | "step_timeout": true, |
| 1100 | "provider_failed": true, |
| 1101 | "provider_rejected": true, |
| 1102 | "policy_rejected": true, |
| 1103 | "account_unavailable": true, |
| 1104 | "sign_in_again": true, |
| 1105 | "no_changes": true, |
| 1106 | "workspace_refused": true, |
| 1107 | "clone_failed": true, |
| 1108 | "push_failed": true, |
| 1109 | "proposal_failed": true, |
| 1110 | "push_conflict": true, |
| 1111 | "superseded": true, |
| 1112 | "interrupted": true, |
| 1113 | // An Engineering step that committed nothing after Equipo refused |
| 1114 | // tool requests it made (no_changes otherwise). An older instance |
| 1115 | // records it as unknown. |
| 1116 | "tools_refused": true, |
| 1117 | // A pushed Engineering fix round whose shell commands all failed: it |
| 1118 | // does not count against the task's rounds. An older instance takes |
| 1119 | // the step as done. |
| 1120 | ReasonShellUnavailable: true, |
| 1121 | // Checks and review. |
| 1122 | "candidate_unavailable": true, |
| 1123 | "no_verdict": true, |
| 1124 | "needs_macos": true, |
| 1125 | "checks_timeout": true, |
| 1126 | "checks_unavailable": true, |
| 1127 | "base_gate_unavailable": true, |
| 1128 | "base_checks_failed": true, |
| 1129 | "preview_secrets": true, |
| 1130 | "preview_headers": true, |
| 1131 | "preview_header_missing": true, |
| 1132 | "preview_scanner": true, |
| 1133 | "preview_public_disabled": true, |
| 1134 | "preview_host": true, |
| 1135 | "needs_network": true, |
| 1136 | // Merge: the branch conflicts with the default branch; the branch is |
| 1137 | // no longer at the judged SHA; the hub's own CI on the commit is not |
| 1138 | // green (still running, or failed); the agent may not merge here; or |
| 1139 | // the hub refused it otherwise. |
| 1140 | "merge_conflict": true, |
| 1141 | "branch_moved": true, |
| 1142 | "amadan_ci_pending": true, |
| 1143 | "amadan_ci_failed": true, |
| 1144 | "merge_forbidden": true, |
| 1145 | "merge_failed": true, |
| 1146 | // The first merge into an empty repository waits on the hub |
| 1147 | // (ReasonMergeUnbornDefault). |
| 1148 | ReasonMergeUnbornDefault: true, |
| 1149 | // merge_not_authorized: the instance refused the merge request's |
| 1150 | // confirmation (merge authority); nothing was sent to the hub. |
| 1151 | "merge_not_authorized": true, |
| 1152 | // The runner has no usable forge credential for the repository and |
| 1153 | // refused the merge itself; nothing was sent to the hub |
| 1154 | // (ReasonMergeCredential). |
| 1155 | ReasonMergeCredential: true, |
| 1156 | // The hub could not confirm write access in time; nothing was sent |
| 1157 | // (ReasonAmadanUnreachable). |
| 1158 | ReasonAmadanUnreachable: true, |
| 1159 | // Previews (protocol 9): the runner is too old (settled at its |
| 1160 | // connection); the account's 20 temporary apps are taken; the task's |
| 1161 | // preview expired and its name is still in the Trash; the config is |
| 1162 | // not one this version uses; the output is over its caps; the |
| 1163 | // preview's state could not be read; a Carloku command failed. |
| 1164 | ReasonRunnerOutdated: true, |
| 1165 | "preview_cap": true, |
| 1166 | "preview_expired": true, |
| 1167 | "preview_config": true, |
| 1168 | "preview_too_large": true, |
| 1169 | "preview_state": true, |
| 1170 | "preview_failed": true, |
| 1171 | // Publishing a site (protocol 16): the runner has no site host; the |
| 1172 | // merged commit is not on the default branch; the config or output is |
| 1173 | // refused or over its caps; the deploy failed. |
| 1174 | "publish_off": true, |
| 1175 | "publish_not_merged": true, |
| 1176 | "publish_config": true, |
| 1177 | "publish_too_large": true, |
| 1178 | "publish_failed": true, |
| 1179 | // The account already holds the app's name: nothing was deployed. |
| 1180 | "publish_app_taken": true, |
| 1181 | // Places (protocol 31). |
| 1182 | "carlos_outdated": true, |
| 1183 | "publish_secrets": true, |
| 1184 | "publish_scanner": true, |
| 1185 | "publish_key_missing": true, |
| 1186 | "publish_mint_failed": true, |
| 1187 | "publish_app_missing": true, |
| 1188 | "publish_app_unproven": true, |
| 1189 | // Connections: the provider refused on quota and no other connection |
| 1190 | // could take the attempt over (limited); nothing the person connected |
| 1191 | // can run this specialist (no_connection). |
| 1192 | "limited": true, |
| 1193 | ReasonNoConnection: true, |
| 1194 | // Runners (protocol 2): the runner lacks a need of the step; the |
| 1195 | // attempt was withdrawn before it started; a pack transfer was |
| 1196 | // refused; the runner that fits was offline too long (checks). |
| 1197 | "placement_refused": true, |
| 1198 | "withdrawn": true, |
| 1199 | // The Mac's sandbox is not proven and nobody chose to run outside it: |
| 1200 | // nothing ran (protocol 7). |
| 1201 | ReasonSandboxUnproven: true, |
| 1202 | "transfer_refused": true, |
| 1203 | "runner_offline": true, |
| 1204 | // Mac Engineering (slice F): the primary could not resolve the base of |
| 1205 | // an attempt on a worker; nothing ran. Its commits were too large to |
| 1206 | // relay to the Mac (workspace_too_large); it never runs on Linux. |
| 1207 | ReasonBaseUnavailable: true, |
| 1208 | ReasonWorkspaceTooLarge: true, |
| 1209 | // A worker found one of its known secrets (or gitleaks found a |
| 1210 | // secret) in the candidate, or could not tell: nothing was uploaded. |
| 1211 | // It could not launch Engineering as certified: nothing ran |
| 1212 | // (slice F task 12). |
| 1213 | ReasonSecretInCandidate: true, |
| 1214 | ReasonEngineeringUnavailable: true, |
| 1215 | // machine_removed: the runner was removed while the step may have been |
| 1216 | // running; nothing proves its end (only Recover settles it). |
| 1217 | "machine_removed": true, |
| 1218 | // Research (protocol 13): nothing to read, no usable grant, a |
| 1219 | // primary too old for it, or one with no address to confirm. |
| 1220 | ReasonResearchNoSources: true, |
| 1221 | ReasonResearchNoGrant: true, |
| 1222 | ReasonResearchUnsupported: true, |
| 1223 | ReasonResearchNoInventory: true, |
| 1224 | // ReasonUnknown is what the instance records for a reason it does not |
| 1225 | // know (a newer runner), rather than refusing the report. |
| 1226 | ReasonUnknown: true, |
| 1227 | } |
| 1228 | |
| 1229 | // ReasonUnknown stands in for a step reason the instance does not know. |
| 1230 | const ReasonUnknown = "unknown" |
| 1231 | |
| 1232 | // ReasonSandboxUnproven is a Mac worker's refusal to run checks outside a |
| 1233 | // sandbox it has not proven, without the person's choice: nothing ran and |
| 1234 | // the Mac is not tainted. The instance puts the step back to wait. |
| 1235 | const ReasonSandboxUnproven = "sandbox_unproven" |
| 1236 | |
| 1237 | // Coordinator tools for tasks. |
| 1238 | const ( |
| 1239 | ToolRecordTask = "record_task" |
| 1240 | ToolAddFinding = "add_finding" |
| 1241 | ToolStartTask = "start_task" |
| 1242 | ToolReadTask = "read_task" |
| 1243 | ToolCancelTask = "cancel_task" |
| 1244 | // ToolAddReport attaches the person's new report to an existing open |
| 1245 | // task instead of recording a duplicate. |
| 1246 | ToolAddReport = "add_report" |
| 1247 | ) |
| 1248 | |
| 1249 | // MaxSimilarTasks bounds the open tasks record_task returns as possibly |
| 1250 | // the same problem. |
| 1251 | const MaxSimilarTasks = 3 |
| 1252 | |
| 1253 | // ReasonMergeUnbornDefault: the hub refused a merge step because the |
| 1254 | // repository's default branch has no commits yet and the hub cannot make |
| 1255 | // the first merge (before amadan#139). Nothing merged; it waits on the |
| 1256 | // platform, never retried on its own (protocol 8). |
| 1257 | const ReasonMergeUnbornDefault = "merge_unborn_default" |
| 1258 | |
| 1259 | // ReasonMergeCredential: the runner refused a merge step before contacting |
| 1260 | // the hub because no forge credential it holds serves the repository. A |
| 1261 | // definite refusal: nothing was sent, and a later Merge may try again |
| 1262 | // once the credential is there. An older instance records it as unknown. |
| 1263 | const ReasonMergeCredential = "merge_credential" |
| 1264 | |
| 1265 | // ReasonAmadanUnreachable: the hub could not be asked whether the runner |
| 1266 | // may still write to the repository, for longer than the merge waits. |
| 1267 | // Nothing was sent; a later Merge may try again. An older instance records |
| 1268 | // it as unknown. |
| 1269 | const ReasonAmadanUnreachable = "amadan_unreachable" |
| 1270 | |
| 1271 | // Maker is a data-defined specialist that makes a task's work: its id |
| 1272 | // (GET /api/v1/specialists) and its profile (design-v1). |
| 1273 | type Maker struct { |
| 1274 | ID string `json:"id"` |
| 1275 | Profile string `json:"profile"` |
| 1276 | } |
| 1277 | |
| 1278 | // Category is the specialist a maker is, as the apps name one: its |
| 1279 | // profile without the version (design for design-v1). |
| 1280 | func (m *Maker) Category() string { |
| 1281 | if m == nil { |
| 1282 | return "" |
| 1283 | } |
| 1284 | if i := strings.LastIndex(m.Profile, "-v"); i > 0 { |
| 1285 | return m.Profile[:i] |
| 1286 | } |
| 1287 | return m.Profile |
| 1288 | } |
| 1289 | |