]> git.giacomolli.uk - onechat/blobdiff - subagent_run.go
Reflow comments and expand event literals
[onechat] / subagent_run.go
index faa6207919d890d4c0c152a1275b4a99ccf9197e..1da858890c7992707dfed02e96b1ee36aedfeb33 100644 (file)
@@ -53,8 +53,8 @@ var errSubagentClosed = errors.New("the daemon stops, so no subagent starts")
 // work.json in the directory of the agent holds the names of the running
 // subagents. Each start and each end of a run writes it whole, but Close does
 // not, so after a stop of the daemon it names the runs that the stop cut, and
-// Resume goes on with them. The logs alone cannot tell this, because a stop
-// can cut a run just after its final reply.
+// Resume goes on with them. The logs alone cannot tell this, because a stop can
+// cut a run just after its final reply.
 //
 // Spawn and Tell split the view with the layout of the agent, which has no
 // lock. They are tools, so they run in the goroutine of the turns, as each
@@ -78,6 +78,25 @@ type SubagentRuns struct {
        workers sync.WaitGroup
 }
 
+// SubagentRun is one run of a subagent: the view that its requests get, its
+// effort, the end of its context, the messages of Tell that wait for a request,
+// whether Stop ended it, and the time it started. The mutex of SubagentRuns
+// protects the messages and the stop.
+type SubagentRun struct {
+       subagent *Subagent
+       view     []string
+       effort   string
+       cancel   context.CancelFunc
+       pending  []Message
+       stopped  bool
+       started  time.Time
+}
+
+// SubagentWorkFile is the content of work.json.
+type SubagentWorkFile struct {
+       Running []string `json:"running"`
+}
+
 // Spawn starts one subagent for each task and returns their names at once. It
 // waits until the view has no pending summary, and gives the view to each
 // subagent. A nil effort is the effort of the agent.
@@ -399,8 +418,8 @@ func (r *SubagentRuns) load() ([]string, error) {
        return file.Running, nil
 }
 
-// save writes the names of the running subagents to work.json. The caller
-// holds the mutex.
+// save writes the names of the running subagents to work.json. The caller holds
+// the mutex.
 func (r *SubagentRuns) save() error {
        file := SubagentWorkFile{
                Running: append([]string{}, slices.Sorted(maps.Keys(r.running))...),
@@ -539,8 +558,8 @@ func (r *SubagentRuns) chain(ctx context.Context, run *SubagentRun) (string, err
        return chain.Run(ctx, input)
 }
 
-// take returns the messages of Tell that wait for a request of run, and
-// removes them.
+// take returns the messages of Tell that wait for a request of run, and removes
+// them.
 func (r *SubagentRuns) take(run *SubagentRun) []Message {
        r.mutex.Lock()
        defer r.mutex.Unlock()
@@ -551,25 +570,6 @@ func (r *SubagentRuns) take(run *SubagentRun) []Message {
        return messages
 }
 
-// SubagentRun is one run of a subagent: the view that its requests get, its
-// effort, the end of its context, the messages of Tell that wait for a request,
-// whether Stop ended it, and the time it started. The mutex of SubagentRuns
-// protects the messages and the stop.
-type SubagentRun struct {
-       subagent *Subagent
-       view     []string
-       effort   string
-       cancel   context.CancelFunc
-       pending  []Message
-       stopped  bool
-       started  time.Time
-}
-
-// SubagentWorkFile is the content of work.json.
-type SubagentWorkFile struct {
-       Running []string `json:"running"`
-}
-
 // subagentReport returns the report of the subagent name with its replies: the
 // name in brackets, a new line, the replies, and the zoom that gives its whole
 // chat.