| 1 | package wire |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // Housekeeping is Equipo's tidying loop (spec |
| 6 | // 2026-11-08-equipo-housekeeping.md): detectors notice things, a ledger |
| 7 | // with a state machine records what each finding became, and everything |
| 8 | // the loop does leaves a receipt with Undo. These are its person API v1 |
| 9 | // resources and events. |
| 10 | |
| 11 | // EventHousekeeping tells the person their housekeeping changed: resource |
| 12 | // "action" carries a HousekeepingAction, resource "housekeeping" a |
| 13 | // HousekeepingSummary (Pause, a detector switched). |
| 14 | const EventHousekeeping = "housekeeping" |
| 15 | |
| 16 | // CardHousekeeping is the daily digest line in the conversation (State |
| 17 | // CardDigest, Question the line). The combined card, a receipt with |
| 18 | // Undo, keeps its kind and carries ActionID and VisibleAt. |
| 19 | const ( |
| 20 | CardHousekeeping = "housekeeping" |
| 21 | CardDigest = "digest" |
| 22 | ) |
| 23 | |
| 24 | // Action states: the ledger's state machine. A row only moves forward. |
| 25 | const ( |
| 26 | ActionClaimed = "claimed" |
| 27 | ActionHeld = "held" |
| 28 | ActionDone = "done" |
| 29 | ActionUndone = "undone" |
| 30 | ActionRefused = "refused" |
| 31 | ActionFailed = "failed" |
| 32 | ActionVetoed = "vetoed" |
| 33 | ActionExpired = "expired" |
| 34 | ) |
| 35 | |
| 36 | // Reasons on an action. |
| 37 | const ( |
| 38 | // ReasonHousekeepingForbidden: the housekeeping principal failed a |
| 39 | // check in the store; nothing it tried survived. |
| 40 | ReasonHousekeepingForbidden = "housekeeping_forbidden" |
| 41 | // ReasonSubjectMoved: the subject changed while the finding waited. |
| 42 | ReasonSubjectMoved = "subject_moved" |
| 43 | // ReasonHeldBudget, ReasonHeldCeiling, ReasonHeldStandDown: why a |
| 44 | // finding is held. |
| 45 | ReasonHeldBudget = "budget" |
| 46 | ReasonHeldCeiling = "ceiling" |
| 47 | ReasonHeldStandDown = "stand_down" |
| 48 | // ReasonHeldOverflow: more held findings than a person keeps. |
| 49 | ReasonHeldOverflow = "held_overflow" |
| 50 | // ReasonDetectorFailures: a detector switched off for the person after |
| 51 | // two failures (Undos count) within seven days. |
| 52 | ReasonDetectorFailures = "failures" |
| 53 | ) |
| 54 | |
| 55 | // Housekeeping is GET /api/v1/housekeeping: the person's own loop. |
| 56 | type Housekeeping struct { |
| 57 | Paused bool `json:"paused"` |
| 58 | // Quiet is the person's quiet hours: receipts made in them wait. |
| 59 | Quiet QuietHours `json:"quiet"` |
| 60 | Budget HousekeepingBudget `json:"budget"` |
| 61 | Detectors []HousekeepingDetector `json:"detectors"` |
| 62 | // Actions are the newest actions, newest first; Refusals the newest |
| 63 | // refused and failed rows. |
| 64 | Actions []HousekeepingAction `json:"actions"` |
| 65 | Refusals []HousekeepingAction `json:"refusals"` |
| 66 | Revision int64 `json:"revision"` |
| 67 | } |
| 68 | |
| 69 | // HousekeepingBudget is today's three budgets, reserved and charged. |
| 70 | type HousekeepingBudget struct { |
| 71 | Turns BudgetMeter `json:"turns"` |
| 72 | Tokens BudgetMeter `json:"tokens"` |
| 73 | Retries BudgetMeter `json:"retries"` |
| 74 | } |
| 75 | |
| 76 | // BudgetMeter is one of the day's budgets. |
| 77 | type BudgetMeter struct { |
| 78 | Reserved int64 `json:"reserved"` |
| 79 | Charged int64 `json:"charged"` |
| 80 | Limit int64 `json:"limit"` |
| 81 | } |
| 82 | |
| 83 | // HousekeepingDetector is one detector as the person sees it. |
| 84 | type HousekeepingDetector struct { |
| 85 | ID string `json:"id"` |
| 86 | Class string `json:"class"` |
| 87 | Enabled bool `json:"enabled"` |
| 88 | DisabledReason string `json:"disabled_reason"` |
| 89 | DisabledAt *time.Time `json:"disabled_at"` |
| 90 | } |
| 91 | |
| 92 | // HousekeepingSubject is what an action is about. |
| 93 | type HousekeepingSubject struct { |
| 94 | Kind string `json:"kind"` |
| 95 | ID string `json:"id"` |
| 96 | } |
| 97 | |
| 98 | // HousekeepingEvidence is structured, never prose: the tasks the finding |
| 99 | // is about, how alike they read and how many words they share. |
| 100 | type HousekeepingEvidence struct { |
| 101 | Tasks []TaskRef `json:"tasks"` |
| 102 | Similarity float64 `json:"similarity"` |
| 103 | Shared int `json:"shared"` |
| 104 | } |
| 105 | |
| 106 | // HousekeepingAction is one ledger row: what a finding became. |
| 107 | type HousekeepingAction struct { |
| 108 | ID string `json:"id"` |
| 109 | Revision int64 `json:"revision"` |
| 110 | Detector string `json:"detector"` |
| 111 | Class string `json:"class"` |
| 112 | State string `json:"state"` |
| 113 | Reason string `json:"reason"` |
| 114 | Subject HousekeepingSubject `json:"subject"` |
| 115 | Evidence HousekeepingEvidence `json:"evidence"` |
| 116 | // Undoable: Undo is offered now; UndoUntil is when it stops. |
| 117 | Undoable bool `json:"undoable"` |
| 118 | UndoUntil *time.Time `json:"undo_until"` |
| 119 | // VisibleAt is when its receipt shows in the conversation (quiet |
| 120 | // hours); null when it showed at once. |
| 121 | VisibleAt *time.Time `json:"visible_at"` |
| 122 | At time.Time `json:"at"` |
| 123 | UndoneAt *time.Time `json:"undone_at"` |
| 124 | } |
| 125 | |
| 126 | // HousekeepingActions is GET /api/v1/housekeeping/actions?before=&limit=. |
| 127 | type HousekeepingActions struct { |
| 128 | Items []HousekeepingAction `json:"items"` |
| 129 | Before string `json:"before"` |
| 130 | } |
| 131 | |
| 132 | // SetHousekeeping is PUT /api/v1/housekeeping: Pause, and quiet hours |
| 133 | // when given. |
| 134 | type SetHousekeeping struct { |
| 135 | Paused bool `json:"paused"` |
| 136 | Quiet *QuietHours `json:"quiet,omitempty"` |
| 137 | Revision int64 `json:"revision"` |
| 138 | } |
| 139 | |
| 140 | // QuietHours is a window in whole hours (0 to 23) of the person's zone, |
| 141 | // UTC until a zone is known; From equal to Until is none. The default is |
| 142 | // 22 to 8. |
| 143 | type QuietHours struct { |
| 144 | From int `json:"from"` |
| 145 | Until int `json:"until"` |
| 146 | } |
| 147 | |
| 148 | // SetDetector is PUT /api/v1/housekeeping/detectors/{id}. |
| 149 | type SetDetector struct { |
| 150 | Enabled bool `json:"enabled"` |
| 151 | Revision int64 `json:"revision"` |
| 152 | } |
| 153 | |
| 154 | // HousekeepingSummary is Snapshot.housekeeping_summary and the data of a |
| 155 | // housekeeping event with resource "housekeeping". |
| 156 | type HousekeepingSummary struct { |
| 157 | OpenSuggestions int `json:"open_suggestions"` |
| 158 | Paused bool `json:"paused"` |
| 159 | Disabled []string `json:"disabled"` |
| 160 | Revision int64 `json:"revision"` |
| 161 | } |
| 162 | |
| 163 | // ActionConflict is the 409 body of an Undo that can no longer apply: |
| 164 | // the action as it is now. |
| 165 | type ActionConflict struct { |
| 166 | Code string `json:"code"` |
| 167 | CopyKey string `json:"copy_key"` |
| 168 | RequestID string `json:"request_id"` |
| 169 | Action HousekeepingAction `json:"action"` |
| 170 | } |
| 171 | |