Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/cli/src/serve/server/rate-limiter-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export function installRateLimiter(
read: { windowMs, max: opts.rateLimitRead ?? 120 },
},
hostname: opts.hostname,
workspaceQualifiedAcpEnabled:
options.workspaceQualifiedAcpEnabled === true,
workspaceQualifiedAcpEnabled: options.workspaceQualifiedAcpEnabled === true,
onLimitReached: daemonLog
? (tier, key, suppressed) => {
daemonLog.warn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ describe('DefaultOpenAICompatibleProvider', () => {
expect(result.max_tokens).toBe(16384);
});

it('should set the 128K output default for Claude Opus 4.8', () => {
const requestWithoutMaxTokens: OpenAI.Chat.ChatCompletionCreateParams = {
model: 'vertex/claude-opus-4-8',
messages: [{ role: 'user', content: 'Hello' }],
};

const result = provider.buildRequest(
requestWithoutMaxTokens,
'prompt-id',
);

expect(result.max_tokens).toBe(131072);
});

it('should ignore malformed QWEN_CODE_MAX_OUTPUT_TOKENS values', () => {
const request: OpenAI.Chat.ChatCompletionCreateParams = {
model: 'gpt-4',
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/core/tokenLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ describe('tokenLimit', () => {
});

describe('Anthropic Claude', () => {
it('should return 200K for all Claude models', () => {
expect(tokenLimit('claude-opus-4-6')).toBe(200000);
it('should return 1M for Opus 4.6 through 4.8', () => {
expect(tokenLimit('claude-opus-4-6')).toBe(1_000_000);
expect(tokenLimit('claude-opus-4-7')).toBe(1_000_000);
expect(tokenLimit('vertex/claude-opus-4-8')).toBe(1_000_000);
});

it('should return 200K for other Claude models', () => {
expect(tokenLimit('claude-sonnet-4-6')).toBe(200000);
expect(tokenLimit('claude-sonnet-4')).toBe(200000);
expect(tokenLimit('claude-opus-4')).toBe(200000);
Expand Down Expand Up @@ -303,8 +308,10 @@ describe('tokenLimit with output type', () => {
expect(tokenLimit('gemini-3-flash-preview', 'output')).toBe(65536);
});

it('should return correct output limits for Claude 4.6', () => {
it('should return correct output limits for Claude Opus 4.6 through 4.8', () => {
expect(tokenLimit('claude-opus-4-6', 'output')).toBe(131072);
expect(tokenLimit('claude-opus-4-7', 'output')).toBe(131072);
expect(tokenLimit('vertex/claude-opus-4-8', 'output')).toBe(131072);
expect(tokenLimit('claude-sonnet-4-6', 'output')).toBe(65536);
});
});
Expand Down Expand Up @@ -461,6 +468,12 @@ describe('defaultOutputCeiling', () => {
expect(defaultOutputCeiling('kimi-k2.5')).toBe(32_768);
});

it('allows Claude Opus 4.6 through 4.8 to use the full 128K default', () => {
expect(defaultOutputCeiling('claude-opus-4-6')).toBe(131_072);
expect(defaultOutputCeiling('claude-opus-4-7')).toBe(131_072);
expect(defaultOutputCeiling('vertex/claude-opus-4-8')).toBe(131_072);
});

it('uses the default output limit for an unknown model', () => {
expect(defaultOutputCeiling('some-unknown-model')).toBe(
Math.min(DEFAULT_OUTPUT_TOKEN_LIMIT, OUTPUT_TOKEN_CEILING),
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/core/tokenLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const PATTERNS: Array<[RegExp, TokenCount]> = [
// -------------------
// Anthropic Claude
// -------------------
[/^claude-opus-4-(?:6|7|8)/, LIMITS['1m']], // Opus 4.6-4.8: 1M
[/^claude-/, LIMITS['200k']], // All Claude models: 200K

// -------------------
Expand Down Expand Up @@ -244,7 +245,7 @@ const OUTPUT_PATTERNS: Array<[RegExp, TokenCount]> = [
[/^o\d/, LIMITS['128k']], // o-series: 128K

// Anthropic Claude
[/^claude-opus-4-6/, LIMITS['128k']], // Opus 4.6: 128K
[/^claude-opus-4-(?:6|7|8)/, LIMITS['128k']], // Opus 4.6-4.8: 128K
[/^claude-sonnet-4-6/, LIMITS['64k']], // Sonnet 4.6: 64K
[/^claude-/, LIMITS['64k']], // Claude fallback: 64K

Expand Down Expand Up @@ -338,7 +339,11 @@ export function tokenLimit(
* so a model advertising >64K output is clamped consistently everywhere.
*/
export function defaultOutputCeiling(model: Model): TokenCount {
return Math.min(tokenLimit(model, 'output'), OUTPUT_TOKEN_CEILING);
const outputLimit = tokenLimit(model, 'output');
if (/^claude-opus-4-(?:6|7|8)/.test(normalize(model))) {
return outputLimit;
}
return Math.min(outputLimit, OUTPUT_TOKEN_CEILING);
}

/**
Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/tools/glob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,39 @@ describe('GlobTool', () => {
expect(result.llmContent).toContain('Found 2 file(s)');
});

it('should not scan later workspace directories after hitting the collection limit', async () => {
const secondDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'glob-tool-second-'),
);
await fs.writeFile(path.join(secondDir, '.git'), '');
const globStreamCallsBefore = vi.mocked(glob.globStream).mock.calls
.length;
const stream = mockGlobStreamResults('limit', 10_005);

const multiDirConfig = {
...mockConfig,
getWorkspaceContext: () =>
createMockWorkspaceContext(tempRootDir, [secondDir]),
} as unknown as Config;

try {
const invocation = new GlobTool(multiDirConfig).build({
pattern: '*.streamlimit',
});
const result = await invocation.execute(abortSignal);
const llmContent = partListUnionToString(result.llmContent);

expect(vi.mocked(glob.globStream).mock.calls.length).toBe(
globStreamCallsBefore + 1,
);
expect(stream.getYielded()).toBeLessThan(10_005);
expect(llmContent).toContain('Found at least');
expect(llmContent).toContain('Narrow the pattern or path');
} finally {
await fs.rm(secondDir, { recursive: true, force: true });
}
});

it('should use single directory description when only one workspace dir', async () => {
const params: GlobToolParams = { pattern: '*.txt' };
const invocation = globTool.build(params);
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/tools/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const debugLogger = createDebugLogger('GLOB');

const MAX_FILE_COUNT = 100;
const MAX_GLOB_COLLECTED_ENTRIES = MAX_FILE_COUNT * 10;
const normalizePathForComparison = (p: string) =>
process.platform === 'win32' || process.platform === 'darwin'
? p.toLowerCase()
: p;

// Subset of 'Path' interface provided by 'glob' that we can implement for testing
export interface GlobPath {
Expand Down Expand Up @@ -276,7 +280,7 @@ class GlobToolInvocation extends BaseToolInvocation<
hitCollectionLimit ||= hitLimit;
for (const entry of entries) {
// Deduplicate entries that might appear in overlapping directories
const normalized = entry.fullpath();
const normalized = normalizePathForComparison(entry.fullpath());
if (!seenPaths.has(normalized)) {
seenPaths.add(normalized);
allFilteredEntries.push(entry);
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile-mcp/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ export function validateOutputPath(filePath: string): void {
* elements scrolled partially off-screen, so each value allows a leading `-`.
*/
export function stripUiBounds(xml: string): string {
return xml.replace(/ bounds="\[-?\d+,-?\d+\]\[-?\d+,-?\d+\]"/g, "");
return xml.replace(/ bounds="\[-?\d+,-?\d+\]\[-?\d+,-?\d+\]"/g, '');
}
50 changes: 25 additions & 25 deletions packages/mobile-mcp/test/strip-ui-bounds.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import { test, expect } from "@playwright/test";
import { stripUiBounds } from "../src/utils";
import { test, expect } from '@playwright/test';
import { stripUiBounds } from '../src/utils';

test("strips positive bounds attributes", () => {
const xml = `<node text="ok" bounds="[0,0][1080,2160]" class="X"/>`;
expect(stripUiBounds(xml)).toBe(`<node text="ok" class="X"/>`);
test('strips positive bounds attributes', () => {
const xml = `<node text="ok" bounds="[0,0][1080,2160]" class="X"/>`;
expect(stripUiBounds(xml)).toBe(`<node text="ok" class="X"/>`);
});

test("strips negative bounds for off-screen elements", () => {
// UIAutomator reports negative coordinates for elements scrolled partially
// off-screen; these must be stripped too.
const xml = `<node bounds="[-5,-20][100,50]"/>`;
expect(stripUiBounds(xml)).toBe(`<node/>`);
test('strips negative bounds for off-screen elements', () => {
// UIAutomator reports negative coordinates for elements scrolled partially
// off-screen; these must be stripped too.
const xml = `<node bounds="[-5,-20][100,50]"/>`;
expect(stripUiBounds(xml)).toBe(`<node/>`);
});

test("strips every bounds attribute in the dump", () => {
const xml = `<a bounds="[0,0][10,10]"/><b bounds="[-1,-1][2,3]"/>`;
expect(stripUiBounds(xml)).toBe(`<a/><b/>`);
test('strips every bounds attribute in the dump', () => {
const xml = `<a bounds="[0,0][10,10]"/><b bounds="[-1,-1][2,3]"/>`;
expect(stripUiBounds(xml)).toBe(`<a/><b/>`);
});

test("leaves XML without bounds untouched", () => {
const xml = `<node text="hi" class="android.widget.TextView"/>`;
expect(stripUiBounds(xml)).toBe(xml);
test('leaves XML without bounds untouched', () => {
const xml = `<node text="hi" class="android.widget.TextView"/>`;
expect(stripUiBounds(xml)).toBe(xml);
});

test("preserves malformed bounds-like strings verbatim", () => {
// Only well-formed `[x,y][x,y]` integer pairs are stripped; anything else
// (extra coordinates, decimals, non-numeric) must pass through untouched.
const threeCoords = `<node bounds="[0,0,0][10,10,10]"/>`;
const decimal = `<node bounds="[0.5,0][10,10]"/>`;
const nonNumeric = `<node bounds="abc"/>`;
expect(stripUiBounds(threeCoords)).toBe(threeCoords);
expect(stripUiBounds(decimal)).toBe(decimal);
expect(stripUiBounds(nonNumeric)).toBe(nonNumeric);
test('preserves malformed bounds-like strings verbatim', () => {
// Only well-formed `[x,y][x,y]` integer pairs are stripped; anything else
// (extra coordinates, decimals, non-numeric) must pass through untouched.
const threeCoords = `<node bounds="[0,0,0][10,10,10]"/>`;
const decimal = `<node bounds="[0.5,0][10,10]"/>`;
const nonNumeric = `<node bounds="abc"/>`;
expect(stripUiBounds(threeCoords)).toBe(threeCoords);
expect(stripUiBounds(decimal)).toBe(decimal);
expect(stripUiBounds(nonNumeric)).toBe(nonNumeric);
});
Loading