X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/a606686934b4028c29dca8e9dae6b2e188cee9c5..2ad578a24f252706976cddb41bee6cc969f251cd:/rebuild.go?ds=sidebyside diff --git a/rebuild.go b/rebuild.go index 8522d70..11c6bfc 100644 --- a/rebuild.go +++ b/rebuild.go @@ -7,7 +7,7 @@ import ( "fmt" "io" "io/fs" - "log" + "log/slog" "os" "path/filepath" "slices" @@ -15,6 +15,11 @@ import ( "time" ) +// rebuildCallLimit is the most model calls of a rebuild. A rebuild summarizes +// the whole merged log, which can need more calls than a probe sample, and the +// quota stop of the build run still guards the account. +const rebuildCallLimit = 1500 + // rebuild merges added messages with the log of agent, in date order, and // builds a new memory beside it. The caller holds the token lock. The model // uses the original agent prompt and cache key. A failed or stopped build @@ -50,12 +55,13 @@ func rebuild(ctx context.Context, agent *Agent, added []DatedMessage, client *Mo } }() - memory, err := openMemory(ctx, root, time.Now, summarizer, log.New(io.Discard, "", 0)) + memory, err := openMemory(ctx, root, time.Now, summarizer, slog.New(slog.DiscardHandler)) if err != nil { return "", fmt.Errorf("open rebuilt memory: %w", err) } - client.LimitCalls(buildCallLimit) + client.LimitCalls(rebuildCallLimit) + run := BuildRun{ memory: memory, client: client, @@ -136,6 +142,7 @@ func rebuildIdle(root string) error { } var work SubagentWorkFile + err = json.Unmarshal(data, &work) if err != nil { return fmt.Errorf("decode running subagents: %w", err) @@ -157,7 +164,9 @@ func rebuildReadLog(ctx context.Context, root string) ([]DatedMessage, error) { } slices.Sort(paths) + var entries []DatedMessage + for _, path := range paths { var day uint32 @@ -168,6 +177,7 @@ func rebuildReadLog(ctx context.Context, root string) ([]DatedMessage, error) { err = journalScanFile(ctx, path, day, 0, false, func(line []byte, _ Position) error { var message Message + err = json.Unmarshal(line, &message) if err != nil { return fmt.Errorf("decode message: %w", err) @@ -215,6 +225,7 @@ func rebuildMerge(old, added []DatedMessage) ([]DatedMessage, error) { } var date time.Time + date, err = time.Parse(time.RFC3339Nano, entry.Date) if err != nil { return nil, fmt.Errorf("parse merge date: %w", err) @@ -263,6 +274,7 @@ func rebuildCopy(source, target string) error { } case entry.Type().IsRegular(): var data []byte + data, err = os.ReadFile(path) if err != nil { return fmt.Errorf("read agent file: %w", err)