package wire import "encoding/json" // Exploration tasks (spec 2026-11-12-equipo-exploration-tasks.md): // mockups, prototypes, design options and spikes end at Review's // approval, a preview and the person's choice of direction, never a // merge. // Task kinds (Task.Kind). "" reads as KindChange. const ( KindChange = "change" KindExplore = "explore" ) // NormalKind is a kind as stored: "" is a change. func NormalKind(k string) string { if k == KindExplore { return KindExplore } return KindChange } // NeedsDirection: an exploration is approved; the person chooses build // this one, try again or drop it. const NeedsDirection = "direction" // CardDirection asks the task's creator which direction to take, once per // candidate; its answers are ChoiceBuild, ChoiceAgain (with a note) and // ChoiceDrop. const ( CardDirection = "direction" ChoiceBuild = "build" ChoiceAgain = "again" ChoiceDrop = "drop" ) // MaxDirectionNote bounds Try again's note and Build this's. const MaxDirectionNote = 1000 // TaskDirection is what the direction card shows: the candidate's // deployed preview, else its branch on Amadan, and whether the primary // said previews are off. Options are what the newest Design attempt kept // (protocol 38), by option; with more than one, NoteNeeded: Build this // needs the person's note saying which. type TaskDirection struct { PreviewURL string `json:"preview_url,omitempty"` BranchURL string `json:"branch_url"` PreviewsOff bool `json:"previews_off,omitempty"` Options []StepDesignOption `json:"options,omitempty"` NoteNeeded bool `json:"note_needed,omitempty"` } // ConflictDirectionNote is the card conflict a Build this without a note // gets on a direction card with more than one option. const ConflictDirectionNote = "direction_note" // SetKind is POST /api/v1/tasks/{id}/kind: the creator switches a task // between a change and an exploration, at the task's current revision. type SetKind struct { Kind string `json:"kind"` Revision int64 `json:"revision"` } // WithoutPreviews drops a hello's previews capability (in a copy, so the // caller's capabilities are untouched). The runner's first hello is sent // before the instance says its protocol, and an older instance's strict // decoder would refuse it; the next hello carries it once the welcome // says ProtocolExplore. It reports whether it dropped anything. func WithoutPreviews(h *Hello) bool { if h.Capabilities == nil || !h.Capabilities.Previews && h.Capabilities.PreviewHost == nil { return false } c := *h.Capabilities c.Previews, c.PreviewHost = false, nil h.Capabilities = &c return true } // WithoutPreviewHost drops a hello's preview host (ProtocolPreviewHost), // in a copy, keeping the previews flag. It reports whether it dropped it. func WithoutPreviewHost(h *Hello) bool { if h.Capabilities == nil || h.Capabilities.PreviewHost == nil { return false } c := *h.Capabilities c.PreviewHost = nil h.Capabilities = &c return true } // ExploreCall reports whether a tool call records an exploration // (record_task with kind explore). func ExploreCall(v *ToolCall) bool { if v.Name != ToolRecordTask { return false } var args struct { Kind string `json:"kind"` } return json.Unmarshal(v.Args, &args) == nil && args.Kind == KindExplore } // downgradeExplore clears ProtocolExplore's fields: a hello's previews // capability, and record_task's kind when it says change. A kind that // says explore is kept, so an older instance's strict decoder refuses the // whole call: an exploration never becomes a change. It reports whether // anything was dropped. func downgradeExplore(body any) bool { switch v := body.(type) { case *Hello: return WithoutPreviews(v) case *ToolCall: if v.Name != ToolRecordTask || ExploreCall(v) { return false } var args map[string]json.RawMessage if json.Unmarshal(v.Args, &args) != nil { return false } if _, ok := args["kind"]; !ok { return false } delete(args, "kind") raw, err := json.Marshal(args) if err != nil { return false } v.Args = raw return true } return false }