feat: differentiate User-Agent for a2a-server and ACP clients

This commit is contained in:
Bryan Morgan
2026-03-11 12:32:26 -04:00
parent 88638c14f7
commit 63ecbc6e26
13 changed files with 1087 additions and 1487 deletions
+22
View File
@@ -112,6 +112,14 @@ vi.mock('@google/gemini-cli-core', async () => {
}),
},
loadEnvironment: vi.fn(),
detectIdeFromEnv: vi.fn().mockImplementation(() => {
if (process.env['TERM_PROGRAM'] === 'Zed')
return actualServer.IDE_DEFINITIONS.zed;
if (process.env['XCODE_VERSION_ACTUAL'])
return actualServer.IDE_DEFINITIONS.xcode;
return actualServer.IDE_DEFINITIONS.vscode;
}),
IDE_DEFINITIONS: actualServer.IDE_DEFINITIONS,
loadServerHierarchicalMemory: vi.fn(
(
cwd,
@@ -311,6 +319,20 @@ describe('parseArguments', () => {
});
});
it('should set clientName to acp-vscode when using --acp flag', async () => {
process.argv = ['node', 'script.js', '--acp'];
// Mock TERM_PROGRAM to ensure a known IDE is detected (default is vscode if nothing else matches)
vi.stubEnv('TERM_PROGRAM', 'vscode');
const args = await parseArguments(createTestMergedSettings());
const config = await loadCliConfig(
createTestMergedSettings(),
'test-session',
args,
);
expect(config.getClientName()).toBe('acp-vscode');
});
it.each([
{
description:
+10 -13
View File
@@ -7,7 +7,6 @@
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import process from 'node:process';
import * as path from 'node:path';
import { mcpCommand } from '../commands/mcp.js';
import { extensionsCommand } from '../commands/extensions.js';
import { skillsCommand } from '../commands/skills.js';
@@ -34,9 +33,9 @@ import {
getAdminErrorMessage,
isHeadlessMode,
Config,
resolveToRealPath,
applyAdminAllowlist,
getAdminBlockedMcpServersMessage,
detectIdeFromEnv,
type HookDefinition,
type HookEventName,
type OutputFormat,
@@ -490,15 +489,6 @@ export async function loadCliConfig(
const experimentalJitContext = settings.experimental?.jitContext ?? false;
let extensionRegistryURI: string | undefined = trustedFolder
? settings.experimental?.extensionRegistryURI
: undefined;
if (extensionRegistryURI && !extensionRegistryURI.startsWith('http')) {
extensionRegistryURI = resolveToRealPath(
path.resolve(cwd, resolvePath(extensionRegistryURI)),
);
}
let memoryContent: string | HierarchicalMemory = '';
let fileCount = 0;
let filePaths: string[] = [];
@@ -704,8 +694,16 @@ export async function loadCliConfig(
}
}
const acpMode = !!argv.acp || !!argv.experimentalAcp;
let clientName: string | undefined = undefined;
if (acpMode) {
const ide = detectIdeFromEnv();
clientName = `acp-${ide.name}`;
}
return new Config({
acpMode: !!argv.acp || !!argv.experimentalAcp,
acpMode,
clientName,
sessionId,
clientVersion: await getVersion(),
embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL,
@@ -775,7 +773,6 @@ export async function loadCliConfig(
deleteSession: argv.deleteSession,
enabledExtensions: argv.extensions,
extensionLoader: extensionManager,
extensionRegistryURI,
enableExtensionReloading: settings.experimental?.extensionReloading,
enableAgents: settings.experimental?.enableAgents,
plan: settings.experimental?.plan,
@@ -118,6 +118,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
ExtensionInstallEvent: vi.fn(),
ExtensionUninstallEvent: vi.fn(),
ExtensionDisableEvent: vi.fn(),
ExtensionUpdateEvent: vi.fn(),
KeychainTokenStorage: vi.fn().mockImplementation(() => ({
getSecret: vi.fn(),
setSecret: vi.fn(),