From 337748fb82393aedbba32f4353fae2800eec9532 Mon Sep 17 00:00:00 2001 From: SaladDay <92240037+SaladDay@users.noreply.github.com> Date: Fri, 4 Dec 2026 16:53:42 +0800 Subject: [PATCH] feat(agent): add DeepSeek Harness to agent setup --- README.md | 2 +- README_CN.md | 2 +- src/agent/availability.ts | 1 + src/agent/configurator.ts | 188 +++++++++++++++++++++++++++- src/agent/installer.ts | 9 +- src/agent/types.ts | 1 + src/commands/agent/setup.ts | 5 +- test/agent/deepseek-harness.test.ts | 99 +++++++++++++++ 8 files changed, 302 insertions(+), 5 deletions(-) create mode 100644 test/agent/deepseek-harness.test.ts diff --git a/README.md b/README.md index a22ca149..3b62a35b 100644 --- a/README.md +++ b/README.md @@ -215,7 +215,7 @@ mmx config export-schema | jq . ### `mmx agent setup` -Configure MiniMax for Claude Code, Codex, Grok Build, OpenCode, Hermes, Pi, [Oh my Pi](https://github.com/can1357/oh-my-pi), or Zed while preserving unrelated settings. Run without options for the interactive wizard; supplying options makes the command non-interactive and suitable for scripts. +Configure MiniMax for Claude Code, Codex, Grok Build, OpenCode, Hermes, Pi, [Oh my Pi](https://github.com/can1357/oh-my-pi), Zed, or DeepSeek Harness while preserving unrelated settings. Run without options for the interactive wizard; supplying options makes the command non-interactive and suitable for scripts. ```bash mmx agent setup diff --git a/README_CN.md b/README_CN.md index e6d59abf..48ed119f 100644 --- a/README_CN.md +++ b/README_CN.md @@ -189,7 +189,7 @@ mmx config export-schema | jq . ### `mmx agent setup` -一键为 Claude Code、Codex、Grok Build、OpenCode、Hermes、Pi、[Oh my Pi](https://github.com/can1357/oh-my-pi) 或 Zed 配置 MiniMax,并保留配置文件中的其他设置。不带选项时进入交互式向导;带选项时自动使用非交互模式,便于脚本调用。 +一键为 Claude Code、Codex、Grok Build、OpenCode、Hermes、Pi、[Oh my Pi](https://github.com/can1357/oh-my-pi)、Zed 或 DeepSeek Harness 配置 MiniMax,并保留配置文件中的其他设置。不带选项时进入交互式向导;带选项时自动使用非交互模式,便于脚本调用。 ```bash mmx agent setup diff --git a/src/agent/availability.ts b/src/agent/availability.ts index 22cb374c..d203edef 100644 --- a/src/agent/availability.ts +++ b/src/agent/availability.ts @@ -12,6 +12,7 @@ const AGENT_EXECUTABLES: Record = { pi: ['pi'], 'oh-my-pi': ['omp'], zed: ['zed', 'zeditor'], + 'deepseek-harness': ['dsh'], }; const AGENT_RUNTIME_MARKERS: Partial> = { diff --git a/src/agent/configurator.ts b/src/agent/configurator.ts index bbf5c2f7..97d6b974 100644 --- a/src/agent/configurator.ts +++ b/src/agent/configurator.ts @@ -22,7 +22,7 @@ import { type ParseError, } from 'jsonc-parser/lib/esm/main.js'; import { parse as parseToml } from 'smol-toml'; -import { parseDocument } from 'yaml'; +import { isMap, isSeq, parseDocument, type Document } from 'yaml'; import { CLIError } from '../errors/base'; import { ExitCode } from '../errors/codes'; @@ -156,6 +156,8 @@ function configPathsForAgent( } case 'oh-my-pi': return ohMyPiConfigPaths(home, env); + case 'deepseek-harness': + return [...dshProfilePaths(options), join(dshHome(options), '.credentials.yaml')]; case 'zed': { // Mirrors Zed's paths::config_dir(). if (process.platform === 'win32') { @@ -1137,6 +1139,187 @@ function prepareZed(options: AgentSetupOptions, path: string): PreparedAgentFile return [{ agent: 'zed', path, ...prepared, after: updateJsonc(prepared.before, label, updates) }]; } +const DSH_PROFILE_PATCH_TEMPLATE = `# Your patch layer for this dsh profile, applied after every bundle layer: +# a top-level YAML array of loader patch entries (id-targeted config +# overrides, disables, and insert lists; \`!!js\` expressions allowed). +[] +`; +const DSH_ALWAYS_PROFILES = ['web', 'desktop']; +const DSH_OPTIONAL_PROFILES = ['headless', 'acp']; +const DSH_REASONING_EFFORTS = { + low: 'low', + medium: 'medium', + high: 'high', + xhigh: 'xhigh', + max: 'max', +}; + +function dshHome(options: AgentSetupOptions): string { + const home = options.homeDir ?? homedir(); + const env = options.env ?? process.env; + return pathFromOverride(env.DSH_HOME, join(home, '.dsh'), home); +} + +function dshProfilePaths(options: AgentSetupOptions): string[] { + const root = join(dshHome(options), 'profiles'); + const paths: string[] = []; + const seen = new Set(); + for (const name of [...DSH_ALWAYS_PROFILES, ...DSH_OPTIONAL_PROFILES]) { + const path = join(root, name, 'cordis.patch.yml'); + if (DSH_OPTIONAL_PROFILES.includes(name) && !existsSync(path)) continue; + const target = writeTarget(path); + if (seen.has(target)) continue; + seen.add(target); + paths.push(path); + } + return paths; +} + +function parseDshDocument(before: string | null, label: string, empty: string): Document { + const document = parseDocument(before ?? empty); + if (document.errors.length > 0) { + throw new CLIError( + `${label} is not valid YAML: ${document.errors[0]?.message ?? 'parse error'}`, + ExitCode.GENERAL, + INVALID_CONFIG_HINT, + ); + } + return document; +} + +function dshPatchIndexes(document: Document, id: string): number[] { + if (!isSeq(document.contents)) return []; + const found: number[] = []; + document.contents.items.forEach((item, index) => { + if (isMap(item) && item.get('id') === id) found.push(index); + }); + return found; +} + +function ensureDshPatchEntry(document: Document, id: string, label: string): number { + if (document.contents === null) { + document.contents = document.createNode([]); + } + if (!isSeq(document.contents)) { + throw new CLIError(`${label} must be a YAML sequence.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + if (document.contents.items.length === 0) document.contents.flow = false; + const found = dshPatchIndexes(document, id); + if (found.length > 1) { + throw new CLIError(`${label} has duplicate ${id} overrides.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + if (found.length === 1) return found[0]!; + document.add(document.createNode({ id, config: {} })); + return document.contents.items.length - 1; +} + +function dshModels() { + return ['MiniMax-M4', 'MiniMax-M3.1-Flash'].map(id => ({ + id, + name: id, + contextWindow: 1_000_000, + maxTokens: 131072, + input: ['text', 'image'], + reasoningEfforts: { ...DSH_REASONING_EFFORTS }, + })); +} + +function upsertDshModels(document: Document, path: Array, models: ReturnType, label: string): void { + const existing = document.getIn(path); + if (existing === undefined) { + document.setIn(path, document.createNode(models)); + return; + } + if (!isSeq(existing)) { + throw new CLIError(`${label} models must be an array.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + for (const model of models) { + const index = existing.items.findIndex(item => isMap(item) && item.get('id') === model.id); + if (index < 0) { + existing.add(document.createNode(model)); + continue; + } + for (const [key, value] of Object.entries(model)) { + document.setIn([...path, index, key], document.createNode(value)); + } + } +} + +function updateDshPatch(before: string | null, options: AgentSetupOptions, path: string): string { + const label = 'DeepSeek Harness cordis.patch.yml'; + const document = parseDshDocument(before, label, DSH_PROFILE_PATCH_TEMPLATE); + const providerId = options.region === 'cn' ? 'minimax-cn' : 'minimax'; + const apiKeyEnv = options.region === 'cn' ? 'MINIMAX_CN_API_KEY' : 'MINIMAX_API_KEY'; + const index = ensureDshPatchEntry(document, 'llm-pi-ai', label); + const providers = document.getIn([index, 'config', 'providers']); + if (providers !== undefined && !isMap(providers)) { + throw new CLIError(`${label} providers must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + const providerPath = [index, 'config', 'providers', providerId]; + const provider = document.getIn(providerPath); + if (provider !== undefined && !isMap(provider)) { + throw new CLIError(`${label} providers.${providerId} must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + document.setIn([...providerPath, 'displayName'], options.region === 'cn' ? 'MiniMax' : 'MiniMax en'); + document.setIn([...providerPath, 'apiKeyEnv'], apiKeyEnv); + document.setIn([...providerPath, 'api'], 'openai-completions'); + document.setIn([...providerPath, 'baseURL'], endpointsForRegion(options.region).openai); + upsertDshModels(document, [...providerPath, 'models'], dshModels(), label); + + const defaultIndex = ensureDshPatchEntry(document, 'agent-default-model', label); + document.setIn([defaultIndex, 'config', 'provider'], providerId); + document.setIn([defaultIndex, 'config', 'model'], options.model); + + if (basename(dirname(path)) === 'headless' + && dshPatchIndexes(document, 'credentials').length === 0) { + document.add(document.createNode({ id: 'credentials', disabled: false })); + } + return document.toString(); +} + +function updateDshCredentials(before: string | null, options: AgentSetupOptions): string { + const label = 'DeepSeek Harness .credentials.yaml'; + const document = parseDshDocument(before, label, 'version: 1\nrefs: {}\n'); + if (document.contents === null) { + document.contents = document.createNode({ version: 1, refs: {} }); + } + if (!isMap(document.contents) || document.get('version') !== 1) { + throw new CLIError( + `${label} is not a version 1 credential document.`, + ExitCode.GENERAL, + INVALID_CONFIG_HINT, + ); + } + const refs = document.get('refs'); + if (refs !== undefined && refs !== null && !isMap(refs)) { + throw new CLIError(`${label} refs must be a mapping.`, ExitCode.GENERAL, INVALID_CONFIG_HINT); + } + const apiKeyEnv = options.region === 'cn' ? 'MINIMAX_CN_API_KEY' : 'MINIMAX_API_KEY'; + document.setIn(['refs', apiKeyEnv], options.apiKey); + return document.toString(); +} + +function prepareDeepseekHarness(options: AgentSetupOptions): PreparedAgentFile[] { + const prepared: PreparedAgentFile[] = dshProfilePaths(options).map((path) => { + const existing = readPrepared(path); + return { + agent: 'deepseek-harness', + path, + ...existing, + after: updateDshPatch(existing.before, options, path), + }; + }); + const credentialsPath = join(dshHome(options), '.credentials.yaml'); + const credentials = readPrepared(credentialsPath); + prepared.push({ + agent: 'deepseek-harness', + path: credentialsPath, + ...credentials, + after: updateDshCredentials(credentials.before, options), + }); + return prepared; +} + export function prepareAgentConfigurations(options: AgentSetupOptions): PreparedAgentFile[] { const prepared: PreparedAgentFile[] = []; for (const agent of options.agents) { @@ -1166,6 +1349,9 @@ export function prepareAgentConfigurations(options: AgentSetupOptions): Prepared case 'zed': prepared.push(...prepareZed(options, paths[0]!)); break; + case 'deepseek-harness': + prepared.push(...prepareDeepseekHarness(options)); + break; } } assertDistinctConfigurationTargets(prepared); diff --git a/src/agent/installer.ts b/src/agent/installer.ts index e2831ac1..eae24e4a 100644 --- a/src/agent/installer.ts +++ b/src/agent/installer.ts @@ -5,7 +5,7 @@ import { ExitCode } from '../errors/codes'; import type { AgentId } from './types'; type NpmAgentId = Extract; -type ScriptAgentId = Exclude; +type ScriptAgentId = Exclude; const NPM_PACKAGES: Record = { codex: '@openai/codex', @@ -127,6 +127,7 @@ export function getAgentInstallIssue( ?? ((executable: string) => defaultCommandExists(executable, platform)); if (agent === 'zed') return 'Install Zed from https://zed.dev/download.'; + if (agent === 'deepseek-harness') return 'Install DeepSeek Harness with npm install -g @deepseek-ai/dsh.'; if (!SUPPORTED_PLATFORMS.has(platform)) { return `Automated installation is not supported on ${platform}.`; } @@ -228,6 +229,9 @@ export function getAgentInstallCommand( if (agent === 'zed') { throw new CLIError('Install Zed from https://zed.dev/download.', ExitCode.USAGE); } + if (agent === 'deepseek-harness') { + throw new CLIError('Install DeepSeek Harness with npm install -g @deepseek-ai/dsh.', ExitCode.USAGE); + } const args = [ 'install', @@ -301,6 +305,9 @@ export function getAgentVerificationCommand( if (agent === 'zed') { return { executable: 'zed', args: ['--version'], display: 'zed --version' }; } + if (agent === 'deepseek-harness') { + return { executable: 'dsh', args: ['--version'], display: 'dsh --version' }; + } const display = `${AGENT_EXECUTABLES[agent]} --version`; if (platform === 'win32') { return { diff --git a/src/agent/types.ts b/src/agent/types.ts index 7c2a2888..bb6fa27f 100644 --- a/src/agent/types.ts +++ b/src/agent/types.ts @@ -10,6 +10,7 @@ export const AGENT_IDS = [ 'pi', 'oh-my-pi', 'zed', + 'deepseek-harness', ] as const; export type AgentId = typeof AGENT_IDS[number]; diff --git a/src/commands/agent/setup.ts b/src/commands/agent/setup.ts index 691c2c4b..e5956641 100644 --- a/src/commands/agent/setup.ts +++ b/src/commands/agent/setup.ts @@ -56,6 +56,8 @@ const AGENT_ALIASES: Record = { 'oh-my-pi': 'oh-my-pi', omp: 'oh-my-pi', zed: 'zed', + 'deepseek-harness': 'deepseek-harness', + dsh: 'deepseek-harness', }; const AGENT_LABELS: Record = { @@ -67,6 +69,7 @@ const AGENT_LABELS: Record = { pi: 'Pi', 'oh-my-pi': 'Oh my Pi (omp)', zed: 'Zed', + 'deepseek-harness': 'DeepSeek Harness', }; // Zed keeps provider keys in the OS keychain or the MINIMAX_API_KEY environment variable. const ZED_API_KEY_HINT = 'Zed: paste your MiniMax API key in Agent Panel > Settings > minimax, ' @@ -482,7 +485,7 @@ export default defineCommand({ options: [ { flag: '--agent ', - description: 'Agent: claude-code, codex, grok/grok-build, opencode, hermes, pi, oh-my-pi/omp, zed (repeatable)', + description: 'Agent: claude-code, codex, grok/grok-build, opencode, hermes, pi, oh-my-pi/omp, zed, deepseek-harness/dsh (repeatable)', type: 'array', }, { diff --git a/test/agent/deepseek-harness.test.ts b/test/agent/deepseek-harness.test.ts new file mode 100644 index 00000000..2d18bd45 --- /dev/null +++ b/test/agent/deepseek-harness.test.ts @@ -0,0 +1,99 @@ +import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; +import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs'; +import { tmpdir } from 'os'; +import { join } from 'path'; +import { parse } from 'yaml'; + +import { applyAgentConfigurations, prepareAgentConfigurations } from '../../src/agent/configurator'; +import type { AgentSetupOptions } from '../../src/agent/types'; + +const FACTORY = `# Your patch layer for this dsh profile, applied after every bundle layer: +# a top-level YAML array of loader patch entries (id-targeted config +# overrides, disables, and insert lists; \`!!js\` expressions allowed). +[] +`; + +describe('DeepSeek Harness configuration', () => { + let homeDir: string; + let options: AgentSetupOptions; + + beforeEach(() => { + homeDir = mkdtempSync(join(tmpdir(), 'mmx-dsh-')); + options = { + agents: ['deepseek-harness'], homeDir, env: {}, region: 'cn', + apiKey: 'sk-cp-test-only', model: 'MiniMax-M4', + }; + }); + + afterEach(() => rmSync(homeDir, { recursive: true, force: true })); + + it('writes MiniMax into web and desktop, plus an initialized headless profile', () => { + const headless = join(homeDir, '.dsh', 'profiles', 'headless'); + mkdirSync(headless, { recursive: true }); + writeFileSync(join(headless, 'cordis.patch.yml'), FACTORY); + + const prepared = prepareAgentConfigurations(options); + expect(prepared.map(file => file.path)).toEqual([ + join(homeDir, '.dsh', 'profiles', 'web', 'cordis.patch.yml'), + join(homeDir, '.dsh', 'profiles', 'desktop', 'cordis.patch.yml'), + join(headless, 'cordis.patch.yml'), + join(homeDir, '.dsh', '.credentials.yaml'), + ]); + applyAgentConfigurations(prepared); + + const web = readFileSync(join(homeDir, '.dsh', 'profiles', 'web', 'cordis.patch.yml'), 'utf8'); + expect(web).toContain('!!js'); + expect(web).not.toContain('&a'); + const patch = parse(web); + expect(patch[0].id).toBe('llm-pi-ai'); + expect(patch[0].config.providers['minimax-cn']).toMatchObject({ + displayName: 'MiniMax', + apiKeyEnv: 'MINIMAX_CN_API_KEY', + api: 'openai-completions', + baseURL: 'https://api.minimax.cn/v1', + }); + expect(patch[0].config.providers['minimax-cn'].models.map((model: { id: string }) => model.id)) + .toEqual(['MiniMax-M4', 'MiniMax-M3.1-Flash']); + expect(patch[0].config.providers['minimax-cn'].models[0]).toMatchObject({ + contextWindow: 1_000_000, + maxTokens: 131072, + input: ['text', 'image'], + reasoningEfforts: { low: 'low', medium: 'medium', high: 'high', xhigh: 'xhigh', max: 'max' }, + }); + expect(patch[1]).toEqual({ + id: 'agent-default-model', + config: { provider: 'minimax-cn', model: 'MiniMax-M4' }, + }); + + const headlessPatch = parse(readFileSync(join(headless, 'cordis.patch.yml'), 'utf8')); + expect(headlessPatch).toContainEqual({ id: 'credentials', disabled: false }); + + const credentials = parse(readFileSync(join(homeDir, '.dsh', '.credentials.yaml'), 'utf8')); + expect(credentials.version).toBe(1); + expect(credentials.refs.MINIMAX_CN_API_KEY).toBe(options.apiKey); + }); + + it('preserves other providers and is idempotent', () => { + const web = join(homeDir, '.dsh', 'profiles', 'web'); + mkdirSync(web, { recursive: true }); + writeFileSync(join(web, 'cordis.patch.yml'), `- id: llm-pi-ai + config: + providers: + existing: + apiKeyEnv: EXISTING_KEY +`); + applyAgentConfigurations(prepareAgentConfigurations({ + ...options, region: 'global', model: 'MiniMax-M3.1-Flash', + })); + const text = readFileSync(join(web, 'cordis.patch.yml'), 'utf8'); + const patch = parse(text); + expect(patch[0].config.providers.existing.apiKeyEnv).toBe('EXISTING_KEY'); + expect(patch[0].config.providers.minimax.baseURL).toBe('https://api.minimax.io/v1'); + expect(patch[1].config).toEqual({ provider: 'minimax', model: 'MiniMax-M3.1-Flash' }); + + const again = prepareAgentConfigurations({ + ...options, region: 'global', model: 'MiniMax-M3.1-Flash', + }); + expect(again.every(file => file.before === file.after)).toBe(true); + }); +});