Files
magpie/internal/agent/omp_advisor.go
T
yetone 3f6b1b0c94 agent: omp's advisor turns on with its model, and its review, wait and call-back are set in magpie (#6408, Awad_Yoo on X)
Awad_Yoo wants omp's advisor gated: one model executes, another reviews
only at key points. omp's advisor (src/advisor, advisor/settings.ts) runs
only while advisor.enabled is true, and omp leaves it off, so a model
picked for the advisor role in magpie reviewed nothing.

- A model picked for the advisor role writes advisor.enabled: true when
  the user hasn't set it. The role's reset takes back only what that pick
  wrote (a stash mark); the user's own on or off stays.
- Three Quiet fields write the rest of config.yml's advisor block, as omp
  reads it (omp_advisor.go):
  - advisor_review: off, turn, agent-end (enabled + reviewMode; off keeps
    the mode);
  - advisor_wait: syncBacklog off, "1", "3", "5", strict, written as
    strings, since omp's enum settings take only strings;
  - advisor_wake: continueSeverity nit, concern, blocker.
- GUI: omp's opened row and its panel sheet get three rows (Advisor; Waits
  for its review; Calls a finished agent back on). The last two show only
  while it reviews, and the rows redraw in place. They live in
  ompadvisor.js, imported the first time. The roles square's advisor line
  says " · off" when the advisor is off. Strings in zh, zh-TW, ja and de.
- Core script budget: +717 for what is left in app.js, after the rows
  moved out.
- docs/subsystems/agent-wiring.md has an "omp's advisor" row.

Not magpie's: taking over from the executor after repeated failures of
the same kind. omp has no such setting; "escalate" in its source is only a
note's severity. An omp extension can do it (pi.on("tool_result") with
pi.setModel), and that keeps the session's trace and completed tool
results. Said on the issue.

Run:
- mica-run go test -count=1 ./internal/agent/: ok.
- go vet ./internal/agent/ ./internal/gui/ for darwin, linux (nogui) and
  windows: clean. gofmt -l: nothing.
- internal/gui Go tests: on mote (below).
- GUI, on mote and mica: omp-advisor.test.cjs (new: chromium + webkit;
  1100 and 390px; en, zh, zh-TW, ja, de; panel sheet at 360) passes, as do
  agent-prefs, old-webkit's own check, i18n-en-no-cjk,
  omp-profile-connect and agent-row-disclose.
- Reds that fail the same on a clean worktree at origin/main 743001128
  (45 of 45, the same tests):
  - agent-details-ready: #6373;
  - i18n-keys "a plugin's words are its own": #6422;
  - old-webkit headerpresets.js: #6030;
  - old-webkit :has(): #5919;
  - omp-roles in Chromium, "no roles square": filed as #6432.
- The real omp 18.9.1, in a sandbox HOME (omp config get), reads
  enabled=true, reviewMode=agent-end and syncBacklog=1 as written.

Broken by hand:
- No auto-enable on the pick: TestOmpAdvisorPickTurnsItOn went red.
- No in-place redraw: the panel sheet cases went red, 3 of 3.

Not tried:
- A real omp session with the advisor reviewing.
- continueSeverity needs omp 18.12.1 or later; 18.9.1 doesn't know it.
- A WATCHDOG.yml roster's per-advisor settings aren't shown; omp uses them
  over these.
2026-11-13 13:18:35 +08:00

98 lines
3.7 KiB
Go

package agent
import (
"fmt"
"slices"
"github.com/yetone/magpie/internal/edit"
)
// omp's advisor (src/advisor in @oh-my-pi/pi-coding-agent): a second model,
// on the advisor role, that reviews the main agent's turns and sends it
// notes. Its model is a role (omp.go); whether it runs, when it reviews,
// how long the main agent waits for it and which note calls a finished
// agent back are these settings of config.yml (advisor/settings.ts, omp
// 18.20.0). A WATCHDOG.yml roster with advisors in it sets each one's own
// review and wait instead; omp reads the global ones only without one
// (#6408).
//
// omp's enum settings take strings only (config/registry.ts accepts), so
// syncBacklog's "1" is written as the string, never the number.
var (
ompAdvisorReviews = []string{"off", "turn", "agent-end"}
ompAdvisorWaits = []string{"off", "1", "3", "5", "strict"}
ompAdvisorWakes = []string{"nit", "concern", "blocker"}
)
// ompAdvisorOn reads advisor.enabled: "" while unset (omp's default, off)
func ompAdvisorOn(path string) string {
v, _ := edit.GetYAML(path, "advisor.enabled")
return v
}
// ompAdvisorTurnedOn is the stash's mark that magpie turned the advisor on
// at the config.yml at path, picking its model: the role's reset turns it
// off again, and the user setting it themselves takes the mark away
func ompAdvisorTurnedOn(path string) string { return "omp:" + path + ":advisor.enabled" }
// ompAdvisorFields are the advisor's settings in the config.yml at path.
// Each is Quiet: a row lists none of them until set.
func ompAdvisorFields(path string) []Field {
setting := func(key, label, setting string, values []string) Field {
return Field{
Key: key, Label: label, Quiet: true,
Get: func() string { v, _ := edit.GetYAML(path, setting); return v },
Set: func(v string) error {
if v == "" {
return edit.DelYAML(path, setting)
}
if !slices.Contains(values, v) {
return fmt.Errorf("%q is not one of omp's values for %s: %v", v, setting, values)
}
return edit.SetYAML(path, edit.KV{Path: setting, Value: v})
},
Options: func(map[string]string) []Option { return static(values...) },
}
}
return []Field{
{
// whether it runs and when it reviews, in one: off, each turn
// (each tool-call round) or only when the agent ends its run.
// Turned off, the review mode it had stays for the next time
Key: "advisor_review", Label: "advisor review", Quiet: true,
Get: func() string {
switch ompAdvisorOn(path) {
case "":
return ""
case "true":
if mode, _ := edit.GetYAML(path, "advisor.reviewMode"); mode == "agent-end" {
return mode
}
return "turn"
}
return "off"
},
Set: func(v string) error {
forget(ompAdvisorTurnedOn(path))
switch v {
case "":
return edit.DelYAML(path, "advisor.enabled")
case "off":
return edit.SetYAML(path, edit.KV{Path: "advisor.enabled", Value: false})
case "turn", "agent-end":
return edit.SetYAML(path, edit.KV{Path: "advisor.enabled", Value: true}, edit.KV{Path: "advisor.reviewMode", Value: v})
}
return fmt.Errorf("%q is not one of omp's advisor reviews: %v", v, ompAdvisorReviews)
},
Options: func(map[string]string) []Option { return static(ompAdvisorReviews...) },
},
// how far the main agent waits for a review it is owed before going
// on: not at all, up to 30 seconds while 1, 3 or 5 are behind, or
// until every review is in (strict, no time limit)
setting("advisor_wait", "advisor wait", "advisor.syncBacklog", ompAdvisorWaits),
// the least note that calls back an agent that has finished; one
// below it waits for the user's next message
setting("advisor_wake", "advisor wakes on", "advisor.continueSeverity", ompAdvisorWakes),
}
}