From bb5ce098a99e4ea8f36c6a725290d5858c36460f Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Tue, 2 Jun 2026 22:50:00 +0900 Subject: feat(tools): add key_usage tool reporting API-key usage levels Adds an agent-callable `key_usage` tool that reports current usage for configured API keys so the agent can pick a key with headroom, warn before hitting a rate limit, and diagnose exhausted-key failures. Per key it reports: provider, active/exhausted status (with last error + when it was exhausted), remaining rate-limit headroom and reset timestamp per window (5-hour, weekly, and monthly where the provider exposes it), and whether the figures are live or served from cache (with the cache's last-fetched-from-source time). Supports anthropic and opencode-go keys (live with cache fallback for anthropic; live scrape for opencode-go). Optional `key_id` reports one key; omitted reports all. Hard permission gate `perm_key_usage` (default off): when disabled the tool is completely removed from the toolset/context. Registered in both the parent permission-gated path and the child whitelist path, advertised in the system prompt (TOOL_DESCRIPTIONS), grantable to subagents via the summon enum, and exposed as a frontend tool-permission checkbox. To report data freshness, claude.ts gains `getAccountUsageWithSource` + `ClaudeUsageResult` (live vs cache + cachedAt from usage_cache.cached_at); the existing `getAccountUsage` now delegates to it, preserving behavior. Tests: core key-usage tool suite (windows, %-conversion, freshness, exhausted status, unsupported/unavailable, filtering) + agent-manager perm-gate test. --- packages/frontend/src/lib/components/ToolPermissions.svelte | 6 ++++++ packages/frontend/src/lib/settings.svelte.ts | 2 ++ 2 files changed, 8 insertions(+) (limited to 'packages/frontend/src/lib') diff --git a/packages/frontend/src/lib/components/ToolPermissions.svelte b/packages/frontend/src/lib/components/ToolPermissions.svelte index 6b09a07..4298724 100644 --- a/packages/frontend/src/lib/components/ToolPermissions.svelte +++ b/packages/frontend/src/lib/components/ToolPermissions.svelte @@ -52,6 +52,12 @@ const toolPermissions: ToolPermission[] = [ label: "Search code", description: "Allow the AI to search the codebase with the cs ranked code-search engine", }, + { + id: "key_usage", + label: "Key usage", + description: + "Allow the AI to read current API-key usage levels, rate-limit headroom, and reset times", + }, { id: "lsp", label: "LSP queries", diff --git a/packages/frontend/src/lib/settings.svelte.ts b/packages/frontend/src/lib/settings.svelte.ts index 0da4e45..1b93804 100644 --- a/packages/frontend/src/lib/settings.svelte.ts +++ b/packages/frontend/src/lib/settings.svelte.ts @@ -15,6 +15,7 @@ let toolPerms = $state>({ web_search: false, youtube_transcribe: false, search_code: false, + key_usage: false, lsp: false, }); let savedToolPerms = $state>({ @@ -29,6 +30,7 @@ let savedToolPerms = $state>({ web_search: false, youtube_transcribe: false, search_code: false, + key_usage: false, lsp: false, }); let skillChecks = $state>({}); -- cgit v1.2.3 From fee14e4509453da7f73efa1fdeb59d66133706ae Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 3 Jun 2026 00:45:12 +0900 Subject: feat(tabs): pulsing status dot to grab attention when agent needs the user Use DaisyUI's status-with-ping pattern on the tab status dot so it pings when the agent has stopped and is likely waiting on the user: - idle with incomplete (pending/in_progress) tasks remaining, or - stopped due to an error. Implements wishlist item #21. --- packages/frontend/src/lib/components/TabBar.svelte | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'packages/frontend/src/lib') diff --git a/packages/frontend/src/lib/components/TabBar.svelte b/packages/frontend/src/lib/components/TabBar.svelte index 354260c..824b86b 100644 --- a/packages/frontend/src/lib/components/TabBar.svelte +++ b/packages/frontend/src/lib/components/TabBar.svelte @@ -1,6 +1,7 @@