+// Report logs the report text of a subagent as a work message and tells the
+// clients. Unless the subagent was stopped, the report joins the waiting
+// messages and wakes the loop, as a user message of Submit does. A failed write
+// stops the loop, because the log refuses all writes after it.
+func (l *TurnLoop) Report(text string, stopped bool) {
+ message, err := l.record("work", "", text)
+
+ l.mutex.Lock()
+ switch {
+ case err != nil:
+ l.failure = fmt.Errorf("%w: %w", errChainLogWrite, err)
+ case !stopped:
+ l.pending = append(l.pending, message)
+ }
+ l.mutex.Unlock()
+
+ select {
+ case l.wake <- struct{}{}:
+ default:
+ }
+}
+
+// StopSubagent ends the run of the subagent name and tells if it ran. Its
+// report is logged, but it starts no turn.
+func (l *TurnLoop) StopSubagent(name string) (bool, error) {
+ return l.runs.Stop(name)
+}
+