Chat usage limit: Claude Code-style banner with auto-continue; drop the approaching-limit banner

- The usage-limit banner now reads 'Out of usage credits' (or the refusal's
  own 'You've hit your 5-hour limit'), 'Auto-resuming at <time>', an
  'Auto-continue when limits reset' checkbox and Try again, keeping the
  account switcher's 'Switch to <account>'.
- Auto-continue (a shared, persisted preference, on by default) hands the
  server a durable scheduled prompt (send_at = reset + 1 min) with an
  idempotent auto-continue-<refusal id> operation id: the refused operator
  message again, or 'continue' when the refused turn had already worked.
  Unchecking unqueues it; Try again unqueues it and sends now.
- Remove the approaching-limit banner, its SnackBar announcements and their
  marks; the send-button usage ring replaces them.
- Claude Code's rate_limit_event overage fields (overageStatus,
  isUsingOverage/overageInUse, overageDisabledReason, overageResetsAt) reach
  clients as usage.account.extra_usage; the ring tooltip and the banner say
  'Extra usage available' or 'Using extra usage'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 16:13:33 +00:00
parent 7a259d8f60
commit 293474ac3c
22 changed files with 905 additions and 1254 deletions
@@ -123,31 +123,107 @@ void main() {
);
});
test('the last prompt is the newest user text and notes its files', () {
final last = chatLastPrompt([
{
'role': 'user',
'parts': [
{'type': 'text', 'text': 'first'},
],
},
{
'role': 'user',
'parts': [
{'type': 'text', 'text': ' fix the build '},
{'type': 'file', 'name': 'log.txt'},
],
},
{
'role': 'assistant',
'parts': [
{'type': 'text', 'text': 'ok'},
],
},
])!;
expect(last.text, 'fix the build');
expect(last.hadAttachments, isTrue);
expect(chatLastPrompt(const []), isNull);
group('chatRefusedTurn', () {
Map<String, Object?> message(
String id,
String role,
String text, {
bool file = false,
int? sendAt,
}) => {
'id': id,
'role': role,
'send_at': ?sendAt,
'parts': [
{'type': 'text', 'text': text},
if (file) {'type': 'file', 'name': 'log.txt'},
],
};
const hit =
"You've hit your 5-hour limit · resets 5:20pm (Europe/London) · "
'out of usage credits';
test('a refused operator message is sent again, without its files', () {
final turn = chatRefusedTurn([
message('u1', 'user', 'first'),
message('a1', 'assistant', 'done'),
message('u2', 'user', ' fix the build ', file: true),
message('r1', 'assistant', hit),
], null)!;
expect(turn.text, 'fix the build');
expect(turn.resends, isTrue);
expect(turn.hadAttachments, isTrue);
expect(turn.wording, "You've hit your 5-hour limit");
expect(turn.autoContinueId, 'auto-continue-r1');
});
test('a refusal after the turn worked continues it', () {
final turn = chatRefusedTurn([
message('u1', 'user', 'fix it'),
message('a1', 'assistant', 'Working on it.'),
message('r1', 'assistant', 'Claude AI usage limit reached|1900000000'),
// A prompt scheduled since is not part of the conversation yet.
message('q1', 'user', 'continue', sendAt: 1900000060000),
], null)!;
expect(turn.text, 'continue');
expect(turn.resends, isFalse);
expect(turn.wording, isNull);
});
test('anything but a refusal last is not a refused turn', () {
expect(chatRefusedTurn(const [], null), isNull);
expect(
chatRefusedTurn([message('a1', 'assistant', 'All done.')], null),
isNull,
);
expect(
chatRefusedTurn([
message('r1', 'assistant', hit),
message('u1', 'user', 'continue'),
], null),
isNull,
);
});
test('a refusal from before an account switch no longer counts', () {
final refusal = {...message('r1', 'assistant', hit), 'created_at': 10};
final switched = ChatAccountUsage(
harness: 'Claude Code',
plan: 'max',
asOf: 0,
windows: const [],
unsupported: false,
switchedAt: 20,
);
expect(chatRefusedTurn([refusal], switched), isNull);
expect(chatRefusedTurn([refusal], null), isNotNull);
});
});
test('extra usage reads as available or in use, else nothing', () {
ChatAccountUsage? parse(Map<String, Object?> extra) => chatAccountUsage({
'harness': 'Claude Code',
'windows': [
{'id': 'five_hour', 'label': '5-hour', 'used_percent': 10},
],
'extra_usage': extra,
});
expect(
chatExtraUsageNote(parse({'status': 'allowed'})),
'Extra usage available',
);
expect(
chatExtraUsageNote(parse({'status': 'allowed', 'in_use': true})),
'Using extra usage',
);
expect(
chatExtraUsageNote(
parse({'status': 'rejected', 'disabled_reason': 'out_of_credits'}),
),
isNull,
);
expect(chatExtraUsageNote(parse({})), isNull);
expect(chatExtraUsageNote(null), isNull);
});
test('scheduled send_at is a future epoch-ms time only', () {