v0.24.0 3dbf466

scheduler_runtime.go RawHistoryFolder

1package agent
2
3import (
4	"context"
5	"fmt"
6	"strings"
7	"sync"
8
9	"github.com/bnema/zut/packages/agent/extensions"
10	"github.com/bnema/zut/packages/agent/scheduler"
11	"github.com/bnema/zut/packages/core"
12	"github.com/bnema/zut/packages/provider"
13)
14
15// runScheduledSession reconstructs an inactive session in the current zut
16// process and appends the resulting turn to its existing transcript. The
17// caller serializes this with session transitions before invoking it.
18func runScheduledSession(ctx context.Context, task scheduler.Task, args Args, base Resolved, extMgr *extensions.Manager, prepareRegistry func(core.Registry) core.Registry) error {
19	path, err := core.FindManagedSessionByID(ctx, ZutHome(), task.SessionID)
20	if err != nil {
21		return fmt.Errorf("find scheduled session %q: %w", task.SessionID, err)
22	}
23	if path == "" {
24		return fmt.Errorf("scheduled session %q no longer exists", task.SessionID)
25	}
26	sess, messages, err := core.OpenSession(path)
27	if err != nil {
28		return fmt.Errorf("open scheduled session: %w", err)
29	}
30	defer sess.Close()
31
32	providerName := strings.TrimSpace(sess.Meta.Provider)
33	if providerName == "" {
34		providerName = base.Provider
35	}
36	model := strings.TrimSpace(sess.Meta.Model)
37	if model == "" {
38		model = base.Model
39	}
40	ag, _, _, err := buildNonInteractiveSessionAgentWithRegistry(ctx, args, base, extMgr, providerName, model, prepareRegistry)
41	if err != nil {
42		return fmt.Errorf("build scheduled session agent: %w", err)
43	}
44	ag.SetMessages(trimMessagesForResume(messages, 100))
45	if cumulative, lastTurn, usageErr := core.SessionUsageDetail(path); usageErr == nil {
46		ag.SeedCost(cumulative)
47		ag.SeedLastTurnUsage(lastTurn)
48	}
49	ag.SetSessionTimeContext(sess.Meta.Started, sess.Meta.Timezone, sess.Meta.TimezoneOffset)
50	var appendMu sync.Mutex
51	var appendErr error
52	recordAppendError := func(err error) {
53		if err == nil {
54			return
55		}
56		appendMu.Lock()
57		defer appendMu.Unlock()
58		if appendErr == nil {
59			appendErr = err
60		}
61	}
62	ag.OnMessageAppended = func(message provider.Message) {
63		recordAppendError(sess.AppendMessage(message))
64	}
65	ag.OnUsage = func(cumulative provider.Usage) {
66		recordAppendError(sess.AppendUsage(cumulative, cumulative))
67	}
68	ag.OnTranscriptCompacted = func(messages []provider.Message) {
69		recordAppendError(sess.AppendCompaction(messages))
70	}
71	if err := ag.Prompt(ctx, task.Message, nil, func(core.AgentEvent) {}); err != nil {
72		return err
73	}
74	appendMu.Lock()
75	err = appendErr
76	appendMu.Unlock()
77	if err != nil {
78		return fmt.Errorf("append scheduled transcript: %w", err)
79	}
80	if err := sess.Flush(); err != nil {
81		return fmt.Errorf("flush scheduled session: %w", err)
82	}
83	return nil
84}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close