Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bc716d27be
commit
bcce34cda1
603 files changed
+1366
-1277
No files matched your search
+2
-2
@@ -52,7 +52,7 @@ func (dc *agentDiffCache) update(ch FileChange) {
|
||||
}
|
||||
|
||||
// agentDiffOf returns the cached diff of ch kept on holder.
|
||||
func agentDiffOf(holder *ui.Element, ch FileChange) *agentDiffCache {
|
||||
func agentDiffOf(holder ui.Element, ch FileChange) *agentDiffCache {
|
||||
dc := ui.Local(holder, "mujica.agent.diff", func() *agentDiffCache { return &agentDiffCache{} })
|
||||
(*dc).update(ch)
|
||||
return *dc
|
||||
@@ -98,7 +98,7 @@ func agentDiffRow(c *ui.Context, l internal.DiffLine) {
|
||||
}
|
||||
|
||||
// agentDiffView shows lines[from:to] in a capped well, virtualized when long.
|
||||
func agentDiffView(c *ui.Context, lines []internal.DiffLine, maxHeight float32) *ui.Element {
|
||||
func agentDiffView(c *ui.Context, lines []internal.DiffLine, maxHeight float32) ui.Element {
|
||||
w := AgentWellRows(c, len(lines), func(i int) { agentDiffRow(c, lines[i]) }, maxHeight)
|
||||
return w.Padding(core.Density(c).Unit(), 0)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func agentTone(k theme.Tokens, s AgentState) (ui.Color, *ui.SVG) {
|
||||
}
|
||||
|
||||
// agentMark draws s; running spins unless still.
|
||||
func agentMark(c *ui.Context, s AgentState, size float32, still bool) *ui.Element {
|
||||
func agentMark(c *ui.Context, s AgentState, size float32, still bool) ui.Element {
|
||||
tone, icon := agentTone(core.Tokens(c), s)
|
||||
if s == AgentRunning && !still {
|
||||
return core.Spinner(c, core.SpinnerOptions{Size: size, Color: tone, Label: core.Msg(c, "agent_status.running")})
|
||||
@@ -95,7 +95,7 @@ func AgentDuration(d time.Duration) string {
|
||||
}
|
||||
|
||||
// AgentCard is the bordered surface every agent card sits on.
|
||||
func AgentCard(c *ui.Context) *ui.Element {
|
||||
func AgentCard(c *ui.Context) ui.Element {
|
||||
k := core.Tokens(c)
|
||||
u := core.Density(c).Unit()
|
||||
return ui.Column(c).Shrink(0).Padding(u*3).Gap(u*2).Radius(theme.CardRadius).
|
||||
@@ -103,12 +103,12 @@ func AgentCard(c *ui.Context) *ui.Element {
|
||||
}
|
||||
|
||||
// AgentCaption is small muted text.
|
||||
func AgentCaption(c *ui.Context, s string) *ui.Element {
|
||||
func AgentCaption(c *ui.Context, s string) ui.Element {
|
||||
return ui.Text(c, s).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(core.Tokens(c).TextMuted)
|
||||
}
|
||||
|
||||
// agentWell styles a sunken monospace well.
|
||||
func agentWell(c *ui.Context, l *ui.Element, maxHeight float32) *ui.Element {
|
||||
func agentWell(c *ui.Context, l ui.Element, maxHeight float32) ui.Element {
|
||||
k := core.Tokens(c)
|
||||
u := core.Density(c).Unit()
|
||||
return l.Shrink(1).MaxHeight(maxHeight).Padding(u*2, u*3).Radius(theme.ControlRadius).
|
||||
@@ -117,12 +117,12 @@ func agentWell(c *ui.Context, l *ui.Element, maxHeight float32) *ui.Element {
|
||||
}
|
||||
|
||||
// AgentWellRows builds n rows in a well.
|
||||
func AgentWellRows(c *ui.Context, n int, row func(i int), maxHeight float32) *ui.Element {
|
||||
func AgentWellRows(c *ui.Context, n int, row func(i int), maxHeight float32) ui.Element {
|
||||
return agentWell(c, AgentRows(c, n, row), maxHeight)
|
||||
}
|
||||
|
||||
// AgentRows builds n scrolling rows, virtualized when many.
|
||||
func AgentRows(c *ui.Context, n int, row func(i int)) *ui.Element {
|
||||
func AgentRows(c *ui.Context, n int, row func(i int)) ui.Element {
|
||||
if n > agentVirtualRows {
|
||||
return ui.List(c, nil, n, row)
|
||||
}
|
||||
@@ -196,7 +196,7 @@ func agentCodeLine(c *ui.Context, language, line string, inBlock bool) {
|
||||
}
|
||||
|
||||
// AgentCode shows highlighted text in a capped well.
|
||||
func AgentCode(c *ui.Context, language, text string, maxHeight float32) *ui.Element {
|
||||
func AgentCode(c *ui.Context, language, text string, maxHeight float32) ui.Element {
|
||||
holder := ui.Column(c).Shrink(1)
|
||||
cc := ui.Local(holder, "mujica.agent.code", func() *agentCodeCache { return &agentCodeCache{} })
|
||||
(*cc).update(language, text)
|
||||
@@ -260,7 +260,7 @@ func agentAnsiSpans(k theme.Tokens, in []internal.AnsiSpan) []ui.Span {
|
||||
}
|
||||
|
||||
// agentBar is a thin progress bar named label.
|
||||
func agentBar(c *ui.Context, frac float64, label string) *ui.Element {
|
||||
func agentBar(c *ui.Context, frac float64, label string) ui.Element {
|
||||
if frac < 0 || frac > 1 || frac != frac {
|
||||
panic(fmt.Sprintf("mujica: progress %v outside 0..1", frac))
|
||||
}
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ func AgentPlan(c *ui.Context, items *[]PlanItem, opts AgentPlanOptions) core.Cho
|
||||
agentBar(c, frac, fmt.Sprintf(core.Msg(c, "agent_plan.progress"), done, counted))
|
||||
list := *items
|
||||
for i := range list {
|
||||
ui.Row(c).Key(list[i].ID).Gap(u * 2).AlignItems(ui.Center).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
||||
ui.Row(c.Key(list[i].ID)).Gap(u * 2).AlignItems(ui.Center).MinHeight(core.Density(c).ControlHeight()).Children(func() {
|
||||
if agentPlanRow(c, &list[i], locked, opts.Still) {
|
||||
r = core.NewChoiceResult(r.Element, true)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ type AgentProgressOptions struct {
|
||||
}
|
||||
|
||||
// AgentProgress shows progress 0 to 1 and the current action.
|
||||
func AgentProgress(c *ui.Context, value float64, opts AgentProgressOptions) *ui.Element {
|
||||
func AgentProgress(c *ui.Context, value float64, opts AgentProgressOptions) ui.Element {
|
||||
label := opts.Label
|
||||
if label == "" {
|
||||
label = core.Msg(c, "agent_progress.label")
|
||||
|
||||
@@ -16,7 +16,7 @@ type AgentStatusOptions struct {
|
||||
}
|
||||
|
||||
// AgentStatus shows a state by icon shape and word.
|
||||
func AgentStatus(c *ui.Context, state AgentState, opts AgentStatusOptions) *ui.Element {
|
||||
func AgentStatus(c *ui.Context, state AgentState, opts AgentStatusOptions) ui.Element {
|
||||
label := opts.Label
|
||||
if label == "" {
|
||||
label = agentWord(c, state) // panics on an unknown state
|
||||
|
||||
@@ -33,16 +33,14 @@ func TestAgentStatusAnimationStopsWhenStill(t *testing.T) {
|
||||
}, 300, 100)
|
||||
tt.Frame()
|
||||
moving := string(tt.Image().Pix)
|
||||
time.Sleep(80 * time.Millisecond)
|
||||
tt.Frame()
|
||||
tt.Advance(80 * time.Millisecond)
|
||||
if moving == string(tt.Image().Pix) {
|
||||
t.Fatal("running status did not animate")
|
||||
}
|
||||
still = true
|
||||
tt.Frame()
|
||||
a := string(tt.Image().Pix)
|
||||
time.Sleep(80 * time.Millisecond)
|
||||
tt.Frame()
|
||||
tt.Advance(80 * time.Millisecond)
|
||||
if a != string(tt.Image().Pix) {
|
||||
t.Fatal("still status kept moving")
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ type AgentStepListOptions struct {
|
||||
|
||||
// AgentStepListResult reports this frame's events.
|
||||
type AgentStepListResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Retry is the failed step to retry, else "".
|
||||
Retry string
|
||||
// Toggled is the step whose detail toggled, else "".
|
||||
@@ -55,7 +55,7 @@ func AgentStepList(c *ui.Context, steps []AgentStep, opts AgentStepListOptions)
|
||||
open := ui.Local(r.Element, "mujica.steps.open", func() map[string]bool { return map[string]bool{} })
|
||||
r.Element.Children(func() {
|
||||
for i, s := range steps {
|
||||
ui.Column(c).Key(s.ID).Children(func() {
|
||||
ui.Column(c.Key(s.ID)).Children(func() {
|
||||
if agentStepRow(c, s, i, len(steps), i == current, (*open)[s.ID], opts.Still, &r) {
|
||||
(*open)[s.ID] = !(*open)[s.ID]
|
||||
r.Toggled = s.ID
|
||||
|
||||
@@ -42,7 +42,7 @@ type ArtifactPanelOptions struct {
|
||||
|
||||
// ArtifactPanelResult reports this frame's events.
|
||||
type ArtifactPanelResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Copied reports the content went to the clipboard.
|
||||
Copied bool
|
||||
// Exported asks the caller to export the artifact.
|
||||
|
||||
@@ -23,7 +23,7 @@ type ArtifactVersionSwitcherOptions struct {
|
||||
|
||||
// ArtifactVersionResult reports this frame's events.
|
||||
type ArtifactVersionResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Changed reports *current moved.
|
||||
Changed bool
|
||||
// Compare asks to diff current against the previous version.
|
||||
|
||||
@@ -91,7 +91,7 @@ func checkpointRow(c *ui.Context, p Checkpoint, current, locked bool) bool {
|
||||
d := core.Density(c)
|
||||
u := d.Unit()
|
||||
asked := false
|
||||
row := ui.Row(c).Key(p.ID).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3)
|
||||
row := ui.Row(c.Key(p.ID)).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3)
|
||||
if current {
|
||||
row.Background(k.Selection)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type FileChangeCardOptions struct {
|
||||
|
||||
// FileChangeResult reports this frame's events.
|
||||
type FileChangeResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Decided reports that *decision changed.
|
||||
Decided bool
|
||||
// OpenDiff asks the caller to show the full diff.
|
||||
|
||||
@@ -28,7 +28,7 @@ type HumanInputRequestOptions struct {
|
||||
|
||||
// HumanInputResult reports this frame's events.
|
||||
type HumanInputResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
Submitted bool
|
||||
// TimedOut reports the frame the deadline passed.
|
||||
TimedOut bool
|
||||
|
||||
@@ -53,7 +53,7 @@ type MCPServerListOptions struct {
|
||||
|
||||
// MCPServerListResult reports this frame's request.
|
||||
type MCPServerListResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
Action MCPAction
|
||||
// Server is the ID the action is for.
|
||||
Server string
|
||||
@@ -105,7 +105,7 @@ func mcpServerRow(c *ui.Context, s MCPServer, locked, still bool) MCPAction {
|
||||
words := [...]string{"stopped", "connecting", "connected", "error"}
|
||||
word := core.Msg(c, "mcp_server_list."+words[s.State])
|
||||
act := MCPNone
|
||||
ui.Row(c).Key(s.ID).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3).
|
||||
ui.Row(c.Key(s.ID)).Gap(u*3).AlignItems(ui.Center).MinHeight(d.ControlHeight()+u*2).Padding(u*2, u*3).
|
||||
Label(s.Name + ", " + word).Children(func() {
|
||||
switch s.State {
|
||||
case MCPConnecting:
|
||||
|
||||
@@ -30,7 +30,7 @@ type MemoryPanelOptions struct {
|
||||
|
||||
// MemoryPanelResult reports this frame's in-place edits.
|
||||
type MemoryPanelResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Edited and Deleted are changed IDs, else "".
|
||||
Edited string
|
||||
Deleted string
|
||||
@@ -74,7 +74,7 @@ func MemoryPanel(c *ui.Context, entries *[]MemoryEntry, opts MemoryPanelOptions)
|
||||
}
|
||||
AgentRows(c, len(st.shown), func(i int) {
|
||||
idx := st.shown[i]
|
||||
ui.Column(c).Key((*entries)[idx].ID).Children(func() { memoryRow(c, entries, idx, st, locked, &r) })
|
||||
ui.Column(c.Key((*entries)[idx].ID)).Children(func() { memoryRow(c, entries, idx, st, locked, &r) })
|
||||
}).Shrink(1).MaxHeight(maxH).Dividers(theme.BorderWidth, core.Tokens(c).Border)
|
||||
})
|
||||
if r.Deleted != "" {
|
||||
@@ -123,7 +123,7 @@ func memoryRow(c *ui.Context, entries *[]MemoryEntry, idx int, st *memoryPanelSt
|
||||
u := core.Density(c).Unit()
|
||||
ui.Column(c).Gap(u).Padding(u*2, 0).Children(func() {
|
||||
if st.editing == e.ID && !locked {
|
||||
input.TextArea(c, &st.draft, input.TextAreaOptions{Label: core.Msg(c, "memory_panel.edit"), MinHeight: 60}).Input.AutoFocus()
|
||||
core.AutoFocus(c, input.TextArea(c, &st.draft, input.TextAreaOptions{Label: core.Msg(c, "memory_panel.edit"), MinHeight: 60}).Input)
|
||||
ui.Row(c).Gap(u * 2).Justify(ui.End).Children(func() {
|
||||
if input.Button(c, core.Msg(c, "memory_panel.cancel"), input.ButtonOptions{Variant: input.Secondary}).Clicked() {
|
||||
st.editing = ""
|
||||
|
||||
@@ -79,7 +79,7 @@ func MultiFileDiffReview(c *ui.Context, decisions *[]FileDecision, files []FileC
|
||||
slog.Debug("mujica: multi_file_diff_review select", "path", files[i].Path)
|
||||
}
|
||||
}
|
||||
var list *ui.Element
|
||||
var list ui.Element
|
||||
if len(files) > agentVirtualRows {
|
||||
list = ui.List(c, nil, len(files), row)
|
||||
} else {
|
||||
@@ -109,7 +109,7 @@ func MultiFileDiffReview(c *ui.Context, decisions *[]FileDecision, files []FileC
|
||||
func multiFileRow(c *ui.Context, f FileChange, d FileDecision, selected bool) bool {
|
||||
k := core.Tokens(c)
|
||||
u := core.Density(c).Unit()
|
||||
row := ui.ButtonBase(c).Key(f.Path).Justify(ui.Start).Gap(u*2).MinHeight(core.Density(c).ControlHeight()).
|
||||
row := ui.ButtonBase(c.Key(f.Path)).Justify(ui.Start).Gap(u*2).MinHeight(core.Density(c).ControlHeight()).
|
||||
Padding(0, u*2).Radius(theme.ControlRadius).Label(f.Path)
|
||||
internal.Ring(row, k.Focus, theme.ControlRadius)
|
||||
dc := agentDiffOf(row, f)
|
||||
@@ -133,7 +133,7 @@ func multiFileRow(c *ui.Context, f FileChange, d FileDecision, selected bool) bo
|
||||
func fileChangeDecide(c *ui.Context, d *FileDecision, f FileChange, locked bool) bool {
|
||||
u := core.Density(c).Unit()
|
||||
changed := false
|
||||
holder := ui.Column(c).Key(f.Path).Grow(1).Shrink(1).Gap(u * 2)
|
||||
holder := ui.Column(c.Key(f.Path)).Grow(1).Shrink(1).Gap(u * 2)
|
||||
dc := agentDiffOf(holder, f)
|
||||
holder.Children(func() {
|
||||
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
||||
|
||||
@@ -32,7 +32,7 @@ type PermissionPromptOptions struct {
|
||||
|
||||
// PermissionResult reports the choice made in this frame.
|
||||
type PermissionResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
Choice PermissionChoice
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func PermissionPrompt(c *ui.Context, open *bool, opts PermissionPromptOptions) P
|
||||
r.Element = overlay.Dialog(c, open, overlay.DialogOptions{
|
||||
Title: opts.Title, Description: opts.Description, KeepOnBackdrop: true, HideClose: true,
|
||||
Actions: func() {
|
||||
if input.Button(c, core.Msg(c, "permission_prompt.deny"), input.ButtonOptions{Variant: input.Secondary}).AutoFocus().Clicked() {
|
||||
if core.AutoFocus(c, input.Button(c, core.Msg(c, "permission_prompt.deny"), input.ButtonOptions{Variant: input.Secondary})).Clicked() {
|
||||
r.Choice = PermissionDeny
|
||||
}
|
||||
if input.Button(c, core.Msg(c, "permission_prompt.always"), input.ButtonOptions{Variant: input.Outline}).Clicked() {
|
||||
|
||||
@@ -45,7 +45,7 @@ type SandboxStatusOptions struct {
|
||||
}
|
||||
|
||||
// SandboxStatus shows sandbox state, resources and time left.
|
||||
func SandboxStatus(c *ui.Context, info SandboxInfo, opts SandboxStatusOptions) *ui.Element {
|
||||
func SandboxStatus(c *ui.Context, info SandboxInfo, opts SandboxStatusOptions) ui.Element {
|
||||
agent := map[SandboxState]AgentState{SandboxStarting: AgentPlanning, SandboxRunning: AgentRunning, SandboxStopped: AgentSkipped, SandboxFailed: AgentFailed}
|
||||
state, ok := agent[info.State]
|
||||
if !ok {
|
||||
|
||||
@@ -74,7 +74,7 @@ func subAgentRow(c *ui.Context, a SubAgent, depth int, open, still bool) bool {
|
||||
d := core.Density(c)
|
||||
u := d.Unit()
|
||||
parent := len(a.Children) > 0
|
||||
row := ui.ButtonBase(c).Key(a.ID).Justify(ui.Start).Gap(u*2).MinHeight(d.ControlHeight()).
|
||||
row := ui.ButtonBase(c.Key(a.ID)).Justify(ui.Start).Gap(u*2).MinHeight(d.ControlHeight()).
|
||||
Padding(0, u*2, 0, u*2+float32(depth)*u*5).Radius(theme.ControlRadius).
|
||||
Label(a.Name + ", " + agentWord(c, a.State))
|
||||
internal.Ring(row, k.Focus, theme.ControlRadius)
|
||||
|
||||
@@ -22,7 +22,7 @@ type ToolApprovalOptions struct {
|
||||
|
||||
// ToolApprovalResult reports the choice made in this frame.
|
||||
type ToolApprovalResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
Allowed bool
|
||||
Denied bool
|
||||
}
|
||||
@@ -39,7 +39,7 @@ func ToolApprovalDialog(c *ui.Context, open *bool, opts ToolApprovalOptions) Too
|
||||
Title: core.Msg(c, "tool_approval_dialog.title"), Description: opts.Reason, KeepOnBackdrop: true, HideClose: true,
|
||||
Actions: func() {
|
||||
// Deny first: a reflexive Enter never runs the tool.
|
||||
if input.Button(c, core.Msg(c, "tool_approval_dialog.deny"), input.ButtonOptions{Variant: input.Secondary}).AutoFocus().Clicked() {
|
||||
if core.AutoFocus(c, input.Button(c, core.Msg(c, "tool_approval_dialog.deny"), input.ButtonOptions{Variant: input.Secondary})).Clicked() {
|
||||
r.Denied = true
|
||||
}
|
||||
if input.Button(c, core.Msg(c, "tool_approval_dialog.allow"), input.ButtonOptions{}).Clicked() {
|
||||
|
||||
@@ -64,7 +64,7 @@ func ToolCallGroup(c *ui.Context, open *bool, calls []ToolCall, opts ToolCallGro
|
||||
})
|
||||
}}, func() {
|
||||
for _, call := range calls {
|
||||
ui.Column(c).Key(call.ID).Children(func() { ToolCallCard(c, call, ToolCallCardOptions{Still: opts.Still}) })
|
||||
ui.Column(c.Key(call.ID)).Children(func() { ToolCallCard(c, call, ToolCallCardOptions{Still: opts.Still}) })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user