X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/6e3e9c5c10f3d35bae7e9846334974a09418aef7..59e1537e1969f7c109084497287d729edbedba04:/subagent.go diff --git a/subagent.go b/subagent.go index 0248751..132ca47 100644 --- a/subagent.go +++ b/subagent.go @@ -115,6 +115,7 @@ func (s *Subagents) Get(ctx context.Context, name string) (*Subagent, error) { subagent = &Subagent{ name: name, + dir: root, log: log, syncer: syncer, } @@ -129,18 +130,22 @@ func (s *Subagents) Close() error { defer s.mutex.Unlock() var err error + for name, subagent := range s.open { err = errors.Join(err, subagent.close()) + delete(s.open, name) } return err } -// Subagent is one subagent and its log. Its mutex protects the log, because -// the run of the subagent writes it while the agent reads it with zoom. +// Subagent is one subagent, its directory, and its log. Its mutex protects the +// log, because the run of the subagent writes it while the agent reads it with +// zoom. type Subagent struct { name string + dir string mutex sync.Mutex log *Log syncer *Syncer @@ -166,6 +171,14 @@ func (a *Subagent) Flush(ctx context.Context) error { return a.syncer.Flush(ctx) } +// First returns the first message of the log. +func (a *Subagent) First() (Message, error) { + a.mutex.Lock() + defer a.mutex.Unlock() + + return a.log.Message(0) +} + // Show returns the whole log, each message as "i|kind: text", with a blank line // between messages. func (a *Subagent) Show() (string, error) { @@ -185,6 +198,12 @@ func (a *Subagent) Show() (string, error) { return strings.Join(lines, "\n\n"), nil } +// WorkDir returns the directory where the tools of the subagent run: work in +// its directory. +func (a *Subagent) WorkDir() string { + return filepath.Join(a.dir, "work") +} + // close makes the writes durable and closes the log. func (a *Subagent) close() error { a.mutex.Lock()