Claude accounts: switch a chat refused for usage to another saved account and continue it

When Claude Code refuses an operator chat's turn for a usage limit, the
server marks the refused account until its reset and, if the chat's Claude
home allows it (claude_account_auto_switch / `pipelines claude-account auto
on|off`, on by default, kept in pipelines-accounts/settings.json), switches
the home to the saved account with the most usage left through the
claude_account_use path. Switches of one home are serialized, so chats
refused together switch once. Each refused chat gets one queued prompt,
marked as sent automatically, that asks the agent to check it is on track
before continuing; the app's auto-continue-at-reset prompt for the refusal is
removed (and refused if it arrives later), and the operator gets a
low-priority notification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 00:23:43 +00:00
parent 1995382e8c
commit ed9072b79a
30 changed files with 1362 additions and 21 deletions
+18
View File
@@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
"unicode/utf8"
@@ -90,6 +91,20 @@ func (NtfyStage) Run(ctx context.Context, def Definition, input Values) (Result,
return Result{Outcome: "success", Output: output}, nil
}
type ntfyPriorityKey struct{}
// WithNtfyPriority makes PublishNtfy calls under ctx send ntfy priority
// (1 min to 5 max); without it ntfy uses its default, 3.
func WithNtfyPriority(ctx context.Context, priority int) context.Context {
return context.WithValue(ctx, ntfyPriorityKey{}, priority)
}
// NtfyPriority is the priority WithNtfyPriority set on ctx, 0 when none.
func NtfyPriority(ctx context.Context) int {
priority, _ := ctx.Value(ntfyPriorityKey{}).(int)
return priority
}
// PublishNtfy is shared by native delivery stages and stage notification hooks.
// An empty filename publishes an event without an attachment. A non-empty click
// is an optional ntfy Click action (an absolute URL) so a tap on the notification
@@ -161,6 +176,9 @@ func PublishNtfy(ctx context.Context, destination, title, summary, filename stri
if click != "" {
request.Header.Set("Click", click)
}
if priority, ok := ctx.Value(ntfyPriorityKey{}).(int); ok && priority >= 1 && priority <= 5 {
request.Header.Set("Priority", strconv.Itoa(priority))
}
if actions != "" {
request.Header.Set("Actions", actions)
}
+20
View File
@@ -169,6 +169,26 @@ func TestNtfyDoesNotRedirectOrRetryAndRedactsErrors(t *testing.T) {
}
}
func TestNtfyPriorityFromContext(t *testing.T) {
var priorities []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
priorities = append(priorities, r.Header.Get("Priority"))
_, _ = w.Write([]byte(`{"id":"msg","event":"message"}`))
}))
defer srv.Close()
t.Setenv("PIPELINES_NTFY_ANIME_URL", srv.URL+"/anime")
t.Setenv("PIPELINES_NTFY_ANIME_TOKEN", "")
t.Setenv("PIPELINES_NTFY_ANIME_TOKEN_FILE", "")
for _, ctx := range []context.Context{context.Background(), WithNtfyPriority(context.Background(), 2), WithNtfyPriority(context.Background(), 9)} {
if _, err := PublishNtfy(ctx, "anime", "Title", "Summary", "", nil, ""); err != nil {
t.Fatal(err)
}
}
if strings.Join(priorities, ",") != ",2," {
t.Fatalf("priorities = %q", priorities)
}
}
func TestNtfyClickAndViewActions(t *testing.T) {
var click, actions []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {