package wire import "time" // The scheduler (connectors spec 2026-11-12 rev 3.1, §6 to §8, slice S3): // a task's priority and deadline, a held step's hold, Run now's release, // a priority change for a step already sent, and a preference that ends // by itself. ProtocolScheduler carries them; Encode refuses or drops all // of them below it (downgradeScheduler). // Task priorities (§6). The coordinator may set low or normal, and by, // only when it creates a task; every later change and every urgent is // the task creator's own tap. const ( PriorityUrgent = "urgent" PriorityNormal = "normal" PriorityLow = "low" ) // ValidPriority reports whether p is a priority ("" is not: it is read as // normal where a priority is optional). func ValidPriority(p string) bool { return p == PriorityUrgent || p == PriorityNormal || p == PriorityLow } // CoordinatorPriority reports whether the coordinator may set p when it // creates a task: low or normal, never urgent. func CoordinatorPriority(p string) bool { return p == PriorityLow || p == PriorityNormal } // Who set a task's priority and deadline: the coordinator from the // person's message (shown "set from your message"), or the person. const ( PrioritySetByCoordinator = "coordinator" PrioritySetByPerson = "person" ) // Hold reasons a held step reports (§7 rule 5): waiting for headroom on // a subscription, a metered connection at its budget, its spend unknown, // its one slot taken (a kept session held on it), or nothing that can // run the step. // (HoldBusy, HoldBudget and HoldSpendUnknown are the metered guard's, // ProtocolMetered.) const ( HoldHeadroom = "headroom" HoldNoConnection = ReasonNoConnection ) // HoldReasons are the values StepHold.Reason may take. var HoldReasons = map[string]bool{HoldHeadroom: true, HoldBudget: true, HoldSpendUnknown: true, HoldBusy: true, HoldNoConnection: true} // What a held step needs from its person (§8, Needs you): the deadline // check fired, no reset in sight, or nothing can run it. const ( HoldNeedsDeadline = "deadline" HoldNeedsNoReset = "no_reset" HoldNeedsNoConnection = "no_connection" ) // HoldNeeds are the values StepHold.NeedsPerson may take. var HoldNeeds = map[string]bool{"": true, HoldNeedsDeadline: true, HoldNeedsNoReset: true, HoldNeedsNoConnection: true} // NeedsHeld is Task.NeedsYou for a step the scheduler holds where the // person's input changes the outcome. const NeedsHeld = "held" // CardHeld is the Needs you card for a held step: Equipo's // recommendation, with Wait and Run it now. const CardHeld = "held" // Routing reasons the scheduler adds (§10): a kept session, metered work // for an urgent task or a release, and a hold. const ( RoutingSticky = "sticky" RoutingMeteredUrgent = "metered_urgent" RoutingMeteredRelease = "metered_release" RoutingHeld = "held" ) // StepHold is why the runner holds a step (§8): reason, the connection // it names (the runner's local id and its provider, "" for none), that // connection's reported reset, when the runner looks again on its own // (null: only a fact change wakes it), what it needs from the person, // and the step revision a Run now must name. A step report carries it // while the step is held, with state running (queued on the instance // until it starts); a report without it ends the hold. type StepHold struct { Reason string `json:"reason"` Connection string `json:"connection,omitempty"` Provider string `json:"provider,omitempty"` ResetsAt *time.Time `json:"resets_at,omitempty"` WakeAt *time.Time `json:"wake_at"` NeedsPerson string `json:"needs_person,omitempty"` StepRevision int64 `json:"step_revision"` } // FrameRelease is Run now (instance to runner, durable, consumed once): // leave for one step revision to start now, metered connections // included, the bars still applying. The runner consumes it atomically // with the admission it causes; it becomes a grant for (step, // step_revision) that covers that revision's failover attempts and ends // with the step. A stale or consumed release is acked and ignored. const FrameRelease = "release" // ReleaseCommand is a release. StepRevision is the dispatch it is for: // the attempt the instance sent (failover attempts the runner makes keep // it). // // Connection (protocol 29) pins it: the runner's local id of the one // connection the person was told Run now would use; the runner admits the // step only there, or keeps holding it. "" is leave on any connection. type ReleaseCommand struct { ID string `json:"id"` Person string `json:"person"` TaskID string `json:"task_id"` StepID string `json:"step_id"` StepRevision int64 `json:"step_revision"` Connection string `json:"connection,omitempty"` } // FramePriority tells the runner a task's priority or deadline changed // (instance to runner, durable): the steps of the task it holds take it. // A revision at or below the one held changes nothing. const FramePriority = "priority" // PriorityCommand is a priority change for the runner. Revision is the // task's priority revision (DispatchCommand.PriorityRevision orders the // same values). type PriorityCommand struct { Person string `json:"person"` TaskID string `json:"task_id"` Priority string `json:"priority"` By *time.Time `json:"by"` Revision int64 `json:"revision"` } // SetPriority is PUT /api/v1/tasks/{id}/priority: the task creator's // priority and deadline (by null clears it), against the task's // revision. type SetPriority struct { Priority string `json:"priority"` By *time.Time `json:"by"` Revision int64 `json:"revision"` } // RunNow is POST /api/v1/tasks/{id}/run-now: the task creator's leave // for the held step at the revision its hold shows. Offer is what the // page showed (paused work review R1): the offer's connection // (RunNowOffer.Connection), or RunNowPlain for plain Run now. When Run // now would do anything else now, the tap is refused (409 // offer_changed) and the page shows the offer as it is. type RunNow struct { Step string `json:"step"` StepRevision int64 `json:"step_revision"` Offer string `json:"offer,omitempty"` } // RunNowPlain is RunNow.Offer for plain "Run it now anyway". const RunNowPlain = "plain" // RunNowAccepted answers Run now: the release written. A second Run now // for the same step revision is refused (409 already_running). type RunNowAccepted struct { Release string `json:"release"` } // TaskPriority is a task's priority on its read shape: the priority, // the deadline, who set them and whether the deadline check fired. type TaskPriority struct { Priority string `json:"priority"` By *time.Time `json:"by"` SetBy string `json:"set_by"` } // MaxByAhead bounds a deadline: at most a year ahead. const MaxByAhead = 366 * 24 * time.Hour // StepPaused is what the instance knows of a waiting step beyond the // runner's hold (paused work, 2026-11-24). Since is when the hold began, // or, for a step whose runner is offline (Offline), when that runner was // last seen. UsedPercent is the held subscription's fullest window as // last read (100 when it is limited), absent when unknown. RunNow is what // Run now would do, absent when it would do nothing or the instance // cannot tell. type StepPaused struct { Since *time.Time `json:"since,omitempty"` Offline bool `json:"offline,omitempty"` UsedPercent *int `json:"used_percent,omitempty"` RunNow *RunNowOffer `json:"run_now,omitempty"` } // RunNowOffer is the instance's prediction of Run now for a held step: // the scheduler's own rule (schedule.Decide) with Run now's leave, over // the task creator's connections on the step's runner as last read. // Connection is the connection's id (cn_…), Name how Equipo names it // ("Codex"), Billing subscription or metered. Same: it is the connection // the hold names, whose last share it would use; LeftPercent is what is // left of that one's fullest window. type RunNowOffer struct { Connection string `json:"connection,omitempty"` Provider string `json:"provider,omitempty"` Name string `json:"name,omitempty"` Billing string `json:"billing,omitempty"` Same bool `json:"same,omitempty"` LeftPercent int `json:"left_percent,omitempty"` // Plain: the runner is below protocol 29 and cannot be held to one // connection, so Run now promises nothing (the other fields empty): // "Run it now anyway". MayBill: and a connection that bills per use // could take it. Plain bool `json:"plain,omitempty"` MayBill bool `json:"may_bill,omitempty"` }