feat(chat): work-status panel, and MCP auth and settings fixes (#2776)
Adds a work-status panel beside the transcript. Context fill, model and cost, todos, running subagents and the permission requests blocking them, branch and working-tree state, MCP servers, pinned messages and context sources were scattered across the header, the composer and the context panel — a blocked subagent was reported nowhere at all. The panel reads them from live channels rather than persisted history, and becomes an overlay where the chat is too narrow to seat a column. It is on by default, including for existing installs. Because it now carries these readouts, the desktop header and composer drop the ones it duplicates: todo and changed-files chips, usage and MCP tabs. VS Code and mobile keep theirs — neither hosts the panel. Fixes MCP authorization, which was broken from the panel, invalidated by a directory switch through a redirect URI that encoded the working directory, and left the desktop app in the background because browsers will not follow a custom-protocol link without a user gesture. The settings page no longer asks the user to understand the MCP spec before adding a server: one field takes the command or the link, with the kind inferred and a visible override, and client-registration fields appear only when a server actually asks for its own credentials. Also: skills load from the panel instead of only when the composer's slash autocomplete opens; the header button names the current instance rather than falling through to the word "Instance" for relay hosts. Three new optional UI settings keys, all migrated. No change to stored MCP server configuration.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { computeContextUsage, DEFAULT_CONTEXT_LIMIT } from './contextUsage';
|
||||
|
||||
const assistant = (tokens: Record<string, unknown>, id = 'msg') => ({ id, role: 'assistant', tokens });
|
||||
|
||||
describe('computeContextUsage', () => {
|
||||
test('sums every token bucket of the newest reporting assistant message', () => {
|
||||
const usage = computeContextUsage(
|
||||
[assistant({ input: 100, output: 20, reasoning: 5, cache: { read: 800, write: 75 } })],
|
||||
2000,
|
||||
);
|
||||
expect(usage?.totalTokens).toBe(1000);
|
||||
expect(usage?.percent).toBe(50);
|
||||
});
|
||||
|
||||
test('reports the latest turn rather than a sum across turns', () => {
|
||||
// Each assistant turn reports the whole window it saw, so adding them up
|
||||
// would report several times the real fill.
|
||||
const usage = computeContextUsage(
|
||||
[
|
||||
assistant({ input: 400, output: 0, reasoning: 0 }, 'old'),
|
||||
assistant({ input: 900, output: 0, reasoning: 0 }, 'new'),
|
||||
],
|
||||
1000,
|
||||
);
|
||||
expect(usage?.totalTokens).toBe(900);
|
||||
});
|
||||
|
||||
test('skips user messages and assistant turns that reported nothing', () => {
|
||||
const usage = computeContextUsage(
|
||||
[
|
||||
assistant({ input: 300, output: 0, reasoning: 0 }, 'real'),
|
||||
assistant({ input: 0, output: 0, reasoning: 0 }, 'zeroed'),
|
||||
{ id: 'user', role: 'user' },
|
||||
],
|
||||
1000,
|
||||
);
|
||||
expect(usage?.totalTokens).toBe(300);
|
||||
});
|
||||
|
||||
test('leaves the percentage unrounded', () => {
|
||||
// Rounding here is what made the panel print "34.0%" against the header's
|
||||
// "33.6%".
|
||||
const usage = computeContextUsage([assistant({ input: 336, output: 0, reasoning: 0 })], 1000);
|
||||
expect(usage?.percent.toFixed(1)).toBe('33.6');
|
||||
});
|
||||
|
||||
test('falls back to the default limit when the model exposes none', () => {
|
||||
const usage = computeContextUsage([assistant({ input: 20_000, output: 0, reasoning: 0 })], 0);
|
||||
expect(usage?.limit).toBe(DEFAULT_CONTEXT_LIMIT);
|
||||
expect(usage?.percent).toBe(10);
|
||||
});
|
||||
|
||||
test('returns null when no message carries usable tokens', () => {
|
||||
expect(computeContextUsage([], 1000)).toBeNull();
|
||||
expect(computeContextUsage([{ id: 'u', role: 'user' }], 1000)).toBeNull();
|
||||
expect(computeContextUsage([assistant({ input: 0, output: 0, reasoning: 0 })], 1000)).toBeNull();
|
||||
});
|
||||
|
||||
test('tolerates partial token payloads', () => {
|
||||
const usage = computeContextUsage([assistant({ input: 10 })], 100);
|
||||
expect(usage?.totalTokens).toBe(10);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user