Merge pull request #1322 from lengyuqu/codebuddy

[Codebuddy] sdk
This commit is contained in:
陈大猫
2026-06-11 10:21:35 +08:00
committed by GitHub
33 changed files with 1753 additions and 105 deletions

View File

@@ -1,11 +1,12 @@
import type { DiscoveredAgent, ExternalAgentConfig } from './types';
export type ManagedAgentKey = 'codex' | 'claude' | 'copilot';
export type ManagedAgentKey = 'codex' | 'claude' | 'copilot' | 'codebuddy';
const MANAGED_AGENT_META: Record<ManagedAgentKey, { commandNames: string[]; sdkBackend: string }> = {
codex: { commandNames: ['codex'], sdkBackend: 'codex' },
claude: { commandNames: ['claude'], sdkBackend: 'claude' },
copilot: { commandNames: ['copilot'], sdkBackend: 'copilot' },
codebuddy: { commandNames: ['codebuddy'], sdkBackend: 'codebuddy' },
};
function getCommandBasename(command: string | undefined): string {
@@ -28,7 +29,7 @@ function matchesPrimaryCliBasename(command: string | undefined, agentKey: Manage
export function isSettingsManagedDiscoveredAgent(
agent: Pick<DiscoveredAgent, 'command'>,
): agent is Pick<DiscoveredAgent, 'command'> & { command: ManagedAgentKey } {
return agent.command === 'codex' || agent.command === 'claude' || agent.command === 'copilot';
return agent.command === 'codex' || agent.command === 'claude' || agent.command === 'copilot' || agent.command === 'codebuddy';
}
export function matchesManagedAgentConfig(

View File

@@ -0,0 +1,21 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {
CODEBUDDY_MODEL_PRESETS,
CODEX_MODEL_PRESETS,
getAgentModelPresets,
} from './types';
test('getAgentModelPresets returns CodeBuddy fallback models for command paths', () => {
assert.deepEqual(
getAgentModelPresets('/opt/homebrew/bin/codebuddy'),
CODEBUDDY_MODEL_PRESETS,
);
assert.ok(CODEBUDDY_MODEL_PRESETS.some((model) => model.id === 'deepseek-v4-pro'));
});
test('getAgentModelPresets keeps Codex presets separate from CodeBuddy presets', () => {
assert.deepEqual(getAgentModelPresets('codex'), CODEX_MODEL_PRESETS);
assert.notDeepEqual(CODEBUDDY_MODEL_PRESETS, CODEX_MODEL_PRESETS);
});

View File

@@ -231,12 +231,14 @@ export interface ExternalAgentConfig {
env?: Record<string, string>;
icon?: string;
enabled: boolean;
/** SDK backend key for managed agents (claude|codex|copilot). */
/** SDK backend key for managed agents (claude|codex|copilot|codebuddy). */
sdkBackend?: string;
/** @deprecated Legacy persisted field from the pre-SDK migration. Read only for compatibility. */
acpCommand?: string;
/** @deprecated Legacy persisted field from the pre-SDK migration. */
acpArgs?: string[];
/** Internal: disabled only because the managed CLI was unavailable. */
autoDisabledUntilAvailable?: boolean;
}
// Discovered agent from system PATH
@@ -252,8 +254,8 @@ export interface DiscoveredAgent {
/** @deprecated Legacy discovery field from the pre-SDK migration. */
acpCommand?: string;
acpArgs?: string[];
/** SDK backend key (claude|codex|copilot) — the post-migration routing value. */
sdkBackend?: 'claude' | 'codex' | 'copilot';
/** SDK backend key (claude|codex|copilot|codebuddy) — the routing value. */
sdkBackend?: 'claude' | 'codex' | 'copilot' | 'codebuddy';
/** Absolute resolved CLI path (preferred over `path`). */
binPath?: string;
installed?: boolean;
@@ -445,11 +447,29 @@ export const CODEX_MODEL_PRESETS: AgentModelPreset[] = [
{ id: 'gpt-4o', name: 'GPT-4o' },
];
// CodeBuddy's SDK model enumeration can be empty depending on CLI/account
// state; keep a CLI-supported fallback list so users can still pass --model.
export const CODEBUDDY_MODEL_PRESETS: AgentModelPreset[] = [
{ id: 'deepseek-v4-pro', name: 'DeepSeek V4 Pro' },
{ id: 'deepseek-v4-flash', name: 'DeepSeek V4 Flash' },
{ id: 'deepseek-v3-2-volc', name: 'DeepSeek V3.2' },
{ id: 'glm-5.1', name: 'GLM 5.1' },
{ id: 'glm-5.0', name: 'GLM 5.0' },
{ id: 'glm-5.0-turbo', name: 'GLM 5.0 Turbo' },
{ id: 'glm-5v-turbo', name: 'GLM 5V Turbo' },
{ id: 'glm-4.7', name: 'GLM 4.7' },
{ id: 'minimax-m3-pay', name: 'MiniMax M3' },
{ id: 'minimax-m2.7', name: 'MiniMax M2.7' },
{ id: 'kimi-k2.6', name: 'Kimi K2.6' },
{ id: 'hy3-preview', name: 'Hy3 Preview' },
];
export function getAgentModelPresets(agentCommand?: string): AgentModelPreset[] {
if (!agentCommand) return [];
const basename = agentCommand.split('/').pop()?.toLowerCase() ?? '';
if (basename.startsWith('claude')) return CLAUDE_MODEL_PRESETS;
if (basename.startsWith('codex')) return CODEX_MODEL_PRESETS;
if (basename.startsWith('codebuddy')) return CODEBUDDY_MODEL_PRESETS;
return [];
}