]> git.giacomolli.uk - onechat/blobdiff - subagent_run.go
Write private data archives with safe extraction
[onechat] / subagent_run.go
index c5e98df7e0f15316f14be60563f0aee4a35d5b60..0780393db3f87c96e5d6aef425535106c102b4f3 100644 (file)
@@ -5,7 +5,7 @@ import (
        "encoding/json"
        "errors"
        "fmt"
-       "log"
+       "log/slog"
        "maps"
        "os"
        "path/filepath"
@@ -69,7 +69,7 @@ type SubagentRuns struct {
        report    func(name, text, status string)
        note      func(text string) error
        fail      func(err error)
-       logger    *log.Logger
+       logger    *slog.Logger
        notify    func(Event)
 
        mutex   sync.Mutex
@@ -243,7 +243,7 @@ func (r *SubagentRuns) Resume(ctx context.Context) error {
        for _, name := range names {
                _, err = r.Tell(ctx, name, text)
                if err != nil {
-                       r.logger.Printf("subagent %s lost at restart: %v", name, err)
+                       r.logger.Error("subagent lost at restart", "name", name, "err", err)
                        r.report(name, subagentReport(name, []string{"failed: " + err.Error()}), subagentFailed)
                }
        }
@@ -355,7 +355,7 @@ func (r *SubagentRuns) start(ctx context.Context, run *SubagentRun) error {
        r.mutex.Unlock()
 
        run.started = r.subagents.clock()
-       r.logger.Printf("subagent %s started", run.subagent.name)
+       r.logger.Info("subagent started", "name", run.subagent.name)
        r.notify(Event{
                Kind: "subagent",
                Text: run.subagent.name,
@@ -470,14 +470,14 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) {
                status = subagentStopped
        }
 
-       length := durationText(r.subagents.clock().Sub(run.started))
+       length := r.subagents.clock().Sub(run.started)
        switch status {
        case subagentStopped:
-               r.logger.Printf("subagent %s stopped after %s", run.subagent.name, length)
+               r.logger.Info("subagent stopped", "name", run.subagent.name, "after", length)
        case subagentFailed:
-               r.logger.Printf("subagent %s failed after %s: %v", run.subagent.name, length, failure)
+               r.logger.Error("subagent failed", "name", run.subagent.name, "after", length, "err", failure)
        default:
-               r.logger.Printf("subagent %s done after %s", run.subagent.name, length)
+               r.logger.Info("subagent done", "name", run.subagent.name, "after", length)
        }
 
        r.report(run.subagent.name, subagentReport(run.subagent.name, replies), status)