633b5953bb
When Claude Code refuses an operator chat's turn for a usage limit and the server does not continue it on another account, the server now queues a durable prompt (auto-continue-<refusal id>, sent as Pipelines (automatic)) for a minute after the reset: the refused operator message when the turn did no work, else "continue". The reset comes from the refusal's text, else the rejected rate_limit_event. Refusals of turns Claude Code started itself are handled too, with no client attached; a restarted server or a device scheduling the same refusal adds nothing. The choice is kept per Claude home beside auto-switch (or by the server for chats without one), read and set with chat_auto_continue, on by default. The app's limit banner now finds the refusal as the latest turn, ignoring notices, agent reports and activity rows after it, reads and writes the server's choice, and only schedules its own prompt for older servers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
package pipeline
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
// openCodeEndpointSetting is the single server_settings key that remembers the
|
|
// operator's chosen OpenCode endpoint across restarts.
|
|
const openCodeEndpointSetting = "opencode_endpoint"
|
|
|
|
// initServerSettings creates the additive single-row settings table that records
|
|
// operator choices that must survive a restart (currently the OpenCode
|
|
// endpoint). It is its own table rather than a column elsewhere so no existing
|
|
// schema or ownership table is touched.
|
|
func (s *Store) initServerSettings() error {
|
|
_, err := s.db.Exec(`CREATE TABLE IF NOT EXISTS server_settings (
|
|
key TEXT PRIMARY KEY, value TEXT NOT NULL);
|
|
CREATE TABLE IF NOT EXISTS storage_workspaces(path TEXT PRIMARY KEY);`)
|
|
return err
|
|
}
|
|
|
|
// RecordOpenCodeEndpoint records the operator's chosen OpenCode endpoint in one
|
|
// bounded upsert, so a restart with no flag or environment keeps brokering from
|
|
// the same place. It is only called after OpenEndpoint validated the endpoint.
|
|
func (s *Store) RecordOpenCodeEndpoint(ctx context.Context, url string) error {
|
|
_, err := s.db.ExecContext(ctx, `INSERT INTO server_settings(key,value) VALUES(?,?)
|
|
ON CONFLICT(key) DO UPDATE SET value=excluded.value`, openCodeEndpointSetting, url)
|
|
return err
|
|
}
|
|
|
|
// ServerSetting reads one server_settings value; found is false when it was
|
|
// never recorded.
|
|
func (s *Store) ServerSetting(ctx context.Context, key string) (value string, found bool, err error) {
|
|
err = s.db.QueryRowContext(ctx, `SELECT value FROM server_settings WHERE key=?`, key).Scan(&value)
|
|
if err == sql.ErrNoRows {
|
|
return "", false, nil
|
|
}
|
|
if err != nil {
|
|
return "", false, err
|
|
}
|
|
return value, true, nil
|
|
}
|
|
|
|
// SetServerSetting records one server_settings value.
|
|
func (s *Store) SetServerSetting(ctx context.Context, key, value string) error {
|
|
_, err := s.db.ExecContext(ctx, `INSERT INTO server_settings(key,value) VALUES(?,?)
|
|
ON CONFLICT(key) DO UPDATE SET value=excluded.value`, key, value)
|
|
return err
|
|
}
|
|
|
|
// OpenCodeEndpoint returns the recorded OpenCode endpoint, or an empty string
|
|
// when none was ever recorded.
|
|
func (s *Store) OpenCodeEndpoint(ctx context.Context) (string, error) {
|
|
var value string
|
|
err := s.db.QueryRowContext(ctx, `SELECT value FROM server_settings WHERE key=?`, openCodeEndpointSetting).Scan(&value)
|
|
if err == sql.ErrNoRows {
|
|
return "", nil
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return value, nil
|
|
}
|