Files
browser-cli/extension/src/commands/perf.ts
T
daniel156161 0c005bc119
Testing / remote-protocol-compat (0.16.0) (push) Successful in 47s
Testing / remote-protocol-compat (0.15.0) (push) Successful in 49s
Testing / test (push) Successful in 59s
Default MCP tab tools to the active tab
Requiring an explicit tab_id forced every navigate or close through a
preceding tabs_list call, which costs an MCP client a full round trip just to
learn the ID the browser already considers current.

navigate and tabs_close now resolve the active tab when tab_id is omitted,
matching the screenshot tool. Resolution is explicit rather than forwarding
None into the SDK, so the acting tool knows which tab it touched; tabs_close
reports it, since closing the wrong tab is not recoverable.

This stays in the MCP layer: the SDK and CLI signatures are unchanged.
2026-08-09 20:39:48 +02:00

43 lines
1.5 KiB
TypeScript

import { getLargeOperationThrottle, getPerformanceProfile, hasAudibleTabs, setPerformanceProfile } from '../core';
import { CommandGroup } from '../classes/CommandGroup';
import type { CommandEntry } from '../classes/CommandGroup';
import type { Job, PerfSetProfileArgs, JobIdArgs } from '../types';
// PerfCommands also owns the jobs.* status/cancel queries: they read the same
// JobManager (ctx.jobs) that perf.status reports, and there is no dedicated
// jobs command group.
export class PerfCommands extends CommandGroup {
readonly namespace = "perf";
readonly commands: Record<string, CommandEntry> = {
"perf.status": () => this.perfStatus(),
"perf.set_profile": (a: PerfSetProfileArgs) => setPerformanceProfile(typeof a.profile === "string" ? a.profile : undefined),
"jobs.status": (a: JobIdArgs) => this.ctx.jobs.status(a),
"jobs.cancel": (a: JobIdArgs) => this.ctx.jobs.cancel(a),
};
private jobSummary(job: Job) {
return {
id: job.id,
command: job.command,
status: job.status,
phase: job.phase,
current: job.current,
total: job.total,
percent: job.percent,
cancelRequested: job.cancelRequested,
};
}
private async perfStatus() {
const profile = await getPerformanceProfile();
const audible = await hasAudibleTabs();
const throttle = await getLargeOperationThrottle(0, "auto");
return {
performanceProfile: profile,
audible,
throttle,
jobs: this.ctx.jobs.list().map(job => this.jobSummary(job)),
};
}
}