]> git.giacomolli.uk - onechat/blobdiff - subagent.go
Keep the schedules in a file
[onechat] / subagent.go
index 024875161aae991f57028182c1e560ad7983745a..2e50d5d87ffdd05e18581f7a9c71e1d74426d864 100644 (file)
@@ -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,
        }
@@ -137,10 +138,12 @@ func (s *Subagents) Close() error {
        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 +169,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 +196,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()