chat: merge authority on the instance (gate, fence, cards, Undo, policy)
authorizeMerge decides every merge: autoMerge at Ready (never for a SHA already asked about, nothing queued while the primary is offline), a person's Merge on the card or task page (a failed, ended attempt is tried again), Retry, and the merge step's lease. An automatic merge needs wire.ProtocolMergeFacts at dispatch and at every hub request: a lower protocol is refused and settled, and the decision becomes the ask card worded as Equipo's call. Review change facts are kept only when exactly the attempt's. Equipo's own merges without checks get a receipt, with Undo only for a hub-named merge commit; Undo opens an ordinary revert task and puts the project in ask mode. The ships question asks once per project; set_merge_policy applies only tighter changes alone; hold_merge only stops. Migration 0059 (renumbered on merge). Existing merge contracts move to a protocol 3 runner.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
36 files changed,
+1,739
−110
internal/equipo/app.go+1 −0internal/equipo/chat/housekeeping_store_test.go+11 −3internal/equipo/chat/http.go+39 −0internal/equipo/chat/merge.go+75 −59internal/equipo/chat/mergeauth.go+1,133 −0internal/equipo/chat/models.go+1 −1internal/equipo/chat/projects.go+15 −1internal/equipo/chat/runners.go+13 −1internal/equipo/chat/stream.go+1 −1internal/equipo/chat/tasks.go+54 −5internal/equipo/chat/tools.go+1 −1internal/equipo/chat_page.go+12 −0internal/equipo/copy.go+82 −0internal/equipo/merge_policy_page.go+80 −0internal/equipo/migrations/0059_thin_merge_authority.sql+12 −0internal/equipo/migrations/schema.sql+6 −2internal/equipo/render.go+1 −1internal/equipo/templates/chat.html+1 −0internal/equipo/templates/merge_policy.html+17 −0internal/equipo/templates/work_project.html+1 −0internal/equipo/work_pages.go+11 −3internal/runner/provider/actions.go+1 −1internal/runner/thin/mcp.go+2 −0internal/thintest/authority_contract_test.go+20 −1internal/thintest/gallery_test.go+5 −5internal/thintest/inner_contract_test.go+1 −1internal/thintest/merge_contract_test.go+12 −13internal/thintest/pages_test.go+1 −1internal/thintest/review_contract_test.go+2 −2internal/thintest/tools_contract_test.go+29 −3internal/wire/frames.go+2 −2internal/wire/merge.go+86 −0internal/wire/tasks.go+8 −0internal/wire/wiretest/testdata/api/needs-you.json+1 −1internal/wire/wiretest/testdata/api/task-merged.json+1 −1internal/wire/wiretest/testdata/api/task-ready.json+1 −1
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index 4dbfd7a6..ac66412c 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -224,6 +224,7 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| r.Post("/conversation/tasks/{id}/recover", a.workTaskRecover) |
| r.Post("/tasks/{id}/duplicate", a.workDuplicate) |
| r.Post("/tasks/{id}/uncombine", a.workUncombine) |
| + r.Post("/projects/{id}/merge-policy", a.workMergePolicy) |
| r.Post("/conversation/tasks/{id}/merge", a.workTaskMerge) |
| r.Get("/tasks/new", a.taskForm) |
| r.Get("/tasks/{id}", a.taskDetail) |
diff --git a/internal/equipo/chat/housekeeping_store_test.go b/internal/equipo/chat/housekeeping_store_test.go| index ae07d265..ac04384f 100644 |
| --- a/internal/equipo/chat/housekeeping_store_test.go |
| +++ b/internal/equipo/chat/housekeeping_store_test.go |
| @@ -1,6 +1,7 @@ |
| package chat |
| import ( |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| "context" |
| "encoding/json" |
| "errors" |
| @@ -286,11 +287,18 @@ func TestHousekeepingNever(t *testing.T) { |
| }, |
| "merge": func(t *txn) error { |
| k := r.load(k.ID) |
| - return t.startMerge(&k, progress{}, nil, false) |
| + return t.startMerge(&k, progress{}, nil, false, decidedPolicy) |
| + }, |
| + "a merge policy": func(t *txn) error { |
| + pr, err := t.mergePolicy(k.ProjectID) |
| + if err != nil { |
| + return err |
| + } |
| + return t.savePolicy(&pr, hkOwner) |
| }, |
| "a merge card": func(t *txn) error { |
| k := r.load(k.ID) |
| - return t.askMerge(&k, progress{}, false) |
| + return t.askMerge(&k, progress{}, mergegate.Decision{Class: mergegate.ClassAsk}) |
| }, |
| "a setting": func(t *txn) error { _, err := t.setSetting("project_home", "x", hkOwner); return err }, |
| "another's notebook": func(t *txn) error { return t.saveNotebook(hkMember, nil) }, |
| @@ -377,7 +385,7 @@ func TestHousekeepingNever(t *testing.T) { |
| for name, act := range map[string]func(*txn, *hkRecord, housekeeping.Finding) (hkResult, error){ |
| "merge": func(t *txn, _ *hkRecord, _ housekeeping.Finding) (hkResult, error) { |
| k := r.load(k.ID) |
| - return hkResult{}, t.startMerge(&k, progress{}, nil, false) |
| + return hkResult{}, t.startMerge(&k, progress{}, nil, false, decidedPolicy) |
| }, |
| "delete": func(t *txn, _ *hkRecord, _ housekeeping.Finding) (hkResult, error) { |
| _, err := t.removeProject(hkOwner, "p1") |
diff --git a/internal/equipo/chat/http.go b/internal/equipo/chat/http.go| index bcad38cc..612244b5 100644 |
| --- a/internal/equipo/chat/http.go |
| +++ b/internal/equipo/chat/http.go |
| @@ -81,6 +81,9 @@ func (h *HTTP) Mount(r chi.Router) { |
| r.Post("/tasks/{id}/recover", h.bearer(h.recoverTask)) |
| r.Post("/tasks/{id}/duplicate", h.bearer(h.markDuplicate)) |
| r.Post("/tasks/{id}/merge", h.bearer(h.mergeTask)) |
| + r.Post("/tasks/{id}/undo-merge", h.bearer(h.undoMerge)) |
| + r.Get("/projects/{id}/merge-policy", h.bearer(h.mergePolicy)) |
| + r.Put("/projects/{id}/merge-policy", h.bearer(h.setMergePolicy)) |
| r.Post("/tasks/{id}/uncombine", h.bearer(h.uncombineTask)) |
| r.Post("/tasks/{id}/thread", h.bearer(h.postThread)) |
| r.Get("/steps/{id}/log", h.bearer(h.stepLog)) |
| @@ -296,6 +299,8 @@ func (h *HTTP) fail(w http.ResponseWriter, r *http.Request, err error) { |
| personapi.WriteError(w, r, 409, "not_retryable", nil) |
| case errors.Is(err, ErrNotMergeable): |
| personapi.WriteError(w, r, 409, "not_mergeable", nil) |
| + case errors.Is(err, ErrNotUndoable): |
| + personapi.WriteError(w, r, 409, "not_undoable", nil) |
| case errors.Is(err, ErrMerging): |
| personapi.WriteError(w, r, 409, "task_merging", nil) |
| case errors.Is(err, ErrNotAskable): |
| @@ -686,6 +691,40 @@ func (h *HTTP) mergeTask(w http.ResponseWriter, r *http.Request, p personapi.Per |
| writeJSON(w, http.StatusAccepted, wire.TaskAccepted{Attempt: attempt}) |
| } |
| +// undoMerge is the creator's Undo of Equipo's own merge: an ordinary |
| +// revert task, returned. |
| +func (h *HTTP) undoMerge(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| + out, err := h.Store.UndoMerge(r.Context(), p.Address, chi.URLParam(r, "id")) |
| + if err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + writeJSON(w, http.StatusCreated, out) |
| +} |
| + |
| +func (h *HTTP) mergePolicy(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| + out, err := h.Store.MergePolicy(r.Context(), p.Address, chi.URLParam(r, "id")) |
| + if err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + writeJSON(w, 200, out) |
| +} |
| + |
| +func (h *HTTP) setMergePolicy(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| + var in wire.SetMergePolicy |
| + if err := readJSON(r, &in); err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + out, err := h.Store.SetMergePolicy(r.Context(), p.Address, chi.URLParam(r, "id"), in) |
| + if err != nil { |
| + h.fail(w, r, err) |
| + return |
| + } |
| + writeJSON(w, 200, out) |
| +} |
| + |
| func (h *HTTP) postThread(w http.ResponseWriter, r *http.Request, p personapi.PersonPrincipal) { |
| var in wire.PostThread |
| if err := readJSON(r, &in); err != nil { |
diff --git a/internal/equipo/chat/merge.go b/internal/equipo/chat/merge.go| index b396d4ae..bbe7ed8a 100644 |
| --- a/internal/equipo/chat/merge.go |
| +++ b/internal/equipo/chat/merge.go |
| @@ -9,6 +9,7 @@ import ( |
| "strings" |
| "amadan.net/oficina/equipo/internal/equipo/housekeeping" |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| "amadan.net/oficina/equipo/internal/wire" |
| "gorm.io/gorm" |
| ) |
| @@ -24,14 +25,6 @@ import ( |
| // candidate is checked and reviewed afresh; only a judged SHA is ever |
| // merged, and the runner checks the head again right before. |
| -// mergeChoices are the merge card's options: merging without checks |
| -// (Merge, Wait for checks), or adopting a candidate that was Ready before |
| -// Equipo merged on its own (Merge, Not now). |
| -var ( |
| - mergeChoices = []string{wire.ChoiceMerge, wire.ChoiceWait} |
| - adoptChoices = []string{wire.ChoiceMerge, wire.ChoiceNotNow} |
| -) |
| - |
| // merging reports whether s is a merge of the judged candidate the |
| // policy allows: approved, and checks passed or the person chose to |
| // merge without them. |
| @@ -51,63 +44,67 @@ func (p progress) checksOutsideSandbox() bool { |
| return p.checks != nil && p.checks.ChecksSandbox == wire.SandboxNone |
| } |
| -// autoMerge is the policy at Ready to merge: merge a fully judged SHA, |
| -// or ask once whether to merge one whose checks could not run. |
| -func (t *txn) autoMerge(k *taskRecord, p progress, steps []stepRecord) error { |
| - if p.merge != nil { |
| - // A merge of this SHA ran or runs; its report decides. |
| - return nil |
| - } |
| - if p.mergeAllowed(false) && k.MergeEligible == p.candidate && !p.checksOutsideSandbox() { |
| - return t.startMerge(k, p, steps, false) |
| - } |
| - checks, _, verdict, _ := p.judged() |
| - if verdict != wire.VerdictApprove || p.moved || k.MergeAsked == p.candidate { |
| - return nil |
| - } |
| - switch checks { |
| - case wire.ChecksCannotRun, wire.ChecksNone: |
| - return t.askMerge(k, p, false) |
| - case wire.ChecksPassed: |
| - // Ready before Equipo merged on its own: the person adopts it. |
| - return t.askMerge(k, p, true) |
| - } |
| - return nil |
| -} |
| - |
| -// startMerge dispatches the merge step for the judged candidate. |
| -func (t *txn) startMerge(k *taskRecord, p progress, steps []stepRecord, withoutChecks bool) error { |
| +// startMerge dispatches the merge step for the judged candidate, decided |
| +// by decidedBy ("policy" or "person:<address>"). Only authorizeMerge's act |
| +// leads here (autoMerge, the card's Merge, MergeTask, Retry). |
| +func (t *txn) startMerge(k *taskRecord, p progress, steps []stepRecord, withoutChecks bool, decidedBy string) error { |
| // Housekeeping never merges. |
| if err := t.hkForbid("merge"); err != nil { |
| return err |
| } |
| - s := stepRecord{Specialist: wire.SpecialistMerge, Person: p.eng.Person, Round: p.eng.Round, BaseSHA: k.BaseSHA, CandidateSHA: p.candidate, WithoutChecks: withoutChecks} |
| + if p.eng == nil || p.candidate == "" || p.moved { |
| + return ErrNotMergeable |
| + } |
| + s := stepRecord{Specialist: wire.SpecialistMerge, Person: p.eng.Person, Round: p.eng.Round, BaseSHA: k.BaseSHA, CandidateSHA: p.candidate, WithoutChecks: withoutChecks, DecidedBy: decidedBy} |
| k.Stage = wire.StageMerging |
| return t.nextStep(k, steps, s) |
| } |
| -// askMerge puts the one merge card in the creator's conversation: merge |
| -// without checks, or (adopt) merge a candidate that was Ready already. |
| -func (t *txn) askMerge(k *taskRecord, p progress, adopt bool) error { |
| - // Nor opens a merge card. |
| - if err := t.hkForbid("merge card"); err != nil { |
| +// personMerge is a person's Merge of the judged candidate (card, task |
| +// page): decided through authorizeMerge, then a new merge step, or the |
| +// failed, ended one attempted again. |
| +func (t *txn) personMerge(k *taskRecord, p progress, steps []stepRecord, person string) error { |
| + online, protocol, err := t.primaryState(p.eng.Person) |
| + if err != nil { |
| return err |
| } |
| - now := t.now() |
| - choices, question := mergeChoices, t.words("chat.card.merge_question", k.Title) |
| - if adopt { |
| - choices, question = adoptChoices, t.words("chat.card.merge_adopt", k.Title) |
| + if !online { |
| + protocol = 0 |
| } |
| - opts, _ := json.Marshal(choices) |
| - c := cardRecord{ID: newID("c_"), Person: k.Creator, Kind: wire.CardMerge, State: wire.CardOpen, ProjectID: k.ProjectID, TaskID: k.ID, Name: k.Title, Question: question, Options: string(opts), Revision: 1, CreatedAt: now, UpdatedAt: now} |
| - if err := t.db.Create(&c).Error; err != nil { |
| + d, err := t.authorizeMerge(k, p, atDispatch, person, protocol) |
| + if err != nil { |
| return err |
| } |
| - k.MergeAsked = p.candidate |
| - if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("merge_asked", p.candidate).Error; err != nil { |
| + if d.Class != mergegate.ClassAct || d.DecidedBy != mergegate.DecidedPerson { |
| + return ErrNotMergeable |
| + } |
| + checks, _, _, _ := p.judged() |
| + if checks == wire.ChecksPassed { |
| + k.MergeEligible = p.candidate |
| + } |
| + if m := p.merge; m != nil { |
| + if m.State != wire.StepFailed || !m.Terminated { |
| + return ErrNotMergeable |
| + } |
| + return t.retryMerge(k, m, decidedPerson+person, checks != wire.ChecksPassed) |
| + } |
| + return t.startMerge(k, p, steps, checks != wire.ChecksPassed, decidedPerson+person) |
| +} |
| + |
| +// retryMerge runs a failed, ended merge step again as its next attempt. |
| +func (t *txn) retryMerge(k *taskRecord, st *stepRecord, decidedBy string, withoutChecks bool) error { |
| + if err := t.hkForbid("merge"); err != nil { |
| + return err |
| + } |
| + st.Attempt++ |
| + st.State, st.Reason, st.Terminated, st.Summary, st.LogTail, st.StartedAt, st.FinishedAt, st.Headline, st.Activity = wire.StepQueued, "", false, "", "", nil, nil, "", "" |
| + st.MergeSHA, st.MergeInto, st.MergeStrategy, st.MergeSource, st.MergeParents = "", "", "", "", "" |
| + st.Withdrawn, st.RefusedBy, st.DecidedBy, st.WithoutChecks = false, "", decidedBy, withoutChecks |
| + k.Stage = wire.StageMerging |
| + if err := t.dispatchStep(k, st); err != nil { |
| return err |
| } |
| - return t.cardEvent(c) |
| + return t.saveStep(st, k) |
| } |
| // answerMerge is the creator's answer on a merge card: Merge merges the |
| @@ -147,7 +144,7 @@ func (t *txn) answerMerge(person string, c cardRecord, in wire.AnswerCard) (wire |
| return wire.Card{}, wire.Card{}, err |
| } |
| p := progressFor(k, steps) |
| - if wire.FinalStage(k.Stage) || k.CancelRequested || k.Stage != wire.StageReadyToMerge || p.candidate != k.MergeAsked || p.merge != nil || !p.mergeAllowed(true) { |
| + if wire.FinalStage(k.Stage) || k.CancelRequested || k.Stage != wire.StageReadyToMerge || p.candidate != k.MergeAsked || !mergeRetryable(p.merge) || !p.mergeAllowed(true) { |
| // Not now: the branch is away from the SHA (the card stays for when |
| // it is back), or the task moved on (withdrawMergeCards resolves |
| // the card for a new candidate or an end). |
| @@ -158,8 +155,9 @@ func (t *txn) answerMerge(person string, c cardRecord, in wire.AnswerCard) (wire |
| return wire.Card{}, wire.Card{}, err |
| } |
| if in.Choice == wire.ChoiceMerge { |
| - checks, _, _, _ := p.judged() |
| - if err := t.startMerge(&k, p, steps, checks != wire.ChecksPassed); err != nil { |
| + if err := t.personMerge(&k, p, steps, person); errors.Is(err, ErrNotMergeable) { |
| + return wire.Card{}, v, ErrCardConflict |
| + } else if err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| } |
| @@ -214,6 +212,22 @@ func (t *txn) mergeDone(k *taskRecord, s *stepRecord, v *wire.StepReport) error |
| if project == "" { |
| project = ProjectTitle(pr.Repo, nil) |
| } |
| + k.MergeVerified = mergeVerified(v, s.CandidateSHA) |
| + parents, _ := json.Marshal(v.MergeParents) |
| + s.MergeSource, s.MergeParents = v.MergeSource, string(parents) |
| + audit := auditMerged |
| + if mergeByPolicy(*s) && s.WithoutChecks && !k.MergeVerified { |
| + audit = auditUnverified |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: k.ProjectID, TaskID: k.ID, Kind: audit, At: "hub", CandidateSHA: s.CandidateSHA, MergeSHA: v.MergeSHA, DecidedBy: s.DecidedBy, Inputs: fmt.Sprintf(`{"source":%q,"parents":%s,"without_checks":%t}`, v.MergeSource, parents, s.WithoutChecks)}); err != nil { |
| + return err |
| + } |
| + if mergeByPolicy(*s) && s.WithoutChecks { |
| + // Equipo's own merge without checks: a receipt, with Undo when the |
| + // hub named the merge commit. |
| + _, err := t.mergeReceipt(k, project, s, k.MergeVerified) |
| + return err |
| + } |
| key := "merged_without_checks" |
| if !s.WithoutChecks { |
| key = "merged" |
| @@ -426,13 +440,19 @@ func reportCount(tx *gorm.DB, id string) (int, error) { |
| return int(n), err |
| } |
| +// mergeRetryable reports whether a person may merge given the newest |
| +// merge step of the candidate: none yet, or one that failed and ended. |
| +func mergeRetryable(m *stepRecord) bool { |
| + return m == nil || m.State == wire.StepFailed && m.Terminated |
| +} |
| + |
| // ErrNotMergeable means the task cannot be merged now: not Ready to |
| // merge, the branch is not at the judged SHA, or a merge ran already. |
| var ErrNotMergeable = errors.New("chat: task not mergeable") |
| // mergeOffered reports whether the creator's Merge action applies now. |
| func (t *txn) mergeOffered(k taskRecord, p progress) (bool, error) { |
| - if k.Stage != wire.StageReadyToMerge || k.CancelRequested || p.moved || p.merge != nil || !p.mergeAllowed(true) { |
| + if k.Stage != wire.StageReadyToMerge || k.CancelRequested || p.moved || !mergeRetryable(p.merge) || !p.mergeAllowed(true) { |
| return false, nil |
| } |
| var open int64 |
| @@ -473,11 +493,7 @@ func (s *Store) MergeTask(ctx context.Context, person, id string) (attempt int64 |
| } else if !ok { |
| return ErrNotMergeable |
| } |
| - checks, _, _, _ := p.judged() |
| - if checks == wire.ChecksPassed { |
| - k.MergeEligible = p.candidate |
| - } |
| - if err := t.startMerge(&k, p, steps, checks != wire.ChecksPassed); err != nil { |
| + if err := t.personMerge(&k, p, steps, person); err != nil { |
| return err |
| } |
| attempt = 1 |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| new file mode 100644 |
| index 00000000..ea901dc0 |
| --- /dev/null |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -0,0 +1,1133 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "slices" |
| + "strings" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/housekeeping" |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "gorm.io/gorm" |
| +) |
| + |
| +// Merge authority, thin v1 (docs/superpowers/specs/2026-11-11-equipo- |
| +// merge-authority.md, Paul's "Refuse old runners"): one gate, |
| +// authorizeMerge, decides every merge, before the step is dispatched and |
| +// again synchronously right before each hub request (the runner's |
| +// merge_request lease). An automatic merge needs a runner at |
| +// wire.ProtocolMergeFacts at both moments: a lower protocol is refused, |
| +// never downgraded, and the decision becomes an ask card. Nothing is |
| +// queued on a decision; the next natural trigger decides again. Every |
| +// decision writes one audit row. |
| + |
| +// mergePolicyRecord is a project's merge policy (a team record). |
| +type mergePolicyRecord struct { |
| + ProjectID string `gorm:"primaryKey"` |
| + Mode string |
| + ModeReason string |
| + MaxLines int |
| + MaxFiles int |
| + MainShips string |
| + ShipsAnsweredBy string |
| + ShipsAsked bool |
| + ExtraSensitive string |
| + Words string |
| + Revision int64 |
| + UpdatedBy string |
| + UpdatedAt time.Time |
| +} |
| + |
| +func (mergePolicyRecord) TableName() string { return "chat_merge_policies" } |
| + |
| +// mergeAuditRecord is one decision or change, with its reasons, written |
| +// in the transaction of its effect. Append only. |
| +type mergeAuditRecord struct { |
| + ID string `gorm:"primaryKey"` |
| + ProjectID string `gorm:"index:chat_merge_audit_project"` |
| + TaskID string `gorm:"index:chat_merge_audit_task"` |
| + Kind string |
| + At string |
| + CandidateSHA string |
| + MergeSHA string |
| + Class string |
| + Stance string |
| + DecidedBy string |
| + Reasons string |
| + Inputs string |
| + CreatedAt time.Time |
| +} |
| + |
| +func (mergeAuditRecord) TableName() string { return "chat_merge_audit" } |
| + |
| +// Audit kinds and decision moments. |
| +const ( |
| + auditDecision = "decision" |
| + auditMerged = "merged" |
| + auditUnverified = "landed_unverified" |
| + auditUndo = "undo" |
| + auditPolicy = "policy" |
| + auditShips = "ships" |
| + auditHold = "hold" |
| + atDispatch = "dispatch" |
| + atConfirm = "confirm" |
| + atFence = "fence" |
| +) |
| + |
| +// decidedPolicy and decidedPerson prefix a merge step's DecidedBy. |
| +const ( |
| + decidedPolicy = "policy" |
| + decidedPerson = "person:" |
| +) |
| + |
| +// ErrNotUndoable means the merge cannot be undone from here: not Equipo's |
| +// own, its commit not named by the hub, out of the window, or a revert |
| +// exists already. |
| +var ErrNotUndoable = errors.New("chat: merge not undoable") |
| + |
| +func policyOf(r mergePolicyRecord) mergegate.Policy { |
| + p := mergegate.Policy{Mode: r.Mode, MaxLines: r.MaxLines, MaxFiles: r.MaxFiles, MainShips: r.MainShips} |
| + _ = json.Unmarshal([]byte(r.ExtraSensitive), &p.ExtraSensitive) |
| + return p |
| +} |
| + |
| +// mergePolicy is the project's policy row, or the defaults (unsaved, |
| +// revision 0). |
| +func (t *txn) mergePolicy(projectID string) (mergePolicyRecord, error) { |
| + var r mergePolicyRecord |
| + err := t.db.Where("project_id = ?", projectID).First(&r).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + d := mergegate.DefaultPolicy() |
| + return mergePolicyRecord{ProjectID: projectID, Mode: d.Mode, MaxLines: d.MaxLines, MaxFiles: d.MaxFiles, MainShips: d.MainShips, ExtraSensitive: "[]"}, nil |
| + } |
| + return r, err |
| +} |
| + |
| +// savePolicy writes the row with the next revision and touches the |
| +// project's open merge cards, so an answer given under the old policy is |
| +// stale. |
| +func (t *txn) savePolicy(r *mergePolicyRecord, by string) error { |
| + return t.writePolicy(r, by, true) |
| +} |
| + |
| +// writePolicy writes the row; touch refreshes the open merge cards. |
| +func (t *txn) writePolicy(r *mergePolicyRecord, by string, touch bool) error { |
| + if err := t.hkForbid("merge policy"); err != nil { |
| + return err |
| + } |
| + r.Revision++ |
| + r.UpdatedBy, r.UpdatedAt = by, t.now() |
| + if r.ExtraSensitive == "" { |
| + r.ExtraSensitive = "[]" |
| + } |
| + if err := t.db.Save(r).Error; err != nil { |
| + return err |
| + } |
| + if !touch { |
| + return nil |
| + } |
| + var open []cardRecord |
| + if err := t.db.Where("project_id = ? AND kind = ? AND state = ?", r.ProjectID, wire.CardMerge, wire.CardOpen).Find(&open).Error; err != nil { |
| + return err |
| + } |
| + for i := range open { |
| + if err := t.saveCard(&open[i]); err != nil { |
| + return err |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// primaryState is whether the person's primary runner is online now and |
| +// the protocol its connection speaks. |
| +func (t *txn) primaryState(person string) (online bool, protocol int, err error) { |
| + id, err := t.s.authority.PrimaryRunner(t.db, person) |
| + if err != nil || id == "" { |
| + return false, 0, err |
| + } |
| + rs, err := t.runners(person) |
| + if err != nil { |
| + return false, 0, err |
| + } |
| + for _, r := range rs { |
| + if r.ID == id { |
| + return r.Online && !r.Removing, r.Protocol, nil |
| + } |
| + } |
| + return false, 0, nil |
| +} |
| + |
| +// personDecides reports whether address may decide this task's merge: |
| +// its creator, a current owner (read inside the transaction). |
| +func (t *txn) personDecides(k taskRecord, address string) bool { |
| + if address == "" || address != k.Creator { |
| + return false |
| + } |
| + return t.isOwner(address) == nil |
| +} |
| + |
| +// mergeInputs gathers the gate's inputs for the task's newest candidate. |
| +func (t *txn) mergeInputs(k taskRecord, p progress, person bool, protocol int) (mergegate.Inputs, mergePolicyRecord, error) { |
| + pr, err := t.mergePolicy(k.ProjectID) |
| + if err != nil { |
| + return mergegate.Inputs{}, pr, err |
| + } |
| + checks, reason, verdict, _ := p.judged() |
| + in := mergegate.Inputs{Verdict: verdict, Checks: checks, ChecksReason: reason, OutsideSandbox: p.checksOutsideSandbox(), |
| + Eligible: k.MergeEligible != "" && k.MergeEligible == p.candidate, Person: person, Protocol: protocol, Policy: policyOf(pr), Hold: k.MergeHold, RevertSHA: k.RevertSHA} |
| + if !p.moved { |
| + in.Candidate = p.candidate |
| + } |
| + if r := p.review; r != nil && r.ChangeFacts != "" { |
| + var f wire.ChangeFacts |
| + if json.Unmarshal([]byte(r.ChangeFacts), &f) == nil && f.SHA == p.candidate { |
| + in.Change = &f |
| + } |
| + } |
| + return in, pr, nil |
| +} |
| + |
| +// authorizeMerge is the one door: it decides the task's merge now, at the |
| +// moment named by at, writes the audit row and returns the decision. |
| +// person is the address that chose Merge ("" for Equipo's own decision); |
| +// protocol the primary's connection's. |
| +func (t *txn) authorizeMerge(k *taskRecord, p progress, at, person string, protocol int) (mergegate.Decision, error) { |
| + decides := t.personDecides(*k, person) |
| + in, _, err := t.mergeInputs(*k, p, decides, protocol) |
| + if err != nil { |
| + return mergegate.Decision{}, err |
| + } |
| + d := mergegate.Decide(in) |
| + by := "" |
| + switch { |
| + case d.Class == mergegate.ClassAct && decides: |
| + by = decidedPerson + person |
| + case d.Class == mergegate.ClassAct: |
| + by = decidedPolicy |
| + } |
| + return d, t.auditDecision(*k, in, d, auditDecision, at, by) |
| +} |
| + |
| +// auditDecision writes one decision's row. |
| +func (t *txn) auditDecision(k taskRecord, in mergegate.Inputs, d mergegate.Decision, kind, at, by string) error { |
| + reasons, _ := json.Marshal(d.Reasons) |
| + type facts struct { |
| + Files, Lines, Binary int |
| + Special, Signing bool |
| + Matched []mergegate.Match `json:",omitempty"` |
| + } |
| + inputs := map[string]any{"checks": in.Checks, "checks_reason": in.ChecksReason, "protocol": in.Protocol, "policy": in.Policy, "hold": in.Hold, "person": in.Person, "eligible": in.Eligible} |
| + if c := in.Change; c != nil { |
| + matched := d.Sensitive |
| + if len(matched) > 10 { |
| + matched = matched[:10] |
| + } |
| + inputs["change"] = facts{c.Files, c.Lines, c.Binary, c.Special, c.Signing, matched} |
| + } |
| + raw, _ := json.Marshal(inputs) |
| + return t.auditRow(mergeAuditRecord{ProjectID: k.ProjectID, TaskID: k.ID, Kind: kind, At: at, CandidateSHA: in.Candidate, Class: d.Class, Stance: d.Stance, DecidedBy: by, Reasons: string(reasons), Inputs: string(raw)}) |
| +} |
| + |
| +func (t *txn) auditRow(a mergeAuditRecord) error { |
| + a.ID, a.CreatedAt = newID("ma_"), t.now() |
| + if a.Reasons == "" { |
| + a.Reasons = "[]" |
| + } |
| + if a.Inputs == "" { |
| + a.Inputs = "{}" |
| + } |
| + return t.db.Create(&a).Error |
| +} |
| + |
| +// autoMerge is Equipo's own decision at Ready to merge: never for a SHA |
| +// it already asked about (only the person acts then), never again after |
| +// an attempt for this SHA ended, and only with the primary online: offline, |
| +// nothing is decided and the next sync is the next trigger. |
| +func (t *txn) autoMerge(k *taskRecord, p progress, steps []stepRecord) error { |
| + if p.merge != nil || p.moved || p.eng == nil || k.MergeAsked == p.candidate { |
| + return nil |
| + } |
| + if _, _, verdict, _ := p.judged(); verdict != wire.VerdictApprove { |
| + return nil |
| + } |
| + online, protocol, err := t.primaryState(p.eng.Person) |
| + if err != nil || !online { |
| + return err |
| + } |
| + d, err := t.authorizeMerge(k, p, atDispatch, "", protocol) |
| + if err != nil { |
| + return err |
| + } |
| + switch d.Class { |
| + case mergegate.ClassAct: |
| + return t.startMerge(k, p, steps, !d.Checks, decidedPolicy) |
| + case mergegate.ClassAsk: |
| + return t.askMerge(k, p, d) |
| + } |
| + return nil |
| +} |
| + |
| +// mergeByPolicy reports whether a merge step is Equipo's own decision. A |
| +// step from before merge authority without a recorded decider counts as |
| +// Equipo's unless it was labelled without checks (only people merged those). |
| +func mergeByPolicy(s stepRecord) bool { |
| + if s.DecidedBy == "" { |
| + return !s.WithoutChecks |
| + } |
| + return s.DecidedBy == decidedPolicy |
| +} |
| + |
| +// authorizeMergeLease is the merge step's part of a lease check: the fence |
| +// (an automatic merge on a connection below ProtocolMergeFacts is refused, |
| +// whatever it asks) and, for a merge_request, the gate again. A refusal |
| +// settles the step in the same transaction (failed, merge_not_authorized: |
| +// nothing was sent by this attempt) and raises the ask card. |
| +func (t *txn) authorizeMergeLease(l Lease, s *stepRecord, purpose string) (string, error) { |
| + policy := mergeByPolicy(*s) |
| + fence := policy && l.Protocol < wire.ProtocolMergeFacts |
| + if !fence && purpose != wire.LeasePurposeMerge { |
| + return "", nil |
| + } |
| + k, err := t.loadTask(s.TaskID) |
| + if err != nil { |
| + return "", err |
| + } |
| + steps, err := t.steps(k.ID) |
| + if err != nil { |
| + return "", err |
| + } |
| + p := progressFor(k, steps) |
| + person := "" |
| + if !policy { |
| + person = strings.TrimPrefix(s.DecidedBy, decidedPerson) |
| + if s.DecidedBy == "" { |
| + person = k.Creator |
| + } |
| + } |
| + at := atConfirm |
| + if fence { |
| + at = atFence |
| + } |
| + if p.candidate != s.CandidateSHA { |
| + // Not the judged SHA any more: never. |
| + return wire.RefusedMergeNotAuthorized, t.refuseMerge(&k, s, p, mergegate.Decision{Class: mergegate.ClassNever}) |
| + } |
| + d, err := t.authorizeMerge(&k, p, at, person, l.Protocol) |
| + if err != nil { |
| + return "", err |
| + } |
| + if d.Class == mergegate.ClassAct && !fence { |
| + return "", nil |
| + } |
| + if fence && d.Class == mergegate.ClassAct { |
| + // The gate would act, but this connection cannot confirm each |
| + // request: the person decides. |
| + d.Class, d.Stance = mergegate.ClassAsk, mergegate.StanceMerge |
| + d.Reasons = append(d.Reasons, mergegate.Criterion{Name: mergegate.CritProtocol}) |
| + } |
| + return wire.RefusedMergeNotAuthorized, t.refuseMerge(&k, s, p, d) |
| +} |
| + |
| +// refuseMerge ends a merge attempt the gate refused before any request |
| +// went, and asks the person when the decision is to ask. |
| +func (t *txn) refuseMerge(k *taskRecord, s *stepRecord, p progress, d mergegate.Decision) error { |
| + now := t.now() |
| + s.State, s.Reason, s.Terminated, s.FinishedAt = wire.StepFailed, "merge_not_authorized", true, &now |
| + if err := t.saveStep(s, k); err != nil { |
| + return err |
| + } |
| + if err := t.advance(k); err != nil { |
| + return err |
| + } |
| + if d.Class != mergegate.ClassAsk || k.MergeAsked == p.candidate { |
| + return nil |
| + } |
| + fresh, err := t.loadTask(k.ID) |
| + if err != nil { |
| + return err |
| + } |
| + return t.askMerge(&fresh, p, d) |
| +} |
| + |
| +// askMerge puts the one merge card in the creator's conversation, worded |
| +// as Equipo's call, and the ships question once per project when the |
| +// decision waits on it. |
| +func (t *txn) askMerge(k *taskRecord, p progress, d mergegate.Decision) error { |
| + // Housekeeping never opens a merge card. |
| + if err := t.hkForbid("merge card"); err != nil { |
| + return err |
| + } |
| + question, choices, err := t.mergeQuestion(*k, p, d) |
| + if err != nil { |
| + return err |
| + } |
| + now := t.now() |
| + opts, _ := json.Marshal(choices) |
| + c := cardRecord{ID: newID("c_"), Person: k.Creator, Kind: wire.CardMerge, State: wire.CardOpen, ProjectID: k.ProjectID, TaskID: k.ID, Name: k.Title, Question: question, Options: string(opts), Revision: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := t.db.Create(&c).Error; err != nil { |
| + return err |
| + } |
| + k.MergeAsked = p.candidate |
| + if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Update("merge_asked", p.candidate).Error; err != nil { |
| + return err |
| + } |
| + if err := t.cardEvent(c); err != nil { |
| + return err |
| + } |
| + for _, r := range d.Reasons { |
| + if r.Name == mergegate.CritShips && !r.OK && r.Value == mergegate.ShipsUnknown { |
| + return t.askShips(*k) |
| + } |
| + } |
| + return nil |
| +} |
| + |
| +// mergeQuestion is the card's words and options for decision d: Equipo's |
| +// stance with what holds and what does not. |
| +func (t *txn) mergeQuestion(k taskRecord, p progress, d mergegate.Decision) (string, []string, error) { |
| + var pr projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&pr).Error; err != nil { |
| + return "", nil, err |
| + } |
| + project := pr.Title |
| + if project == "" { |
| + project = ProjectTitle(pr.Repo, nil) |
| + } |
| + checks, reason, _, _ := p.judged() |
| + var good, bad []string |
| + var facts *wire.ChangeFacts |
| + if r := p.review; r != nil && r.ChangeFacts != "" { |
| + var f wire.ChangeFacts |
| + if json.Unmarshal([]byte(r.ChangeFacts), &f) == nil { |
| + facts = &f |
| + } |
| + } |
| + for _, c := range d.Reasons { |
| + var phrase string |
| + switch { |
| + case c.OK && c.Name == mergegate.CritApproved: |
| + phrase = t.words("chat.merge.why.approved") |
| + case c.OK && c.Name == mergegate.CritSmall && facts != nil: |
| + phrase = t.words("chat.merge.why.small", facts.Lines, facts.Files) |
| + case c.OK && c.Name == mergegate.CritShips: |
| + phrase = t.words("chat.merge.why.not_shipping") |
| + case c.OK && c.Name == mergegate.CritRevert: |
| + phrase = t.words("chat.merge.why.exact_revert", short(k.RevertSHA)) |
| + case c.OK: |
| + case c.Name == mergegate.CritEnvironment: |
| + why := t.words("work.decide.reason." + reason) |
| + switch { |
| + case checks == wire.ChecksNone: |
| + phrase = t.words("chat.merge.not.no_checks") |
| + case why != "": |
| + phrase = t.words("chat.merge.not.environment", why) |
| + } |
| + case c.Name == mergegate.CritProtocol: |
| + phrase = t.words("chat.merge.not.protocol") |
| + case c.Name == mergegate.CritFacts: |
| + phrase = t.words("chat.merge.not.facts") |
| + case c.Name == mergegate.CritSmall && facts != nil: |
| + phrase = t.words("chat.merge.not.small", facts.Lines, facts.Files) |
| + case c.Name == mergegate.CritSensitive && facts != nil: |
| + phrase = t.words("chat.merge.not.special") |
| + if len(d.Sensitive) > 0 { |
| + phrase = t.words("chat.merge.not.sensitive", t.words("chat.merge.area."+d.Sensitive[0].Class), d.Sensitive[0].Path) |
| + } else if facts != nil && facts.Signing { |
| + phrase = t.words("chat.merge.not.signing") |
| + } |
| + case c.Name == mergegate.CritShips && c.Value == mergegate.ShipsYes: |
| + phrase = t.words("chat.merge.not.ships", project) |
| + case c.Name == mergegate.CritShips: |
| + phrase = t.words("chat.merge.not.ships_unknown", project) |
| + case c.Name == mergegate.CritPolicy: |
| + phrase = t.words("chat.merge.not.policy") |
| + case c.Name == mergegate.CritHold: |
| + phrase = k.MergeHold |
| + case c.Name == mergegate.CritRevert: |
| + phrase = t.words("chat.merge.not.revert", short(k.RevertSHA)) |
| + case c.Name == mergegate.CritEligible: |
| + phrase = t.words("chat.merge.not.eligible") |
| + case c.Name == mergegate.CritSandbox: |
| + phrase = t.words("chat.merge.not.sandbox") |
| + } |
| + if phrase == "" { |
| + continue |
| + } |
| + if c.OK { |
| + good = append(good, phrase) |
| + } else if !slices.Contains(bad, phrase) { |
| + bad = append(bad, phrase) |
| + } |
| + } |
| + question := "" |
| + if d.Stance == mergegate.StanceMerge { |
| + question = t.words("chat.merge.stance_merge", k.Title, strings.Join(good[:min(len(good), 3)], ", "), strings.Join(bad[:min(len(bad), 2)], "; ")) |
| + } else { |
| + question = t.words("chat.merge.stance_wait", k.Title, strings.Join(bad[:min(len(bad), 2)], "; ")) |
| + } |
| + choices := []string{wire.ChoiceMerge, wire.ChoiceNotNow} |
| + switch { |
| + case checks == wire.ChecksCannotRun && (reason == "needs_macos" || reason == "runner_offline" && t.needsMac(p)): |
| + choices = []string{wire.ChoiceMerge, wire.ChoiceWaitMac} |
| + case checks == wire.ChecksCannotRun || checks == wire.ChecksNone: |
| + choices = []string{wire.ChoiceMerge, wire.ChoiceWait} |
| + } |
| + return question, choices, nil |
| +} |
| + |
| +// needsMac reports whether the candidate's checks need macOS. |
| +func (t *txn) needsMac(p progress) bool { |
| + if p.checks == nil { |
| + return false |
| + } |
| + return slices.Contains(decodeList(p.checks.Needs), wire.TagMacOS) |
| +} |
| + |
| +// askShips sends the one question per project to the task's creator when |
| +// they are an owner: does merging to main ship to users? |
| +func (t *txn) askShips(k taskRecord) error { |
| + pr, err := t.mergePolicy(k.ProjectID) |
| + if err != nil || pr.ShipsAsked || pr.MainShips != mergegate.ShipsUnknown || t.isOwner(k.Creator) != nil { |
| + return err |
| + } |
| + var proj projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&proj).Error; err != nil { |
| + return err |
| + } |
| + name := proj.Title |
| + if name == "" { |
| + name = ProjectTitle(proj.Repo, nil) |
| + } |
| + pr.ShipsAsked = true |
| + if err := t.writePolicy(&pr, k.Creator, false); err != nil { |
| + return err |
| + } |
| + now := t.now() |
| + opts, _ := json.Marshal([]string{wire.ChoiceShips, wire.ChoiceNotShips}) |
| + undo, _ := json.Marshal(map[string]int64{"policy_revision": pr.Revision}) |
| + c := cardRecord{ID: newID("c_"), Person: k.Creator, Kind: wire.CardMergeShips, State: wire.CardOpen, ProjectID: k.ProjectID, Name: name, Question: t.words("chat.merge.ships_question", name), Options: string(opts), Undo: string(undo), Revision: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := t.db.Create(&c).Error; err != nil { |
| + return err |
| + } |
| + return t.cardEvent(c) |
| +} |
| + |
| +// cardPolicyRevision is the policy revision a ships or policy card was |
| +// made against. |
| +func cardPolicyRevision(c cardRecord) int64 { |
| + var v struct { |
| + Revision int64 `json:"policy_revision"` |
| + } |
| + _ = json.Unmarshal([]byte(c.Undo), &v) |
| + return v.Revision |
| +} |
| + |
| +// answerShips records an owner's answer as policy, for decisions after |
| +// it. A card made against an older policy revision is stale. |
| +func (t *txn) answerShips(person string, c cardRecord, in wire.AnswerCard) (wire.Card, wire.Card, error) { |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if in.Choice != wire.ChoiceShips && in.Choice != wire.ChoiceNotShips { |
| + return wire.Card{}, wire.Card{}, ErrInvalid |
| + } |
| + if c.State != wire.CardOpen || c.Revision != in.Revision { |
| + return wire.Card{}, v, ErrCardConflict |
| + } |
| + if err := t.isOwner(person); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + pr, err := t.mergePolicy(c.ProjectID) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if pr.Revision != cardPolicyRevision(c) { |
| + c.State = wire.CardResolved |
| + if err := t.saveCard(&c); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + cur, _ := t.cardView(c) |
| + return wire.Card{}, cur, ErrCardConflict |
| + } |
| + pr.MainShips, pr.ShipsAnsweredBy = mergegate.ShipsNo, person |
| + if in.Choice == wire.ChoiceShips { |
| + pr.MainShips = mergegate.ShipsYes |
| + } |
| + if err := t.savePolicy(&pr, person); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: c.ProjectID, Kind: auditShips, At: "card", DecidedBy: decidedPerson + person, Inputs: fmt.Sprintf(`{"main_ships":%q}`, pr.MainShips)}); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + c.State, c.Choice = wire.CardAnswered, in.Choice |
| + if err := t.saveCard(&c); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + out, err := t.cardView(c) |
| + return out, wire.Card{}, err |
| +} |
| + |
| +// mergeReceipt is Equipo's own merge without checks, told with a |
| +// receipt: Undo when the hub named the merge commit, within the window. |
| +func (t *txn) mergeReceipt(k *taskRecord, project string, s *stepRecord, verified bool) (bool, error) { |
| + var n int64 |
| + if err := t.db.Model(&cardRecord{}).Where("task_id = ? AND kind = ?", k.ID, wire.CardMergeReceipt).Count(&n).Error; err != nil || n > 0 { |
| + return n > 0, err |
| + } |
| + steps, err := t.steps(k.ID) |
| + if err != nil { |
| + return false, err |
| + } |
| + p := progressOf(steps) |
| + in, _, err := t.mergeInputs(*k, p, false, wire.ProtocolMergeFacts) |
| + if err != nil { |
| + return false, err |
| + } |
| + d := mergegate.Decide(in) |
| + var why []string |
| + for _, c := range d.Reasons { |
| + switch { |
| + case !c.OK: |
| + case c.Name == mergegate.CritApproved: |
| + why = append(why, t.words("chat.merge.why.approved")) |
| + case c.Name == mergegate.CritSmall && in.Change != nil: |
| + why = append(why, t.words("chat.merge.why.small", in.Change.Lines, in.Change.Files)) |
| + case c.Name == mergegate.CritShips: |
| + why = append(why, t.words("chat.merge.why.not_shipping")) |
| + } |
| + } |
| + text := t.words("chat.merge.receipt", mdLabel(k.Title), TaskLink(k.ID), project, strings.Join(why, ", ")) |
| + opts := "[]" |
| + if verified { |
| + opts = `["undo"]` |
| + } else { |
| + text = t.words("chat.merge.receipt_unverified", mdLabel(k.Title), TaskLink(k.ID), project) |
| + } |
| + if text == "" { |
| + return false, nil |
| + } |
| + now := t.now() |
| + c := cardRecord{ID: newID("c_"), Person: k.Creator, Kind: wire.CardMergeReceipt, State: wire.CardOpen, ProjectID: k.ProjectID, TaskID: k.ID, Name: k.Title, Question: text, Options: opts, Revision: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := t.db.Create(&c).Error; err != nil { |
| + return false, err |
| + } |
| + return true, t.cardEvent(c) |
| +} |
| + |
| +// mergeVerified reports whether a merge report names the hub's own merge |
| +// commit with the candidate as its second parent. |
| +func mergeVerified(v *wire.StepReport, candidate string) bool { |
| + return v.MergeSource == wire.MergeSourceHub && len(v.MergeParents) == 2 && v.MergeParents[1] == candidate && v.MergeParents[0] != candidate |
| +} |
| + |
| +// undoOffered reports whether the creator may Undo the task's merge now. |
| +func (t *txn) undoOffered(k taskRecord) (bool, error) { |
| + if !k.MergeVerified || k.MergedSHA == "" || k.MergedAt == nil || !k.MergedWithoutChecks || t.now().Sub(*k.MergedAt) > housekeeping.UndoWindow { |
| + return false, nil |
| + } |
| + var n int64 |
| + err := t.db.Model(&taskRecord{}).Where("revert_of = ?", k.ID).Count(&n).Error |
| + return n == 0, err |
| +} |
| + |
| +// UndoMerge is the creator's Undo of Equipo's own merge: an ordinary |
| +// revert task through the normal flow, and the project to ask mode. |
| +func (s *Store) UndoMerge(ctx context.Context, person, id string) (out wire.Task, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + k, err := t.loadTask(id) |
| + if err != nil { |
| + return err |
| + } |
| + if k.Creator != person { |
| + return ErrNotFound |
| + } |
| + if err := t.isOwner(person); err != nil { |
| + return err |
| + } |
| + rev, err := t.undoMerge(person, k) |
| + if err != nil { |
| + return err |
| + } |
| + out, err = t.taskView(rev) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +func (t *txn) undoMerge(person string, k taskRecord) (taskRecord, error) { |
| + if err := t.hkForbid("merge"); err != nil { |
| + return taskRecord{}, err |
| + } |
| + ok, err := t.undoOffered(k) |
| + if err != nil { |
| + return taskRecord{}, err |
| + } |
| + if !ok { |
| + return taskRecord{}, ErrNotUndoable |
| + } |
| + var pr projectRecord |
| + if err := t.db.Where("id = ?", k.ProjectID).First(&pr).Error; err != nil { |
| + return taskRecord{}, err |
| + } |
| + project := pr.Title |
| + if project == "" { |
| + project = ProjectTitle(pr.Repo, nil) |
| + } |
| + now := t.now() |
| + title := clipText(t.words("chat.merge.revert_title", short(k.MergedSHA), project), wire.MaxTaskTitle) |
| + brief := fmt.Sprintf("Revert merge commit %s on %s with `git revert -m 1 %s` and change nothing else. It undoes %q (task %s).", k.MergedSHA, k.MergedInto, k.MergedSHA, k.Title, k.ID) |
| + rev := taskRecord{ID: newTaskID(), ProjectID: k.ProjectID, Title: title, Brief: brief, Stage: wire.StageNoted, Creator: person, Revision: 1, CreatedAt: now, UpdatedAt: now, RevertOf: k.ID, RevertSHA: k.MergedSHA} |
| + rev.Branch = wire.TaskBranch(rev.ID, title) |
| + if err := t.db.Create(&rev).Error; err != nil { |
| + return taskRecord{}, err |
| + } |
| + if err := t.taskEvent(rev); err != nil { |
| + return taskRecord{}, err |
| + } |
| + s := stepRecord{ID: newID("s_"), TaskID: rev.ID, Idx: 1, Specialist: wire.SpecialistEngineering, Person: person, State: wire.StepQueued, Attempt: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := t.db.Create(&s).Error; err != nil { |
| + return taskRecord{}, err |
| + } |
| + if err := t.dispatchStep(&rev, &s); err != nil { |
| + return taskRecord{}, err |
| + } |
| + rev.Stage = wire.StageInProgress |
| + if err := t.saveStep(&s, &rev); err != nil { |
| + return taskRecord{}, err |
| + } |
| + // Any revert of Equipo's own merge puts the project in ask mode until |
| + // an owner says otherwise. |
| + policy, err := t.mergePolicy(k.ProjectID) |
| + if err != nil { |
| + return taskRecord{}, err |
| + } |
| + policy.Mode, policy.ModeReason = mergegate.ModeAsk, t.words("chat.merge.mode_reason_reverted", short(k.MergedSHA)) |
| + if err := t.savePolicy(&policy, person); err != nil { |
| + return taskRecord{}, err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: k.ProjectID, TaskID: k.ID, Kind: auditUndo, At: "undo", MergeSHA: k.MergedSHA, DecidedBy: decidedPerson + person, Inputs: fmt.Sprintf(`{"revert_task":%q,"mode":"ask"}`, rev.ID)}); err != nil { |
| + return taskRecord{}, err |
| + } |
| + var receipts []cardRecord |
| + if err := t.db.Where("task_id = ? AND kind = ?", k.ID, wire.CardMergeReceipt).Find(&receipts).Error; err != nil { |
| + return taskRecord{}, err |
| + } |
| + for i := range receipts { |
| + c := &receipts[i] |
| + c.State, c.Choice = wire.CardUndoneMerge, wire.ChoiceUndo |
| + c.Question = t.words("chat.merge.reverting", mdLabel(rev.Title), TaskLink(rev.ID)) |
| + if err := t.db.Model(&cardRecord{}).Where("id = ?", c.ID).Update("question", c.Question).Error; err != nil { |
| + return taskRecord{}, err |
| + } |
| + if err := t.saveCard(c); err != nil { |
| + return taskRecord{}, err |
| + } |
| + } |
| + return rev, nil |
| +} |
| + |
| +// answerReceipt is Undo on a merge receipt. |
| +func (t *txn) answerReceipt(person string, c cardRecord, in wire.AnswerCard) (wire.Card, wire.Card, error) { |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if in.Choice != wire.ChoiceUndo { |
| + return wire.Card{}, wire.Card{}, ErrInvalid |
| + } |
| + if c.State != wire.CardOpen || c.Revision != in.Revision { |
| + return wire.Card{}, v, ErrCardConflict |
| + } |
| + k, err := t.loadTask(c.TaskID) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if k.Creator != person { |
| + return wire.Card{}, wire.Card{}, ErrForbidden |
| + } |
| + if err := t.isOwner(person); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if _, err := t.undoMerge(person, k); errors.Is(err, ErrNotUndoable) { |
| + return wire.Card{}, v, ErrCardConflict |
| + } else if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + var fresh cardRecord |
| + if err := t.db.Where("id = ?", c.ID).First(&fresh).Error; err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + out, err := t.cardView(fresh) |
| + return out, wire.Card{}, err |
| +} |
| + |
| +// mergeDecisionView is the task's newest decision, nil when none. |
| +func (t *txn) mergeDecisionView(taskID string) (*wire.MergeDecision, error) { |
| + var a mergeAuditRecord |
| + err := t.db.Where("task_id = ? AND kind = ?", taskID, auditDecision).Order("created_at DESC, id DESC").First(&a).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + return nil, nil |
| + } |
| + if err != nil { |
| + return nil, err |
| + } |
| + return decisionView(a), nil |
| +} |
| + |
| +func decisionView(a mergeAuditRecord) *wire.MergeDecision { |
| + d := &wire.MergeDecision{Class: a.Class, Stance: a.Stance, DecidedBy: a.DecidedBy, Reasons: []wire.MergeCriterion{}, At: a.CreatedAt} |
| + var rs []mergegate.Criterion |
| + _ = json.Unmarshal([]byte(a.Reasons), &rs) |
| + for _, r := range rs { |
| + d.Reasons = append(d.Reasons, wire.MergeCriterion{Name: r.Name, OK: r.OK, Value: r.Value}) |
| + } |
| + return d |
| +} |
| + |
| +// holdMerge is the coordinator's hold_merge: stricter only. |
| +func (t *txn) holdMerge(r turnRecord, args json.RawMessage) (wire.ToolResult, error) { |
| + var in struct { |
| + Task string `json:"task"` |
| + Reason string `json:"reason"` |
| + } |
| + if wire.Strict(args, &in) != nil { |
| + return refused("invalid", toolBadInput), nil |
| + } |
| + reason, ok := cleanText(in.Reason, wire.MaxMergeHold) |
| + if !ok { |
| + return refused("invalid", toolBadInput), nil |
| + } |
| + k, res, err := t.ownTask(r.Person, in.Task) |
| + if res != nil || err != nil { |
| + return deref(res), err |
| + } |
| + k.MergeHold = reason |
| + if err := t.saveTask(&k); err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: k.ProjectID, TaskID: k.ID, Kind: auditHold, At: "tool", DecidedBy: "coordinator:" + r.Person, Inputs: fmt.Sprintf(`{"reason":%q}`, reason)}); err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + return wire.ToolResult{Code: "held", Text: toolHeld}, nil |
| +} |
| + |
| +// setMergePolicy is the coordinator's set_merge_policy: a stricter |
| +// policy applies at once; a looser one waits for the person's Save. |
| +func (t *txn) setMergePolicy(r turnRecord, args json.RawMessage) (wire.ToolResult, error) { |
| + var in struct { |
| + Project string `json:"project"` |
| + Words string `json:"words"` |
| + Mode *string `json:"mode"` |
| + MaxLines *int `json:"max_lines"` |
| + MaxFiles *int `json:"max_files"` |
| + MainShips *string `json:"main_ships"` |
| + AddSensitive []string `json:"add_sensitive"` |
| + } |
| + if wire.Strict(args, &in) != nil { |
| + return refused("invalid", toolBadInput), nil |
| + } |
| + words, ok := cleanText(in.Words, wire.MaxMergeWords) |
| + if !ok { |
| + return refused("invalid", toolBadInput), nil |
| + } |
| + var proj projectRecord |
| + err := t.db.Where("repo = ? AND state = ?", NormalizeRepo(in.Project), wire.ProjectActive).First(&proj).Error |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + err = t.db.Where("id = ? AND state = ?", strings.TrimSpace(in.Project), wire.ProjectActive).First(&proj).Error |
| + } |
| + if errors.Is(err, gorm.ErrRecordNotFound) { |
| + return refused("not_found", toolNoProject), nil |
| + } |
| + if err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + if t.isOwner(r.Person) != nil { |
| + return refused("not_owner", toolNotOwner), nil |
| + } |
| + pr, err := t.mergePolicy(proj.ID) |
| + if err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + old := policyOf(pr) |
| + next := old |
| + next.ExtraSensitive = slices.Clone(old.ExtraSensitive) |
| + if in.Mode != nil { |
| + next.Mode = *in.Mode |
| + } |
| + if in.MaxLines != nil { |
| + next.MaxLines = *in.MaxLines |
| + } |
| + if in.MaxFiles != nil { |
| + next.MaxFiles = *in.MaxFiles |
| + } |
| + if in.MainShips != nil { |
| + next.MainShips = *in.MainShips |
| + } |
| + for _, g := range in.AddSensitive { |
| + if !slices.Contains(next.ExtraSensitive, g) { |
| + next.ExtraSensitive = append(next.ExtraSensitive, g) |
| + } |
| + } |
| + if !mergegate.ValidPolicy(next) { |
| + return refused("invalid", toolBadPolicy), nil |
| + } |
| + name := proj.Title |
| + if name == "" { |
| + name = ProjectTitle(proj.Repo, nil) |
| + } |
| + if mergegate.Tighter(old, next) { |
| + applyPolicy(&pr, next, words) |
| + if err := t.savePolicy(&pr, r.Person); err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: proj.ID, Kind: auditPolicy, At: "tool", DecidedBy: "coordinator:" + r.Person, Inputs: policyJSON(next)}); err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + return wire.ToolResult{Code: "policy_set", Text: toolPolicySet}, nil |
| + } |
| + // Looser: the person confirms with a tap. |
| + raw, _ := json.Marshal(struct { |
| + Revision int64 `json:"policy_revision"` |
| + Policy mergegate.Policy `json:"policy"` |
| + Words string `json:"words"` |
| + }{pr.Revision, next, words}) |
| + now := t.now() |
| + opts, _ := json.Marshal([]string{wire.ChoiceSave, wire.ChoiceCancel}) |
| + c := cardRecord{ID: newID("c_"), Person: r.Person, Kind: wire.CardMergePolicy, State: wire.CardOpen, TurnID: r.ID, ProjectID: proj.ID, Name: name, Question: t.words("chat.merge.policy_confirm", name, t.policySentence(next)), Options: string(opts), Undo: string(raw), Revision: 1, CreatedAt: now, UpdatedAt: now} |
| + if err := t.db.Create(&c).Error; err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + if err := t.cardEvent(c); err != nil { |
| + return wire.ToolResult{}, err |
| + } |
| + return wire.ToolResult{Code: "policy_proposed", Text: toolPolicyProposed}, nil |
| +} |
| + |
| +// answerPolicyCard is Save or Cancel on a proposed looser policy. |
| +func (t *txn) answerPolicyCard(person string, c cardRecord, in wire.AnswerCard) (wire.Card, wire.Card, error) { |
| + v, err := t.cardView(c) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if in.Choice != wire.ChoiceSave && in.Choice != wire.ChoiceCancel { |
| + return wire.Card{}, wire.Card{}, ErrInvalid |
| + } |
| + if c.State != wire.CardOpen || c.Revision != in.Revision { |
| + return wire.Card{}, v, ErrCardConflict |
| + } |
| + if in.Choice == wire.ChoiceSave { |
| + if err := t.isOwner(person); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + var prop struct { |
| + Revision int64 `json:"policy_revision"` |
| + Policy mergegate.Policy `json:"policy"` |
| + Words string `json:"words"` |
| + } |
| + if err := json.Unmarshal([]byte(c.Undo), &prop); err != nil || !mergegate.ValidPolicy(prop.Policy) { |
| + return wire.Card{}, wire.Card{}, ErrInvalid |
| + } |
| + pr, err := t.mergePolicy(c.ProjectID) |
| + if err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if pr.Revision != prop.Revision { |
| + c.State = wire.CardResolved |
| + if err := t.saveCard(&c); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + cur, _ := t.cardView(c) |
| + return wire.Card{}, cur, ErrCardConflict |
| + } |
| + applyPolicy(&pr, prop.Policy, prop.Words) |
| + if prop.Policy.MainShips != mergegate.ShipsUnknown { |
| + pr.ShipsAnsweredBy = person |
| + } |
| + if err := t.savePolicy(&pr, person); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: c.ProjectID, Kind: auditPolicy, At: "card", DecidedBy: decidedPerson + person, Inputs: policyJSON(prop.Policy)}); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + } |
| + c.State, c.Choice = wire.CardAnswered, in.Choice |
| + if err := t.saveCard(&c); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + out, err := t.cardView(c) |
| + return out, wire.Card{}, err |
| +} |
| + |
| +func applyPolicy(r *mergePolicyRecord, p mergegate.Policy, words string) { |
| + extra := p.ExtraSensitive |
| + if extra == nil { |
| + extra = []string{} |
| + } |
| + raw, _ := json.Marshal(extra) |
| + if r.Mode != p.Mode { |
| + r.ModeReason = "" |
| + } |
| + r.Mode, r.MaxLines, r.MaxFiles, r.MainShips, r.ExtraSensitive = p.Mode, p.MaxLines, p.MaxFiles, p.MainShips, string(raw) |
| + if words != "" { |
| + r.Words = words |
| + } |
| +} |
| + |
| +func policyJSON(p mergegate.Policy) string { |
| + raw, _ := json.Marshal(p) |
| + return string(raw) |
| +} |
| + |
| +// policySentence is a policy in plain words. |
| +func (t *txn) policySentence(p mergegate.Policy) string { |
| + parts := []string{t.words("chat.merge.policy.rules", p.MaxLines, p.MaxFiles)} |
| + if p.Mode == mergegate.ModeAsk { |
| + parts = []string{t.words("chat.merge.policy.ask")} |
| + } |
| + parts = append(parts, t.words("chat.merge.policy.ships_"+p.MainShips)) |
| + if len(p.ExtraSensitive) > 0 { |
| + parts = append(parts, t.words("chat.merge.policy.extra", strings.Join(p.ExtraSensitive, ", "))) |
| + } |
| + return strings.Join(parts, "; ") |
| +} |
| + |
| +// MergePolicy is GET /api/v1/projects/{id}/merge-policy: every member |
| +// reads it; owners may edit. |
| +func (s *Store) MergePolicy(ctx context.Context, person, projectID string) (out wire.MergePolicy, err error) { |
| + err = s.read(ctx, func(tx *gorm.DB) error { |
| + if err := s.authority.CurrentPerson(ctx, tx); err != nil { |
| + return err |
| + } |
| + t := &txn{s: s, db: tx} |
| + out, err = t.mergePolicyView(person, projectID) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +func (t *txn) mergePolicyView(person, projectID string) (wire.MergePolicy, error) { |
| + var proj projectRecord |
| + if err := t.db.Where("id = ?", projectID).First(&proj).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return wire.MergePolicy{}, ErrNotFound |
| + } else if err != nil { |
| + return wire.MergePolicy{}, err |
| + } |
| + pr, err := t.mergePolicy(projectID) |
| + if err != nil { |
| + return wire.MergePolicy{}, err |
| + } |
| + p := policyOf(pr) |
| + if p.ExtraSensitive == nil { |
| + p.ExtraSensitive = []string{} |
| + } |
| + out := wire.MergePolicy{ProjectID: projectID, Mode: p.Mode, ModeReason: pr.ModeReason, MaxLines: p.MaxLines, MaxFiles: p.MaxFiles, MainShips: p.MainShips, ExtraSensitive: p.ExtraSensitive, Words: pr.Words, Revision: pr.Revision, Editable: t.isOwner(person) == nil, Decisions: []wire.MergeDecision{}} |
| + var rows []mergeAuditRecord |
| + if err := t.db.Where("project_id = ? AND kind = ?", projectID, auditDecision).Order("created_at DESC, id DESC").Limit(5).Find(&rows).Error; err != nil { |
| + return out, err |
| + } |
| + for _, a := range rows { |
| + out.Decisions = append(out.Decisions, *decisionView(a)) |
| + } |
| + return out, nil |
| +} |
| + |
| +// SetMergePolicy is PUT /api/v1/projects/{id}/merge-policy and the |
| +// project page's form: an owner's own action, so it may loosen. |
| +func (s *Store) SetMergePolicy(ctx context.Context, person, projectID string, in wire.SetMergePolicy) (out wire.MergePolicy, err error) { |
| + err = s.tx(ctx, func(t *txn) error { |
| + if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| + return err |
| + } |
| + if err := t.isOwner(person); err != nil { |
| + return err |
| + } |
| + var proj projectRecord |
| + if err := t.db.Where("id = ?", projectID).First(&proj).Error; errors.Is(err, gorm.ErrRecordNotFound) { |
| + return ErrNotFound |
| + } else if err != nil { |
| + return err |
| + } |
| + words := strings.TrimSpace(in.Words) |
| + if len(words) > wire.MaxMergeWords || strings.ContainsRune(words, 0) { |
| + return ErrInvalid |
| + } |
| + next := mergegate.Policy{Mode: in.Mode, MaxLines: in.MaxLines, MaxFiles: in.MaxFiles, MainShips: in.MainShips, ExtraSensitive: in.ExtraSensitive} |
| + if !mergegate.ValidPolicy(next) { |
| + return ErrInvalid |
| + } |
| + pr, err := t.mergePolicy(projectID) |
| + if err != nil { |
| + return err |
| + } |
| + if pr.Revision != in.Revision { |
| + return ErrRevision |
| + } |
| + applyPolicy(&pr, next, words) |
| + if words == "" { |
| + pr.Words = "" |
| + } |
| + if next.MainShips != mergegate.ShipsUnknown { |
| + pr.ShipsAnsweredBy = person |
| + } |
| + if err := t.savePolicy(&pr, person); err != nil { |
| + return err |
| + } |
| + if err := t.auditRow(mergeAuditRecord{ProjectID: projectID, Kind: auditPolicy, At: "form", DecidedBy: decidedPerson + person, Inputs: policyJSON(next)}); err != nil { |
| + return err |
| + } |
| + out, err = t.mergePolicyView(person, projectID) |
| + return err |
| + }) |
| + return out, err |
| +} |
| + |
| +// acceptFacts keeps a review report's change facts only when they are |
| +// exactly this attempt's, from the person's primary on a connection that |
| +// speaks ProtocolMergeFacts, about this project and SHA, and whole. |
| +func acceptFacts(l Lease, role string, s stepRecord, repo string, f *wire.ChangeFacts) string { |
| + if f == nil || role != wire.RolePrimary || l.Protocol < wire.ProtocolMergeFacts || s.Specialist != wire.SpecialistReview { |
| + return "" |
| + } |
| + if f.ReviewStep != s.ID || f.Attempt != s.Attempt || f.Repo != repo || f.SHA != s.CandidateSHA || !validSHA(f.Base) || !f.Complete { |
| + return "" |
| + } |
| + if f.Files != len(f.Entries) || f.Files > wire.MaxChangeEntries || f.Lines < 0 || f.Binary < 0 || f.Binary > f.Files { |
| + return "" |
| + } |
| + modes := map[string]bool{"000000": true, "100644": true, "100755": true, "120000": true, "160000": true, "040000": true} |
| + for _, e := range f.Entries { |
| + if e.Status == "" || !strings.ContainsRune("ACDMRTUX", rune(e.Status[0])) || !modes[e.OldMode] || !modes[e.NewMode] { |
| + return "" |
| + } |
| + if _, ok := cleanPath(e.New); !ok { |
| + return "" |
| + } |
| + if e.Old != "" { |
| + if _, ok := cleanPath(e.Old); !ok { |
| + return "" |
| + } |
| + } |
| + } |
| + if f.Revert != nil && !validSHA(f.Revert.SHA) { |
| + return "" |
| + } |
| + raw, _ := json.Marshal(f) |
| + return string(raw) |
| +} |
| + |
| +// Model-facing tool texts for merge authority. |
| +const ( |
| + toolHeld = "Held: Equipo will not merge this task on its own; the person's merge card shows your reason. Tell them in one line." |
| + toolPolicySet = "Saved: it only makes Equipo more careful, so it applies now. Tell the person in one line what changed." |
| + toolPolicyProposed = "That would let Equipo merge more on its own, so nothing changed yet: the person has a card to Save it. Tell them in one line." |
| + toolBadPolicy = "That policy is out of bounds: mode is rules or ask, max_lines 0 to 2000, max_files 0 to 100, main_ships yes or no, at most 20 relative globs." |
| + toolNoProject = "No such project. Use its repository as add_project returned it." |
| +) |
diff --git a/internal/equipo/chat/models.go b/internal/equipo/chat/models.go| index 79c04304..71e8ea01 100644 |
| --- a/internal/equipo/chat/models.go |
| +++ b/internal/equipo/chat/models.go |
| @@ -7,7 +7,7 @@ package chat |
| import "time" |
| // Models are the tables this package owns, for the migration check. |
| -var Models = []any{&turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}} |
| +var Models = []any{&turnRecord{}, &messageRecord{}, &eventRecord{}, &commandRecord{}, &inboxRecord{}, &runnerSessionRecord{}, &projectRecord{}, &cardRecord{}, &toolCallRecord{}, &settingRecord{}, &coordinatorRecord{}, ¬ebookRecord{}, &taskRecord{}, &stepRecord{}, &entryRecord{}, &attachmentRecord{}, &questionRecord{}, &connectionRecord{}, &usageRecord{}, &distinctRecord{}, &hkRecord{}, &hkFailureRecord{}, &hkSettingsRecord{}, &fileRecord{}, &fileDataRecord{}, &transferRecord{}, &mergePolicyRecord{}, &mergeAuditRecord{}} |
| type turnRecord struct { |
| ID string `gorm:"primaryKey"` |
diff --git a/internal/equipo/chat/projects.go b/internal/equipo/chat/projects.go| index 87e16ecb..c3b78f94 100644 |
| --- a/internal/equipo/chat/projects.go |
| +++ b/internal/equipo/chat/projects.go |
| @@ -242,7 +242,7 @@ func (t *txn) cardView(c cardRecord) (wire.Card, error) { |
| if c.Kind == wire.CardHome { |
| v.Name = c.Choice |
| } |
| - if c.Kind == wire.CardAccess || c.Kind == wire.CardMerge { |
| + if c.Kind == wire.CardAccess || c.Kind == wire.CardMerge || c.Kind == wire.CardMergeShips || c.Kind == wire.CardMergePolicy || c.Kind == wire.CardMergeReceipt { |
| v.Name = c.Name |
| } |
| if c.Kind == wire.CardTask { |
| @@ -552,6 +552,20 @@ func (s *Store) Answer(ctx context.Context, person, id string, in wire.AnswerCar |
| out.Card, current = card, cur |
| return e |
| } |
| + if c.Kind == wire.CardMergeShips || c.Kind == wire.CardMergePolicy || c.Kind == wire.CardMergeReceipt { |
| + var card, cur wire.Card |
| + var e error |
| + switch c.Kind { |
| + case wire.CardMergeShips: |
| + card, cur, e = t.answerShips(person, c, in) |
| + case wire.CardMergePolicy: |
| + card, cur, e = t.answerPolicyCard(person, c, in) |
| + default: |
| + card, cur, e = t.answerReceipt(person, c, in) |
| + } |
| + out.Card, current = card, cur |
| + return e |
| + } |
| if c.Kind != wire.CardQuestion && c.Kind != wire.CardProject { |
| return ErrNotFound |
| } |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index 3922070c..36a1fc88 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -543,7 +543,12 @@ func (t *txn) withdraw(k *taskRecord, s *stepRecord) error { |
| // lease naming it): granted only to the runner the attempt is placed on, |
| // while it is current and not withdrawn, and the first grant records that |
| // it started. Refused is the reason a lease is refused, "" when granted. |
| -func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt int64) (refused string, err error) { |
| +// |
| +// A merge step's lease is also merge authority's (authorizeMergeLease): |
| +// an automatic merge on a connection below wire.ProtocolMergeFacts is |
| +// refused, and purpose merge_request decides the merge again, right before |
| +// the hub request, on every call. |
| +func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt int64, purpose string) (refused string, err error) { |
| err = s.tx(ctx, func(t *txn) error { |
| if _, err := t.current(l); err != nil { |
| return err |
| @@ -559,6 +564,13 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i |
| refused = "withdrawn" |
| return nil |
| } |
| + if st.Specialist == wire.SpecialistMerge { |
| + r, err := t.authorizeMergeLease(l, &st, purpose) |
| + if err != nil || r != "" { |
| + refused = r |
| + return err |
| + } |
| + } |
| if st.StartedAt != nil { |
| return nil |
| } |
diff --git a/internal/equipo/chat/stream.go b/internal/equipo/chat/stream.go| index 66410f90..821ef57a 100644 |
| --- a/internal/equipo/chat/stream.go |
| +++ b/internal/equipo/chat/stream.go |
| @@ -183,7 +183,7 @@ func (rc *runnerConn) read(ctx context.Context) websocket.StatusCode { |
| case v.StepID != "" && v.Publication != "": |
| refused, err = store.AuthorizePublication(ctx, rc.lease, v.StepID, v.Attempt, v.Publication) |
| case v.StepID != "": |
| - refused, err = store.Authorize(ctx, rc.lease, v.StepID, v.Attempt) |
| + refused, err = store.Authorize(ctx, rc.lease, v.StepID, v.Attempt, v.Purpose) |
| default: |
| err = store.Confirm(ctx, rc.lease) |
| } |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index 2d40a2e4..997e496f 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -14,6 +14,7 @@ import ( |
| "unicode/utf8" |
| "amadan.net/oficina/equipo/internal/equipo/housekeeping" |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| "amadan.net/oficina/equipo/internal/wire" |
| "gorm.io/gorm" |
| ) |
| @@ -83,6 +84,15 @@ type taskRecord struct { |
| // rounds, retries and republishes go there, so two runners never |
| // touch one branch. |
| EngineeringRunner string |
| + // Merge authority: MergeHold is the coordinator's hold (it can only |
| + // stop Equipo merging on its own); MergeVerified, that the merge SHA |
| + // came from the hub's own answer with the candidate as second parent |
| + // (only then is Undo offered); RevertOf and RevertSHA make this task |
| + // the revert of another task's merge commit. |
| + MergeHold string |
| + MergeVerified bool |
| + RevertOf string |
| + RevertSHA string |
| } |
| func (taskRecord) TableName() string { return "chat_tasks" } |
| @@ -166,6 +176,14 @@ type stepRecord struct { |
| // none when they ran outside the sandbox (Paul's ruling 2). "" is the |
| // primary's bubblewrap. |
| ChecksSandbox string |
| + // ChangeFacts is the review's measured change (wire.ChangeFacts JSON), |
| + // kept only when it passed acceptance. DecidedBy is who decided a |
| + // merge step ("policy", or "person:<address>"); MergeSource and |
| + // MergeParents (JSON) where its SHA came from. |
| + ChangeFacts string |
| + DecidedBy string |
| + MergeSource string |
| + MergeParents string |
| } |
| func (stepRecord) TableName() string { return "chat_steps" } |
| @@ -400,6 +418,13 @@ func (t *txn) taskView(k taskRecord) (wire.Task, error) { |
| v.Questions = qs |
| v.Merged = mergedView(k) |
| v.AskOpen = askOpen(k, t.now()) |
| + v.MergeHold, v.RevertOf = k.MergeHold, k.RevertOf |
| + if v.MergeDecision, err = t.mergeDecisionView(k.ID); err != nil { |
| + return v, err |
| + } |
| + if v.UndoOffered, err = t.undoOffered(k); err != nil { |
| + return v, err |
| + } |
| if v.MergeOffered, err = t.mergeOffered(k, pr); err != nil { |
| return v, err |
| } |
| @@ -432,7 +457,7 @@ func (t *txn) saveTask(k *taskRecord) error { |
| now := t.now() |
| k.DoneAt = &now |
| } |
| - if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Select("stage", "base_sha", "cancel_requested", "revision", "updated_at", "moved_from", "branch_head", "merged_sha", "merged_into", "merge_strategy", "merged_without_checks", "merged_at", "engineering_runner", "ready_sha", "merge_eligible", "done_at", "duplicate_of").Updates(k).Error; err != nil { |
| + if err := t.db.Model(&taskRecord{}).Where("id = ?", k.ID).Select("stage", "base_sha", "cancel_requested", "revision", "updated_at", "moved_from", "branch_head", "merged_sha", "merged_into", "merge_strategy", "merged_without_checks", "merged_at", "engineering_runner", "ready_sha", "merge_eligible", "done_at", "duplicate_of", "merge_hold", "merge_verified").Updates(k).Error; err != nil { |
| return err |
| } |
| if wire.FinalStage(k.Stage) && !wire.FinalStage(before) { |
| @@ -472,7 +497,7 @@ func (t *txn) saveStep(s *stepRecord, k *taskRecord) error { |
| } |
| s.Revision++ |
| s.UpdatedAt = t.now() |
| - if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox").Updates(s).Error; err != nil { |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_facts", "decided_by", "merge_source", "merge_parents").Updates(s).Error; err != nil { |
| return err |
| } |
| members, err := t.members() |
| @@ -746,6 +771,8 @@ func (t *txn) dispatchStep(k *taskRecord, s *stepRecord) error { |
| } |
| if s.Specialist == wire.SpecialistReview { |
| cmd.AvoidAccount = s.Account |
| + // A revert task's review measures whether it reverts exactly that. |
| + cmd.RevertSHA = k.RevertSHA |
| } |
| if s.Rebase { |
| // The runner takes the default branch's tip and puts the change |
| @@ -1030,6 +1057,9 @@ func (t *txn) stepReport(l Lease, v *wire.StepReport) error { |
| if err := t.db.Where("id = ?", k.ProjectID).First(&pr).Error; err != nil { |
| return err |
| } |
| + // Merge authority: the review's measured change, kept only |
| + // when it is exactly this attempt's, whole, from the primary. |
| + s.ChangeFacts = acceptFacts(l, role, s, pr.Repo, v.Change) |
| found := cleanFindings(v.Findings) |
| for i := range found { |
| found[i].Repo, found[i].At = pr.Repo, now |
| @@ -1293,14 +1323,29 @@ func (s *Store) RetryTask(ctx context.Context, person, id string) (attempt int64 |
| return ErrForbidden |
| } |
| if st.Specialist == wire.SpecialistMerge { |
| - // Never merge a SHA that is not the judged one, as it stands. |
| + // Never merge a SHA that is not the judged one, as it stands; a |
| + // person's Retry is their decision, through the gate. |
| + if err := t.hkForbid("merge"); err != nil { |
| + return err |
| + } |
| steps, err := t.steps(k.ID) |
| if err != nil { |
| return err |
| } |
| - if p := progressFor(k, steps); p.candidate != st.CandidateSHA || !p.mergeAllowed(st.WithoutChecks) { |
| + p := progressFor(k, steps) |
| + if p.candidate != st.CandidateSHA || !p.mergeAllowed(st.WithoutChecks) { |
| + return ErrNotRetryable |
| + } |
| + _, protocol, err := t.primaryState(st.Person) |
| + if err != nil { |
| + return err |
| + } |
| + if d, err := t.authorizeMerge(&k, p, atDispatch, person, protocol); err != nil { |
| + return err |
| + } else if d.Class != mergegate.ClassAct { |
| return ErrNotRetryable |
| } |
| + st.DecidedBy = decidedPerson + person |
| } |
| primary, err := s.authority.PrimaryRunner(t.db, st.Person) |
| if err != nil { |
| @@ -1334,7 +1379,7 @@ func (s *Store) RetryTask(ctx context.Context, person, id string) (attempt int64 |
| st.BaseSHA = k.BaseSHA |
| } |
| if st.Specialist == wire.SpecialistMerge { |
| - st.MergeSHA, st.MergeInto, st.MergeStrategy = "", "", "" |
| + st.MergeSHA, st.MergeInto, st.MergeStrategy, st.MergeSource, st.MergeParents = "", "", "", "", "" |
| } |
| st.Withdrawn, st.RefusedBy = false, "" |
| if err := t.dispatchStep(&k, &st); err != nil { |
| @@ -1438,6 +1483,10 @@ func (t *txn) taskTool(r turnRecord, v *wire.ToolCall) (wire.ToolResult, error) |
| return t.recordTask(r, in.Repo, title, brief, in.Separate) |
| case wire.ToolAddReport: |
| return t.addReport(r, v.Args) |
| + case wire.ToolHoldMerge: |
| + return t.holdMerge(r, v.Args) |
| + case wire.ToolSetMergePolicy: |
| + return t.setMergePolicy(r, v.Args) |
| case wire.ToolAddFinding: |
| return t.addFinding(r, v.Args) |
| case wire.ToolStartTask: |
diff --git a/internal/equipo/chat/tools.go b/internal/equipo/chat/tools.go| index 1fecf012..b7c1279b 100644 |
| --- a/internal/equipo/chat/tools.go |
| +++ b/internal/equipo/chat/tools.go |
| @@ -424,7 +424,7 @@ func (t *txn) runTool(l Lease, v *wire.ToolCall) (wire.ToolResult, error) { |
| return refused("invalid", toolBadInput), nil |
| } |
| return t.setProjectHome(r, strings.TrimSpace(in.Namespace)) |
| - case wire.ToolRecordTask, wire.ToolAddFinding, wire.ToolStartTask, wire.ToolReadTask, wire.ToolCancelTask, wire.ToolAddReport: |
| + case wire.ToolRecordTask, wire.ToolAddFinding, wire.ToolStartTask, wire.ToolReadTask, wire.ToolCancelTask, wire.ToolAddReport, wire.ToolHoldMerge, wire.ToolSetMergePolicy: |
| return t.taskTool(r, v) |
| case wire.ToolAskPerson: |
| var in struct { |
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go| index 0ebaa18d..1faf3923 100644 |
| --- a/internal/equipo/chat_page.go |
| +++ b/internal/equipo/chat_page.go |
| @@ -120,6 +120,18 @@ func cardView(c wire.Card, choices []string, tasks map[string]wire.Task) chatCar |
| case c.State == wire.CardResolved: |
| v.Note = copyText("chat.card.merge_resolved") |
| } |
| + case wire.CardMergeShips, wire.CardMergePolicy, wire.CardMergeReceipt: |
| + // Merge authority: the ships question, a proposed policy, and the |
| + // receipt of Equipo's own merge (Undo when offered). |
| + v.Line, v.Open = c.Question, c.State == wire.CardOpen && len(c.Options) > 0 |
| + switch { |
| + case c.State == wire.CardAnswered && c.Kind == wire.CardMergeShips: |
| + v.Note = copyText("chat.card.ships_chose_" + c.Choice) |
| + case c.State == wire.CardAnswered && c.Kind == wire.CardMergePolicy: |
| + v.Note = copyText("chat.card.policy_chose_" + c.Choice) |
| + case c.State == wire.CardResolved: |
| + v.Note = copyText("chat.card.merge_policy_stale") |
| + } |
| case wire.CardCombined: |
| // Equipo combined two of the person's tasks: a quiet line, Undo. |
| v.Line, v.Open = c.Question, c.State == wire.CardOpen |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index 9c2508bb..c75b8963 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -1438,6 +1438,88 @@ var pageCopy = map[string]string{ |
| "specialist.model": "Model", |
| "specialist.concurrent": "Runs at once", |
| "specialist.instructions": "Instructions", |
| + |
| + // Merge authority (spec 2026-11-11-equipo-merge-authority.md). |
| + "chat.merge.stance_merge": "Merge %s? I'd merge: %s, but %s.", // COPY REVIEW REQUIRED |
| + "chat.merge.stance_wait": "Merge %s? I'd wait: %s.", // COPY REVIEW REQUIRED |
| + "chat.merge.why.approved": "approved by Review", // COPY REVIEW REQUIRED |
| + "chat.merge.why.small": "a small change, %d lines in %d files", // COPY REVIEW REQUIRED |
| + "chat.merge.why.not_shipping": "nothing ships until a release", // COPY REVIEW REQUIRED |
| + "chat.merge.why.exact_revert": "it exactly reverts %s", // COPY REVIEW REQUIRED |
| + "chat.merge.not.environment": "checks couldn't run because %s", // COPY REVIEW REQUIRED |
| + "chat.merge.not.no_checks": "it has no checks to run", // COPY REVIEW REQUIRED |
| + "chat.merge.not.protocol": "your runner needs an update before I merge on my own", // COPY REVIEW REQUIRED |
| + "chat.merge.not.facts": "the runner didn't say what changed", // COPY REVIEW REQUIRED |
| + "chat.merge.not.small": "it's bigger than I merge on my own (%d lines in %d files)", // COPY REVIEW REQUIRED |
| + "chat.merge.not.special": "it changes a symlink, a submodule or a file mode", // COPY REVIEW REQUIRED |
| + "chat.merge.not.sensitive": "it touches %s (%s)", // COPY REVIEW REQUIRED |
| + "chat.merge.not.signing": "it changes signing or version settings", // COPY REVIEW REQUIRED |
| + "chat.merge.not.ships": "merging to %s's main ships to users", // COPY REVIEW REQUIRED |
| + "chat.merge.not.ships_unknown": "I don't know yet whether %s's main ships to users", // COPY REVIEW REQUIRED |
| + "chat.merge.not.policy": "this project asks before every merge", // COPY REVIEW REQUIRED |
| + "chat.merge.not.revert": "it doesn't exactly revert %s", // COPY REVIEW REQUIRED |
| + "chat.merge.not.eligible": "it was ready before I merged on my own", // COPY REVIEW REQUIRED |
| + "chat.merge.not.sandbox": "its checks ran outside the sandbox", // COPY REVIEW REQUIRED |
| + "chat.merge.area.migrations": "the database schema", // COPY REVIEW REQUIRED |
| + "chat.merge.area.auth_secrets": "sign-in, keys or secrets", // COPY REVIEW REQUIRED |
| + "chat.merge.area.payments": "payments", // COPY REVIEW REQUIRED |
| + "chat.merge.area.ci_config": "the checks or CI setup", // COPY REVIEW REQUIRED |
| + "chat.merge.area.dependencies": "dependencies", // COPY REVIEW REQUIRED |
| + "chat.merge.area.release_signing": "release or signing settings", // COPY REVIEW REQUIRED |
| + "chat.merge.area.infrastructure": "infrastructure", // COPY REVIEW REQUIRED |
| + "chat.merge.area.project": "a path this project asks about", // COPY REVIEW REQUIRED |
| + "chat.card.wait_mac": "Wait for a Mac", // COPY REVIEW REQUIRED |
| + "chat.card.merge_chose_wait_mac": "Waiting for a Mac.", // COPY REVIEW REQUIRED |
| + "chat.merge.ships_question": "Does merging to %s's main ship to users?", // COPY REVIEW REQUIRED |
| + "chat.card.ships": "It ships", // COPY REVIEW REQUIRED |
| + "chat.card.not_ships": "It doesn't", // COPY REVIEW REQUIRED |
| + "chat.card.ships_chose_ships": "Merging to main ships, so I'll ask first.", // COPY REVIEW REQUIRED |
| + "chat.card.ships_chose_not_ships": "Main isn't a release, so I can merge small changes on my own.", // COPY REVIEW REQUIRED |
| + "chat.card.merge_policy_stale": "The policy changed since, so nothing was saved.", // COPY REVIEW REQUIRED |
| + "chat.merge.policy_confirm": "Change how Equipo merges %s: %s?", // COPY REVIEW REQUIRED |
| + "chat.card.save": "Save", // COPY REVIEW REQUIRED |
| + "chat.card.cancel": "Cancel", // COPY REVIEW REQUIRED |
| + "chat.card.policy_chose_save": "Saved.", // COPY REVIEW REQUIRED |
| + "chat.card.policy_chose_cancel": "Left as it was.", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.rules": "merge on its own when every rule holds, up to %d lines in %d files", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.ask": "ask before every merge", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.ships_unknown": "not yet told whether main ships to users", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.ships_yes": "main ships to users", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.ships_no": "main is not a release", // COPY REVIEW REQUIRED |
| + "chat.merge.policy.extra": "always ask about %s", // COPY REVIEW REQUIRED |
| + "chat.merge.receipt": "Merged [%s](%s) into %s without checks: %s.", // COPY REVIEW REQUIRED |
| + "chat.merge.receipt_unverified": "Merged [%s](%s) into %s without checks, but I couldn't tell which commit on main it is, so I can't undo it.", // COPY REVIEW REQUIRED |
| + "chat.merge.reverting": "Reverting it: [%s](%s).", // COPY REVIEW REQUIRED |
| + "chat.merge.revert_title": "Revert %s in %s", // COPY REVIEW REQUIRED |
| + "chat.merge.mode_reason_reverted": "a merge was undone (%s)", // COPY REVIEW REQUIRED |
| + "work.reason.merge_not_authorized": "Equipo's rules said to ask before merging", // COPY REVIEW REQUIRED |
| + "work.merge_policy.title": "How Equipo merges", // COPY REVIEW REQUIRED |
| + "work.merge_policy.rules": "Equipo merges on its own when Review approved it and its checks passed, or when checks couldn't run here and the change is small (up to %d lines in %d files), touches nothing sensitive and main is not a release.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ask": "Equipo asks before every merge in this project.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.reason": "It asks because %s.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_unknown": "Nobody has said yet whether merging to main ships to users, so Equipo asks.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_yes": "Merging to main ships to users, so Equipo asks before merging without checks.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_no": "Main is not a release: nothing ships until one.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.extra": "It always asks about %s.", // COPY REVIEW REQUIRED |
| + "work.merge_policy.words": "In your words: %s", // COPY REVIEW REQUIRED |
| + "work.merge_policy.decisions": "Recent decisions", // COPY REVIEW REQUIRED |
| + "work.merge_policy.decision.act": "Merged on its own", // COPY REVIEW REQUIRED |
| + "work.merge_policy.decision.ask": "Asked", // COPY REVIEW REQUIRED |
| + "work.merge_policy.decision.never": "Not ready to merge", // COPY REVIEW REQUIRED |
| + "work.merge_policy.mode": "How it decides", // COPY REVIEW REQUIRED |
| + "work.merge_policy.mode_rules": "Merge on its own when every rule holds", // COPY REVIEW REQUIRED |
| + "work.merge_policy.mode_ask": "Ask before every merge", // COPY REVIEW REQUIRED |
| + "work.merge_policy.max_lines": "Most lines changed", // COPY REVIEW REQUIRED |
| + "work.merge_policy.max_files": "Most files changed", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships": "Does merging to main ship to users?", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_opt_unknown": "Not answered", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_opt_yes": "Yes, it ships", // COPY REVIEW REQUIRED |
| + "work.merge_policy.ships_opt_no": "No, main is not a release", // COPY REVIEW REQUIRED |
| + "work.merge_policy.extra_label": "Paths that always ask, one per line", // COPY REVIEW REQUIRED |
| + "work.merge_policy.words_label": "In your words", // COPY REVIEW REQUIRED |
| + "work.merge_policy.save": "Save", // COPY REVIEW REQUIRED |
| + "work.merge_policy.edit": "Change", // COPY REVIEW REQUIRED |
| + "work.merge_policy.saved": "Saved.", // COPY REVIEW REQUIRED |
| } |
| func copyText(key string) string { |
diff --git a/internal/equipo/merge_policy_page.go b/internal/equipo/merge_policy_page.go| new file mode 100644 |
| index 00000000..67be83ee |
| --- /dev/null |
| +++ b/internal/equipo/merge_policy_page.go |
| @@ -0,0 +1,80 @@ |
| +package equipo |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "net/http" |
| + "strconv" |
| + "strings" |
| + |
| + "amadan.net/oficina/equipo/internal/equipo/mergegate" |
| + "amadan.net/oficina/equipo/internal/wire" |
| + "github.com/go-chi/chi/v5" |
| +) |
| + |
| +// mergePolicyView is a project page's "How Equipo merges" section: the |
| +// policy in plain sentences, the person's words, the recent decisions, |
| +// and an owner's form. |
| +type mergePolicyView struct { |
| + wire.MergePolicy |
| + Sentences []string |
| + Extra string |
| + Recent []mergeDecisionLine |
| +} |
| + |
| +type mergeDecisionLine struct { |
| + Label, Failing string |
| +} |
| + |
| +func mergePolicyViewOf(p wire.MergePolicy) *mergePolicyView { |
| + v := &mergePolicyView{MergePolicy: p, Extra: strings.Join(p.ExtraSensitive, "\n")} |
| + if p.Mode == mergegate.ModeAsk { |
| + v.Sentences = append(v.Sentences, copyText("work.merge_policy.ask")) |
| + if p.ModeReason != "" { |
| + v.Sentences = append(v.Sentences, fmt.Sprintf(copyText("work.merge_policy.reason"), p.ModeReason)) |
| + } |
| + } else { |
| + v.Sentences = append(v.Sentences, fmt.Sprintf(copyText("work.merge_policy.rules"), p.MaxLines, p.MaxFiles)) |
| + } |
| + v.Sentences = append(v.Sentences, copyText("work.merge_policy.ships_"+p.MainShips)) |
| + if len(p.ExtraSensitive) > 0 { |
| + v.Sentences = append(v.Sentences, fmt.Sprintf(copyText("work.merge_policy.extra"), strings.Join(p.ExtraSensitive, ", "))) |
| + } |
| + for _, d := range p.Decisions { |
| + var failing []string |
| + for _, r := range d.Reasons { |
| + if !r.OK { |
| + failing = append(failing, r.Name) |
| + } |
| + } |
| + v.Recent = append(v.Recent, mergeDecisionLine{Label: copyText("work.merge_policy.decision." + d.Class), Failing: strings.Join(failing, ", ")}) |
| + } |
| + return v |
| +} |
| + |
| +// workMergePolicy is an owner's form on the project page: their own |
| +// action, so it may loosen the policy. |
| +func (a *application) workMergePolicy(w http.ResponseWriter, r *http.Request) { |
| + id := chi.URLParam(r, "id") |
| + a.chatActionTo(w, r, "/projects/"+id, func(ctx context.Context, address string) error { |
| + atoi := func(name string) int { |
| + n, err := strconv.Atoi(strings.TrimSpace(r.PostFormValue(name))) |
| + if err != nil { |
| + return -1 |
| + } |
| + return n |
| + } |
| + rev, err := strconv.ParseInt(r.PostFormValue("revision"), 10, 64) |
| + if err != nil { |
| + return ErrInvalid |
| + } |
| + var extra []string |
| + for _, line := range strings.Split(r.PostFormValue("extra_sensitive"), "\n") { |
| + if g := strings.TrimSpace(line); g != "" { |
| + extra = append(extra, g) |
| + } |
| + } |
| + _, err = a.store.Chat().SetMergePolicy(ctx, address, id, wire.SetMergePolicy{Mode: r.PostFormValue("mode"), MaxLines: atoi("max_lines"), MaxFiles: atoi("max_files"), MainShips: r.PostFormValue("main_ships"), ExtraSensitive: extra, Words: r.PostFormValue("words"), Revision: rev}) |
| + return err |
| + }) |
| +} |
diff --git a/internal/equipo/migrations/0059_thin_merge_authority.sql b/internal/equipo/migrations/0059_thin_merge_authority.sql| new file mode 100644 |
| index 00000000..c3eacbc7 |
| --- /dev/null |
| +++ b/internal/equipo/migrations/0059_thin_merge_authority.sql |
| @@ -0,0 +1,12 @@ |
| +CREATE TABLE chat_merge_policies (project_id text PRIMARY KEY, mode text, mode_reason text, max_lines integer, max_files integer, main_ships text, ships_answered_by text, ships_asked numeric, extra_sensitive text, words text, revision integer, updated_by text, updated_at datetime); |
| +CREATE TABLE chat_merge_audit (id text PRIMARY KEY, project_id text, task_id text, kind text, at text, candidate_sha text, merge_sha text, class text, stance text, decided_by text, reasons text, inputs text, created_at datetime); |
| +CREATE INDEX chat_merge_audit_project ON chat_merge_audit(project_id); |
| +CREATE INDEX chat_merge_audit_task ON chat_merge_audit(task_id); |
| +ALTER TABLE chat_steps ADD COLUMN change_facts text; |
| +ALTER TABLE chat_steps ADD COLUMN decided_by text; |
| +ALTER TABLE chat_steps ADD COLUMN merge_source text; |
| +ALTER TABLE chat_steps ADD COLUMN merge_parents text; |
| +ALTER TABLE chat_tasks ADD COLUMN merge_hold text; |
| +ALTER TABLE chat_tasks ADD COLUMN merge_verified numeric; |
| +ALTER TABLE chat_tasks ADD COLUMN revert_of text; |
| +ALTER TABLE chat_tasks ADD COLUMN revert_sha text; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 909141b8..2c07b69b 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -596,9 +596,9 @@ CREATE TABLE chat_coordinators (person text PRIMARY KEY, state text, turn_id tex |
| CREATE TABLE chat_notebooks (person text PRIMARY KEY, entries text, revision integer, updated_at datetime); |
| CREATE INDEX chat_card_task ON chat_cards(task_id); |
| CREATE TABLE chat_project_attachments (project_id text, kind text, ref text, name text, created_at datetime, PRIMARY KEY (project_id, kind, ref)); |
| -CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, ready_sha text, merge_eligible text, done_at datetime, duplicate_of text, folded_into text, folded_stage text, folded_at datetime, engineering_runner text); |
| +CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, ready_sha text, merge_eligible text, done_at datetime, duplicate_of text, folded_into text, folded_stage text, folded_at datetime, engineering_runner text, merge_hold text, merge_verified numeric, revert_of text, revert_sha text); |
| CREATE INDEX chat_task_project ON chat_tasks(project_id); |
| -CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text); |
| +CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, change_facts text, decided_by text, merge_source text, merge_parents text); |
| CREATE INDEX chat_step_task ON chat_steps(task_id); |
| CREATE TABLE chat_task_entries (id text PRIMARY KEY, task_id text, idempotency_key text, kind text, author text, text text, repo text, path text, line integer, created_at datetime, headline text, folded_from text); |
| CREATE INDEX chat_entry_task ON chat_task_entries(task_id); |
| @@ -628,3 +628,7 @@ CREATE INDEX runner_command_runner ON runner_commands(runner_id); |
| CREATE INDEX chat_step_runner ON chat_steps(runner_id); |
| CREATE TABLE runner_transfers (id text PRIMARY KEY, person text, from_runner text, to_runner text, repo text, task_id text, step_id text, attempt integer, base_sha text, candidate_sha text, direction text, state text, sha256 text, total integer, received integer, bytes integer, expires_at datetime, created_at datetime); |
| CREATE INDEX runner_transfer_step ON runner_transfers(step_id); |
| +CREATE TABLE chat_merge_policies (project_id text PRIMARY KEY, mode text, mode_reason text, max_lines integer, max_files integer, main_ships text, ships_answered_by text, ships_asked numeric, extra_sensitive text, words text, revision integer, updated_by text, updated_at datetime); |
| +CREATE TABLE chat_merge_audit (id text PRIMARY KEY, project_id text, task_id text, kind text, at text, candidate_sha text, merge_sha text, class text, stance text, decided_by text, reasons text, inputs text, created_at datetime); |
| +CREATE INDEX chat_merge_audit_project ON chat_merge_audit(project_id); |
| +CREATE INDEX chat_merge_audit_task ON chat_merge_audit(task_id); |
diff --git a/internal/equipo/render.go b/internal/equipo/render.go| index 895db5d1..5e84a590 100644 |
| --- a/internal/equipo/render.go |
| +++ b/internal/equipo/render.go |
| @@ -52,7 +52,7 @@ func init() { |
| page = template.Must(page.ParseFS(appFS, "templates/layout.html")) |
| } |
| if name != "signin_page" && name != "errors" { |
| - page = template.Must(page.ParseFS(appFS, "templates/chrome.html", "templates/forms.html", "templates/task_card.html", "templates/conversation_card.html", "templates/work_parts.html", "templates/housekeeping_settings.html", "templates/settings_nav.html")) |
| + page = template.Must(page.ParseFS(appFS, "templates/chrome.html", "templates/forms.html", "templates/task_card.html", "templates/conversation_card.html", "templates/work_parts.html", "templates/housekeeping_settings.html", "templates/settings_nav.html", "templates/merge_policy.html")) |
| } |
| pages[name] = template.Must(page.ParseFS(appFS, "templates/"+name+".html")) |
| } |
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html| index 019006d6..f72825f6 100644 |
| --- a/internal/equipo/templates/chat.html |
| +++ b/internal/equipo/templates/chat.html |
| @@ -7,6 +7,7 @@ |
| {{else if eq .Kind "question"}}<p equipo-card-line>{{.Line}}</p>{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{range .Options}}<button rst-btn name="choice" value="{{.}}" type="submit">{{.}}</button>{{else}}<input rst-input name="choice" required maxlength="2000" aria-label="{{copy "chat.card.answer"}}"><button rst-btn="primary" type="submit">{{copy "chat.card.answer"}}</button>{{end}}</form>{{else}}<p equipo-card-note>{{printf (copy "chat.card.answered") .Choice}}</p>{{end}} |
| {{else if eq .Kind "home"}}<p equipo-card-line>{{icon "folder"}}<span>{{.Line}}</span></p><form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}"><button rst-btn="primary" name="choice" value="confirm" type="submit">{{copy "chat.card.confirm"}}</button></form> |
| {{else if eq .Kind "merge"}}<p equipo-card-line>{{.Line}}</p>{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{range .Options}}<button rst-btn="{{if eq . "merge"}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-merge-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}} |
| +{{else if or (eq .Kind "merge_ships") (eq .Kind "merge_policy") (eq .Kind "merge_receipt")}}{{if eq .Kind "merge_receipt"}}<div equipo-card-line equipo-markdown data-merge-receipt>{{chatMarkdown .Line}}</div>{{else}}<p equipo-card-line>{{.Line}}</p>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{range .Options}}<button rst-btn="{{if or (eq . "save") (eq . "not_ships")}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-merge-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}} |
| {{else if eq .Kind "access"}}<p equipo-card-line>{{.Line}}</p>{{if .Open}}<details equipo-grant><summary rst-btn>{{copy "chat.card.grant"}}</summary><p>{{copy "chat.card.grant_how"}}</p><code>amadan agent grant {{.Agent}} {{.Namespace}}</code><form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{.Revision}}"><button rst-btn name="choice" value="check" type="submit" data-grant-check>{{copy "chat.card.grant_check"}}</button></form></details>{{end}} |
| {{end}}</li>{{end}} |
| {{define "work-task-receipt"}}{{with .Task}}<p equipo-card-line>{{icon "check-circle"}}<span><a href="/tasks/{{.ID}}">{{.Title}}</a></span><span equipo-stage data-stage="{{.Stage}}" data-needs="{{.NeedsYou}}">{{.StageLine}}</span></p>{{if and .Pushed (not .MergedLine)}}<p equipo-card-note data-pushed><span>{{.Pushed}}</span><a href="{{.URL}}" rel="noopener" target="_blank" data-open-amadan>{{copy "work.open"}}</a></p>{{end}}{{if or .ChecksLine .ReviewLine}}<p equipo-card-note data-judged>{{with .ChecksLine}}<span data-checks>{{.}}</span>{{end}}{{with .ReviewLine}}<span data-verdict>{{.}}</span>{{end}}</p>{{end}}{{if .MergedLine}}<p equipo-card-note data-merged><span>{{.MergedLine}}</span><a href="{{.RepoURL}}" rel="noopener" target="_blank" data-open-amadan>{{copy "work.open"}}</a></p>{{end}}{{end}}{{if .Open}}<button type="button" equipo-receipt-more aria-expanded="false" aria-controls="acts-{{.ID}}" aria-label="{{copy "chat.card.more"}}">⋯</button><span equipo-receipt-actions id="acts-{{.ID}}">{{template "work-task-actions" .Task}}</span>{{end}}{{end}} |
diff --git a/internal/equipo/templates/merge_policy.html b/internal/equipo/templates/merge_policy.html| new file mode 100644 |
| index 00000000..8ced5c1a |
| --- /dev/null |
| +++ b/internal/equipo/templates/merge_policy.html |
| @@ -0,0 +1,17 @@ |
| +{{define "merge-policy"}}{{with .}}<section equipo-p-section data-merge-policy> |
| +<h2>{{copy "work.merge_policy.title"}}</h2> |
| +{{range .Sentences}}<p>{{.}}</p>{{end}} |
| +{{with .Words}}<p equipo-quiet data-merge-words>{{printf (copy "work.merge_policy.words") .}}</p>{{end}} |
| +{{if .Recent}}<h3>{{copy "work.merge_policy.decisions"}}</h3><ul equipo-notes>{{range .Recent}}<li data-merge-decision><p>{{.Label}}</p>{{with .Failing}}<p equipo-cap>{{.}}</p>{{end}}</li>{{end}}</ul>{{end}} |
| +{{if .Editable}}<details data-merge-policy-edit><summary rst-btn>{{copy "work.merge_policy.edit"}}</summary> |
| +<form method="post" action="/projects/{{.ProjectID}}/merge-policy" data-merge-policy-form> |
| +<input type="hidden" name="revision" value="{{.Revision}}"> |
| +<label>{{copy "work.merge_policy.mode"}} <select rst-input name="mode"><option value="rules"{{if eq .Mode "rules"}} selected{{end}}>{{copy "work.merge_policy.mode_rules"}}</option><option value="ask"{{if eq .Mode "ask"}} selected{{end}}>{{copy "work.merge_policy.mode_ask"}}</option></select></label> |
| +<label>{{copy "work.merge_policy.max_lines"}} <input rst-input type="number" name="max_lines" min="0" max="2000" value="{{.MaxLines}}"></label> |
| +<label>{{copy "work.merge_policy.max_files"}} <input rst-input type="number" name="max_files" min="0" max="100" value="{{.MaxFiles}}"></label> |
| +<label>{{copy "work.merge_policy.ships"}} <select rst-input name="main_ships"><option value="unknown"{{if eq .MainShips "unknown"}} selected{{end}}>{{copy "work.merge_policy.ships_opt_unknown"}}</option><option value="yes"{{if eq .MainShips "yes"}} selected{{end}}>{{copy "work.merge_policy.ships_opt_yes"}}</option><option value="no"{{if eq .MainShips "no"}} selected{{end}}>{{copy "work.merge_policy.ships_opt_no"}}</option></select></label> |
| +<label>{{copy "work.merge_policy.extra_label"}} <textarea rst-input name="extra_sensitive" rows="3">{{.Extra}}</textarea></label> |
| +<label>{{copy "work.merge_policy.words_label"}} <input rst-input name="words" maxlength="300" value="{{.Words}}"></label> |
| +<button rst-btn="primary" type="submit" data-merge-policy-save>{{copy "work.merge_policy.save"}}</button> |
| +</form></details>{{end}} |
| +</section>{{end}}{{end}} |
diff --git a/internal/equipo/templates/work_project.html b/internal/equipo/templates/work_project.html| index b352e11b..a4e1f38c 100644 |
| --- a/internal/equipo/templates/work_project.html |
| +++ b/internal/equipo/templates/work_project.html |
| @@ -13,6 +13,7 @@ |
| <section equipo-p-section><h2>{{copy "work.project.attachments"}}</h2><ul equipo-attach>{{range .Repos}}{{$r := .}}<li>{{icon "git"}}<div><p equipo-attach-name>{{.Name}}</p><p equipo-attach-sub>{{with .DefaultBranch}}<span>{{.}}</span>{{end}}{{with .HeadSubject}}<span>{{.}}</span>{{end}}{{with .HeadAt}}<span equipo-ago{{agoData . ""}}>{{$r.Ago}}</span>{{end}}</p></div>{{with .URL}}<span equipo-quiet><a href="{{.}}" rel="noopener" target="_blank" data-open-amadan>{{copy "work.open"}}</a></span>{{end}}</li>{{end}}</ul>{{with .ChecksLine}}<p equipo-quiet equipo-after>{{.}}</p>{{end}}</section> |
| {{if $.Thin.Activity}}<section equipo-p-section><h2>{{copy "work.project.recently"}}</h2><ol equipo-activity-list>{{range $.Thin.Activity}}<li><time equipo-ago{{agoData .At ""}} datetime="{{.At.Format "2006-01-02T15:04:05Z07:00"}}">{{.Ago}}</time><span>{{template "recent" .}}</span></li>{{end}}</ol></section>{{end}} |
| <section equipo-p-section><h2>{{copy "work.project.notes"}}</h2>{{if $.Thin.Notes}}<ul equipo-notes>{{range $.Thin.Notes}}<li equipo-note2><p>{{.Text}}</p><p equipo-cap>{{.From}}</p></li>{{end}}</ul>{{else}}<p equipo-quiet>{{copy "work.project.notes_empty"}}</p>{{end}}</section> |
| +{{template "merge-policy" $.Thin.MergePolicy}} |
| </aside> |
| </div> |
| </section>{{end}} |
diff --git a/internal/equipo/work_pages.go b/internal/equipo/work_pages.go| index 0f812abf..a06d022f 100644 |
| --- a/internal/equipo/work_pages.go |
| +++ b/internal/equipo/work_pages.go |
| @@ -314,9 +314,11 @@ type workView struct { |
| ProjectCount int |
| // Thread is the task page's thread. |
| Thread threadView |
| - // Notes and Activity are a project page's. |
| - Notes []projectNote |
| - Activity []projectEvent |
| + // Notes and Activity are a project page's, and MergePolicy its "How |
| + // Equipo merges" section. |
| + Notes []projectNote |
| + Activity []projectEvent |
| + MergePolicy *mergePolicyView |
| } |
| // workFilter is the Tasks page's two quiet filters. |
| @@ -564,6 +566,12 @@ func (a *application) workProject(w http.ResponseWriter, r *http.Request) bool { |
| return true |
| } |
| data.Thin.Notes = projectNotes(*data.Thin.Project, notebook.Entries) |
| + policy, err := a.store.Chat().MergePolicy(ctx, address, id) |
| + if err != nil { |
| + a.failure(w, r, chatError(err)) |
| + return true |
| + } |
| + data.Thin.MergePolicy = mergePolicyViewOf(policy) |
| data.Title = "nav.projects" |
| render(w, "work_project", data) |
| return true |
diff --git a/internal/runner/provider/actions.go b/internal/runner/provider/actions.go| index a569d04a..cf7f92d8 100644 |
| --- a/internal/runner/provider/actions.go |
| +++ b/internal/runner/provider/actions.go |
| @@ -79,7 +79,7 @@ func CoordinatorAction(action string) bool { return action == "coordinate" || ac |
| // ConverseTools is the thin coordinator's tool set (wire.ConverseTools |
| // plus create_project, which the runner carries out itself). |
| func ConverseTools() []string { |
| - return []string{"status", "find", "search_code", "read_file", "add_project", "create_project", "set_project_home", "ask_person", "write_note", "read_notes", "record_task", "add_finding", "start_task", "read_task", "cancel_task", "add_report"} |
| + return []string{"status", "find", "search_code", "read_file", "add_project", "create_project", "set_project_home", "ask_person", "write_note", "read_notes", "record_task", "add_finding", "start_task", "read_task", "cancel_task", "add_report", "hold_merge", "set_merge_policy"} |
| } |
| // AnswerTools are an answering session's Equipo tools: read-only git |
diff --git a/internal/runner/thin/mcp.go b/internal/runner/thin/mcp.go| index 7ee3e664..5037d7a3 100644 |
| --- a/internal/runner/thin/mcp.go |
| +++ b/internal/runner/thin/mcp.go |
| @@ -164,6 +164,8 @@ var converseTools = []any{ |
| map[string]any{"name": "read_task", "description": "Read a task: its stage, findings, steps (state, branch, commit, summary) and the person's notes on it.", "inputSchema": toolSchema(map[string]any{"task": str}, "task")}, |
| map[string]any{"name": "cancel_task", "description": "Cancel a task when the person asks; a running step stops.", "inputSchema": toolSchema(map[string]any{"task": str}, "task")}, |
| map[string]any{"name": "add_report", "description": "Add the person's new report of a problem that is already an open task (from record_task's similar list, or one you know) to that task, instead of recording a duplicate. text is what the person said. The person sees the task card.", "inputSchema": toolSchema(map[string]any{"task": str, "text": str}, "task", "text")}, |
| + map[string]any{"name": "hold_merge", "description": "Stop Equipo merging this task on its own when you have a concrete reason it needs the person's look (reason: one plain sentence, shown on their merge card). It can only make Equipo more careful: the person's own Merge still merges. There is no tool to lift a hold.", "inputSchema": toolSchema(map[string]any{"task": str, "reason": str}, "task", "reason")}, |
| + map[string]any{"name": "set_merge_policy", "description": "Record how Equipo merges a project, from what the person said (words: their sentence). mode is rules (merge on its own when every rule holds) or ask (ask before every merge); max_lines and max_files bound a merge without checks; main_ships is yes or no (does merging to main ship to users); add_sensitive adds path globs that always ask. A stricter change applies at once; a looser one waits for the person to tap Save on a card.", "inputSchema": toolSchema(map[string]any{"project": str, "words": str, "mode": str, "max_lines": map[string]any{"type": "integer"}, "max_files": map[string]any{"type": "integer"}, "main_ships": str, "add_sensitive": map[string]any{"type": "array", "items": str}}, "project", "words")}, |
| } |
| // stepTools are the tools the implement profile pins for an Engineering |
diff --git a/internal/thintest/authority_contract_test.go b/internal/thintest/authority_contract_test.go| index 190351a2..f5d2b1c8 100644 |
| --- a/internal/thintest/authority_contract_test.go |
| +++ b/internal/thintest/authority_contract_test.go |
| @@ -12,6 +12,12 @@ import ( |
| // personToolRig is a second team member with their own device, runner |
| // and running turn on the same instance as a. |
| func personToolRig(t *testing.T, a *toolRig, person string, role equipo.Role) *toolRig { |
| + t.Helper() |
| + return personToolRigAt(t, a, person, role, wire.Protocol1) |
| +} |
| + |
| +// personToolRigAt is personToolRig with a runner speaking protocol. |
| +func personToolRigAt(t *testing.T, a *toolRig, person string, role equipo.Role, protocol int) *toolRig { |
| t.Helper() |
| ctx := a.ctx |
| if err := a.inst.Store.SetMember(context.Background(), equipo.Actor{Address: Owner}, person, role, true, 0); err != nil { |
| @@ -30,8 +36,21 @@ func personToolRig(t *testing.T, a *toolRig, person string, role equipo.Role) *t |
| if role != equipo.RoleOwner { |
| return &toolRig{rig: r} |
| } |
| - runner := r.dial(0) |
| + var runner *FakeRunner |
| + if protocol <= wire.Protocol1 { |
| + runner = r.dial(0) |
| + } else { |
| + f, err := DialRunnerHello(ctx, a.inst.URL, r.runner, primaryAt(wire.Hello{Repos: []string{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{"runner": "test"}}, protocol)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(f.Close) |
| + runner = f |
| + } |
| hello := wire.Hello{Generation: runner.Welcome.Generation, Repos: []string{"amadan.net/oficina/sample", "amadan.net/oficina/equipo"}, CreateIn: []string{}, Agent: "equipo-test", Catalog: []wire.RepoInfo{{Repo: "amadan.net/oficina/sample", DefaultBranch: "main", Summary: "Woodstar is a reading app.", Names: []string{"sample", "Woodstar"}, Hints: []string{"go"}}}, Connections: []wire.HeldConnection{}, Versions: map[string]string{}} |
| + if protocol > wire.Protocol1 { |
| + hello = primaryAt(hello, protocol) |
| + } |
| if err := runner.Send(ctx, "h1", wire.FrameHello, hello); err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/thintest/gallery_test.go b/internal/thintest/gallery_test.go| index f013150f..cefe5acb 100644 |
| --- a/internal/thintest/gallery_test.go |
| +++ b/internal/thintest/gallery_test.go |
| @@ -71,15 +71,15 @@ func (r *toolRig) galleryJudged(key string, base, cand, outcome, reason string) |
| func newGallery(t *testing.T) *gallery { |
| t.Helper() |
| - a := newToolRig(t) |
| + a := newToolRigAt(t, wire.ProtocolMergeFacts) |
| g := &gallery{a: a} |
| - if err := a.runner.Send(a.ctx, "h-gallery", wire.FrameHello, galleryHello(a, a.runner.Welcome.Generation)); err != nil { |
| + if err := a.runner.Send(a.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(a, a.runner.Welcome.Generation), wire.ProtocolMergeFacts)); err != nil { |
| t.Fatal(err) |
| } |
| a.wait("catalog", func(c *Conversation) bool { return true }) |
| - g.b = personToolRig(t, a, "nora@example.com", equipo.RoleOwner) |
| + g.b = personToolRigAt(t, a, "nora@example.com", equipo.RoleOwner, wire.ProtocolMergeFacts) |
| b := g.b |
| - if err := b.runner.Send(b.ctx, "h-gallery", wire.FrameHello, galleryHello(b, b.runner.Welcome.Generation)); err != nil { |
| + if err := b.runner.Send(b.ctx, "h-gallery", wire.FrameHello, primaryAt(galleryHello(b, b.runner.Welcome.Generation), wire.ProtocolMergeFacts)); err != nil { |
| t.Fatal(err) |
| } |
| sha := func(c string) string { return strings.Repeat(c, 40) } |
| @@ -194,7 +194,7 @@ func TestPagesInnerScreens(t *testing.T) { |
| needs := a.get(owner, "/tasks?needs=you", 200) |
| has(needs, "Needs you", "2 decisions, each in one tap.", `data-decision="`+g.unchecked+`"`, "Merge without checks?", |
| - `data-merge-choice="merge"`, `data-merge-choice="wait"`, `name="from" value="needs"`, `data-decision="`+g.stopped+`"`, "Try again?", `data-group="others"`, `data-task="`+g.noras+`"`) |
| + `data-merge-choice="merge"`, `data-merge-choice="wait_mac"`, `name="from" value="needs"`, `data-decision="`+g.stopped+`"`, "Try again?", `data-group="others"`, `data-task="`+g.noras+`"`) |
| // No card for duplicates: Equipo tidies them, or names them quietly. |
| not(needs, "Needs you", `data-decision="`+g.noras+`"`, "Fold it into the other task?", `action="/tasks/`+g.stopped+`/duplicate"`) |
diff --git a/internal/thintest/inner_contract_test.go b/internal/thintest/inner_contract_test.go| index 4ce15ee4..547daaa1 100644 |
| --- a/internal/thintest/inner_contract_test.go |
| +++ b/internal/thintest/inner_contract_test.go |
| @@ -161,7 +161,7 @@ func TestContractTaskSourceAndDuplicates(t *testing.T) { |
| // TestContractCoordinatorMerging: while Equipo merges a task, the task |
| // says the coordinator is merging it, since the merge step started. |
| func TestContractCoordinatorMerging(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| id := r.judgedTask("a", "Fix the README typo", base, cand, wire.ChecksPassed, "") |
| _, body := r.expect(wire.FrameDispatch) |
diff --git a/internal/thintest/merge_contract_test.go b/internal/thintest/merge_contract_test.go| index c0e5583a..80dd25bc 100644 |
| --- a/internal/thintest/merge_contract_test.go |
| +++ b/internal/thintest/merge_contract_test.go |
| @@ -56,12 +56,11 @@ func (r *toolRig) replies() []string { |
| // the commit, the branch it went into and how; the coordinator says so in |
| // one outcome-level line, once. |
| func TestContractAutoMerge(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand, other := strings.Repeat("1", 40), strings.Repeat("2", 40), strings.Repeat("3", 40) |
| id := r.judgedTask("a", "Fix the README typo", base, cand, wire.ChecksPassed, "") |
| _, body := r.expect(wire.FrameDispatch) |
| - shape(t, "frames/dispatch.json", r.runner.Received[len(r.runner.Received)-1]) |
| m := body.(*wire.DispatchCommand) |
| if m.Specialist != wire.SpecialistMerge || m.CandidateSHA != cand || m.BaseSHA != base || m.Attempt != 1 || m.Person != Owner || m.Repo != "amadan.net/oficina/sample" || !wire.ValidTaskBranch(m.Branch) { |
| t.Fatalf("merge dispatch %+v", m) |
| @@ -134,7 +133,7 @@ func TestContractAutoMerge(t *testing.T) { |
| // answer it. Wait leaves the task at Ready to merge; Merge merges exactly |
| // that SHA, labelled without checks. A new candidate withdraws the card. |
| func TestContractMergeWithoutChecks(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| id := r.judgedTask("w", "Swipe back on iOS", base, cand, wire.ChecksCannotRun, "needs_macos") |
| @@ -159,7 +158,7 @@ func TestContractMergeWithoutChecks(t *testing.T) { |
| } |
| }) |
| shape(t, "api/card-merge.json", card) |
| - if cards != 1 || card.State != wire.CardOpen || card.Question != "Merge Swipe back on iOS without checks?" || !slices.Equal(card.Options, []string{"merge", "wait"}) || card.Name != "Swipe back on iOS" || card.TaskID != id { |
| + if cards != 1 || card.State != wire.CardOpen || card.Question != "Merge Swipe back on iOS? I'd wait: the runner didn't say what changed; I don't know yet whether Woodstar's main ships to users." || !slices.Equal(card.Options, []string{"merge", "wait_mac"}) || card.Name != "Swipe back on iOS" || card.TaskID != id { |
| t.Fatalf("merge card %+v (%d)", card, cards) |
| } |
| if r.heldKinds(wire.FrameDispatch) != 0 { |
| @@ -200,11 +199,11 @@ func TestContractMergeWithoutChecks(t *testing.T) { |
| t.Fatalf("other choice: %v", err) |
| } |
| // Wait: stays ready to merge, no merge. |
| - out, err := r.client.Answer(ctx, card.ID, wire.ChoiceWait, card.Revision) |
| - if err != nil || out.Card.State != wire.CardAnswered || out.Card.Choice != wire.ChoiceWait { |
| + out, err := r.client.Answer(ctx, card.ID, wire.ChoiceWaitMac, card.Revision) |
| + if err != nil || out.Card.State != wire.CardAnswered || out.Card.Choice != wire.ChoiceWaitMac { |
| t.Fatalf("wait %+v %v", out, err) |
| } |
| - if page := r.get(r.inst.Cookie(), "/conversation", 200); !strings.Contains(page, "Merge Swipe back on iOS without checks?") || !strings.Contains(page, "Waiting for checks.") || strings.Contains(page, `data-merge-choice="merge"`) { |
| + if page := r.get(r.inst.Cookie(), "/conversation", 200); !strings.Contains(page, "Merge Swipe back on iOS? I'd wait") || !strings.Contains(page, "Waiting for a Mac.") || strings.Contains(page, `data-merge-choice="merge"`) { |
| t.Fatalf("answered card: %s", page) |
| } |
| if k, _ := r.client.Task(ctx, id); k.Stage != wire.StageReadyToMerge || k.NeedsYou != wire.NeedsMerge || r.heldKinds(wire.FrameDispatch) != 0 { |
| @@ -227,7 +226,7 @@ func TestContractMergeWithoutChecks(t *testing.T) { |
| } |
| return false |
| }) |
| - if page := r.get(r.inst.Cookie(), "/conversation", 200); !strings.Contains(page, `data-merge-choice="merge"`) || !strings.Contains(page, ">Wait for checks</button>") { |
| + if page := r.get(r.inst.Cookie(), "/conversation", 200); !strings.Contains(page, `data-merge-choice="merge"`) || !strings.Contains(page, ">Wait for a Mac</button>") { |
| t.Fatalf("open card: %s", page) |
| } |
| if out, err := r.client.Answer(ctx, card2.ID, wire.ChoiceMerge, card2.Revision); err != nil || out.Card.Choice != wire.ChoiceMerge { |
| @@ -301,7 +300,7 @@ func TestContractMergeWithoutChecks(t *testing.T) { |
| // is judged afresh, from the new base, then merged. A second conflict |
| // needs the person. |
| func TestContractMergeConflictRebase(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand, tip, cand2 := strings.Repeat("1", 40), strings.Repeat("2", 40), strings.Repeat("6", 40), strings.Repeat("7", 40) |
| id := r.judgedTask("c", "Fix the README typo", base, cand, wire.ChecksPassed, "") |
| @@ -345,7 +344,7 @@ func TestContractMergeConflictRebase(t *testing.T) { |
| // task at Ready to merge with the reason and Retry; Retry merges the same |
| // judged SHA again (a new attempt), and a cancel is not offered mid-merge. |
| func TestContractMergeRefusedAndRetry(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| id := r.judgedTask("p", "Fix the README typo", base, cand, wire.ChecksPassed, "") |
| @@ -498,7 +497,7 @@ func (r *toolRig) cardOf(id string) wire.Card { |
| // Merge and Not now. Leaving Ready and coming back grants nothing; Merge |
| // on the card adopts it. |
| func TestContractNoRetroactiveMerge(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| id := r.legacyReady("l", "Fix the README typo", base, cand) |
| @@ -507,7 +506,7 @@ func TestContractNoRetroactiveMerge(t *testing.T) { |
| } |
| r.syncNow("l-sync") |
| card := r.cardOf(id) |
| - if card.State != wire.CardOpen || card.Question != "Merge Fix the README typo?" || !slices.Equal(card.Options, []string{"merge", "not_now"}) { |
| + if card.State != wire.CardOpen || card.Question != "Merge Fix the README typo? I'd merge: approved by Review, but it was ready before I merged on my own." || !slices.Equal(card.Options, []string{"merge", "not_now"}) { |
| t.Fatalf("adoption card %+v", card) |
| } |
| if r.heldKinds(wire.FrameDispatch) != 0 { |
| @@ -636,7 +635,7 @@ func TestContractMergeCardStaleAfterMove(t *testing.T) { |
| // merging it (API and the coordinator's tool); the runner's report of the |
| // hub's outcome ends it, here Done after a lost answer was settled. |
| func TestContractCancelRefusedWhileMerging(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| id := r.judgedTask("c", "Fix the README typo", base, cand, wire.ChecksPassed, "") |
diff --git a/internal/thintest/pages_test.go b/internal/thintest/pages_test.go| index ad35813a..6ba4ea3b 100644 |
| --- a/internal/thintest/pages_test.go |
| +++ b/internal/thintest/pages_test.go |
| @@ -66,7 +66,7 @@ func (r *toolRig) memberCookie() *http.Cookie { |
| // TestPagesTasksAndProjects: the task card, the Tasks and Projects pages |
| // and their actions are a thin layer over the same store a device reads. |
| func TestPagesTasksAndProjects(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| owner := r.inst.Cookie() |
| id := taskID(t, r.call("p1", wire.ToolRecordTask, map[string]string{"repo": "oficina/sample", "title": "Swipe back does nothing", "brief": "On iOS."})) |
| r.call("p2", wire.ToolAddFinding, map[string]any{"task": id, "text": "EdgeSwipe returns false.", "repo": "oficina/sample", "path": "panes/swipe.go", "line": 4}) |
diff --git a/internal/thintest/review_contract_test.go b/internal/thintest/review_contract_test.go| index 9a60e2d4..366ab6a6 100644 |
| --- a/internal/thintest/review_contract_test.go |
| +++ b/internal/thintest/review_contract_test.go |
| @@ -62,7 +62,7 @@ func (r *toolRig) verdict(key string, d *wire.DispatchCommand, verdict string, f |
| // decision; the runner watches the branch and a merge of that candidate |
| // makes the task done. |
| func TestContractReviewAndChecks(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand, cand2 := strings.Repeat("1", 40), strings.Repeat("2", 40), strings.Repeat("3", 40) |
| id, eng := r.pushed("a", "Fix the README typo", base, cand) |
| @@ -309,7 +309,7 @@ func TestContractSyncJudgesOldCandidates(t *testing.T) { |
| // opens B); the branch back at A restores it. A report about an older |
| // candidate changes nothing. |
| func TestContractBranchMovedInvalidatesReadiness(t *testing.T) { |
| - r := newToolRig(t) |
| + r := newToolRigAt(t, wire.ProtocolMergeFacts) |
| ctx := r.ctx |
| base, cand, other := strings.Repeat("1", 40), strings.Repeat("2", 40), strings.Repeat("5", 40) |
| id, _ := r.pushed("g", "Fix the README typo", base, cand) |
diff --git a/internal/thintest/tools_contract_test.go b/internal/thintest/tools_contract_test.go| index 92d71b00..87ce928e 100644 |
| --- a/internal/thintest/tools_contract_test.go |
| +++ b/internal/thintest/tools_contract_test.go |
| @@ -29,17 +29,43 @@ type heldFrame struct { |
| raw []byte |
| } |
| -func newToolRig(t *testing.T) *toolRig { |
| +func newToolRig(t *testing.T) *toolRig { return newToolRigAt(t, wire.Protocol1) } |
| + |
| +// primaryAt is a Linux primary's protocol 2+ hello fields. |
| +func primaryAt(h wire.Hello, protocol int) wire.Hello { |
| + h.Protocol, h.Platform, h.Label, h.Sandbox = protocol, &wire.Platform{OS: "linux", Arch: "amd64"}, "docs-t1", wire.SandboxBubblewrap |
| + h.Capabilities = &wire.Capabilities{Tags: []string{wire.TagLinux, wire.TagClaude, wire.TagCodex, wire.TagGo}} |
| + return h |
| +} |
| + |
| +// newToolRigAt is a tool rig whose runner speaks protocol: 1 is the |
| +// slice 4 wire; wire.ProtocolMergeFacts lets Equipo merge on its own. |
| +func newToolRigAt(t *testing.T, protocol int) *toolRig { |
| r := newRig(t) |
| // Housekeeping's clock runs from midday UTC today, so no test meets |
| // the default quiet hours (22:00 to 08:00) because of when it runs. |
| r.inst.Store.Chat().SetHousekeepingClock(daytime()) |
| - runner := r.dial(0) |
| + var runner *FakeRunner |
| + if protocol <= wire.Protocol1 { |
| + runner = r.dial(0) |
| + } else { |
| + f, err := DialRunnerHello(r.ctx, r.inst.URL, r.runner, primaryAt(wire.Hello{Repos: []string{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{"runner": "test"}}, protocol)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(f.Close) |
| + runner = f |
| + } |
| hello := toolHello(runner.Welcome.Generation) |
| + if protocol > wire.Protocol1 { |
| + hello = primaryAt(hello, protocol) |
| + } |
| if err := runner.Send(r.ctx, "h1", wire.FrameHello, hello); err != nil { |
| t.Fatal(err) |
| } |
| - shape(t, "frames/hello.json", runner.Sent[len(runner.Sent)-1]) |
| + if protocol <= wire.Protocol1 { |
| + shape(t, "frames/hello.json", runner.Sent[len(runner.Sent)-1]) |
| + } |
| r.wait("runner online", func(c *Conversation) bool { return c.Runner.Online }) |
| sent, err := r.client.Send(r.ctx, "hello", "k-tools") |
| if err != nil { |
diff --git a/internal/wire/frames.go b/internal/wire/frames.go| index 7eeb45db..2c4c252c 100644 |
| --- a/internal/wire/frames.go |
| +++ b/internal/wire/frames.go |
| @@ -484,7 +484,7 @@ const ( |
| ) |
| // ConverseTools is the coordinator's tool set in a conversation. |
| -var ConverseTools = []string{ToolStatus, ToolFind, ToolSearchCode, ToolReadFile, ToolAddProject, ToolCreateProject, ToolSetProjectHome, ToolAskPerson, ToolWriteNote, ToolReadNotes, ToolRecordTask, ToolAddFinding, ToolStartTask, ToolReadTask, ToolCancelTask, ToolAddReport} |
| +var ConverseTools = []string{ToolStatus, ToolFind, ToolSearchCode, ToolReadFile, ToolAddProject, ToolCreateProject, ToolSetProjectHome, ToolAskPerson, ToolWriteNote, ToolReadNotes, ToolRecordTask, ToolAddFinding, ToolStartTask, ToolReadTask, ToolCancelTask, ToolAddReport, ToolHoldMerge, ToolSetMergePolicy} |
| // MoveInTools are the tools a move_in or explore turn may use: it looks |
| // around and takes notes, and never acts for the person. |
| @@ -575,7 +575,7 @@ var MutationKinds = map[string]string{ |
| // WriteTools change something outside the coordinator's session: the |
| // runner replays an exact repeat of one in a later attempt from its own |
| // record. |
| -var WriteTools = []string{ToolAddProject, ToolCreateProject, ToolSetProjectHome, ToolAskPerson, ToolWriteNote, ToolRecordTask, ToolAddFinding, ToolStartTask, ToolCancelTask, ToolAddReport, ToolProjectCreated} |
| +var WriteTools = []string{ToolAddProject, ToolCreateProject, ToolSetProjectHome, ToolAskPerson, ToolWriteNote, ToolRecordTask, ToolAddFinding, ToolStartTask, ToolCancelTask, ToolAddReport, ToolHoldMerge, ToolSetMergePolicy, ToolProjectCreated} |
| // ActivityReport is what the coordinator started doing: thinking, or a |
| // tool by name. Sent once, never acked, like a delta. |
diff --git a/internal/wire/merge.go b/internal/wire/merge.go| new file mode 100644 |
| index 00000000..cb7d6663 |
| --- /dev/null |
| +++ b/internal/wire/merge.go |
| @@ -0,0 +1,86 @@ |
| +package wire |
| + |
| +import "time" |
| + |
| +// Merge authority (spec docs/superpowers/specs/2026-11-11-equipo-merge- |
| +// authority.md): cards, choices, tools and the API shapes. |
| + |
| +// Cards. A merge receipt says Equipo merged on its own, with Undo when |
| +// the merge SHA is the hub's word; the ships card asks once per project |
| +// whether merging to main ships to users; the policy card confirms a |
| +// change the coordinator proposed that would loosen the policy. |
| +const ( |
| + CardMergeReceipt = "merge_receipt" |
| + CardMergeShips = "merge_ships" |
| + CardMergePolicy = "merge_policy" |
| + // CardUndoneMerge is a receipt's state once Undo opened the revert. |
| + CardUndoneMerge = "undone" |
| +) |
| + |
| +// Choices. |
| +const ( |
| + ChoiceWaitMac = "wait_mac" |
| + ChoiceShips = "ships" |
| + ChoiceNotShips = "not_ships" |
| + ChoiceSave = "save" |
| + ChoiceCancel = "cancel" |
| +) |
| + |
| +// Coordinator tools: hold_merge stops Equipo merging a task on its own; |
| +// set_merge_policy proposes a project's policy (tighter applies at once, |
| +// looser needs the person's tap). |
| +const ( |
| + ToolHoldMerge = "hold_merge" |
| + ToolSetMergePolicy = "set_merge_policy" |
| +) |
| + |
| +// Merge policy bounds on the wire. |
| +const ( |
| + MaxMergeWords = 300 |
| + MaxMergeHold = 200 |
| +) |
| + |
| +// MergeDecision is the newest decision on a task's merge, as the task |
| +// shows it: the class, Equipo's stance and every criterion. |
| +type MergeDecision struct { |
| + Class string `json:"class"` |
| + Stance string `json:"stance,omitempty"` |
| + DecidedBy string `json:"decided_by,omitempty"` |
| + Reasons []MergeCriterion `json:"reasons"` |
| + At time.Time `json:"at"` |
| +} |
| + |
| +// MergeCriterion is one rule's outcome. |
| +type MergeCriterion struct { |
| + Name string `json:"name"` |
| + OK bool `json:"ok"` |
| + Value string `json:"value,omitempty"` |
| +} |
| + |
| +// MergePolicy is a project's merge policy (GET/PUT |
| +// /api/v1/projects/{id}/merge-policy). |
| +type MergePolicy struct { |
| + ProjectID string `json:"project_id"` |
| + Mode string `json:"mode"` |
| + ModeReason string `json:"mode_reason"` |
| + MaxLines int `json:"max_lines"` |
| + MaxFiles int `json:"max_files"` |
| + MainShips string `json:"main_ships"` |
| + ExtraSensitive []string `json:"extra_sensitive"` |
| + Words string `json:"words"` |
| + Revision int64 `json:"revision"` |
| + Editable bool `json:"editable"` |
| + Decisions []MergeDecision `json:"decisions"` |
| +} |
| + |
| +// SetMergePolicy is PUT /api/v1/projects/{id}/merge-policy: the whole |
| +// policy at Revision. |
| +type SetMergePolicy struct { |
| + Mode string `json:"mode"` |
| + MaxLines int `json:"max_lines"` |
| + MaxFiles int `json:"max_files"` |
| + MainShips string `json:"main_ships"` |
| + ExtraSensitive []string `json:"extra_sensitive"` |
| + Words string `json:"words"` |
| + Revision int64 `json:"revision"` |
| +} |
diff --git a/internal/wire/tasks.go b/internal/wire/tasks.go| index a158e60d..1a63cb22 100644 |
| --- a/internal/wire/tasks.go |
| +++ b/internal/wire/tasks.go |
| @@ -344,6 +344,14 @@ type Task struct { |
| // judged SHA, no merge yet and no merge card open (after Not now, or |
| // Wait for checks). |
| MergeOffered bool `json:"merge_offered"` |
| + // Merge authority: the newest decision on its merge, the coordinator's |
| + // hold, and the task it reverts (all absent when none). |
| + MergeDecision *MergeDecision `json:"merge_decision,omitempty"` |
| + MergeHold string `json:"merge_hold,omitempty"` |
| + RevertOf string `json:"revert_of,omitempty"` |
| + // UndoOffered: Equipo merged it on its own, the hub named the merge |
| + // commit, and the creator may still Undo it. |
| + UndoOffered bool `json:"undo_offered,omitempty"` |
| // CreatorName is the creator's display name (from the address until |
| // people have profiles). |
| CreatorName string `json:"creator_name"` |
diff --git a/internal/wire/wiretest/testdata/api/needs-you.json b/internal/wire/wiretest/testdata/api/needs-you.json| index 4130b761..c59872a4 100644 |
| --- a/internal/wire/wiretest/testdata/api/needs-you.json |
| +++ b/internal/wire/wiretest/testdata/api/needs-you.json |
| @@ -1 +1 @@ |
| -{"items":[{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":null,"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1"}]} |
| \ No newline at end of file |
| +{"items":[{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":null,"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1","merge_decision":{"class":"ask","stance":"wait","reasons":[{"name":"approved_exact_sha","ok":true},{"name":"facts_present","ok":false}],"at":"2026-11-11T10:00:00Z"}}]} |
diff --git a/internal/wire/wiretest/testdata/api/task-merged.json b/internal/wire/wiretest/testdata/api/task-merged.json| index f49b9eb3..90b1c9aa 100644 |
| --- a/internal/wire/wiretest/testdata/api/task-merged.json |
| +++ b/internal/wire/wiretest/testdata/api/task-merged.json |
| @@ -1 +1 @@ |
| -{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"done","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0009","revision":2,"task_id":"tk0001","index":4,"specialist":"merge","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":{"sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"at":"2026-11-07T12:00:00Z"},"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1"} |
| \ No newline at end of file |
| +{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"done","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0009","revision":2,"task_id":"tk0001","index":4,"specialist":"merge","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":{"sha":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","into":"main","strategy":"merge","without_checks":false,"at":"2026-11-07T12:00:00Z"},"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1","merge_decision":{"class":"act","decided_by":"policy","reasons":[{"name":"approved_exact_sha","ok":true}],"at":"2026-11-11T10:00:00Z"}} |
diff --git a/internal/wire/wiretest/testdata/api/task-ready.json b/internal/wire/wiretest/testdata/api/task-ready.json| index 681416c1..18d89323 100644 |
| --- a/internal/wire/wiretest/testdata/api/task-ready.json |
| +++ b/internal/wire/wiretest/testdata/api/task-ready.json |
| @@ -1 +1 @@ |
| -{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":null,"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1"} |
| \ No newline at end of file |
| +{"id":"tk0001","revision":9,"project_id":"p_0001","project":"Sample","repo":"amadan.net/oficina/sample","title":"Swipe back from the edge does nothing","brief":"Swiping from the left edge should go back a pane.","stage":"ready_to_merge","branch":"equipo/tk0001-swipe-back-from-the-edge-does-nothing","base_sha":"1111111111111111111111111111111111111111","url":"https://amadan.net/oficina/sample?branch=equipo/tk0001-swipe-back-from-the-edge-does-nothing","creator":"owner@example.com","turn_id":"t_0001","findings":[{"id":"f_0001","headline":"Found it: the edge swipe never reaches the back handler.","text":"The edge-swipe handler returns false, so back never fires.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:00:02Z"}],"steps":[{"id":"s_0001","revision":3,"task_id":"tk0001","index":1,"specialist":"engineering","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":true,"terminated":true,"summary":"EdgeSwipe now goes back on a swipe from the edge.","headline":"Fixed swipe-back from the edge.","log_tail":"Edit panes/swipe.go\nDone.","started_at":"2026-11-07T10:00:03Z","finished_at":"2026-11-07T10:01:40Z","round":0,"family":"claude","account":"claude-a","verdict":"","review_label":"","findings":[],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[{"kind":"read","subject":"panes/swipe.go","at":"2026-11-07T10:00:20Z"},{"kind":"edit","subject":"panes/swipe.go","at":"2026-11-07T10:01:02Z"},{"kind":"run","subject":"go test ./panes","at":"2026-11-07T10:01:20Z"}],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0002","revision":2,"task_id":"tk0001","index":2,"specialist":"checks","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"","headline":"","log_tail":"ok \tamadan.net/oficina/sample/panes\t0.012s","started_at":"2026-11-07T10:01:45Z","finished_at":"2026-11-07T10:02:30Z","round":0,"family":"","account":"","verdict":"","review_label":"","findings":[],"checks":"passed","gate":"make ci","exit_code":0,"askable":false,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"},{"id":"s_0003","revision":2,"task_id":"tk0001","index":3,"specialist":"review","state":"done","reason":"","attempt":1,"base_sha":"1111111111111111111111111111111111111111","candidate_sha":"2222222222222222222222222222222222222222","pushed":false,"terminated":true,"summary":"The change makes EdgeSwipe go back and keeps the pane order. Approved.","headline":"Approved.","log_tail":"Read panes/swipe.go","started_at":"2026-11-07T10:02:31Z","finished_at":"2026-11-07T10:04:10Z","round":0,"family":"claude","account":"claude-a","verdict":"approve","review_label":"same_family","findings":[{"id":"rf_0001","headline":"One note: worth a test for swipes that start mid-screen.","text":"Consider a test for a swipe that starts mid-screen.","repo":"amadan.net/oficina/sample","path":"panes/swipe.go","line":4,"at":"2026-11-07T10:04:10Z"}],"checks":"","gate":"","exit_code":null,"askable":true,"rebase":false,"merge_sha":"","into":"","strategy":"","without_checks":false,"switched":null,"activity":[],"runner_id":"RUNNER1","runner_label":"","needs":[],"placement":"","publication":"","termination_kind":"namespace"}],"thread":[{"id":"e_0001","author":"owner@example.com","text":"It happens on the iPhone only.","at":"2026-11-07T10:00:30Z"}],"created_at":"2026-11-07T10:00:01Z","updated_at":"2026-11-07T10:04:10Z","candidate_sha":"2222222222222222222222222222222222222222","checks":"passed","checks_reason":"","verdict":"approve","review_label":"same_family","needs_you":"merge","fix_rounds":0,"branch_head":"","questions":[{"id":"q_0001","revision":3,"task_id":"tk0001","step_id":"s_0001","specialist":"engineering","asker":"owner@example.com","text":"What did you change and why?","state":"answered","reason":"","attempt":1,"answer":"I made the edge swipe return true, so a swipe from the left edge goes back a pane. Before, the handler always said no.","created_at":"2026-11-07T10:05:00Z","updated_at":"2026-11-07T10:05:09Z","timing":null}],"merged":null,"reports":0,"ask_open":false,"merge_offered":false,"creator_name":"Owner","source_message_id":"m_0001","source_at":"2026-11-07T09:59:58Z","duplicate_of":null,"coordinator":null,"folded":null,"combined":null,"engineering_runner":"RUNNER1","merge_decision":{"class":"act","decided_by":"policy","reasons":[{"name":"approved_exact_sha","ok":true}],"at":"2026-11-11T10:00:00Z"}} |