Chat tools: argument validation, replace, file snapshots, server-fetched images, show_run, show_diff head/paths, schedule_followup
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
@@ -100,8 +101,10 @@ func (h *chatHub) admitPrompt(ctx context.Context, sessionID string, broker chat
|
||||
}
|
||||
// A prompt scheduled for later is always queued: never run or steered now.
|
||||
scheduled := p.sendAt.After(h.clock())
|
||||
busy := scheduled || room.running || len(room.queue) > 0 || room.observedTurn
|
||||
queuedAhead := scheduled || len(room.queue) > 0
|
||||
// Agent follow-ups that are not due yet hold nothing up.
|
||||
head, _ := chatQueueHead(room.queue, h.clock())
|
||||
busy := scheduled || room.running || head >= 0 || room.observedTurn
|
||||
queuedAhead := scheduled || head >= 0
|
||||
h.mu.Unlock()
|
||||
if !busy {
|
||||
busy = brokerTurnRunning(broker, sessionID)
|
||||
@@ -154,6 +157,35 @@ func (h *chatHub) admitPrompt(ctx context.Context, sessionID string, broker chat
|
||||
return chatAdmitQueued, nil
|
||||
}
|
||||
|
||||
// chatFollowupPrefix starts the operation id of a prompt an agent scheduled
|
||||
// for itself (schedule_followup). Such a prompt is the one exception to the
|
||||
// queue's FIFO order: until it is due it steps aside, so the operator's own
|
||||
// prompts are never held behind an agent's reminder for hours.
|
||||
const chatFollowupPrefix = "followup-"
|
||||
|
||||
// isFollowup reports whether p is an agent's scheduled follow-up.
|
||||
func (p *chatQueuedPrompt) isFollowup() bool {
|
||||
return strings.HasPrefix(p.operationID, chatFollowupPrefix)
|
||||
}
|
||||
|
||||
// chatQueueHead is the index of the prompt the runner considers next: the
|
||||
// first one that is not an agent follow-up still waiting for its time, or -1
|
||||
// when there is none. followupWait is how long until the earliest of the
|
||||
// skipped follow-ups is due (zero when none was skipped).
|
||||
func chatQueueHead(queue []*chatQueuedPrompt, now time.Time) (int, time.Duration) {
|
||||
var followupWait time.Duration
|
||||
for i, p := range queue {
|
||||
if p.isFollowup() && p.sendAt.After(now) {
|
||||
if wait := p.sendAt.Sub(now); followupWait == 0 || wait < followupWait {
|
||||
followupWait = wait
|
||||
}
|
||||
continue
|
||||
}
|
||||
return i, followupWait
|
||||
}
|
||||
return -1, followupWait
|
||||
}
|
||||
|
||||
func errChatQueueFull(sessionID string) error {
|
||||
return errors.New("session " + sessionID + " already has the maximum number of prompts queued")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user