package wire import ( "regexp" "time" ) // Asking the implementer (Paul, 2026-11-07): from a task's page its // creator asks the specialist that did the work a question, and the // answer streams into the task's thread. The runner resumes that step's // own session, read-only, in a fresh tree of the commit the step made or // judged. The coordinator never relays technical detail; it points here. // Question states. A question ends in exactly one of answered, failed or // cancelled. One question of a task runs at a time; later ones queue. const ( QuestionQueued = "queued" QuestionRunning = "running" QuestionAnswered = "answered" QuestionFailed = "failed" QuestionCancelled = "cancelled" ) // QuestionTerminal reports whether a question has ended. func QuestionTerminal(state string) bool { return state == QuestionAnswered || state == QuestionFailed || state == QuestionCancelled } // EventQuestion carries a Question to every active team member. While it // runs, its answer streams as delta and activity events whose resource is // "question" and whose turn_id is the question's id; the answered // question replaces the draft, as a committed message does in the chat. const EventQuestion = "question" // ResourceQuestion is the event resource for a question and its stream. const ResourceQuestion = "question" // Bounds for questions. const ( MaxQuestionText = 4000 MaxAnswerText = 16 << 10 MaxQuestions = 50 ) // Question is one question a task's creator asked a specialist, and its // answer. StepID is the step whose session answers: by default the // newest Engineering step, or the newest Review step when the person // addresses Review. Answer is "" until it is answered. type Question struct { ID string `json:"id"` Revision int64 `json:"revision"` TaskID string `json:"task_id"` StepID string `json:"step_id"` Specialist string `json:"specialist"` Asker string `json:"asker"` Text string `json:"text"` State string `json:"state"` Reason string `json:"reason"` Attempt int64 `json:"attempt"` Answer string `json:"answer"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Timing *TurnTiming `json:"timing"` } // AskQuestion is the body of POST /api/v1/tasks/{id}/questions. // Specialist is "engineering", "review" or "" (Review when the text // addresses it, else Engineering). The same key with another body is 409. // The response is 202 with the Question; POST /api/v1/questions/{id}/ // cancel answers 202 with TaskAccepted, or 409 once it has ended. type AskQuestion struct { Text string `json:"text"` IdempotencyKey string `json:"idempotency_key"` Specialist string `json:"specialist"` } var reviewWord = regexp.MustCompile(`(?i)\breview(?:er|ers|ed|ing|s)?\b`) // AddressesReview reports whether a question with no chosen specialist // goes to Review: the person addresses Review or asks about the review. func AddressesReview(text string) bool { return reviewWord.MatchString(text) } // Frames for questions. ask and cancel_ask go to the runner; answer // comes back; forget_task tells the runner a task ended, so it can // delete the sessions it kept for the task's steps. const ( FrameAsk = "ask" FrameCancelAsk = "cancel_ask" FrameAnswer = "answer" FrameForgetTask = "forget_task" ) // AskCommand asks the step's own session one question. CandidateSHA is // the commit the step made (Engineering) or judged (Review); BaseSHA the // task's base, for the change. The runner keeps the session id and its // account; neither leaves the runner. type AskCommand struct { Person string `json:"person"` TaskID string `json:"task_id"` StepID string `json:"step_id"` QuestionID string `json:"question_id"` Attempt int64 `json:"attempt"` Specialist string `json:"specialist"` Repo string `json:"repo"` Branch string `json:"branch"` BaseSHA string `json:"base_sha"` CandidateSHA string `json:"candidate_sha"` Title string `json:"title"` Text string `json:"text"` // Protocol 37: the Engineering attempt, account and kept session the // question resumes, frozen when it was created (exact pinning). EngAttempt int64 `json:"eng_attempt,omitempty"` EngAccount string `json:"eng_account,omitempty"` EngSession string `json:"eng_session,omitempty"` } // CancelAskCommand stops one attempt of a question. type CancelAskCommand struct { Person string `json:"person"` TaskID string `json:"task_id"` QuestionID string `json:"question_id"` Attempt int64 `json:"attempt"` } // AnswerReport moves a question forward: running when its session // starts, then answered with the text, or failed or cancelled with a // reason from AnswerReasons. type AnswerReport struct { TaskID string `json:"task_id"` QuestionID string `json:"question_id"` Attempt int64 `json:"attempt"` State string `json:"state"` Reason string `json:"reason"` Text string `json:"text"` Timing *TurnTiming `json:"timing"` Usage []Usage `json:"usage"` } // ForgetTaskCommand: the task is done or cancelled. type ForgetTaskCommand struct { Person string `json:"person"` TaskID string `json:"task_id"` // KeepUntil, when set, keeps the task's sessions until then (a merged // task can still be asked about for KeepMergedSessions); null forgets // them now (a cancelled task). KeepUntil *time.Time `json:"keep_until"` // KeepPreview keeps the task's preview running after the task is // forgotten (protocol 19; Encode drops it below). KeepPreview bool `json:"keep_preview,omitempty"` } // KeepMergedSessions is how long a done task's specialists can still be // asked about their work (Paul, 2026-11-08). const KeepMergedSessions = 14 * 24 * time.Hour // AskRun is a question attempt the runner holds, in sync. type AskRun struct { QuestionID string `json:"question_id"` Attempt int64 `json:"attempt"` State string `json:"state"` } // AnswerReasons are the codes a runner may report for a question that // was not answered. session_gone: the step's session is no longer kept // (it ran before sessions were kept, or its retention ended). var AnswerReasons = map[string]bool{ "": true, "cancelled": true, "interrupted": true, "runner_restarted": true, "turn_timeout": true, "provider_failed": true, "provider_rejected": true, "policy_rejected": true, "account_unavailable": true, "sign_in_again": true, "clone_failed": true, "candidate_unavailable": true, "session_gone": true, "superseded": true, "task_ended": true, // limited: the step's own connection is limited by its provider now. "limited": true, // A question held by its metered connection's guard (queued, with // the hold as its reason; ProtocolMetered). HoldBusy: true, HoldBudget: true, HoldSpendUnknown: true, // The question's session model was removed from its connection's // allowed set or is unhealthy (ProtocolModels, ยง16.3): it fails, never // moving to another model. ReasonModelUnavailable: true, }